Make SIGHUP just take down the link now, not the bundle.
authorPaul Mackerras <paulus@samba.org>
Sat, 13 Nov 2004 12:05:48 +0000 (12:05 +0000)
committerPaul Mackerras <paulus@samba.org>
Sat, 13 Nov 2004 12:05:48 +0000 (12:05 +0000)
Be a bit more careful about quitting when we get a SIGTERM
or SIGINT.

pppd/main.c
pppd/tty.c

index 862a2d4bafc63e4b8fd6abb7522cd0f983043386..65a8877c6f276da8a96f0a96200aef54ecfd1daa 100644 (file)
@@ -66,7 +66,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: main.c,v 1.147 2004/11/13 12:02:22 paulus Exp $"
+#define RCSID  "$Id: main.c,v 1.148 2004/11/13 12:05:48 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -172,6 +172,7 @@ int devfd = -1;                     /* fd of underlying device */
 int fd_ppp = -1;               /* fd for talking PPP */
 int phase;                     /* where the link is at */
 int kill_link;
+int asked_to_quit;
 int open_ccp_flag;
 int listen_time;
 int got_sigusr2;
@@ -511,13 +512,13 @@ main(argc, argv)
            add_fd(fd_loop);
            for (;;) {
                handle_events();
-               if (kill_link && !persist)
+               if (asked_to_quit)
                    break;
                if (get_loop_output())
                    break;
            }
            remove_fd(fd_loop);
-           if (kill_link && !persist)
+           if (asked_to_quit)
                break;
 
            /*
@@ -536,9 +537,10 @@ main(argc, argv)
        while (phase != PHASE_DEAD) {
            handle_events();
            get_input();
-           if (kill_link) {
-               bundle_terminating = 1;
+           if (kill_link)
                lcp_close(0, "User request");
+           if (asked_to_quit) {
+               bundle_terminating = 1;
                if (phase == PHASE_MASTER)
                    mp_bundle_terminated();
            }
@@ -550,7 +552,7 @@ main(argc, argv)
            }
        }
 
-       if (!persist || (maxfail > 0 && unsuccess >= maxfail))
+       if (!persist || asked_to_quit || (maxfail > 0 && unsuccess >= maxfail))
            break;
 
        if (demand)
@@ -624,6 +626,7 @@ handle_events()
     if (got_sigterm) {
        info("Terminating on signal %d", got_sigterm);
        kill_link = 1;
+       asked_to_quit = 1;
        persist = 0;
        status = EXIT_USER_REQUEST;
        got_sigterm = 0;
index 991a148de0cfe1417a98d14dac16d8d3eeab1ebd..85a80323c7f40414d7f364f905aacd59716b796c 100644 (file)
@@ -68,7 +68,7 @@
  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#define RCSID  "$Id: tty.c,v 1.20 2004/11/12 09:51:23 paulus Exp $"
+#define RCSID  "$Id: tty.c,v 1.21 2004/11/13 12:05:48 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
@@ -152,6 +152,8 @@ int using_pty = 0;          /* we're allocating a pty as the device */
 
 extern uid_t uid;
 extern int kill_link;
+extern int asked_to_quit;
+extern int got_sigterm;
 
 /* XXX */
 extern int privopen;           /* don't lock, open device as root */
@@ -547,7 +549,7 @@ int connect_tty()
         * in order to wait for the carrier detect signal from the modem.
         */
        hungup = 0;
-       kill_link = 0;
+       got_sigterm = 0;
        connector = doing_callback? callback_script: connect_script;
        if (devnam[0] != 0) {
                for (;;) {
@@ -679,7 +681,7 @@ int connect_tty()
                                status = EXIT_INIT_FAILED;
                                goto errret;
                        }
-                       if (kill_link) {
+                       if (got_sigterm) {
                                disconnect_tty();
                                goto errret;
                        }
@@ -692,7 +694,7 @@ int connect_tty()
                                status = EXIT_CONNECT_FAILED;
                                goto errret;
                        }
-                       if (kill_link) {
+                       if (got_sigterm) {
                                disconnect_tty();
                                goto errret;
                        }
@@ -718,7 +720,7 @@ int connect_tty()
                                error("Failed to reopen %s: %m", devnam);
                                status = EXIT_OPEN_FAILED;
                        }
-                       if (!persist || errno != EINTR || hungup || kill_link)
+                       if (!persist || errno != EINTR || hungup || got_sigterm)
                                goto errret;
                }
                close(i);
@@ -757,6 +759,8 @@ int connect_tty()
                real_ttyfd = -1;
        }
        ttyfd = -1;
+       if (got_sigterm)
+               asked_to_quit = 1;
        return -1;
 }