X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fmain.c;h=1b3f1e54bdd3250cb41fb986b89b3aaff355128e;hp=f1986ed68d0b7e4d00f81b956e2abbb263b79d7a;hb=d00f8a0e184cc73b1ca33a9b22c1b1f87292a72f;hpb=31dd7268cf971b5ed10508c41594a2ea99cdc17a diff --git a/pppd/main.c b/pppd/main.c index f1986ed..1b3f1e5 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -80,7 +80,6 @@ #include #include #include -#include #include #include #include @@ -121,7 +120,6 @@ #include "atcp.h" #endif -static const char rcsid[] = RCSID; /* interface vars */ char ifname[MAXIFNAMELEN]; /* Interface name */ @@ -181,7 +179,7 @@ int got_sighup; static sigset_t signals_handled; static int waiting; -static sigjmp_buf sigjmp; +static int sigpipe[2]; char **script_env; /* Env. variable values for scripts */ int s_env_nalloc; /* # words avail at script_env */ @@ -257,7 +255,6 @@ static void cleanup_db __P((void)); static void handle_events __P((void)); void print_link_stats __P((void)); -extern char *ttyname __P((int)); extern char *getlogin __P((void)); int main __P((int, char *[])); @@ -600,19 +597,21 @@ static void handle_events() { struct timeval timo; + unsigned char buf[16]; kill_link = open_ccp_flag = 0; - if (sigsetjmp(sigjmp, 1) == 0) { - sigprocmask(SIG_BLOCK, &signals_handled, NULL); - if (got_sighup || got_sigterm || got_sigusr2 || got_sigchld) { - sigprocmask(SIG_UNBLOCK, &signals_handled, NULL); - } else { - waiting = 1; - sigprocmask(SIG_UNBLOCK, &signals_handled, NULL); - wait_input(timeleft(&timo)); - } - } + + /* alert via signal pipe */ + waiting = 1; + /* flush signal pipe */ + for (; read(sigpipe[0], buf, sizeof(buf)) > 0; ); + add_fd(sigpipe[0]); + /* wait if necessary */ + if (!(got_sighup || got_sigterm || got_sigusr2 || got_sigchld)) + wait_input(timeleft(&timo)); waiting = 0; + remove_fd(sigpipe[0]); + calltimeout(); if (got_sighup) { info("Hangup (SIGHUP)"); @@ -647,6 +646,14 @@ setup_signals() { struct sigaction sa; + /* create pipe to wake up event handler from signal handler */ + if (pipe(sigpipe) < 0) + fatal("Couldn't create signal pipe: %m"); + fcntl(sigpipe[0], F_SETFD, fcntl(sigpipe[0], F_GETFD) | FD_CLOEXEC); + fcntl(sigpipe[1], F_SETFD, fcntl(sigpipe[1], F_GETFD) | FD_CLOEXEC); + fcntl(sigpipe[0], F_SETFL, fcntl(sigpipe[0], F_GETFL) | O_NONBLOCK); + fcntl(sigpipe[1], F_SETFL, fcntl(sigpipe[1], F_GETFL) | O_NONBLOCK); + /* * Compute mask of all interesting signals and install signal handlers * for each. Only one signal handler may be active at a time. Therefore, @@ -1433,7 +1440,7 @@ hup(sig) kill_my_pg(sig); notify(sigreceived, sig); if (waiting) - siglongjmp(sigjmp, 1); + write(sigpipe[1], &sig, sizeof(sig)); } @@ -1454,7 +1461,7 @@ term(sig) kill_my_pg(sig); notify(sigreceived, sig); if (waiting) - siglongjmp(sigjmp, 1); + write(sigpipe[1], &sig, sizeof(sig)); } @@ -1468,7 +1475,7 @@ chld(sig) { got_sigchld = 1; if (waiting) - siglongjmp(sigjmp, 1); + write(sigpipe[1], &sig, sizeof(sig)); } @@ -1503,7 +1510,7 @@ open_ccp(sig) { got_sigusr2 = 1; if (waiting) - siglongjmp(sigjmp, 1); + write(sigpipe[1], &sig, sizeof(sig)); } @@ -1567,7 +1574,8 @@ safe_fork(int infd, int outfd, int errfd) /* Executing in the child */ sys_close(); #ifdef USE_TDB - tdb_close(pppdb); + if (pppdb != NULL) + tdb_close(pppdb); #endif /* make sure infd, outfd and errfd won't get tromped on below */ @@ -1752,7 +1760,7 @@ update_script_environment() script_env[i] = newstring; else add_script_env(i, newstring); - } else { + } else if (p != NULL) { remove_script_env(i); } }