Changeset 82d3c1f in code for icbd.c


Ignore:
Timestamp:
Mar 7, 2014, 5:37:37 PM (11 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
709589d
Parents:
9c04f2a
Message:

stat(2) the modtab every time pass is requested

plus some minor style changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icbd.c

    r9c04f2a r82d3c1f  
    4444
    4545uint64_t sessionid;
     46struct stat modtabst;
    4647char modtabpath[MAXPATHLEN];
    4748char modtab[ICB_MTABLEN][ICB_MAXNICKLEN];
     
    6465void icbd_log(struct icb_session *, int, const char *, ...);
    6566void icbd_grplist(char *);
    66 void icbd_modtab(char *);
    6767void icbd_restrict(void);
    6868void icbd_write(struct icb_session *, char *, ssize_t);
    69 void icbd_signal(int);
    7069
    7170static inline int icbd_session_cmp(struct icb_session *, struct icb_session *);
     
    8281main(int argc, char *argv[])
    8382{
    84         struct event ev_sig;
    8583        struct icbd_callbacks ic = { icbd_drop, icbd_log, icbd_write };
    8684        const char *cause = NULL;
     
    239237                icbd_restrict();
    240238
     239        icbd_modupdate();
     240
    241241        (void)signal(SIGPIPE, SIG_IGN);
    242         if (strlen(modtabpath) > 0) {
    243                 icbd_modtab(modtabpath);
    244                 signal_set(&ev_sig, SIGHUP,
    245                     (void (*)(int, short, void *))icbd_signal, NULL);
    246                 signal_add(&ev_sig, NULL);
    247         }
    248242
    249243        (void)event_dispatch();
     
    549543
    550544void
    551 icbd_modtab(char *mtab)
    552 {
     545icbd_modupdate(void)
     546{
     547        struct stat st;
    553548        FILE *fp;
    554549        char *buf, *lbuf;
    555550        size_t len;
    556551
    557         if ((fp = fopen(mtab, "r")) == NULL)
    558                 err(EX_NOINPUT, "%s", mtab);
     552        if (strlen(modtabpath) == 0)
     553                return;
     554        if (stat(modtabpath, &st)) {
     555                syslog(LOG_ERR, "stat %s", modtabpath);
     556                return;
     557        }
     558        /* see if there are any changes */
     559        if (timespeccmp(&st.st_mtim, &modtabst.st_mtim, ==) ||
     560            st.st_size == 0)
     561                return;
     562
     563        if ((fp = fopen(modtabpath, "r")) == NULL)
     564                err(EX_NOINPUT, "open %s", modtabpath);
    559565
    560566        modtabcnt = 0;
     
    577583                        continue;
    578584                strlcpy(modtab[modtabcnt++], buf, ICB_MAXNICKLEN);
     585                fprintf(stderr, "%s\n", buf);
    579586        }
    580587        free(lbuf);
     
    584591
    585592        fclose(fp);
    586 }
    587 
    588 void
    589 icbd_signal(int sig)
    590 {
    591         switch (sig) {
    592         case SIGHUP:
    593                 if (strlen(modtabpath) > 0)
    594                         icbd_modtab(modtabpath);
    595                 break;
    596         default:
    597                 syslog(LOG_WARNING, "unexpected signal %d", sig);
    598                 break;
    599         }
    600593}
    601594
Note: See TracChangeset for help on using the changeset viewer.