Changeset 9a2a703 in code


Ignore:
Timestamp:
Mar 5, 2014, 11:36:39 PM (11 years ago)
Author:
Mike Belopuhov <mike@…>
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)
Message:

Stuff logger_setts into the logger_tick directly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • logger.c

    rc1888a5 r9a2a703  
    3939void logger_dispatch(int, short, void *);
    4040FILE *logger_open(char *);
    41 void logger_tick(int, short, void *);
    42 void logger_setts(void);
     41void logger_tick(void);
    4342
    4443struct icbd_logentry {
     
    5756
    5857char file_ts[sizeof "0000-00"];
    59 char line_ts[sizeof "[00:00] "];
     58char line_ts[sizeof "00:00"];
    6059struct event ev_tick;
    6160
     
    6867        static struct event ev;
    6968        struct passwd *pw;
    70         struct timeval tv = { 60, 0 };
    7169        int pipes[2];
    7270
     
    125123        }
    126124
    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();
    134127        return event_dispatch();
    135128}
     
    171164                return;
    172165        if (strlen(e.nick) == 0)
    173                 fprintf(fp, "%s%s\n", line_ts, buf);
     166                fprintf(fp, "[%s] %s\n", line_ts, buf);
    174167        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);
    176169}
    177170
     
    224217
    225218void
    226 logger_tick(int fd __attribute__((unused)), short event __attribute__((unused)),
    227     void *arg __attribute__((unused)))
     219logger_tick(void)
    228220{
    229221        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 void
    239 logger_setts(void)
    240 {
    241222        static int last_mon = -1;
    242223        struct tm *tm;
     
    250231                    1900, tm->tm_mon + 1);
    251232                last_mon = tm->tm_mon;
     233                /* rotate log files */
    252234                for (i = 0; i < nlogfiles; i++) {
    253235                        fclose(logfiles[i].fp);
     
    256238                nlogfiles = 0;
    257239        }
    258         snprintf(line_ts, sizeof line_ts, "[%02d:%02d] ", tm->tm_hour,
     240        snprintf(line_ts, sizeof line_ts, "%02d:%02d", tm->tm_hour,
    259241            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.