Fix reload behaviour

Re-read the filter file with the runtime user permissions,
create useful log message when the filter cannot be read.
Fixes Debian #756040.
This commit is contained in:
Heiko Schlittermann (HS12-RIPE) 2018-12-19 18:28:46 +01:00
parent b131f45cbb
commit 8ca0fbefc2
3 changed files with 13 additions and 11 deletions

View File

@ -33,6 +33,7 @@
#include "conf.h" #include "conf.h"
static vector_t listen_fds; static vector_t listen_fds;
volatile int children; /* referenced from main.c */
/* /*
* Stores the internal data needed for each child (connection) * Stores the internal data needed for each child (connection)
@ -202,6 +203,11 @@ static void child_main (struct child_s *ptr)
ptr->connects = 0; ptr->connects = 0;
srand(time(NULL)); srand(time(NULL));
#ifdef FILTER_ENABLE
if (config.filter)
filter_init ();
#endif /* FILTER_ENABLE */
/* /*
* We have to wait for connections on multiple fds, * We have to wait for connections on multiple fds,
* so use select. * so use select.
@ -226,7 +232,6 @@ static void child_main (struct child_s *ptr)
FD_SET(*fd, &rfds); FD_SET(*fd, &rfds);
maxfd = max(maxfd, *fd); maxfd = max(maxfd, *fd);
} }
ptr->status = T_WAITING; ptr->status = T_WAITING;
clilen = sizeof(struct sockaddr_storage); clilen = sizeof(struct sockaddr_storage);
@ -358,8 +363,10 @@ static pid_t child_make (struct child_s *ptr)
{ {
pid_t pid; pid_t pid;
if ((pid = fork ()) > 0) if ((pid = fork ()) > 0) {
++children;
return pid; /* parent */ return pid; /* parent */
}
/* /*
* Reset the SIGNALS so that the child can be reaped. * Reset the SIGNALS so that the child can be reaped.
@ -513,10 +520,7 @@ void child_main_loop (void)
* This should actually be handled somehow... * This should actually be handled somehow...
*/ */
reload_config (); reload_config ();
#ifdef FILTER_ENABLE
filter_reload (); filter_reload ();
#endif /* FILTER_ENABLE */
/* propagate filter reload to all children */ /* propagate filter reload to all children */
child_kill_children (SIGHUP); child_kill_children (SIGHUP);

View File

@ -61,7 +61,9 @@ void filter_init (void)
fd = fopen (config.filter, "r"); fd = fopen (config.filter, "r");
if (!fd) { if (!fd) {
return; log_message(LOG_ERR, "Can't read the filter from %s: %s",
config.filter, strerror(errno));
exit(3);
} }
p = NULL; p = NULL;

View File

@ -50,6 +50,7 @@
struct config_s config; struct config_s config;
struct config_s config_defaults; struct config_s config_defaults;
unsigned int received_sighup = FALSE; /* boolean */ unsigned int received_sighup = FALSE; /* boolean */
extern volatile int children; /* defined in child.c */
/* /*
* Handle a signal * Handle a signal
@ -374,11 +375,6 @@ main (int argc, char **argv)
exit (EX_OSERR); exit (EX_OSERR);
} }
#ifdef FILTER_ENABLE
if (config.filter)
filter_init ();
#endif /* FILTER_ENABLE */
/* Start listening on the selected port. */ /* Start listening on the selected port. */
if (child_listening_sockets(config.listen_addrs, config.port) < 0) { if (child_listening_sockets(config.listen_addrs, config.port) < 0) {
fprintf (stderr, "%s: Could not create listening sockets.\n", fprintf (stderr, "%s: Could not create listening sockets.\n",