stat(2) the modtab every time pass is requested
plus some minor style changes
This commit is contained in:
parent
9c04f2a610
commit
82d3c1fc7b
1
icb.c
1
icb.c
@ -550,6 +550,7 @@ icb_modpermit(struct icb_session *is, int enforce)
|
||||
extern char modtab[ICB_MTABLEN][ICB_MAXNICKLEN];
|
||||
extern int modtabcnt;
|
||||
|
||||
icbd_modupdate();
|
||||
if ((enforce ? 0 : modtabcnt == 0) ||
|
||||
bsearch(is->nick, modtab, modtabcnt, ICB_MAXNICKLEN,
|
||||
(int (*)(const void *, const void *))strcmp))
|
||||
|
37
icb.h
37
icb.h
@ -128,25 +128,26 @@ struct icbd_callbacks {
|
||||
void *icb_cmd_lookup(char *);
|
||||
|
||||
/* icb.c */
|
||||
struct icb_group *icb_addgroup(struct icb_session *, char *, char *);
|
||||
void icb_cmdout(struct icb_session *, int, char *);
|
||||
void icb_delgroup(struct icb_group *);
|
||||
void icb_error(struct icb_session *, const char *, ...);
|
||||
void icb_init(struct icbd_callbacks *);
|
||||
void icb_input(struct icb_session *);
|
||||
inline int icb_ismod(struct icb_group *, struct icb_session *);
|
||||
int icb_modpermit(struct icb_session *, int);
|
||||
int icb_pass(struct icb_group *, struct icb_session *,
|
||||
struct icb_session *);
|
||||
void icb_privmsg(struct icb_session *, char *, char *);
|
||||
void icb_remove(struct icb_session *, char *);
|
||||
void icb_sendfmt(struct icb_session *, const char *, ...);
|
||||
void icb_start(struct icb_session *);
|
||||
void icb_status(struct icb_session *, int, const char *, ...);
|
||||
void icb_status_group(struct icb_group *, struct icb_session *,
|
||||
struct icb_group *
|
||||
icb_addgroup(struct icb_session *, char *, char *);
|
||||
void icb_cmdout(struct icb_session *, int, char *);
|
||||
void icb_delgroup(struct icb_group *);
|
||||
void icb_error(struct icb_session *, const char *, ...);
|
||||
void icb_init(struct icbd_callbacks *);
|
||||
void icb_input(struct icb_session *);
|
||||
inline int icb_ismod(struct icb_group *, struct icb_session *);
|
||||
int icb_modpermit(struct icb_session *, int);
|
||||
int icb_pass(struct icb_group *, struct icb_session *,
|
||||
struct icb_session *);
|
||||
void icb_privmsg(struct icb_session *, char *, char *);
|
||||
void icb_remove(struct icb_session *, char *);
|
||||
void icb_sendfmt(struct icb_session *, const char *, ...);
|
||||
void icb_start(struct icb_session *);
|
||||
void icb_status(struct icb_session *, int, const char *, ...);
|
||||
void icb_status_group(struct icb_group *, struct icb_session *,
|
||||
int, const char *, ...);
|
||||
void icb_who(struct icb_session *, struct icb_group *);
|
||||
int icb_vis(char *, const char *, size_t, int);
|
||||
void icb_who(struct icb_session *, struct icb_group *);
|
||||
int icb_vis(char *, const char *, size_t, int);
|
||||
|
||||
/* callbacks from icbd.c */
|
||||
void (*icb_drop)(struct icb_session *, char *);
|
||||
|
45
icbd.c
45
icbd.c
@ -43,6 +43,7 @@
|
||||
#include "icbd.h"
|
||||
|
||||
uint64_t sessionid;
|
||||
struct stat modtabst;
|
||||
char modtabpath[MAXPATHLEN];
|
||||
char modtab[ICB_MTABLEN][ICB_MAXNICKLEN];
|
||||
int modtabcnt;
|
||||
@ -63,10 +64,8 @@ void icbd_ioerr(struct bufferevent *, short, void *);
|
||||
void icbd_dispatch(struct bufferevent *, void *);
|
||||
void icbd_log(struct icb_session *, int, const char *, ...);
|
||||
void icbd_grplist(char *);
|
||||
void icbd_modtab(char *);
|
||||
void icbd_restrict(void);
|
||||
void icbd_write(struct icb_session *, char *, ssize_t);
|
||||
void icbd_signal(int);
|
||||
|
||||
static inline int icbd_session_cmp(struct icb_session *, struct icb_session *);
|
||||
|
||||
@ -81,7 +80,6 @@ struct icbd_listener {
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct event ev_sig;
|
||||
struct icbd_callbacks ic = { icbd_drop, icbd_log, icbd_write };
|
||||
const char *cause = NULL;
|
||||
int ch, nsocks = 0, save_errno = 0;
|
||||
@ -238,13 +236,9 @@ main(int argc, char *argv[])
|
||||
if (!foreground)
|
||||
icbd_restrict();
|
||||
|
||||
icbd_modupdate();
|
||||
|
||||
(void)signal(SIGPIPE, SIG_IGN);
|
||||
if (strlen(modtabpath) > 0) {
|
||||
icbd_modtab(modtabpath);
|
||||
signal_set(&ev_sig, SIGHUP,
|
||||
(void (*)(int, short, void *))icbd_signal, NULL);
|
||||
signal_add(&ev_sig, NULL);
|
||||
}
|
||||
|
||||
(void)event_dispatch();
|
||||
|
||||
@ -548,14 +542,26 @@ icbd_grplist(char *list)
|
||||
}
|
||||
|
||||
void
|
||||
icbd_modtab(char *mtab)
|
||||
icbd_modupdate(void)
|
||||
{
|
||||
struct stat st;
|
||||
FILE *fp;
|
||||
char *buf, *lbuf;
|
||||
size_t len;
|
||||
|
||||
if ((fp = fopen(mtab, "r")) == NULL)
|
||||
err(EX_NOINPUT, "%s", mtab);
|
||||
if (strlen(modtabpath) == 0)
|
||||
return;
|
||||
if (stat(modtabpath, &st)) {
|
||||
syslog(LOG_ERR, "stat %s", modtabpath);
|
||||
return;
|
||||
}
|
||||
/* see if there are any changes */
|
||||
if (timespeccmp(&st.st_mtim, &modtabst.st_mtim, ==) ||
|
||||
st.st_size == 0)
|
||||
return;
|
||||
|
||||
if ((fp = fopen(modtabpath, "r")) == NULL)
|
||||
err(EX_NOINPUT, "open %s", modtabpath);
|
||||
|
||||
modtabcnt = 0;
|
||||
bzero(modtab, ICB_MTABLEN * ICB_MAXNICKLEN);
|
||||
@ -576,6 +582,7 @@ icbd_modtab(char *mtab)
|
||||
if (buf[0] == '#' || buf[0] == '\0')
|
||||
continue;
|
||||
strlcpy(modtab[modtabcnt++], buf, ICB_MAXNICKLEN);
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
free(lbuf);
|
||||
|
||||
@ -585,20 +592,6 @@ icbd_modtab(char *mtab)
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void
|
||||
icbd_signal(int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
case SIGHUP:
|
||||
if (strlen(modtabpath) > 0)
|
||||
icbd_modtab(modtabpath);
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "unexpected signal %d", sig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
time_t
|
||||
getmonotime(void)
|
||||
{
|
||||
|
14
icbd.h
14
icbd.h
@ -23,14 +23,16 @@
|
||||
extern int verbose;
|
||||
|
||||
/* icbd.c */
|
||||
inline struct icb_session *icbd_session_lookup(uint64_t);
|
||||
time_t getmonotime(void);
|
||||
inline struct icb_session *
|
||||
icbd_session_lookup(uint64_t);
|
||||
void icbd_modupdate(void);
|
||||
time_t getmonotime(void);
|
||||
|
||||
/* dns.c */
|
||||
struct sockaddr_storage;
|
||||
int dns_init(void);
|
||||
void dns_rresolv(struct icb_session *, struct sockaddr_storage *);
|
||||
int dns_init(void);
|
||||
void dns_rresolv(struct icb_session *, struct sockaddr_storage *);
|
||||
|
||||
/* logger.c */
|
||||
int logger_init(void);
|
||||
void logger(char *, char *, char *);
|
||||
int logger_init(void);
|
||||
void logger(char *, char *, char *);
|
||||
|
Loading…
x
Reference in New Issue
Block a user