Changeset 82d3c1f in code


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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icb.c

    r9c04f2a r82d3c1f  
    551551        extern int modtabcnt;
    552552
     553        icbd_modupdate();
    553554        if ((enforce ? 0 : modtabcnt == 0) ||
    554555            bsearch(is->nick, modtab, modtabcnt, ICB_MAXNICKLEN,
  • icb.h

    r9c04f2a r82d3c1f  
    129129
    130130/* icb.c */
    131 struct icb_group *icb_addgroup(struct icb_session *, char *, char *);
    132 void             icb_cmdout(struct icb_session *, int, char *);
    133 void             icb_delgroup(struct icb_group *);
    134 void             icb_error(struct icb_session *, const char *, ...);
    135 void             icb_init(struct icbd_callbacks *);
    136 void             icb_input(struct icb_session *);
    137 inline int       icb_ismod(struct icb_group *, struct icb_session *);
    138 int              icb_modpermit(struct icb_session *, int);
    139 int              icb_pass(struct icb_group *, struct icb_session *,
    140                      struct icb_session *);
    141 void             icb_privmsg(struct icb_session *, char *, char *);
    142 void             icb_remove(struct icb_session *, char *);
    143 void             icb_sendfmt(struct icb_session *, const char *, ...);
    144 void             icb_start(struct icb_session *);
    145 void             icb_status(struct icb_session *, int, const char *, ...);
    146 void             icb_status_group(struct icb_group *, struct icb_session *,
     131struct icb_group *
     132                icb_addgroup(struct icb_session *, char *, char *);
     133void            icb_cmdout(struct icb_session *, int, char *);
     134void            icb_delgroup(struct icb_group *);
     135void            icb_error(struct icb_session *, const char *, ...);
     136void            icb_init(struct icbd_callbacks *);
     137void            icb_input(struct icb_session *);
     138inline int      icb_ismod(struct icb_group *, struct icb_session *);
     139int             icb_modpermit(struct icb_session *, int);
     140int             icb_pass(struct icb_group *, struct icb_session *,
     141                    struct icb_session *);
     142void            icb_privmsg(struct icb_session *, char *, char *);
     143void            icb_remove(struct icb_session *, char *);
     144void            icb_sendfmt(struct icb_session *, const char *, ...);
     145void            icb_start(struct icb_session *);
     146void            icb_status(struct icb_session *, int, const char *, ...);
     147void            icb_status_group(struct icb_group *, struct icb_session *,
    147148                    int, const char *, ...);
    148 void             icb_who(struct icb_session *, struct icb_group *);
    149 int              icb_vis(char *, const char *, size_t, int);
     149void            icb_who(struct icb_session *, struct icb_group *);
     150int             icb_vis(char *, const char *, size_t, int);
    150151
    151152/* callbacks from icbd.c */
  • 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
  • icbd.h

    r9c04f2a r82d3c1f  
    2424
    2525/* icbd.c */
    26 inline struct icb_session *icbd_session_lookup(uint64_t);
    27 time_t  getmonotime(void);
     26inline struct icb_session *
     27                icbd_session_lookup(uint64_t);
     28void            icbd_modupdate(void);
     29time_t          getmonotime(void);
    2830
    2931/* dns.c */
    3032struct sockaddr_storage;
    31 int     dns_init(void);
    32 void    dns_rresolv(struct icb_session *, struct sockaddr_storage *);
     33int             dns_init(void);
     34void            dns_rresolv(struct icb_session *, struct sockaddr_storage *);
    3335
    3436/* logger.c */
    35 int     logger_init(void);
    36 void    logger(char *, char *, char *);
     37int             logger_init(void);
     38void            logger(char *, char *, char *);
Note: See TracChangeset for help on using the changeset viewer.