]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/main.c
don't fall over in the charshunt if we get an EAGAIN or EINTR
[ppp.git] / pppd / main.c
index ca6e50a7be34c69228cbe115c7ef76d10a024ead..0722e9104076417b68500f16058a98f31f1e8f2d 100644 (file)
@@ -17,7 +17,7 @@
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
-#define RCSID  "$Id: main.c,v 1.93 2000/04/13 12:05:59 paulus Exp $"
+#define RCSID  "$Id: main.c,v 1.98 2000/04/29 12:32:59 paulus Exp $"
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -83,7 +83,7 @@ static uid_t uid;             /* Our real user-id */
 static int conn_running;       /* we have a [dis]connector running */
 
 int ttyfd;                     /* Serial port file descriptor */
 static int conn_running;       /* we have a [dis]connector running */
 
 int ttyfd;                     /* Serial port file descriptor */
-mode_t tty_mode = -1;          /* Original access permissions to tty */
+mode_t tty_mode = (mode_t)-1;  /* Original access permissions to tty */
 int baud_rate;                 /* Actual bits/second for serial device */
 int hungup;                    /* terminal has been hung up */
 int privileged;                        /* we're running as real uid root */
 int baud_rate;                 /* Actual bits/second for serial device */
 int hungup;                    /* terminal has been hung up */
 int privileged;                        /* we're running as real uid root */
@@ -226,6 +226,14 @@ struct protent *protocols[] = {
     NULL
 };
 
     NULL
 };
 
+/*
+ * If PPP_DRV_NAME is not defined, use the legacy "ppp" as the
+ * device name.
+ */
+#if !defined(PPP_DRV_NAME)
+#define PPP_DRV_NAME   "ppp"
+#endif /* !defined(PPP_DRV_NAME) */
+
 int
 main(argc, argv)
     int argc;
 int
 main(argc, argv)
     int argc;
@@ -1014,11 +1022,13 @@ void
 set_ifunit(iskey)
     int iskey;
 {
 set_ifunit(iskey)
     int iskey;
 {
-    info("Using interface ppp%d", ifunit);
-    slprintf(ifname, sizeof(ifname), "ppp%d", ifunit);
+    info("Using interface %s%d", PPP_DRV_NAME, ifunit);
+    slprintf(ifname, sizeof(ifname), PPP_DRV_NAME "%d", ifunit);
     script_setenv("IFNAME", ifname, iskey);
     script_setenv("IFNAME", ifname, iskey);
-    create_pidfile();  /* write pid to file */
-    create_linkpidfile();
+    if (iskey) {
+       create_pidfile();       /* write pid to file */
+       create_linkpidfile();
+    }
 }
 
 /*
 }
 
 /*
@@ -2143,7 +2153,7 @@ open_socket(dest)
     sad.sin_family = AF_INET;
     sad.sin_port = htons(port);
     sad.sin_addr.s_addr = host;
     sad.sin_family = AF_INET;
     sad.sin_port = htons(port);
     sad.sin_addr.s_addr = host;
-    if (connect(sock, &sad, sizeof(sad)) < 0) {
+    if (connect(sock, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
        error("Can't connect to %s: %m", dest);
        close(sock);
        return -1;
        error("Can't connect to %s: %m", dest);
        close(sock);
        return -1;
@@ -2407,12 +2417,13 @@ charshunt(ifd, ofd, record_file)
                n = max_level - olevel;
            n = write(ofd, obufp, n);
            if (n < 0) {
                n = max_level - olevel;
            n = write(ofd, obufp, n);
            if (n < 0) {
-               if (errno != EIO) {
+               if (errno == EIO) {
+                   pty_readable = 0;
+                   nobuf = 0;
+               } else if (errno != EAGAIN && errno != EINTR) {
                    error("Error writing standard output: %m");
                    break;
                }
                    error("Error writing standard output: %m");
                    break;
                }
-               pty_readable = 0;
-               nobuf = 0;
            } else {
                obufp += n;
                nobuf -= n;
            } else {
                obufp += n;
                nobuf -= n;
@@ -2425,12 +2436,13 @@ charshunt(ifd, ofd, record_file)
                n = max_level - ilevel;
            n = write(pty_master, ibufp, n);
            if (n < 0) {
                n = max_level - ilevel;
            n = write(pty_master, ibufp, n);
            if (n < 0) {
-               if (errno != EIO) {
+               if (errno == EIO) {
+                   stdin_readable = 0;
+                   nibuf = 0;
+               } else if (errno != EAGAIN && errno != EINTR) {
                    error("Error writing pseudo-tty master: %m");
                    break;
                }
                    error("Error writing pseudo-tty master: %m");
                    break;
                }
-               stdin_readable = 0;
-               nibuf = 0;
            } else {
                ibufp += n;
                nibuf -= n;
            } else {
                ibufp += n;
                nibuf -= n;