From 38d13c350ef8e082435fccacfb0f7749be3a15a1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sun, 28 Sep 1997 20:28:13 +0000 Subject: Closer control of interrupts. svn path=/trunk/; revision=1431 --- fetchmail.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'fetchmail.c') diff --git a/fetchmail.c b/fetchmail.c index c255530e..80856024 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -304,6 +304,14 @@ int main (int argc, char **argv) if (!nodetach) daemonize(logfile, termhook); error( 0, 0, "starting fetchmail %s daemon ", RELEASE_ID); + + /* + * We'll set up a handler for these when we're sleeping, + * but ignore them otherwise so as not to interrupt a poll. + */ + signal(SIGUSR1, SIG_IGN); + if (poll_interval && !getuid()) + signal(SIGHUP, SIG_IGN); } /* beyond here we don't want more than one fetchmail running per user */ @@ -315,20 +323,8 @@ int main (int argc, char **argv) signal(SIGPIPE, termhook); signal(SIGQUIT, termhook); - /* - * With this simple hack, we make it possible for a foreground - * fetchmail to wake up one in daemon mode. What we want is the - * side effect of interrupting any sleep that may be going on, - * forcing fetchmail to re-poll its hosts. - */ - signal(SIGUSR1, donothing); - - /* pacify people who think all system daemons wake up on SIGHUP */ - if (poll_interval && !getuid()) - signal(SIGHUP, donothing); - /* here's the exclusion lock */ - if ( (lockfp = fopen(lockfile,"w")) != NULL ) { + if ((lockfp = fopen(lockfile,"w")) != NULL) { fprintf(lockfp,"%d",getpid()); if (poll_interval) fprintf(lockfp," %d", poll_interval); @@ -466,6 +462,17 @@ int main (int argc, char **argv) fprintf(stderr, "fetchmail: sleeping at %s", ctime(&now)); } + /* + * With this simple hack, we make it possible for a foreground + * fetchmail to wake up one in daemon mode. What we want is the + * side effect of interrupting any sleep that may be going on, + * forcing fetchmail to re-poll its hosts. The second line is + * for people who think all system daemons wake up on SIGHUP. + */ + signal(SIGUSR1, donothing); + if (!getuid()) + signal(SIGHUP, donothing); + /* * We can't use sleep(3) here because we need an alarm(3) * equivalent in order to implement server nonresponse timeout. @@ -494,6 +501,11 @@ int main (int argc, char **argv) } } + /* now lock out interrupts again */ + signal(SIGUSR1, SIG_IGN); + if (!getuid()) + signal(SIGHUP, SIG_IGN); + if (outlevel == O_VERBOSE) { time_t now; -- cgit v1.2.3