]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/tty.c
Add include/linux/if_pppol2tp.h, missed in a previous commit
[ppp.git] / pppd / tty.c
index 991a148de0cfe1417a98d14dac16d8d3eeab1ebd..c356483d1974ee9358010cc585049eddcc1de569 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.25 2006/06/04 07:04:57 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 */
@@ -443,7 +445,12 @@ tty_check_options()
        struct stat statbuf;
        int fdflags;
 
-       if (demand && connect_script == 0) {
+       if (demand && notty) {
+               option_error("demand-dialling is incompatible with notty");
+               exit(EXIT_OPTION_ERROR);
+       }
+       if (demand && connect_script == 0 && ptycommand == NULL
+           && pty_socket == NULL) {
                option_error("connect script is required for demand-dialling\n");
                exit(EXIT_OPTION_ERROR);
        }
@@ -547,7 +554,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 (;;) {
@@ -556,12 +563,16 @@ int connect_tty()
                        int err, prio;
 
                        prio = privopen? OPRIO_ROOT: tty_options[0].priority;
-                       if (prio < OPRIO_ROOT)
-                               seteuid(uid);
+                       if (prio < OPRIO_ROOT && seteuid(uid) == -1) {
+                               error("Unable to drop privileges before opening %s: %m\n",
+                                     devnam);
+                               status = EXIT_OPEN_FAILED;
+                               goto errret;
+                       }
                        real_ttyfd = open(devnam, O_NONBLOCK | O_RDWR, 0);
                        err = errno;
-                       if (prio < OPRIO_ROOT)
-                               seteuid(0);
+                       if (prio < OPRIO_ROOT && seteuid(0) == -1)
+                               fatal("Unable to regain privileges");
                        if (real_ttyfd >= 0)
                                break;
                        errno = err;
@@ -679,7 +690,7 @@ int connect_tty()
                                status = EXIT_INIT_FAILED;
                                goto errret;
                        }
-                       if (kill_link) {
+                       if (got_sigterm) {
                                disconnect_tty();
                                goto errret;
                        }
@@ -692,7 +703,7 @@ int connect_tty()
                                status = EXIT_CONNECT_FAILED;
                                goto errret;
                        }
-                       if (kill_link) {
+                       if (got_sigterm) {
                                disconnect_tty();
                                goto errret;
                        }
@@ -718,7 +729,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);
@@ -738,7 +749,7 @@ int connect_tty()
         * time for something from the peer.  This can avoid bouncing
         * our packets off his tty before he has it set up.
         */
-       if (connector != NULL || ptycommand != NULL)
+       if (connector != NULL || ptycommand != NULL || pty_socket != NULL)
                listen_time = connect_delay;
 
        return ttyfd;
@@ -748,15 +759,9 @@ int connect_tty()
                close(pty_master);
                pty_master = -1;
        }
-       if (pty_slave >= 0) {
-               close(pty_slave);
-               pty_slave = -1;
-       }
-       if (real_ttyfd >= 0) {
-               close(real_ttyfd);
-               real_ttyfd = -1;
-       }
        ttyfd = -1;
+       if (got_sigterm)
+               asked_to_quit = 1;
        return -1;
 }
 
@@ -772,6 +777,7 @@ void disconnect_tty()
        } else {
                info("Serial link disconnected.");
        }
+       stop_charshunt(NULL, 0);
 }
 
 void tty_close_fds()
@@ -935,7 +941,6 @@ start_charshunt(ifd, ofd)
        exit(0);
     }
     charshunt_pid = cpid;
-    add_notifier(&sigreceived, stop_charshunt, 0);
     record_child(cpid, "pppd (charshunt)", charshunt_done, NULL);
     return 1;
 }