print_msg(), _Exit_isdnlog(), etc. call lots of potentially unsafe functions -- see signal(7).
Since execv() is no longer called from the signal handler, SIGHUP does not need to be treated differently. --- isdnlog/isdnlog/isdnlog.c | 56 ++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/isdnlog/isdnlog/isdnlog.c b/isdnlog/isdnlog/isdnlog.c index a6a73bb..287c419 100644 --- a/isdnlog/isdnlog/isdnlog.c +++ b/isdnlog/isdnlog/isdnlog.c @@ -607,31 +607,41 @@ static int sqldump = 0; static char *param_myarea = NULL; static char *param_skipprov = NULL; +static int exit_signal = 0; +static int hup_signal = 0; + /*****************************************************************************/ static void exit_on_signal(int Sign) { - signal(Sign, SIG_DFL); - - print_msg(PRT_NORMAL, "Got signal %d\n", Sign); - - Exit(7); + exit_signal = Sign; } /* exit_on_signal */ /*****************************************************************************/ static void hup_handler(int isig) { - print_msg(PRT_INFO, "restarting %s\n", myname); - Exit(-9); - if (param_closefds) - Close_Fds(3); /* avoid duplicate fds after restart */ - execv(myname, hup_argv); - print_msg(PRT_ERR,"Cannot restart %s: %s!\n", myname, strerror(errno)); + hup_signal = isig; } /* hup_handler */ /*****************************************************************************/ +static void handle_signals(void) { + if (exit_signal) { + print_msg(PRT_NORMAL, "Got signal %d\n", exit_signal); + Exit(7); + } else if (hup_signal) { + print_msg(PRT_INFO, "restarting %s\n", myname); + Exit(-9); + if (param_closefds) + Close_Fds(3); /* avoid duplicate fds after restart */ + execv(myname, hup_argv); + print_msg(PRT_ERR,"Cannot restart %s: %s!\n", myname, strerror(errno)); + } +} + +/*****************************************************************************/ + static void loop(void) { auto fd_set readmask; @@ -698,12 +708,15 @@ static void loop(void) else Interval = 0; - while ((Cnt = select(maxdesc+1, &readmask, NULL, &exceptmask, Get_Interval(Interval))) < 0 && (errno == EINTR)); - - if ((Cnt < 0) && (errno != EINTR)) { /* kill -HUP ausgeschlossen */ - print_msg(PRT_DEBUG_CS, "Error select: %s\n", strerror(errno)); - Exit(12); - } /* if */ + while ((Cnt = select(maxdesc+1, &readmask, NULL, &exceptmask, Get_Interval(Interval))) < 0) { + if (errno == EINTR) { + handle_signals(); + continue; + } else { + print_msg(PRT_DEBUG_CS, "Error select: %s\n", strerror(errno)); + Exit(12); + } + } processflow(); @@ -1580,15 +1593,6 @@ int main(int argc, char *argv[], char *envp[]) if (!(allflags & PRT_DEBUG_GENERAL)) signal(SIGSEGV, exit_on_signal); - /* - * If hup_handler() already did an execve(), then SIGHUP is still - * blocked, and so you can only send a SIGHUP once. Here we unblock - * SIGHUP so that this feature can be used more than once. - */ - sigemptyset(&unblock_set); - sigaddset(&unblock_set, SIGHUP); - sigprocmask(SIG_UNBLOCK, &unblock_set, NULL); - sockets[ISDNCTRL].descriptor = !strcmp(isdnctrl, "-") ? fileno(stdin) : open(isdnctrl, O_RDONLY | O_NONBLOCK); if (*isdnctrl2) sockets[ISDNCTRL2].descriptor = open(isdnctrl2, O_RDONLY | O_NONBLOCK); -- 1.7.10.4 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org