Changeset 9a2a703 in code
- Timestamp:
- Mar 5, 2014, 11:36:39 PM (11 years ago)
- Branches:
- master
- Children:
- 21477e9, 6e89d69
- Parents:
- c1888a5
- git-author:
- Mike Belopuhov <mike@…> (03/05/14 23:35:37)
- git-committer:
- Mike Belopuhov <mike@…> (03/05/14 23:36:39)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
logger.c
rc1888a5 r9a2a703 39 39 void logger_dispatch(int, short, void *); 40 40 FILE *logger_open(char *); 41 void logger_tick(int, short, void *); 42 void logger_setts(void); 41 void logger_tick(void); 43 42 44 43 struct icbd_logentry { … … 57 56 58 57 char file_ts[sizeof "0000-00"]; 59 char line_ts[sizeof " [00:00]"];58 char line_ts[sizeof "00:00"]; 60 59 struct event ev_tick; 61 60 … … 68 67 static struct event ev; 69 68 struct passwd *pw; 70 struct timeval tv = { 60, 0 };71 69 int pipes[2]; 72 70 … … 125 123 } 126 124 127 /* event for the tick */ 128 evtimer_set(&ev_tick, logger_tick, NULL); 129 if (evtimer_add(&ev_tick, &tv) < 0) { 130 syslog(LOG_ERR, "evtimer_add: %m"); 131 exit (EX_UNAVAILABLE); 132 } 133 logger_setts(); 125 evtimer_set(&ev_tick, (void (*)(int, short, void *))logger_tick, NULL); 126 logger_tick(); 134 127 return event_dispatch(); 135 128 } … … 171 164 return; 172 165 if (strlen(e.nick) == 0) 173 fprintf(fp, " %s%s\n", line_ts, buf);166 fprintf(fp, "[%s] %s\n", line_ts, buf); 174 167 else 175 fprintf(fp, " %s<%s> %s\n", line_ts, e.nick, buf);168 fprintf(fp, "[%s] <%s> %s\n", line_ts, e.nick, buf); 176 169 } 177 170 … … 224 217 225 218 void 226 logger_tick(int fd __attribute__((unused)), short event __attribute__((unused)), 227 void *arg __attribute__((unused))) 219 logger_tick(void) 228 220 { 229 221 struct timeval tv = { 60, 0 }; 230 231 logger_setts();232 if (evtimer_add(&ev_tick, &tv) < 0) {233 syslog(LOG_ERR, "evtimer_add: %m");234 exit (EX_UNAVAILABLE);235 }236 }237 238 void239 logger_setts(void)240 {241 222 static int last_mon = -1; 242 223 struct tm *tm; … … 250 231 1900, tm->tm_mon + 1); 251 232 last_mon = tm->tm_mon; 233 /* rotate log files */ 252 234 for (i = 0; i < nlogfiles; i++) { 253 235 fclose(logfiles[i].fp); … … 256 238 nlogfiles = 0; 257 239 } 258 snprintf(line_ts, sizeof line_ts, " [%02d:%02d]", tm->tm_hour,240 snprintf(line_ts, sizeof line_ts, "%02d:%02d", tm->tm_hour, 259 241 tm->tm_min); 260 } 242 if (evtimer_add(&ev_tick, &tv) < 0) { 243 syslog(LOG_ERR, "evtimer_add: %m"); 244 exit (EX_UNAVAILABLE); 245 } 246 }
Note:
See TracChangeset
for help on using the changeset viewer.