From 20fbf3bbe1bd053de29134eb9139282a044b9093 Mon Sep 17 00:00:00 2001 From: Heikki Hannikainen Date: Tue, 16 Oct 2012 00:35:12 +0300 Subject: [PATCH] reconfig: more work towards reconfiguring active listeners Update listeners, ACLs, socket flags. --- src/accept.c | 54 +++++++++++++++++++++++++++++++++++++++++++++------- src/aprsc.c | 2 +- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/accept.c b/src/accept.c index e49f147..dfb255a 100644 --- a/src/accept.c +++ b/src/accept.c @@ -125,6 +125,26 @@ static void listener_free(struct listen_t *l) hfree(l); } +/* + * Copy / duplicate filters from listener config to an actual listener + * Free old filters if any are set. + */ + +static void listener_copy_filters(struct listen_t *l, struct listen_config_t *lc) +{ + int i; + + for (i = 0; i < (sizeof(l->filters)/sizeof(l->filters[0])); ++i) { + if (l->filters[i]) { + hfree(l->filters[i]); + l->filters[i] = NULL; + } + + if (i < (sizeof(lc->filters)/sizeof(lc->filters[0]))) + l->filters[i] = (lc->filters[i]) ? hstrdup(lc->filters[i]) : NULL; + } +} + /* * Open the TCP/SCTP listening socket */ @@ -273,12 +293,7 @@ static int open_listener(struct listen_config_t *lc) l->acl = acl_dup(lc->acl); /* Copy filter definitions */ - for (i = 0; i < (sizeof(l->filters)/sizeof(l->filters[0])); ++i) { - if (i < (sizeof(lc->filters)/sizeof(lc->filters[0]))) - l->filters[i] = (lc->filters[i]) ? hstrdup(lc->filters[i]) : NULL; - else - l->filters[i] = NULL; - } + listener_copy_filters(l, lc); hlog(LOG_DEBUG, "... adding %s to listened sockets", l->addr_s); // put (first) in the list of listening sockets @@ -304,15 +319,40 @@ struct listen_t *find_listener_id(int id) return NULL; } +static void listener_update_config(struct listen_t *l, struct listen_config_t *lc) +{ + hlog(LOG_DEBUG, "listener_update_config: %d '%s': %s:%d", lc->id, lc->name, lc->host, lc->portnum); + + /* basic flags which can be changed on the fly */ + l->clients_max = lc->clients_max; /* could drop clients when decreasing maxclients (done in worker) */ + l->hidden = lc->hidden; /* could mark old clients on port hidden, too - needs to be done in worker */ + l->client_flags = lc->client_flags; /* this one must not change old clients */ + + /* Filters */ + listener_copy_filters(l, lc); + + /* ACLs */ + /* TODO: reconfiguration should scan old clients against ACL (in worker context, probably) */ + if (l->acl) { + acl_free(l->acl); + l->acl = NULL; + } + if (lc->acl) + l->acl = acl_dup(lc->acl); + + /* Listen address change? Rebind? */ +} static int open_missing_listeners(void) { struct listen_config_t *lc; + struct listen_t *l; int opened = 0; for (lc = listen_config; (lc); lc = lc->next) { - if (find_listener_id(lc->id)) { + if ((l = find_listener_id(lc->id))) { hlog(LOG_DEBUG, "open_missing_listeners: already listening %d '%s': %s:%d", lc->id, lc->name, lc->host, lc->portnum); + listener_update_config(l, lc); continue; } diff --git a/src/aprsc.c b/src/aprsc.c index 4019e01..d2cdf65 100644 --- a/src/aprsc.c +++ b/src/aprsc.c @@ -871,7 +871,7 @@ int main(int argc, char **argv) signal(SIGUSR2, (void *)sighandler); signal(SIGPIPE, SIG_IGN); signal(SIGURG, SIG_IGN); - signal(SIGUSR1, SIG_IGN); + //signal(SIGUSR1, SIG_IGN); /* Early inits in single-thread mode */ keyhash_init();