]> git.ozlabs.org Git - ppp.git/commitdiff
added add_fd, remove_fd, removed wait_loop_output, wait_time.
authorPaul Mackerras <paulus@samba.org>
Tue, 16 Mar 1999 02:57:08 +0000 (02:57 +0000)
committerPaul Mackerras <paulus@samba.org>
Tue, 16 Mar 1999 02:57:08 +0000 (02:57 +0000)
changed syslog -> notice/error/fatal etc.

pppd/sys-NeXT.c
pppd/sys-aix4.c
pppd/sys-bsd.c
pppd/sys-osf.c
pppd/sys-sunos4.c
pppd/sys-svr4.c
pppd/sys-ultrix.c

index 6ec682fb23b06995dbca8e22ec969c6331d81eae..830213652d8a9ca55219d8633380560a774e5fe5 100644 (file)
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-NeXT.c,v 1.12 1999/03/12 06:07:20 paulus Exp $";
+static char rcsid[] = "$Id: sys-NeXT.c,v 1.13 1999/03/16 02:57:05 paulus Exp $";
 #endif
 
 #include <stdio.h>
-#include <syslog.h>
 #include <termios.h>
 #include <utmp.h>
 #include <unistd.h>
@@ -66,6 +65,9 @@ static int loop_slave = -1;
 static int loop_master;
 static char loop_name[20];
 
+static fd_set in_fds;          /* set of fds that wait_input waits for */
+static int max_in_fd;          /* highest fd set in in_fds */
+
 extern int errno;
 
 static int     restore_term;   /* 1 => we've munged the terminal */
@@ -102,17 +104,14 @@ sys_init()
     setlogmask(LOG_UPTO(LOG_INFO));
 
     /* Get an internet socket for doing socket ioctl's on. */
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-       syslog(LOG_ERR, "Couldn't create IP socket: %m");
-       die(1);
-    }
+    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+       fatal("Couldn't create IP socket: %m");
 
     if((pppdev = open("/dev/ppp0", O_RDWR, O_NONBLOCK)) == NULL)
-      {
-       syslog(LOG_ERR, "Couldn't open /dev/ppp0: %m");
-       die(1);
-      }
+       fatal("Couldn't open /dev/ppp0: %m");
       
+    FD_ZERO(&in_fds);
+    max_in_fd = 0;
 }
 
 /*
@@ -149,7 +148,7 @@ void
 note_debug_level()
 {
     if (debug) {
-       syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
+       info("Debug turned ON, Level %d", debug);
        setlogmask(LOG_UPTO(LOG_DEBUG));
     } else {
        setlogmask(LOG_UPTO(LOG_WARNING));
@@ -192,33 +191,27 @@ establish_ppp(fd)
     int pppdisc = PPPDISC;
     int x;
 
-    if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
-       die(1);
-    }
-    if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(establish TIOCSETD): %m");
-       die(1);
-    }
+    if (ioctl(fd, TIOCGETD, &initdisc) < 0)
+       fatal("ioctl(TIOCGETD): %m");
+    if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
+       fatal("ioctl(establish TIOCSETD): %m");
 
     /*
      * Find out which interface we were given.
      */
-    if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) { 
-       syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-       die(1);
-    }
+    if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0)
+       fatal("ioctl(PPPIOCGUNIT): %m");
 
     /*
      * Enable debug in the driver if requested.
      */
     if (kdebugflag) {
        if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-           syslog(LOG_WARNING, "ioctl(PPPIOCGFLAGS): %m");
+           warn("ioctl(PPPIOCGFLAGS): %m");
        } else {
            x |= (kdebugflag & 0xFF) * SC_DEBUG;
            if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
-               syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+               warn("ioctl(PPPIOCSFLAGS): %m");
        }
     }
 
@@ -228,7 +221,7 @@ establish_ppp(fd)
      */
     if ((initfdflags = fcntl(fd, F_GETFL)) == -1
        || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
-       syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+       warn("Couldn't set device to non-blocking mode: %m");
     }
 
 }
@@ -244,12 +237,12 @@ disestablish_ppp(fd)
 {
     /* Reset non-blocking mode on fd. */
     if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
-       syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+       warn("Couldn't restore device fd flags: %m");
     initfdflags = -1;
 
     /* Restore old line discipline. */
     if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+       error("ioctl(TIOCSETD): %m");
     initdisc = -1;
 }
 
@@ -279,8 +272,8 @@ clean_check()
            break;
        }
        if (s != NULL) {
-           syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-           syslog(LOG_WARNING, "All received characters had %s", s);
+           warn("Serial link is not 8-bit clean:");
+           warn("All received characters had %s", s);
        }
     }
 }
@@ -389,7 +382,7 @@ translate_speed(bps)
     for (speedp = speeds; speedp->speed_int; speedp++)
        if (bps == speedp->speed_int)
            return speedp->speed_val;
-    syslog(LOG_WARNING, "speed %d not supported", bps);
+    warn("speed %d not supported", bps);
     return 0;
 }
 
@@ -423,10 +416,8 @@ set_up_tty(fd, local)
     int speed, x, modembits;
     struct termios tios;
 
-    if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
-       die(1);
-    }
+    if (tcgetattr(fd, &tios) < 0)
+       fatal("tcgetattr: %m");
 
     if (!restore_term)
        inittermios = tios;
@@ -459,23 +450,19 @@ set_up_tty(fd, local)
         * We can't proceed if the serial port speed is B0,
         * since that implies that the serial port is disabled.
         */
-       if (speed == B0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
-                  devnam);
-           die(1);
-       }
+       if (speed == B0)
+           fatal("Baud rate for %s is 0; need explicit baud rate",
+                 devnam);
     }
 
     if (modem) {
       modembits = TIOCM_RTS | TIOCM_CTS;
       if (ioctl(fd, (crtscts ? TIOCMBIS : TIOCMBIC), &modembits) < 0)
-       syslog(LOG_ERR, "ioctl: TIOCMBIS/BIC: %m");
+       error("ioctl: TIOCMBIS/BIC: %m");
     }
 
-    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
-       die(1);
-    }
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+       fatal("tcsetattr: %m");
 
    baud_rate = inspeed = baud_rate_of(speed);
    restore_term = 1;
@@ -491,7 +478,7 @@ restore_tty(fd)
     if (restore_term) {
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
        restore_term = 0;
     }
 }
@@ -532,22 +519,21 @@ output(unit, p, len)
     int len;
 {
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     if (write(ttyfd, p, len) < 0) {
        if (errno == EWOULDBLOCK || errno == ENOBUFS
            || errno == ENXIO || errno == EIO) {
-           syslog(LOG_WARNING, "write: warning: %m");
+           warn("write: warning: %m");
        } else {
-           syslog(LOG_ERR, "write: %m");
-           die(1);
+           fatal("write: %m");
        }
     }
 }
 
 
 /*
- * wait_input - wait until there is data available on ttyfd,
+ * wait_input - wait until there is data available,
  * for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
@@ -558,15 +544,30 @@ wait_input(timo)
     fd_set ready;
     int n;
 
-    FD_ZERO(&ready);
-    FD_SET(ttyfd, &ready);
-    n = select(ttyfd+1, &ready, NULL, &ready, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    ready = in_fds;
+    n = select(max_in_fd + 1, &ready, NULL, &ready, timo);
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
+}
+
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+    FD_SET(fd, &in_fds);
+    if (fd > max_in_fd)
+       max_in_fd = fd;
 }
 
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+    FD_CLR(fd, &in_fds);
+}
 
 /*
  * read_packet - get a PPP packet from the serial device.
@@ -579,11 +580,10 @@ read_packet(buf)
 
     if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
        if (errno == EWOULDBLOCK || errno == EINTR) {
-           MAINDEBUG((LOG_DEBUG, "read: %m"));
+           SYSDEBUG(("read: %m"));
            return -1;
        }
-       syslog(LOG_ERR, "read: %m");
-       die(1);
+       fatal("read: %m");
     }
     return len;
 }
@@ -604,26 +604,19 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     ifr.ifr_mtu = mtu;
-    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
-       quit();
-    }
+    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+       fatal("ioctl(SIOCSIFMTU): %m");
 
-    if (ioctl(ttyfd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
-       quit();
-    }
+    if (ioctl(ttyfd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+       fatal("ioctl(PPPIOCSASYNCMAP): %m");
+
+    if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl(PPPIOCGFLAGS): %m");
 
-    if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
-       quit();
-    }
     x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
     x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
-    if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl(PPPIOCSFLAGS): %m");
 }
 
 
@@ -636,7 +629,7 @@ ppp_set_xaccm(unit, accm)
     ext_accm accm;
 {
     if (ioctl(ttyfd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
-       syslog(LOG_WARNING, "ioctl(PPPIOCSXASYNCMAP): %m");
+       warn("ioctl(PPPIOCSXASYNCMAP): %m");
 }
 
 
@@ -652,23 +645,15 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
 {
     int x;
 
-    if (ioctl(ttyfd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
-       quit();
-    }
-    if (ioctl(ttyfd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
-       quit();
-    }
-    if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ttyfd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+       fatal("ioctl(PPPIOCSMRU): %m");
+    if (ioctl(ttyfd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+       fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+    if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl(PPPIOCGFLAGS): %m");
     x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
-    if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl(PPPIOCSFLAGS): %m");
 }
 
 /*
@@ -700,13 +685,13 @@ ccp_flags_set(unit, isopen, isup)
     int x;
 
     if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+       error("ioctl(PPPIOCGFLAGS): %m");
        return;
     }
     x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
     x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
     if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
 }
 
 /*
@@ -721,7 +706,7 @@ ccp_fatal_error(unit)
     int x;
 
     if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+       error("ioctl(PPPIOCGFLAGS): %m");
        return 0;
     }
     return x & SC_DC_FERROR;
@@ -737,17 +722,17 @@ sifvjcomp(u, vjcomp, cidcomp, maxcid)
     u_int x;
 
     if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPIOCGFLAGS): %m");
+       error("ioctl(PPIOCGFLAGS): %m");
        return 0;
     }
     x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
     x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
     if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        return 0;
     }
     if (ioctl(ttyfd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        return 0;
     }
     return 1;
@@ -770,12 +755,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+       error("ioctl(SIOCSIFFLAGS): %m");
        return 0;
     }
     if_is_up = 1;
@@ -783,17 +768,17 @@ sifup(u)
     npi.mode = NPMODE_PASS;
     if (ioctl(ttyfd, PPPIOCSNPMODE, &npi) < 0) {
        if (errno != ENOTTY) {
-           syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
+           error("ioctl(PPPIOCSNPMODE): %m");
            return 0;
        }
        /* for backwards compatibility */
        if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-           syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+           error("ioctl (PPPIOCGFLAGS): %m");
            return 0;
        }
        x |= SC_ENABLE_IP;
        if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-           syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+           error("ioctl(PPPIOCSFLAGS): %m");
            return 0;
        }
     }
@@ -821,12 +806,12 @@ sifdown(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        rv = 0;
     } else {
        ifr.ifr_flags &= ~IFF_UP;
        if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-           syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+           error("ioctl(SIOCSIFFLAGS): %m");
            rv = 0;
        } else
            if_is_up = 0;
@@ -858,19 +843,19 @@ sifaddr(u, o, h, m)
     SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
     if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCAIFADDR): %m");
+       error("ioctl(SIOCAIFADDR): %m");
        ret = 0;
     }
     ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
     if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
+       error("ioctl(SIOCSIFDSTADDR): %m");
        ret = 0;
     }
     if (m != 0) {
        ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
-       syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+       info("Setting interface mask to %s\n", ip_ntoa(m));
        if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
-           syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
+           error("ioctl(SIOCSIFNETMASK): %m");
            ret = 0;
        }
     }
@@ -902,7 +887,7 @@ cifaddr(u, o, h)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
     rt.rt_flags = RTF_HOST;
     if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
+       error("ioctl(SIOCDELRT): %m");
        return 0;
     }
     return 1;
@@ -946,7 +931,7 @@ dodefaultroute(g, cmd)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, (cmd == 's') ? SIOCADDRT : SIOCDELRT, &rt) < 0) {
-       syslog(LOG_ERR, "%cifdefaultroute: ioctl(%s): %m", cmd,
+       error("%cifdefaultroute: ioctl(%s): %m", cmd,
               (cmd == 's') ? "SIOCADDRT" : "SIOCDELRT");
        return 0;
     }
@@ -971,7 +956,7 @@ sifproxyarp(unit, hisaddr)
      * as our local address.
      */
     if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
-       syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+       error("Cannot determine ethernet address for proxy ARP");
        return 0;
     }
 
@@ -979,7 +964,7 @@ sifproxyarp(unit, hisaddr)
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+       error("ioctl(SIOCSARP): %m");
        return 0;
     }
 
@@ -1001,7 +986,7 @@ cifproxyarp(unit, hisaddr)
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_WARNING, "ioctl(SIOCDARP): %m");
+       warn("ioctl(SIOCDARP): %m");
        return 0;
     }
     proxy_arp_addr = 0;
@@ -1030,7 +1015,7 @@ get_ether_addr(ipaddr, hwaddr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+       error("ioctl(SIOCGIFCONF): %m");
        return 0;
     }
 
@@ -1069,7 +1054,7 @@ get_ether_addr(ipaddr, hwaddr)
 
     if (ifr >= ifend)
        return 0;
-    syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+    info("found interface %s for proxy arp", ifr->ifr_name);
 
     /*
      * Get the hostname and look for an entry using the ethers database.
@@ -1079,7 +1064,7 @@ get_ether_addr(ipaddr, hwaddr)
        return 0;
 
     if (ether_by_host(hostent->h_name, &dla)) {
-       syslog(LOG_INFO, "Add entry for %s in /etc/ethers", hostent->h_name);
+       info("Add entry for %s in /etc/ethers", hostent->h_name);
        return 0;       /* it's not there */
     }
     hwaddr->sa_family = AF_UNSPEC;
@@ -1159,7 +1144,7 @@ GetMask(addr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+       warn("ioctl(SIOCGIFCONF): %m");
        return mask;
     }
     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -1314,26 +1299,25 @@ lock(dev)
            /* Read the lock file to find out who has the device locked */
            n = read(fd, &pid, sizeof(pid));
            if (n <= 0) {
-               syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+               error("Can't read pid from lock file %s", lock_file);
                close(fd);
            } else {
                if (kill(pid, 0) == -1 && errno == ESRCH) {
                    /* pid no longer exists - remove the lock file */
                    if (unlink(lock_file) == 0) {
                        close(fd);
-                       syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+                       notice("Removed stale lock on %s (pid %d)",
                               dev, pid);
                        continue;
                    } else
-                       syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
-                              dev);
+                       warn("Couldn't remove stale lock on %s", dev);
                } else
-                   syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+                   notice("Device %s is locked by pid %d",
                           dev, pid);
            }
            close(fd);
        } else
-           syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+           error("Can't create lock file %s: %m", lock_file);
        free(lock_file);
        lock_file = NULL;
        return -1;
@@ -1377,7 +1361,7 @@ ioctl(fd, cmd, c)
     code = cmd;
 
     if (let == 't' && (75 <= code && code <= 90))
-    syslog(LOG_INFO, "ioctl(%d, 0x%x ('%c', %d, %d), 0x%x)\n", fd, cmd,
+    info("ioctl(%d, 0x%x ('%c', %d, %d), 0x%x)\n", fd, cmd,
           let, code, size, c);
 #endif
 
@@ -1386,12 +1370,12 @@ ioctl(fd, cmd, c)
 #ifdef DEBUGIOCTL
     serrno = errno;
     if (ret == -1)
-       syslog(LOG_INFO, "ioctl('%c', %d, %d) errno = %d (%m)\n",
+       info("ioctl('%c', %d, %d) errno = %d (%m)\n",
                let, code, size, errno);
     if (let == 't' && (75 <= code && code <= 90) && (cmd & IOC_OUT)) {
        int i, len = ((cmd >> 16) & IOCPARM_MASK);
        for (i = 0; i < len / 4; ++i)
-               syslog(LOG_INFO, "word[%d] @ 0x%06x = 0x%x\n",
+               info("word[%d] @ 0x%06x = 0x%x\n",
                       i, &((int *) c)[i],((int *)c)[i]);
     }
     errno = serrno;
@@ -1452,7 +1436,7 @@ int sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
    if (!in)
      {
        in = 1;
-       syslog(LOG_WARNING, "PPPD: Inside modified HP and SPARC sigaction\n");
+       warn("PPPD: Inside modified HP and SPARC sigaction\n");
      }
 
    return sigvec(sig, &sv, NULL);
@@ -1495,13 +1479,10 @@ get_loop_output()
            rv = 1;
     }
 
-    if (n == 0) {
-       syslog(LOG_ERR, "eof on loopback");
-       die(1);
-    } else if (errno != EWOULDBLOCK){
-       syslog(LOG_ERR, "read from loopback: %m");
-       die(1);
-    }
+    if (n == 0)
+       fatal("eof on loopback");
+    if (errno != EWOULDBLOCK)
+       fatal("read from loopback: %m");
 
     return rv;
 #endif
@@ -1523,7 +1504,7 @@ sifnpmode(u, proto, mode)
     npi.protocol = proto;
     npi.mode = mode;
     if (ioctl(ttyfd, PPPIOCSNPMODE, &npi) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -1544,14 +1525,11 @@ open_ppp_loopback()
     struct termios tios;
     int pppdisc = PPPDISC;
 
-    syslog(LOG_ERR, "open_ppp_loopback called!");
-    die(1);
+    fatal("open_ppp_loopback called!");
 
-    if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0) {
-       syslog(LOG_ERR, "No free pty for loopback");
-       die(1);
-    }
-    SYSDEBUG((LOG_DEBUG, "using %s for loopback", loop_name));
+    if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0)
+       fatal("No free pty for loopback");
+    SYSDEBUG(("using %s for loopback", loop_name));
 
     if (tcgetattr(loop_slave, &tios) == 0) {
        tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
@@ -1560,37 +1538,33 @@ open_ppp_loopback()
        tios.c_oflag = 0;
        tios.c_lflag = 0;
        if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0)
-           syslog(LOG_WARNING, "couldn't set attributes on loopback: %m");
+           warn("couldn't set attributes on loopback: %m");
     }
 
     if ((flags = fcntl(loop_master, F_GETFL)) != -1) 
        if (fcntl(loop_master, F_SETFL, flags | O_NONBLOCK) == -1)
-           syslog(LOG_WARNING, "couldn't set loopback to nonblock: %m");
+           warn("couldn't set loopback to nonblock: %m");
 
     ttyfd = loop_slave;
-    if (ioctl(ttyfd, TIOCSETD, &pppdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
-       die(1);
-    }
+    if (ioctl(ttyfd, TIOCSETD, &pppdisc) < 0)
+       fatal("ioctl(TIOCSETD): %m");
 
     /*
      * Find out which interface we were given.
      */
-    if (ioctl(ttyfd, PPPIOCGUNIT, &ifunit) < 0) {      
-       syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-       die(1);
-    }
+    if (ioctl(ttyfd, PPPIOCGUNIT, &ifunit) < 0)
+       fatal("ioctl(PPPIOCGUNIT): %m");
 
     /*
      * Enable debug in the driver if requested.
      */
     if (kdebugflag) {
        if (ioctl(ttyfd, PPPIOCGFLAGS, (caddr_t) &flags) < 0) {
-           syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+           warn("ioctl (PPPIOCGFLAGS): %m");
        } else {
            flags |= (kdebugflag & 0xFF) * SC_DEBUG;
            if (ioctl(ttyfd, PPPIOCSFLAGS, (caddr_t) &flags) < 0)
-               syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+               warn("ioctl(PPPIOCSFLAGS): %m");
        }
     }
 
@@ -1609,28 +1583,20 @@ restore_loop()
     /*
      * Transfer the ppp interface back to the loopback.
      */
-    if (ioctl(ttyfd, PPPIOCXFERUNIT, 0) < 0) {
-       syslog(LOG_ERR, "ioctl(transfer ppp unit): %m");
-       die(1);
-    }
+    if (ioctl(ttyfd, PPPIOCXFERUNIT, 0) < 0)
+       fatal("ioctl(transfer ppp unit): %m");
     x = PPPDISC;
-    if (ioctl(loop_slave, TIOCSETD, &x) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
-       die(1);
-    }
+    if (ioctl(loop_slave, TIOCSETD, &x) < 0)
+       fatal("ioctl(TIOCSETD): %m");
 
     /*
      * Check that we got the same unit again.
      */
-    if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0) {      
-       syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-       die(1);
-    }
-    if (x != ifunit) {
-       syslog(LOG_ERR, "transfer_ppp failed: wanted unit %d, got %d",
-              ifunit, x);
-       die(1);
-    }
+    if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0)
+       fatal("ioctl(PPPIOCGUNIT): %m");
+    if (x != ifunit)
+       fatal("transfer_ppp failed: wanted unit %d, got %d",
+             ifunit, x);
     ttyfd = loop_slave;
 }
 
@@ -1656,7 +1622,7 @@ sys_check_options()
    */
   if (demand)
     {
-      syslog(LOG_WARNING, "PPP-2.3 for NeXTSTEP does not yet support demand dialing\n");
+      option_error("PPP-2.3 for NeXTSTEP does not yet support demand dialing");
       return 0;
     }
   return 1;
@@ -1677,7 +1643,7 @@ sys_close()
     closelog();
 }
 
-
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -1692,13 +1658,10 @@ void wait_loop_output(timo)
     FD_ZERO(&ready);
     FD_SET(loop_master, &ready);
     n = select(loop_master + 1, &ready, NULL, &ready, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
 
-
 /*
  * wait_time - wait for a given length of time or until a
  * signal is received.
@@ -1709,8 +1672,7 @@ void wait_time(timo)
     int n;
 
     n = select(0, NULL, NULL, NULL, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
+#endif
index 9fcd1015d992cc7697e11f58eef450f210e1e378..7de3ff60d53894ba3a4ee0ae7be859aa8914b196 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-aix4.c,v 1.15 1999/03/12 06:07:21 paulus Exp $";
+static char rcsid[] = "$Id: sys-aix4.c,v 1.16 1999/03/16 02:57:05 paulus Exp $";
 #endif
 
 /*
@@ -33,7 +33,6 @@ static char rcsid[] = "$Id: sys-aix4.c,v 1.15 1999/03/12 06:07:21 paulus Exp $";
 #include <stdlib.h>
 */
 #include <errno.h>
-#include <syslog.h>
 #include <termios.h>
 #include <sys/termiox.h>
 #include <fcntl.h>
@@ -78,6 +77,10 @@ static u_int32_t ifaddrs[2]; /* local and remote addresses */
 static u_int32_t default_route_gateway;        /* Gateway for default route added */
 static u_int32_t proxy_arp_addr;       /* Addr for proxy arp entry added */
 
+#define MAX_POLLFDS    32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
 /* Prototypes for procedures local to this file. */
 static int translate_speed __P((int));
 static int baud_rate_of __P((int));
@@ -91,10 +94,10 @@ void
 sys_init()
 {
     /* Get an internet socket for doing socket ioctl's on. */
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-       syslog(LOG_ERR, "Couldn't create IP socket: %m");
-       die(1);
-    }
+    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+       fatal("Couldn't create IP socket: %m");
+
+    n_pollfds = 0;
 }
 
 /*
@@ -189,45 +192,37 @@ establish_ppp(fd)
        if (ioctl(fd, I_LOOK, str_modules[str_module_count].modname) < 0 ||
            ioctl(fd, I_POP, 0) < 0)
            break;
-       MAINDEBUG((LOG_DEBUG, "popped stream module : %s",
+       SYSDEBUG(("popped stream module : %s",
                   str_modules[str_module_count].modname));
        str_module_count++;
     }
 
     /* now push the async/fcs module */
-    if (ioctl(fd, I_PUSH, "pppasync") < 0) {
-       syslog(LOG_ERR, "ioctl(I_PUSH, ppp_async): %m");
-       die(1);
-    }
+    if (ioctl(fd, I_PUSH, "pppasync") < 0)
+       fatal("ioctl(I_PUSH, ppp_async): %m");
     /* push the compress module */
     if (ioctl(fd, I_PUSH, "pppcomp") < 0) {
-       syslog(LOG_WARNING, "ioctl(I_PUSH, ppp_comp): %m");
+       warn("ioctl(I_PUSH, ppp_comp): %m");
     }
     /* finally, push the ppp_if module that actually handles the */
     /* network interface */ 
-    if (ioctl(fd, I_PUSH, "pppif") < 0) {
-       syslog(LOG_ERR, "ioctl(I_PUSH, ppp_if): %m");
-       die(1);
-    }
+    if (ioctl(fd, I_PUSH, "pppif") < 0)
+       fatal("ioctl(I_PUSH, ppp_if): %m");
     pushed_ppp = 1;
     /* read mode, message non-discard mode
-    if (ioctl(fd, I_SRDOPT, RMSGN) < 0) {
-       syslog(LOG_ERR, "ioctl(I_SRDOPT, RMSGN): %m");
-       die(1);
-    }
+    if (ioctl(fd, I_SRDOPT, RMSGN) < 0)
+       fatal("ioctl(I_SRDOPT, RMSGN): %m");
 */
     /*
      * Find out which interface we were given.
      * (ppp_if handles this ioctl)
      */
-    if (ioctl(fd, SIOCGETU, &ifunit) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGETU): %m");
-       die(1);
-    }
+    if (ioctl(fd, SIOCGETU, &ifunit) < 0)
+       fatal("ioctl(SIOCGETU): %m");
 
     /* Set debug flags in driver */
     if (ioctl(fd, SIOCSIFDEBUG, kdebugflag) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFDEBUG): %m");
+       error("ioctl(SIOCSIFDEBUG): %m");
     }
 
     /* close stdin, stdout, stderr if they might refer to the device */
@@ -245,7 +240,7 @@ establish_ppp(fd)
      */
     if ((initfdflags = fcntl(fd, F_GETFL)) == -1
        || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
-       syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+       warn("Couldn't set device to non-blocking mode: %m");
     }
 }
 
@@ -263,7 +258,7 @@ disestablish_ppp(fd)
 
     /* Reset non-blocking mode on the file descriptor. */
     if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
-       syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+       warn("Couldn't restore device fd flags: %m");
     initfdflags = -1;
 
     if (hungup) {
@@ -294,8 +289,8 @@ disestablish_ppp(fd)
                break;
            }
            if (s != NULL) {
-               syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-               syslog(LOG_WARNING, "All received characters had %s", s);
+               warn("Serial link is not 8-bit clean:");
+               warn("All received characters had %s", s);
            }
        }
     }
@@ -307,11 +302,11 @@ disestablish_ppp(fd)
     for (; str_module_count > 0; str_module_count--) {
        if (ioctl(fd, I_PUSH, str_modules[str_module_count-1].modname)) {
            if (errno != ENXIO)
-               syslog(LOG_WARNING, "str_restore: couldn't push module %s: %m",
-                      str_modules[str_module_count-1].modname);
+               warn("str_restore: couldn't push module %s: %m",
+                    str_modules[str_module_count-1].modname);
        } else {
-           MAINDEBUG((LOG_INFO, "str_restore: pushed module %s",
-                      str_modules[str_module_count-1].modname));
+           SYSDEBUG(("str_restore: pushed module %s",
+                     str_modules[str_module_count-1].modname));
        }
     }
 }
@@ -406,7 +401,7 @@ translate_speed(bps)
     for (speedp = speeds; speedp->speed_int; speedp++)
        if (bps == speedp->speed_int)
            return speedp->speed_val;
-    syslog(LOG_WARNING, "speed %d not supported", bps);
+    warn("speed %d not supported", bps);
     return 0;
 }
 
@@ -440,10 +435,9 @@ set_up_tty(fd, local)
     struct termios tios;
     struct termiox tiox;
 
-    if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
-       die(1);
-    }
+    if (tcgetattr(fd, &tios) < 0)
+       fatal("tcgetattr: %m");
+
 
     if (!restore_term)
        inittermios = tios;
@@ -488,17 +482,12 @@ set_up_tty(fd, local)
         * We can't proceed if the serial port speed is B0,
         * since that implies that the serial port is disabled.
         */
-       if (speed == B0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
-                  devnam);
-           die(1);
-       }
+       if (speed == B0)
+           fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
 
-    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
-       die(1);
-    }
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+       fatal("tcsetattr: %m");
 
     baud_rate = inspeed = baud_rate_of(speed);
     restore_term = 1;
@@ -523,7 +512,7 @@ restore_tty(fd)
        }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
        restore_term = 0;
     }
 }
@@ -556,7 +545,7 @@ output(unit, p, len)
     struct pollfd pfd;
 
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     str.len = len;
     str.buf = (caddr_t) p;
@@ -564,7 +553,7 @@ output(unit, p, len)
     while (putmsg(ttyfd, NULL, &str, 0) < 0) {
        if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
            if (errno != ENXIO)
-               syslog(LOG_ERR, "Couldn't send packet: %m");
+               error("Couldn't send packet: %m");
            break;
        }
        pfd.fd = ttyfd;
@@ -581,17 +570,48 @@ wait_input(timo)
     struct timeval *timo;
 {
     int t;
-    struct pollfd pfd;
 
     t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
-    pfd.fd = ttyfd;
-    pfd.events = POLLIN | POLLPRI | POLLHUP;
-    if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "poll: %m");
-       die(1);
+    if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+       fatal("poll: %m");
+}
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n)
+       if (pollfds[n].fd == fd)
+           return;
+    if (n_pollfds < MAX_POLLFDS) {
+       pollfds[n_pollfds].fd = fd;
+       pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+       ++n_pollfds;
+    } else
+       error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n) {
+       if (pollfds[n].fd == fd) {
+           while (++n < n_pollfds)
+               pollfds[n-1] = pollfds[n];
+           --n_pollfds;
+           break;
+       }
     }
 }
 
+
 /*
  * read_packet - get a PPP packet from the serial device.
  */
@@ -613,17 +633,15 @@ read_packet(buf)
        if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
            return -1;
        }
-       syslog(LOG_ERR, "getmsg %m");
-       die(1);
+       fatal("getmsg %m");
     }
     if (len) 
-       MAINDEBUG((LOG_DEBUG, "getmsg returned 0x%x",len));
+       SYSDEBUG(("getmsg returned 0x%x", len));
     if (ctl.len > 0)
-       syslog(LOG_NOTICE, "got ctrl msg len %d %x %x\n", ctl.len,
-              ctlbuf[0], ctlbuf[1]);
+       notice("got ctrl msg len %d %x %x\n", ctl.len, ctlbuf[0], ctlbuf[1]);
 
     if (str.len < 0) {
-       MAINDEBUG((LOG_DEBUG, "getmsg short return length %d", str.len));
+       SYSDEBUG(("getmsg short return length %d", str.len));
        return -1;
     }
 
@@ -646,27 +664,19 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     ifr.ifr_mtu = mtu;
-    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
-       quit();
-    }
+    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+       fatal("ioctl(SIOCSIFMTU): %m");
 
-    if(ioctl(ttyfd, SIOCSIFASYNCMAP, asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFASYNCMAP): %m");
-       quit();
-    }
+    if(ioctl(ttyfd, SIOCSIFASYNCMAP, asyncmap) < 0)
+       fatal("ioctl(SIOCSIFASYNCMAP): %m");
 
     c = (pcomp? 1: 0);
-    if(ioctl(ttyfd, SIOCSIFCOMPPROT, c) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m");
-       quit();
-    }
+    if(ioctl(ttyfd, SIOCSIFCOMPPROT, c) < 0)
+       fatal("ioctl(SIOCSIFCOMPPROT): %m");
 
     c = (accomp? 1: 0);
-    if(ioctl(ttyfd, SIOCSIFCOMPAC, c) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m");
-       quit();
-    }
+    if(ioctl(ttyfd, SIOCSIFCOMPAC, c) < 0)
+       fatal("ioctl(SIOCSIFCOMPAC): %m");
 }
 
 
@@ -679,7 +689,7 @@ ppp_set_xaccm(unit, accm)
     ext_accm accm;
 {
     if (ioctl(ttyfd, SIOCSIFXASYNCMAP, accm) < 0 && errno != ENOTTY)
-       syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
+       warn("ioctl(set extended ACCM): %m");
 }
 
 
@@ -696,21 +706,21 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     char c;
 
     if (ioctl(ttyfd, SIOCSIFMRU, mru) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFMRU): %m");
+       error("ioctl(SIOCSIFMRU): %m");
     }
 
     if (ioctl(ttyfd, SIOCSIFRASYNCMAP, (caddr_t) asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFRASYNCMAP): %m");
+       error("ioctl(SIOCSIFRASYNCMAP): %m");
     }
 
     c = 2 + (pcomp? 1: 0);
     if(ioctl(ttyfd, SIOCSIFCOMPPROT, c) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m");
+       error("ioctl(SIOCSIFCOMPPROT): %m");
     }
 
     c = 2 + (accomp? 1: 0);
     if (ioctl(ttyfd, SIOCSIFCOMPAC, c) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m");
+       error("ioctl(SIOCSIFCOMPAC): %m");
     }
 }
 
@@ -746,7 +756,7 @@ ccp_flags_set(unit, isopen, isup)
 
     x = (isopen? 1: 0) + (isup? 2: 0);
     if (ioctl(ttyfd, SIOCSIFCOMP, x) < 0 && errno != ENOTTY)
-       syslog(LOG_ERR, "ioctl (SIOCSIFCOMP): %m");
+       error("ioctl (SIOCSIFCOMP): %m");
 }
 
 /*
@@ -761,7 +771,7 @@ ccp_fatal_error(unit)
     int x;
 
     if (ioctl(ttyfd, SIOCGIFCOMP, &x) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGIFCOMP): %m");
+       error("ioctl(SIOCGIFCOMP): %m");
        return 0;
     }
     return x & CCP_FATALERROR;
@@ -778,7 +788,7 @@ sifvjcomp(u, vjcomp, cidcomp, maxcid)
 
     x = (vjcomp? 1: 0) + (cidcomp? 0: 2) + (maxcid << 4);
     if (ioctl(ttyfd, SIOCSIFVJCOMP, x) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFVJCOMP): %m");
+       error("ioctl(SIOCSIFVJCOMP): %m");
        return 0;
     }
     return 1;
@@ -795,12 +805,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+       error("ioctl(SIOCSIFFLAGS): %m");
        return 0;
     }
 
@@ -822,7 +832,7 @@ sifnpmode(u, proto, mode)
     npi.protocol = proto;
     npi.mode = mode;
     if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -847,12 +857,12 @@ sifdown(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+        error("ioctl (SIOCGIFFLAGS): %m");
         rv = 0;
     } else {
         ifr.ifr_flags &= ~IFF_UP;
         if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-            syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+            error("ioctl(SIOCSIFFLAGS): %m");
             rv = 0;
         } else
            if_is_up = 0;
@@ -882,31 +892,31 @@ sifaddr(u, o, h, m)
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
     if (m != 0) {
-        syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+        info("Setting interface mask to %s\n", ip_ntoa(m));
         ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
         if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
-            syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
+            error("ioctl(SIOCSIFNETMASK): %m");
             ret = 0;
         }
     }
 
     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
     if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
+        error("ioctl(SIOCSIFADDR): %m");
         ret = 0;
     }
 
     SET_SA_FAMILY(ifr.ifr_dstaddr, AF_INET);
     ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
     if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
+        error("ioctl(SIOCSIFDSTADDR): %m");
         ret = 0;
     }
 
     /* XXX is this necessary? */
     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
     if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
+        error("ioctl(SIOCSIFADDR): %m");
         ret = 0;
     }
 
@@ -934,7 +944,7 @@ cifaddr(u, o, h)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
     rt.rt_flags = RTF_HOST;
     if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
+       error("ioctl(SIOCDELRT): %m");
        return 0;
     }
     return 1;
@@ -956,7 +966,7 @@ sifdefaultroute(u, l, g)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
-       syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
+       error("default route ioctl(SIOCADDRT): %m");
        return 0;
     }
     default_route_gateway = g;
@@ -979,7 +989,7 @@ cifdefaultroute(u, l, g)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, SIOCDELRT, &rt) < 0) {
-       syslog(LOG_ERR, "default route ioctl(SIOCDELRT): %m");
+       error("default route ioctl(SIOCDELRT): %m");
        return 0;
     }
     default_route_gateway = 0;
@@ -1003,7 +1013,7 @@ sifproxyarp(unit, hisaddr)
      * as our local address.
      */
     if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
-       syslog(LOG_WARNING, "Cannot determine ethernet address for proxy ARP");
+       warn("Cannot determine ethernet address for proxy ARP");
        return 0;
     }
 
@@ -1011,7 +1021,7 @@ sifproxyarp(unit, hisaddr)
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+       error("ioctl(SIOCSARP): %m");
        return 0;
     }
 
@@ -1033,7 +1043,7 @@ cifproxyarp(unit, hisaddr)
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCDARP): %m");
+       error("ioctl(SIOCDARP): %m");
        return 0;
     }
     proxy_arp_addr = 0;
@@ -1086,7 +1096,7 @@ static struct nlist nl[] = {
 int kvm_read(int fd, off_t offset, void *buf, int nbytes)
 {
     if (lseek(fd, offset, SEEK_SET) != offset) {
-        syslog(LOG_ERR,"lseek in kmem: %m");
+        error("lseek in kmem: %m");
         return(0);
     }
     return(read(fd, buf, nbytes));
@@ -1118,13 +1128,13 @@ get_ether_addr(ipaddr, hwaddr)
 
 /* Open kernel memory for reading */
     if ((kd = open("/dev/kmem", O_RDONLY)) < 0) {
-        syslog(LOG_ERR, "/dev/kmem: %m");
+        error("/dev/kmem: %m");
         return 0;
     }
 
 /* Fetch namelist */
     if (nlist("/unix", nl) != 0) {
-        syslog(LOG_ERR, "nlist(): %m");
+        error("nlist(): %m");
         return 0;
     }
 
@@ -1135,12 +1145,12 @@ get_ether_addr(ipaddr, hwaddr)
 
     if (kvm_read(kd, nl[N_IFNET].n_value, (char *)&addr, sizeof(addr))
         != sizeof(addr)) {
-        syslog(LOG_ERR, "error reading ifnet addr");
+        error("error reading ifnet addr");
         return 0;
     }
     for ( ; addr && !found; addr = (u_long)ifp->if_next) {
         if (kvm_read(kd, addr, (char *)ac, sizeof(*ac)) != sizeof(*ac)) {
-            syslog(LOG_ERR, "error reading ifnet");
+            error("error reading ifnet");
             return 0;
         }
 
@@ -1155,17 +1165,17 @@ get_ether_addr(ipaddr, hwaddr)
         for (ifap = ifp->if_addrlist; ifap; ifap=ifaddr.ifa.ifa_next) {
             if (kvm_read(kd, (u_long)ifap, (char *)&ifaddr,
                      sizeof(ifaddr)) != sizeof(ifaddr)) {
-                syslog(LOG_ERR, "error reading ifaddr");
+                error("error reading ifaddr");
                 return 0;
             }
             if (kvm_read(kd, (u_long)ifaddr.ifa.ifa_addr, &ifaddrsaddr,
                 sizeof(struct sockaddr_in)) != sizeof(struct sockaddr_in)) {
-                syslog(LOG_ERR, "error reading ifaddrsaddr");
+                error("error reading ifaddrsaddr");
                 return(0);
             }
             if (kvm_read(kd, (u_long)ifaddr.ifa.ifa_netmask, &ifmasksaddr,
                 sizeof(struct sockaddr_in)) != sizeof(struct sockaddr_in)) {
-                syslog(LOG_ERR, "error reading ifmasksaddr");
+                error("error reading ifmasksaddr");
                 return(0);
             }
     /* Check if this interface on the right subnet */
@@ -1180,7 +1190,7 @@ get_ether_addr(ipaddr, hwaddr)
                 ifip = ifinetptr->sin_addr.s_addr;
                 if (kvm_read(kd, (u_long)ifaddr.ifa.ifa_netmask, &ifmasksaddr,
                     sizeof(struct sockaddr_in)) != sizeof(struct sockaddr_in)) {
-                    syslog(LOG_ERR, "error reading ifmasksaddr");
+                    error("error reading ifmasksaddr");
                     return(0);
                 }
                 mask = ifmasksaddr.sin_addr.s_addr;
@@ -1231,7 +1241,7 @@ GetMask(addr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+       warn("ioctl(SIOCGIFCONF): %m");
        return mask;
     }
     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -1313,8 +1323,7 @@ int lock(char *device)
        devname = device;
 
     if ((rc = ttylock(devname)) == 0) {
-       devlocked = (char *) malloc(strlen(devname) + 1);
-       sprintf(devlocked,"%s",devname);
+       devlocked = strdup(devname);
     } else
        devlocked = (char *) 0;
 
index c2475a18d0b28cee72aba20a06ea0786a6f08a3c..b830e01c3935851040b4a3ab96571639db2fa4ca 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-bsd.c,v 1.36 1999/03/12 06:07:21 paulus Exp $";
+static char rcsid[] = "$Id: sys-bsd.c,v 1.37 1999/03/16 02:57:06 paulus Exp $";
 /*     $NetBSD: sys-bsd.c,v 1.1.1.3 1997/09/26 18:53:04 christos Exp $ */
 #endif
 
@@ -30,7 +30,6 @@ static char rcsid[] = "$Id: sys-bsd.c,v 1.36 1999/03/12 06:07:21 paulus Exp $";
  */
 
 #include <stdio.h>
-#include <syslog.h>
 #include <string.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -94,6 +93,9 @@ static unsigned char inbuf[512]; /* buffer for chars read from loopback */
 
 static int sockfd;             /* socket for doing interface ioctls */
 
+static fd_set in_fds;          /* set of fds that wait_input waits for */
+static int max_in_fd;          /* highest fd set in in_fds */
+
 static int if_is_up;           /* the interface is currently up */
 static u_int32_t ifaddrs[2];   /* local and remote addresses we set */
 static u_int32_t default_route_gateway;        /* gateway addr for default route */
@@ -111,10 +113,11 @@ void
 sys_init()
 {
     /* Get an internet socket for doing socket ioctl's on. */
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-       syslog(LOG_ERR, "Couldn't create IP socket: %m");
-       die(1);
-    }
+    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+       fatal("Couldn't create IP socket: %m");
+
+    FD_ZERO(&in_fds);
+    max_in_fd = 0;
 }
 
 /*
@@ -164,7 +167,7 @@ sys_check_options()
 {
 #ifndef CDTRCTS
     if (crtscts == 2) {
-       syslog(LOG_WARNING, "DTR/CTS flow control is not supported on this system");
+       warn("DTR/CTS flow control is not supported on this system");
        return 0;
     }
 #endif
@@ -210,45 +213,32 @@ establish_ppp(fd)
        /*
         * Demand mode - prime the old ppp device to relinquish the unit.
         */
-       if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0) {
-           syslog(LOG_ERR, "ioctl(transfer ppp unit): %m");
-           die(1);
-       }
+       if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
+           fatal("ioctl(transfer ppp unit): %m");
     }
 
     /*
      * Save the old line discipline of fd, and set it to PPP.
      */
-    if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
-       die(1);
-    }
-    if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
-       die(1);
-    }
+    if (ioctl(fd, TIOCGETD, &initdisc) < 0)
+       fatal("ioctl(TIOCGETD): %m");
+    if (ioctl(fd, TIOCSETD, &pppdisc) < 0)
+       fatal("ioctl(TIOCSETD): %m");
 
     if (!demand) {
        /*
         * Find out which interface we were given.
         */
-       if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {      
-           syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-           die(1);
-       }
+       if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {    
+           fatal("ioctl(PPPIOCGUNIT): %m");
     } else {
        /*
         * Check that we got the same unit again.
         */
-       if (ioctl(fd, PPPIOCGUNIT, &x) < 0) {   
-           syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-           die(1);
-       }
-       if (x != ifunit) {
-           syslog(LOG_ERR, "transfer_ppp failed: wanted unit %d, got %d",
-                  ifunit, x);
-           die(1);
-       }
+       if (ioctl(fd, PPPIOCGUNIT, &x) < 0) { 
+           fatal("ioctl(PPPIOCGUNIT): %m");
+       if (x != ifunit)
+           fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
        x = TTYDISC;
        ioctl(loop_slave, TIOCSETD, &x);
     }
@@ -260,11 +250,11 @@ establish_ppp(fd)
      */
     if (kdebugflag) {
        if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-           syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+           warn("ioctl (PPPIOCGFLAGS): %m");
        } else {
            x |= (kdebugflag & 0xFF) * SC_DEBUG;
            if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
-               syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+               warn("ioctl(PPPIOCSFLAGS): %m");
        }
     }
 
@@ -273,7 +263,7 @@ establish_ppp(fd)
      */
     if ((initfdflags = fcntl(fd, F_GETFL)) == -1
        || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
-       syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+       warn("Couldn't set device to non-blocking mode: %m");
     }
 }
 
@@ -288,28 +278,19 @@ restore_loop()
     /*
      * Transfer the ppp interface back to the loopback.
      */
-    if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0) {
-       syslog(LOG_ERR, "ioctl(transfer ppp unit): %m");
-       die(1);
-    }
+    if (ioctl(ppp_fd, PPPIOCXFERUNIT, 0) < 0)
+       fatal("ioctl(transfer ppp unit): %m");
     x = PPPDISC;
-    if (ioctl(loop_slave, TIOCSETD, &x) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
-       die(1);
-    }
+    if (ioctl(loop_slave, TIOCSETD, &x) < 0)
+       fatal("ioctl(TIOCSETD): %m");
 
     /*
      * Check that we got the same unit again.
      */
-    if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0) {      
-       syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-       die(1);
-    }
-    if (x != ifunit) {
-       syslog(LOG_ERR, "transfer_ppp failed: wanted unit %d, got %d",
-              ifunit, x);
-       die(1);
-    }
+    if (ioctl(loop_slave, PPPIOCGUNIT, &x) < 0)
+       fatal("ioctl(PPPIOCGUNIT): %m");
+    if (x != ifunit)
+       fatal("transfer_ppp failed: wanted unit %d, got %d", ifunit, x);
     ppp_fd = loop_slave;
 }
 
@@ -324,12 +305,12 @@ disestablish_ppp(fd)
 {
     /* Reset non-blocking mode on fd. */
     if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
-       syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+       warn("Couldn't restore device fd flags: %m");
     initfdflags = -1;
 
     /* Restore old line discipline. */
     if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+       error("ioctl(TIOCSETD): %m");
     initdisc = -1;
 
     if (fd == ppp_fd)
@@ -362,8 +343,8 @@ clean_check()
            break;
        }
        if (s != NULL) {
-           syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-           syslog(LOG_WARNING, "All received characters had %s", s);
+           warn("Serial link is not 8-bit clean:");
+           warn("All received characters had %s", s);
        }
     }
 }
@@ -381,10 +362,8 @@ set_up_tty(fd, local)
 {
     struct termios tios;
 
-    if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
-       die(1);
-    }
+    if (tcgetattr(fd, &tios) < 0)
+       fatal("tcgetattr: %m");
 
     if (!restore_term) {
        inittermios = tios;
@@ -430,18 +409,13 @@ set_up_tty(fd, local)
         * We can't proceed if the serial port speed is 0,
         * since that implies that the serial port is disabled.
         */
-       if (inspeed == 0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
-                  devnam);
-           die(1);
-       }
+       if (inspeed == 0)
+           fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
     baud_rate = inspeed;
 
-    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
-       die(1);
-    }
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+       fatal("tcsetattr: %m");
 
     restore_term = 1;
 }
@@ -465,7 +439,7 @@ restore_tty(fd)
        }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
        ioctl(fd, TIOCSWINSZ, &wsinfo);
        restore_term = 0;
     }
@@ -497,11 +471,9 @@ open_ppp_loopback()
     struct termios tios;
     int pppdisc = PPPDISC;
 
-    if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0) {
-       syslog(LOG_ERR, "No free pty for loopback");
-       die(1);
-    }
-    SYSDEBUG((LOG_DEBUG, "using %s for loopback", loop_name));
+    if (openpty(&loop_master, &loop_slave, loop_name, NULL, NULL) < 0)
+       fatal("No free pty for loopback");
+    SYSDEBUG(("using %s for loopback", loop_name));
 
     if (tcgetattr(loop_slave, &tios) == 0) {
        tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
@@ -510,37 +482,33 @@ open_ppp_loopback()
        tios.c_oflag = 0;
        tios.c_lflag = 0;
        if (tcsetattr(loop_slave, TCSAFLUSH, &tios) < 0)
-           syslog(LOG_WARNING, "couldn't set attributes on loopback: %m");
+           warn("couldn't set attributes on loopback: %m");
     }
 
     if ((flags = fcntl(loop_master, F_GETFL)) != -1) 
        if (fcntl(loop_master, F_SETFL, flags | O_NONBLOCK) == -1)
-           syslog(LOG_WARNING, "couldn't set loopback to nonblock: %m");
+           warn("couldn't set loopback to nonblock: %m");
 
     ppp_fd = loop_slave;
-    if (ioctl(ppp_fd, TIOCSETD, &pppdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
-       die(1);
-    }
+    if (ioctl(ppp_fd, TIOCSETD, &pppdisc) < 0)
+       fatal("ioctl(TIOCSETD): %m");
 
     /*
      * Find out which interface we were given.
      */
-    if (ioctl(ppp_fd, PPPIOCGUNIT, &ifunit) < 0) {     
-       syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
-       die(1);
-    }
+    if (ioctl(ppp_fd, PPPIOCGUNIT, &ifunit) < 0)
+       fatal("ioctl(PPPIOCGUNIT): %m");
 
     /*
      * Enable debug in the driver if requested.
      */
     if (kdebugflag) {
        if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &flags) < 0) {
-           syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+           warn("ioctl (PPPIOCGFLAGS): %m");
        } else {
            flags |= (kdebugflag & 0xFF) * SC_DEBUG;
            if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &flags) < 0)
-               syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+               warn("ioctl(PPPIOCSFLAGS): %m");
        }
     }
 
@@ -557,17 +525,17 @@ output(unit, p, len)
     int len;
 {
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     if (write(ttyfd, p, len) < 0) {
        if (errno != EIO)
-           syslog(LOG_ERR, "write: %m");
+           error("write: %m");
     }
 }
 
 
 /*
- * wait_input - wait until there is data available on ttyfd,
+ * wait_input - wait until there is data available,
  * for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
@@ -578,16 +546,32 @@ wait_input(timo)
     fd_set ready;
     int n;
 
-    FD_ZERO(&ready);
-    FD_SET(ttyfd, &ready);
-    n = select(ttyfd+1, &ready, NULL, &ready, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    ready = in_fds;
+    n = select(max_in_fd + 1, &ready, NULL, &ready, timo);
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
 
 
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+    FD_SET(fd, &in_fds);
+    if (fd > max_in_fd)
+       max_in_fd = fd;
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+    FD_CLR(fd, &in_fds);
+}
+
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -603,10 +587,8 @@ wait_loop_output(timo)
     FD_ZERO(&ready);
     FD_SET(loop_master, &ready);
     n = select(loop_master + 1, &ready, NULL, &ready, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
 
 
@@ -621,11 +603,10 @@ wait_time(timo)
     int n;
 
     n = select(0, NULL, NULL, NULL, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
+#endif
 
 
 /*
@@ -640,8 +621,7 @@ read_packet(buf)
     if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
        if (errno == EWOULDBLOCK || errno == EINTR)
            return -1;
-       syslog(LOG_ERR, "read: %m");
-       die(1);
+       fatal("read: %m");
     }
     return len;
 }
@@ -663,13 +643,10 @@ get_loop_output()
            rv = 1;
     }
 
-    if (n == 0) {
-       syslog(LOG_ERR, "eof on loopback");
-       die(1);
-    } else if (errno != EWOULDBLOCK){
-       syslog(LOG_ERR, "read from loopback: %m");
-       die(1);
-    }
+    if (n == 0)
+       fatal("eof on loopback");
+    if (errno != EWOULDBLOCK)
+       fatal("read from loopback: %m");
 
     return rv;
 }
@@ -690,26 +667,18 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     ifr.ifr_mtu = mtu;
-    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
-       quit();
-    }
+    if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
+       fatal("ioctl(SIOCSIFMTU): %m");
 
-    if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
-       quit();
-    }
+    if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
+       fatal("ioctl(PPPIOCSASYNCMAP): %m");
 
-    if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl (PPPIOCGFLAGS): %m");
     x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
     x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
-    if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl(PPPIOCSFLAGS): %m");
 }
 
 
@@ -722,7 +691,7 @@ ppp_set_xaccm(unit, accm)
     ext_accm accm;
 {
     if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
-       syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
+       warn("ioctl(set extended ACCM): %m");
 }
 
 
@@ -738,23 +707,15 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
 {
     int x;
 
-    if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
-       quit();
-    }
-    if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
-       quit();
-    }
-    if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
+       fatal("ioctl(PPPIOCSMRU): %m");
+    if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
+       fatal("ioctl(PPPIOCSRASYNCMAP): %m");
+    if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl (PPPIOCGFLAGS): %m");
     x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
-    if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
-       quit();
-    }
+    if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
+       fatal("ioctl(PPPIOCSFLAGS): %m");
 }
 
 /*
@@ -788,13 +749,13 @@ ccp_flags_set(unit, isopen, isup)
     int x;
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       error("ioctl (PPPIOCGFLAGS): %m");
        return;
     }
     x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
     x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
 }
 
 /*
@@ -809,7 +770,7 @@ ccp_fatal_error(unit)
     int x;
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+       error("ioctl(PPPIOCGFLAGS): %m");
        return 0;
     }
     return x & SC_DC_FERROR;
@@ -839,13 +800,13 @@ set_filters(pass, active)
 
     if (pass->bf_len > 0) {
        if (ioctl(ppp_fd, PPPIOCSPASS, pass) < 0) {
-           syslog(LOG_ERR, "Couldn't set pass-filter in kernel: %m");
+           error("Couldn't set pass-filter in kernel: %m");
            ret = 0;
        }
     }
     if (active->bf_len > 0) {
        if (ioctl(ppp_fd, PPPIOCSACTIVE, active) < 0) {
-           syslog(LOG_ERR, "Couldn't set active-filter in kernel: %m");
+           error("Couldn't set active-filter in kernel: %m");
            ret = 0;
        }
     }
@@ -863,17 +824,17 @@ sifvjcomp(u, vjcomp, cidcomp, maxcid)
     u_int x;
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       error("ioctl (PPPIOCGFLAGS): %m");
        return 0;
     }
     x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
     x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        return 0;
     }
     if (vjcomp && ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        return 0;
     }
     return 1;
@@ -890,12 +851,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+       error("ioctl(SIOCSIFFLAGS): %m");
        return 0;
     }
     if_is_up = 1;
@@ -916,7 +877,7 @@ sifnpmode(u, proto, mode)
     npi.protocol = proto;
     npi.mode = mode;
     if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -941,12 +902,12 @@ sifdown(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        rv = 0;
     } else {
        ifr.ifr_flags &= ~IFF_UP;
        if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-           syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+           error("ioctl(SIOCSIFFLAGS): %m");
            rv = 0;
        } else
            if_is_up = 0;
@@ -988,16 +949,14 @@ sifaddr(u, o, h, m)
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) {
        if (errno != EADDRNOTAVAIL)
-           syslog(LOG_WARNING, "Couldn't remove interface address: %m");
+           warn("Couldn't remove interface address: %m");
     }
     if (ioctl(sockfd, SIOCAIFADDR, (caddr_t) &ifra) < 0) {
        if (errno != EEXIST) {
-           syslog(LOG_ERR, "Couldn't set interface address: %m");
+           error("Couldn't set interface address: %m");
            return 0;
        }
-       syslog(LOG_WARNING,
-              "Couldn't set interface address: Address %s already exists",
-               ip_ntoa(o));
+       warn("Couldn't set interface address: Address %I already exists", o);
     }
     ifaddrs[0] = o;
     ifaddrs[1] = h;
@@ -1024,7 +983,7 @@ cifaddr(u, o, h)
     BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask));
     if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifra) < 0) {
        if (errno != EADDRNOTAVAIL)
-           syslog(LOG_WARNING, "Couldn't delete interface address: %m");
+           warn("Couldn't delete interface address: %m");
        return 0;
     }
     return 1;
@@ -1069,7 +1028,7 @@ dodefaultroute(g, cmd)
     } rtmsg;
 
     if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
-       syslog(LOG_ERR, "Couldn't %s default route: socket: %m",
+       error("Couldn't %s default route: socket: %m",
               cmd=='s'? "add": "delete");
        return 0;
     }
@@ -1090,7 +1049,7 @@ dodefaultroute(g, cmd)
 
     rtmsg.hdr.rtm_msglen = sizeof(rtmsg);
     if (write(routes, &rtmsg, sizeof(rtmsg)) < 0) {
-       syslog(LOG_ERR, "Couldn't %s default route: %m",
+       error("Couldn't %s default route: %m",
               cmd=='s'? "add": "delete");
        close(routes);
        return 0;
@@ -1128,12 +1087,12 @@ sifproxyarp(unit, hisaddr)
      */
     memset(&arpmsg, 0, sizeof(arpmsg));
     if (!get_ether_addr(hisaddr, &arpmsg.hwa)) {
-       syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+       error("Cannot determine ethernet address for proxy ARP");
        return 0;
     }
 
     if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
-       syslog(LOG_ERR, "Couldn't add proxy arp entry: socket: %m");
+       error("Couldn't add proxy arp entry: socket: %m");
        return 0;
     }
 
@@ -1151,7 +1110,7 @@ sifproxyarp(unit, hisaddr)
     arpmsg.hdr.rtm_msglen = (char *) &arpmsg.hwa - (char *) &arpmsg
        + arpmsg.hwa.sdl_len;
     if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
-       syslog(LOG_ERR, "Couldn't add proxy arp entry: %m");
+       error("Couldn't add proxy arp entry: %m");
        close(routes);
        return 0;
     }
@@ -1180,12 +1139,12 @@ cifproxyarp(unit, hisaddr)
     arpmsg.hdr.rtm_seq = ++rtm_seq;
 
     if ((routes = socket(PF_ROUTE, SOCK_RAW, AF_INET)) < 0) {
-       syslog(LOG_ERR, "Couldn't delete proxy arp entry: socket: %m");
+       error("Couldn't delete proxy arp entry: socket: %m");
        return 0;
     }
 
     if (write(routes, &arpmsg, arpmsg.hdr.rtm_msglen) < 0) {
-       syslog(LOG_ERR, "Couldn't delete proxy arp entry: %m");
+       error("Couldn't delete proxy arp entry: %m");
        close(routes);
        return 0;
     }
@@ -1218,7 +1177,7 @@ sifproxyarp(unit, hisaddr)
      * as our local address.
      */
     if (!get_ether_addr(hisaddr, &dls.sdl)) {
-       syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+       error("Cannot determine ethernet address for proxy ARP");
        return 0;
     }
 
@@ -1229,7 +1188,7 @@ sifproxyarp(unit, hisaddr)
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "Couldn't add proxy arp entry: %m");
+       error("Couldn't add proxy arp entry: %m");
        return 0;
     }
 
@@ -1251,7 +1210,7 @@ cifproxyarp(unit, hisaddr)
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_WARNING, "Couldn't delete proxy arp entry: %m");
+       warn("Couldn't delete proxy arp entry: %m");
        return 0;
     }
     proxy_arp_addr = 0;
@@ -1281,7 +1240,7 @@ get_ether_addr(ipaddr, hwaddr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+       error("ioctl(SIOCGIFCONF): %m");
        return 0;
     }
 
@@ -1320,7 +1279,7 @@ get_ether_addr(ipaddr, hwaddr)
 
     if (ifr >= ifend)
        return 0;
-    syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+    info("found interface %s for proxy arp", ifr->ifr_name);
 
     /*
      * Now scan through again looking for a link-level address
@@ -1376,7 +1335,7 @@ GetMask(addr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+       warn("ioctl(SIOCGIFCONF): %m");
        return mask;
     }
     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -1458,7 +1417,7 @@ lock(dev)
            /* Read the lock file to find out who has the device locked */
            n = read(fd, hdb_lock_buffer, 11);
            if (n <= 0) {
-               syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+               error("Can't read pid from lock file %s", lock_file);
                close(fd);
            } else {
                hdb_lock_buffer[n] = 0;
@@ -1467,25 +1426,25 @@ lock(dev)
                    /* pid no longer exists - remove the lock file */
                    if (unlink(lock_file) == 0) {
                        close(fd);
-                       syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+                       notice("Removed stale lock on %s (pid %d)",
                               dev, pid);
                        continue;
                    } else
-                       syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+                       warn("Couldn't remove stale lock on %s",
                               dev);
                } else
-                   syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+                   notice("Device %s is locked by pid %d",
                           dev, pid);
            }
            close(fd);
        } else
-           syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+           error("Can't create lock file %s: %m", lock_file);
        free(lock_file);
        lock_file = NULL;
        return -1;
     }
 
-    sprintf(hdb_lock_buffer, "%10d\n", getpid());
+    slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid());
     write(fd, hdb_lock_buffer, 11);
 
     close(fd);
index cba5e356ee5674e1b752e92b940ed14e22e4da6a..f11a9961a418056e3dba54c136f87f2e1d07e936 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-osf.c,v 1.18 1999/03/12 06:07:22 paulus Exp $";
+static char rcsid[] = "$Id: sys-osf.c,v 1.19 1999/03/16 02:57:06 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -46,7 +46,6 @@ static char rcsid[] = "$Id: sys-osf.c,v 1.18 1999/03/12 06:07:22 paulus Exp $";
 #include <sys/socket.h>
 #include <sys/stream.h>
 #include <sys/stropts.h>
-#include <sys/syslog.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/poll.h>
@@ -89,6 +88,10 @@ static u_int32_t ifaddrs[2]; /* local and remote addresses */
 static u_int32_t default_route_gateway;        /* Gateway for default route added */
 static u_int32_t proxy_arp_addr;       /* Addr for proxy arp entry added */
 
+#define MAX_POLLFDS    32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
 /* Prototypes for procedures local to this file. */
 static int translate_speed __P((int));
 static int baud_rate_of __P((int));
@@ -110,10 +113,8 @@ sys_init()
        setlogmask(LOG_UPTO(LOG_DEBUG));
 
     /* Get an internet socket for doing socket ioctl's on. */
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-       syslog(LOG_ERR, "Couldn't create IP socket: %m");
-       die(1);
-    }
+    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+       fatal("Couldn't create IP socket: %m");
 
     if (default_device)
        tty_sid = getsid((pid_t)0);
@@ -122,54 +123,42 @@ sys_init()
      * Open the ppp device.
      */
     pppfd = open("/dev/streams/ppp", O_RDWR | O_NONBLOCK, 0);
-    if (pppfd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/streams/ppp: %m");
-       die(1);
-    }
+    if (pppfd < 0)
+       fatal("Can't open /dev/streams/ppp: %m");
     if (kdebugflag) {
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
 
     /* Assign a new PPA and get its unit number. */
-    if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Can't create new PPP interface: %m");
-       die(1);
-    }
+    if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
+       fatal("Can't create new PPP interface: %m");
 
     /*
      * Open the ppp device again and push the if_ppp module on it.
      */
     iffd = open("/dev/streams/ppp", O_RDWR, 0);
-    if (iffd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/streams/ppp (2): %m");
-       die(1);
-    }
+    if (iffd < 0)
+       fatal("Can't open /dev/streams/ppp (2): %m");
     if (kdebugflag) {
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
-    if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't attach ppp interface to device: %m");
-       die(1);
-    }
-    if (ioctl(iffd, I_PUSH, "if_ppp") < 0) {
-       syslog(LOG_ERR, "Can't push ppp interface module: %m");
-       die(1);
-    }
+    if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0)
+       fatal("Couldn't attach ppp interface to device: %m");
+    if (ioctl(iffd, I_PUSH, "if_ppp") < 0)
+       fatal("Can't push ppp interface module: %m");
     if (kdebugflag) {
        x = PPPDBG_LOG + PPPDBG_IF;
        strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
-    if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't create ppp interface unit: %m");
-       die(1);
-    }
+    if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0)
+       fatal("Couldn't create ppp interface unit: %m");
     x = PPP_IP;
-    if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't bind ppp interface to IP SAP: %m");
-       die(1);
-    }
+    if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0)
+       fatal("Couldn't bind ppp interface to IP SAP: %m");
+
+    n_pollfds = 0;
 }
 
 /*
@@ -300,10 +289,10 @@ streamify(int fd)
     struct sigaction sa;
 
     if (streampipe(fdes) != 0)
-       syslog(LOG_ERR, "streampipe(): %m\n");
+       error("streampipe(): %m\n");
     else if (isastream(fdes[0]) == 1) {
        if ((fret=fork()) < 0) {
-           syslog(LOG_ERR, "fork(): %m\n");
+           error("fork(): %m\n");
        } else if (fret == 0) {
            /*  Process to forward things from pipe to tty  */
             sigemptyset(&(sa.sa_mask));
@@ -326,7 +315,7 @@ streamify(int fd)
                if (FD_ISSET(fd, &readfds)) {
                    rret = read(fd, buffer, BUFFSIZE);
                    if (rret == 0) {
-                       MAINDEBUG((LOG_DEBUG, "slave died:  EOF on tty."));
+                       SYSDEBUG(("slave died:  EOF on tty."));
                        exit(0);
                    } else {
                        write(fdes[1], buffer, rret);
@@ -335,7 +324,7 @@ streamify(int fd)
                if (FD_ISSET(fdes[1], &readfds)) {
                    rret = read(fdes[1], buffer, BUFFSIZE);
                    if (rret == 0) {
-                       MAINDEBUG((LOG_DEBUG, "slave died:  EOF on pipe."));
+                       SYSDEBUG(("slave died:  EOF on pipe."));
                        exit(0);
                    } else {
                        write(fd, buffer, rret);
@@ -362,10 +351,8 @@ establish_ppp(fd)
     int i;
 
     if (isastream(fd) != 1) {
-       if ((ttyfd = fd = streamify(fd)) < 0) {
-           syslog(LOG_ERR, "Couldn't get a STREAMS module!\n");
-           die(1);
-       }
+       if ((ttyfd = fd = streamify(fd)) < 0)
+           fatal("Couldn't get a STREAMS module!\n");
     }
 
     /* Pop any existing modules off the tty stream. */
@@ -373,32 +360,24 @@ establish_ppp(fd)
        if (ioctl(fd, I_LOOK, tty_modules[i]) < 0
            || ioctl(fd, I_POP, 0) < 0)
            break;
-        syslog(LOG_ERR, "popping module %s\n", tty_modules[i]);
+        error("popping module %s\n", tty_modules[i]);
     }
 
     tty_nmodules = i;
 
     /* Push the async hdlc module and the compressor module. */
-    if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
-       syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
-       die(1);
-    }
-    if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
-       syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
-/*     die(1); */
-    }
+    if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0)
+       fatal("Couldn't push PPP Async HDLC module: %m");
+    if (ioctl(fd, I_PUSH, "ppp_comp") < 0)
+       error("Couldn't push PPP compression module: %m");
 
     /* read mode, message non-discard mode */
-    if (ioctl(fd, I_SRDOPT, RMSGN|RPROTNORM) < 0) {
-        syslog(LOG_ERR, "ioctl(I_SRDOPT, RMSGN): %m");
-        die(1);
-    }
+    if (ioctl(fd, I_SRDOPT, RMSGN|RPROTNORM) < 0)
+        fatal("ioctl(I_SRDOPT, RMSGN): %m");
 
     /* Link the serial port under the PPP multiplexor. */
-    if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
-       syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
-       die(1);
-    }
+    if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0)
+       fatal("Can't link tty to PPP mux: %m");
 
     /* close stdin, stdout, stderr if they might refer to the device */
     if (default_device && !closed_stdio) {
@@ -415,7 +394,7 @@ establish_ppp(fd)
      */
     if ((initfdflags = fcntl(fd, F_GETFL)) == -1
         || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
-        syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+        warn("Couldn't set device to non-blocking mode: %m");
     }
 }
 
@@ -442,13 +421,13 @@ disestablish_ppp(fd)
     if (fdmuxid >= 0) {
        if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
            if (!hungup)
-               syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
+               error("Can't unlink tty from PPP mux: %m");
        }
        fdmuxid = -1;
 
         /* Reset non-blocking mode on the file descriptor. */
         if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
-            syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+            warn("Couldn't restore device fd flags: %m");
         initfdflags = -1;
 
        if (!hungup) {
@@ -456,7 +435,7 @@ disestablish_ppp(fd)
                ;
            for (i = tty_nmodules - 1; i >= 0; --i)
                if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
-                   syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
+                   error("Couldn't restore tty module %s: %m",
                           tty_modules[i]);
        }
 
@@ -468,9 +447,9 @@ disestablish_ppp(fd)
             * seen the M_HANGUP message (it went up through the ppp
             * driver to the stream head for our fd to /dev/ppp).
             */
-           syslog(LOG_DEBUG, "sending hangup to %d", tty_sid);
+           dbglog("sending hangup to %d", tty_sid);
            if (kill(tty_sid, SIGHUP) < 0)
-               syslog(LOG_ERR, "couldn't kill pgrp: %m");
+               error("couldn't kill pgrp: %m");
        }
        if (orig_ttyfd >= 0) {
            close(fd);
@@ -508,8 +487,8 @@ clean_check()
        break;
     }
     if (s != NULL) {
-       syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-       syslog(LOG_WARNING, "All received characters had %s", s);
+       warn("Serial link is not 8-bit clean:");
+       warn("All received characters had %s", s);
     }
 }
 
@@ -602,7 +581,7 @@ translate_speed(bps)
     for (speedp = speeds; speedp->speed_int; speedp++)
        if (bps == speedp->speed_int)
            return speedp->speed_val;
-    syslog(LOG_WARNING, "speed %d not supported", bps);
+    warn("speed %d not supported", bps);
     return 0;
 }
 
@@ -635,10 +614,8 @@ set_up_tty(fd, local)
     int speed;
     struct termios tios;
 
-    if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
-       die(1);
-    }
+    if (tcgetattr(fd, &tios) < 0)
+       fatal("tcgetattr: %m");
 
     if (!restore_term) {
        inittermios = tios;
@@ -676,17 +653,12 @@ set_up_tty(fd, local)
         * We can't proceed if the serial port speed is 0,
         * since that implies that the serial port is disabled.
         */
-       if (speed == B0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
-                  devnam);
-           die(1);
-       }
+       if (speed == B0)
+           fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
 
-    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
-       die(1);
-    }
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+       fatal("tcsetattr: %m");
 
     baud_rate = inspeed = baud_rate_of(speed);
     restore_term = 1;
@@ -711,7 +683,7 @@ restore_tty(fd)
        }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (!hungup && errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
        ioctl(fd, TIOCSWINSZ, &wsinfo);
        restore_term = 0;
     }
@@ -754,7 +726,7 @@ output(unit, p, len)
     struct pollfd pfd;
 
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     data.len = len;
     data.buf = (caddr_t) p;
@@ -762,7 +734,7 @@ output(unit, p, len)
     while (putmsg(pppfd, NULL, &data, 0) < 0) {
        if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
            if (errno != ENXIO)
-               syslog(LOG_ERR, "Couldn't send packet: %m");
+               error("Couldn't send packet: %m");
            break;
        }
        pfd.fd = pppfd;
@@ -782,17 +754,48 @@ wait_input(timo)
     struct timeval *timo;
 {
     int t;
-    struct pollfd pfd;
 
     t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
-    pfd.fd = pppfd;
-    pfd.events = POLLIN | POLLPRI | POLLHUP;
-    if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "poll: %m");
-       die(1);
+    if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+       fatal("poll: %m");
+}
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n)
+       if (pollfds[n].fd == fd)
+           return;
+    if (n_pollfds < MAX_POLLFDS) {
+       pollfds[n_pollfds].fd = fd;
+       pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+       ++n_pollfds;
+    } else
+       error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n) {
+       if (pollfds[n].fd == fd) {
+           while (++n < n_pollfds)
+               pollfds[n-1] = pollfds[n];
+           --n_pollfds;
+           break;
+       }
     }
 }
 
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -816,12 +819,10 @@ wait_time(timo)
     int n;
 
     n = select(0, NULL, NULL, NULL, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
-
+#endif
 
 /*
  * read_packet - get a PPP packet from the serial device.
@@ -844,8 +845,7 @@ read_packet(buf)
        if (len < 0) {
            if (errno = EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
                return -1;
-           syslog(LOG_ERR, "Error reading packet: %m");
-           die(1);
+           fatal("Error reading packet: %m");
        }
 
        if (ctrl.len <= 0)
@@ -855,7 +855,7 @@ read_packet(buf)
         * Got a M_PROTO or M_PCPROTO message.  Huh?
         */
        if (debug)
-           syslog(LOG_DEBUG, "got ctrl msg len=%d", ctrl.len);
+           dbglog("got ctrl msg len=%d", ctrl.len);
 
     }
 }
@@ -894,15 +894,15 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
        if (hungup && errno == ENXIO)
            return;
-       syslog(LOG_ERR, "Couldn't set MTU: %m");
+       error("Couldn't set MTU: %m");
     }
     if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
+       error("Couldn't set transmit ACCM: %m");
     }
     cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
     cf[1] = COMP_PROT | COMP_AC;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
+       error("Couldn't set prot/AC compression: %m");
     }
 }
 
@@ -916,7 +916,7 @@ ppp_set_xaccm(unit, accm)
 {
     if (strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
        if (!hungup || errno != ENXIO)
-           syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
+           warn("Couldn't set extended ACCM: %m");
     }
 }
 
@@ -936,15 +936,15 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
        if (hungup && errno == ENXIO)
            return;
-       syslog(LOG_ERR, "Couldn't set MRU: %m");
+       error("Couldn't set MRU: %m");
     }
     if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
+       error("Couldn't set receive ACCM: %m");
     }
     cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
     cf[1] = DECOMP_PROT | DECOMP_AC;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
+       error("Couldn't set prot/AC decompression: %m");
     }
 }
 
@@ -986,7 +986,7 @@ ccp_test(unit, opt_ptr, opt_len, for_transmit)
         wait_time(&tval);
     }
     if (errno != 0)
-       syslog(LOG_ERR, "hard failure trying to get memory for a compressor: %m");
+       error("hard failure trying to get memory for a compressor: %m");
     return (errno == ENOSR)? 0: -1;
 }
 
@@ -1003,7 +1003,7 @@ ccp_flags_set(unit, isopen, isup)
     cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (!hungup || errno != ENXIO)
-           syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
+           error("Couldn't set kernel CCP state: %m");
     }
 }
 
@@ -1033,7 +1033,7 @@ ccp_fatal_error(unit)
     cf[0] = cf[1] = 0;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (errno != ENXIO && errno != EINVAL)
-           syslog(LOG_ERR, "Couldn't get compression flags: %m");
+           error("Couldn't get compression flags: %m");
        return 0;
     }
     return cf[0] & CCP_FATALERROR;
@@ -1053,7 +1053,7 @@ sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
        maxcid[0] = xcidcomp;
        maxcid[1] = 15;         /* XXX should be rmaxcid */
        if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
+           error("Couldn't initialize VJ compression: %m");
        }
     }
 
@@ -1062,7 +1062,7 @@ sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
     cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (vjcomp)
-           syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
+           error("Couldn't enable VJ compression: %m");
     }
 
     return 1;
@@ -1079,12 +1079,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
+       error("Couldn't mark interface up (get): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
+       error("Couldn't mark interface up (set): %m");
        return 0;
     }
     if_is_up = 1;
@@ -1102,13 +1102,13 @@ sifdown(u)
 
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
+       error("Couldn't mark interface down (get): %m");
        return 0;
     }
     if ((ifr.ifr_flags & IFF_UP) != 0) {
        ifr.ifr_flags &= ~IFF_UP;
        if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
-           syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
+           error("Couldn't mark interface down (set): %m");
            return 0;
        }
     }
@@ -1130,7 +1130,7 @@ sifnpmode(u, proto, mode)
     npi[0] = proto;
     npi[1] = (int) mode;
     if (strioctl(pppfd, PPPIO_NPMODE, npi, 2 * sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -1168,7 +1168,7 @@ sifaddr(u, o, h, m)
     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
     if ((ioctl(sockfd, (int)SIOCDIFADDR, (caddr_t) &ifr) < 0)
         && errno != EADDRNOTAVAIL) {
-        syslog(LOG_ERR, "ioctl(SIOCDIFADDR): %m");
+        error("ioctl(SIOCDIFADDR): %m");
         ret = 0;
     }
 
@@ -1182,19 +1182,19 @@ sifaddr(u, o, h, m)
     if (m != 0) {
         ((struct sockaddr_in *)&addreq.ifra_mask)->sin_addr.s_addr = m;
         addreq.ifra_mask.sa_len = sizeof (struct sockaddr);
-        syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+        info("Setting interface mask to %s\n", ip_ntoa(m));
     }
 
     /* install new src/dst and (possibly) netmask
      */
     if (ioctl(sockfd, SIOCPIFADDR, &addreq) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCPIFADDR): %m");
+        error("ioctl(SIOCPIFADDR): %m");
         ret = 0;
     }
 
     ifr.ifr_metric = link_mtu;
     if (ioctl(sockfd, SIOCSIPMTU, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+       error("Couldn't set IP MTU: %m");
         ret = 0;
     }
 
@@ -1222,7 +1222,7 @@ cifaddr(u, o, h)
     SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
     if (ioctl(sockfd, (int)SIOCDIFADDR, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCDIFADDR): %m");
+        error("ioctl(SIOCDIFADDR): %m");
         return 0;
     }
     return 1;
@@ -1245,7 +1245,7 @@ sifdefaultroute(u, l, g)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, (int)SIOCADDRT, &rt) < 0) {
-        syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
+        error("default route ioctl(SIOCADDRT): %m");
         return 0;
     }
     default_route_gateway = g;
@@ -1269,7 +1269,7 @@ cifdefaultroute(u, l, g)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, (int)SIOCDELRT, &rt) < 0) {
-        syslog(LOG_ERR, "default route ioctl(SIOCDELRT): %m");
+        error("default route ioctl(SIOCDELRT): %m");
         return 0;
     }
     default_route_gateway = 0;
@@ -1293,7 +1293,7 @@ sifproxyarp(unit, hisaddr)
      * as our local address.
      */
     if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
-        syslog(LOG_WARNING, "Cannot determine ethernet address for proxy ARP");
+        warn("Cannot determine ethernet address for proxy ARP");
         return 0;
     }
 
@@ -1301,7 +1301,7 @@ sifproxyarp(unit, hisaddr)
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(sockfd, (int)SIOCSARP, (caddr_t)&arpreq) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
+        error("ioctl(SIOCSARP): %m");
         return 0;
     }
 
@@ -1324,7 +1324,7 @@ cifproxyarp(unit, hisaddr)
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     if (ioctl(sockfd, (int)SIOCDARP, (caddr_t)&arpreq) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCDARP): %m");
+        error("ioctl(SIOCDARP): %m");
         return 0;
     }
     proxy_arp_addr = 0;
@@ -1352,7 +1352,7 @@ get_ether_addr(ipaddr, hwaddr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+       error("ioctl(SIOCGIFCONF): %m");
        return 0;
     }
 
@@ -1395,7 +1395,7 @@ get_ether_addr(ipaddr, hwaddr)
 
     if (ifr >= ifend)
        return 0;
-    syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+    info("found interface %s for proxy arp", ifr->ifr_name);
 
     strlcpy(ifdevreq.ifr_name, sizeof(ifdevreq.ifr_name), ifr->ifr_name);
 
@@ -1466,7 +1466,7 @@ GetMask(addr)
     if (ifc.ifc_req == 0)
        return mask;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+       warn("Couldn't get system interface list: %m");
        return mask;
     }
     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -1582,7 +1582,7 @@ strioctl(fd, cmd, ptr, ilen, olen)
     if (ioctl(fd, I_STR, &str) == -1)
        return -1;
     if (str.ic_len != olen)
-       syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
+       dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
               olen, str.ic_len, cmd);
     return 0;
 }
@@ -1650,33 +1650,33 @@ lock(dev)
            n = read(fd, &pid, sizeof(pid));
 #endif
            if (n <= 0) {
-               syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+               error("Can't read pid from lock file %s", lock_file);
                close(fd);
            } else {
                if (kill(pid, 0) == -1 && errno == ESRCH) {
                    /* pid no longer exists - remove the lock file */
                    if (unlink(lock_file) == 0) {
                        close(fd);
-                       syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+                       notice("Removed stale lock on %s (pid %d)",
                               dev, pid);
                        continue;
                    } else
-                       syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+                       warn("Couldn't remove stale lock on %s",
                               dev);
                } else
-                   syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+                   notice("Device %s is locked by pid %d",
                           dev, pid);
            }
            close(fd);
        } else
-           syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+           error("Can't create lock file %s: %m", lock_file);
        free(lock_file);
        lock_file = NULL;
        return -1;
     }
 
 #ifdef PIDSTRING
-    sprintf(hdb_lock_buffer, "%10d\n", getpid());
+    slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid());
     write(fd, hdb_lock_buffer, 11);
 #else
     pid = getpid();
index 9e84b7e6260917397951e6ae525476eadccdb812..b0d0eaaf8ef21149abd7b60b920fead6ae1d65b7 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-sunos4.c,v 1.13 1999/03/12 06:07:23 paulus Exp $";
+static char rcsid[] = "$Id: sys-sunos4.c,v 1.14 1999/03/16 02:57:07 paulus Exp $";
 #endif
 
 #include <stdio.h>
@@ -47,7 +47,6 @@ static char rcsid[] = "$Id: sys-sunos4.c,v 1.13 1999/03/12 06:07:23 paulus Exp $
 #include <sys/sockio.h>
 #include <sys/stream.h>
 #include <sys/stropts.h>
-#include <sys/syslog.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/poll.h>
@@ -80,6 +79,10 @@ static pid_t parent_pid;     /* PID of our parent */
 
 extern u_char  inpacket_buf[]; /* borrowed from main.c */
 
+#define MAX_POLLFDS    32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
 static int     link_mtu, link_mru;
 
 #define NMODULES       32
@@ -107,10 +110,8 @@ sys_init()
     int x;
 
     /* Get an internet socket for doing socket ioctl's on. */
-    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-       syslog(LOG_ERR, "Couldn't create IP socket: %m");
-       die(1);
-    }
+    if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
+       fatal("Couldn't create IP socket: %m");
 
     /*
      * We may want to send a SIGHUP to the session leader associated
@@ -124,54 +125,42 @@ sys_init()
      * Open the ppp device.
      */
     pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
-    if (pppfd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/ppp: %m");
-       die(1);
-    }
+    if (pppfd < 0)
+       fatal("Can't open /dev/ppp: %m");
     if (kdebugflag) {
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
 
     /* Assign a new PPA and get its unit number. */
-    if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Can't create new PPP interface: %m");
-       die(1);
-    }
+    if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
+       fatal("Can't create new PPP interface: %m");
 
     /*
      * Open the ppp device again and push the if_ppp module on it.
      */
     iffd = open("/dev/ppp", O_RDWR, 0);
-    if (iffd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
-       die(1);
-    }
+    if (iffd < 0)
+       fatal("Can't open /dev/ppp (2): %m");
     if (kdebugflag) {
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
-    if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't attach ppp interface to device: %m");
-       die(1);
-    }
-    if (ioctl(iffd, I_PUSH, "if_ppp") < 0) {
-       syslog(LOG_ERR, "Can't push ppp interface module: %m");
-       die(1);
-    }
+    if (strioctl(iffd, PPPIO_ATTACH, &ifunit, sizeof(int), 0) < 0)
+       fatal("Couldn't attach ppp interface to device: %m");
+    if (ioctl(iffd, I_PUSH, "if_ppp") < 0)
+       fatal("Can't push ppp interface module: %m");
     if (kdebugflag) {
        x = PPPDBG_LOG + PPPDBG_IF;
        strioctl(iffd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
-    if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't create ppp interface unit: %m");
-       die(1);
-    }
+    if (strioctl(iffd, PPPIO_NEWPPA, &ifunit, sizeof(int), 0) < 0)
+       fatal("Couldn't create ppp interface unit: %m");
     x = PPP_IP;
-    if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't bind ppp interface to IP SAP: %m");
-       die(1);
-    }
+    if (strioctl(iffd, PPPIO_BIND, &x, sizeof(int), 0) < 0)
+       fatal("Couldn't bind ppp interface to IP SAP: %m");
+
+    n_pollfds = 0;
 }
 
 /*
@@ -265,20 +254,14 @@ establish_ppp(fd)
     tty_nmodules = i;
 
     /* Push the async hdlc module and the compressor module. */
-    if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
-       syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
-       die(1);
-    }
-    if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
-       syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
-/*     die(1); */
-    }
+    if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0)
+       fatal("Couldn't push PPP Async HDLC module: %m");
+    if (ioctl(fd, I_PUSH, "ppp_comp") < 0)
+       error("Couldn't push PPP compression module: %m");
 
     /* Link the serial port under the PPP multiplexor. */
-    if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
-       syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
-       die(1);
-    }
+    if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0)
+       fatal("Can't link tty to PPP mux: %m");
 }
 
 /*
@@ -304,7 +287,7 @@ disestablish_ppp(fd)
     if (fdmuxid >= 0) {
        if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
            if (!hungup)
-               syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
+               error("Can't unlink tty from PPP mux: %m");
        }
        fdmuxid = -1;
 
@@ -313,7 +296,7 @@ disestablish_ppp(fd)
                ;
            for (i = tty_nmodules - 1; i >= 0; --i)
                if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
-                   syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
+                   error("Couldn't restore tty module %s: %m",
                           tty_modules[i]);
        }
        if (hungup && default_device && parent_pid > 0) {
@@ -358,8 +341,8 @@ clean_check()
        break;
     }
     if (s != NULL) {
-       syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-       syslog(LOG_WARNING, "All received characters had %s", s);
+       warn("Serial link is not 8-bit clean:");
+       warn("All received characters had %s", s);
     }
 }
 
@@ -452,7 +435,7 @@ translate_speed(bps)
     for (speedp = speeds; speedp->speed_int; speedp++)
        if (bps == speedp->speed_int)
            return speedp->speed_val;
-    syslog(LOG_WARNING, "speed %d not supported", bps);
+    warn("speed %d not supported", bps);
     return 0;
 }
 
@@ -485,10 +468,8 @@ set_up_tty(fd, local)
     int speed;
     struct termios tios;
 
-    if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
-       die(1);
-    }
+    if (tcgetattr(fd, &tios) < 0)
+       fatal("tcgetattr: %m");
 
     if (!restore_term) {
        inittermios = tios;
@@ -526,17 +507,12 @@ set_up_tty(fd, local)
         * We can't proceed if the serial port speed is 0,
         * since that implies that the serial port is disabled.
         */
-       if (speed == B0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
-                  devnam);
-           die(1);
-       }
+       if (speed == B0)
+           fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
 
-    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
-       die(1);
-    }
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+       fatal("tcsetattr: %m");
 
     baud_rate = inspeed = baud_rate_of(speed);
     restore_term = 1;
@@ -561,7 +537,7 @@ restore_tty(fd)
        }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (!hungup && errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
        ioctl(fd, TIOCSWINSZ, &wsinfo);
        restore_term = 0;
     }
@@ -604,7 +580,7 @@ output(unit, p, len)
     struct pollfd pfd;
 
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     data.len = len;
     data.buf = (caddr_t) p;
@@ -612,7 +588,7 @@ output(unit, p, len)
     while (putmsg(pppfd, NULL, &data, 0) < 0) {
        if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
            if (errno != ENXIO)
-               syslog(LOG_ERR, "Couldn't send packet: %m");
+               error("Couldn't send packet: %m");
            break;
        }
        pfd.fd = pppfd;
@@ -623,7 +599,7 @@ output(unit, p, len)
 
 
 /*
- * wait_input - wait until there is data available on fd,
+ * wait_input - wait until there is data available,
  * for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
@@ -632,15 +608,10 @@ wait_input(timo)
     struct timeval *timo;
 {
     int t;
-    struct pollfd pfd;
 
     t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
-    pfd.fd = pppfd;
-    pfd.events = POLLIN | POLLPRI | POLLHUP;
-    if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "poll: %m");
-       die(1);
-    }
+    if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+       fatal("poll: %m");
 }
 
 /*
@@ -666,10 +637,8 @@ wait_time(timo)
     int n;
 
     n = select(0, NULL, NULL, NULL, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
 
 
@@ -694,8 +663,7 @@ read_packet(buf)
        if (len < 0) {
            if (errno = EAGAIN || errno == EINTR)
                return -1;
-           syslog(LOG_ERR, "Error reading packet: %m");
-           die(1);
+           fatal("Error reading packet: %m");
        }
 
        if (ctrl.len <= 0)
@@ -705,7 +673,7 @@ read_packet(buf)
         * Got a M_PROTO or M_PCPROTO message.  Huh?
         */
        if (debug)
-           syslog(LOG_DEBUG, "got ctrl msg len=%d", ctrl.len);
+           dbglog("got ctrl msg len=%d", ctrl.len);
 
     }
 }
@@ -745,15 +713,15 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
        if (hungup && errno == ENXIO)
            return;
-       syslog(LOG_ERR, "Couldn't set MTU: %m");
+       error("Couldn't set MTU: %m");
     }
     if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
+       error("Couldn't set transmit ACCM: %m");
     }
     cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
     cf[1] = COMP_PROT | COMP_AC;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
+       error("Couldn't set prot/AC compression: %m");
     }
 
     /* set mtu for ip as well */
@@ -761,7 +729,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     ifr.ifr_metric = link_mtu;
     if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+       error("Couldn't set IP MTU: %m");
     }
 }
 
@@ -775,7 +743,7 @@ ppp_set_xaccm(unit, accm)
 {
     if (strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
        if (!hungup || errno != ENXIO)
-           syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
+           warn("Couldn't set extended ACCM: %m");
     }
 }
 
@@ -795,15 +763,15 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
        if (hungup && errno == ENXIO)
            return;
-       syslog(LOG_ERR, "Couldn't set MRU: %m");
+       error("Couldn't set MRU: %m");
     }
     if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
-       syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
+       error("Couldn't set receive ACCM: %m");
     }
     cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
     cf[1] = DECOMP_PROT | DECOMP_AC;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
+       error("Couldn't set prot/AC decompression: %m");
     }
 }
 
@@ -835,7 +803,7 @@ ccp_flags_set(unit, isopen, isup)
     cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (!hungup || errno != ENXIO)
-           syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
+           error("Couldn't set kernel CCP state: %m");
     }
 }
 
@@ -865,7 +833,7 @@ ccp_fatal_error(unit)
     cf[0] = cf[1] = 0;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (errno != ENXIO && errno != EINVAL)
-           syslog(LOG_ERR, "Couldn't get compression flags: %m");
+           error("Couldn't get compression flags: %m");
        return 0;
     }
     return cf[0] & CCP_FATALERROR;
@@ -885,7 +853,7 @@ sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
        maxcid[0] = xcidcomp;
        maxcid[1] = 15;         /* XXX should be rmaxcid */
        if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
+           error("Couldn't initialize VJ compression: %m");
        }
     }
 
@@ -894,7 +862,7 @@ sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
     cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (vjcomp)
-           syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
+           error("Couldn't enable VJ compression: %m");
     }
 
     return 1;
@@ -911,12 +879,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
+       error("Couldn't mark interface up (get): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
+       error("Couldn't mark interface up (set): %m");
        return 0;
     }
     if_is_up = 1;
@@ -934,13 +902,13 @@ sifdown(u)
 
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
+       error("Couldn't mark interface down (get): %m");
        return 0;
     }
     if ((ifr.ifr_flags & IFF_UP) != 0) {
        ifr.ifr_flags &= ~IFF_UP;
        if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
-           syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
+           error("Couldn't mark interface down (set): %m");
            return 0;
        }
     }
@@ -962,7 +930,7 @@ sifnpmode(u, proto, mode)
     npi[0] = proto;
     npi[1] = (int) mode;
     if (strioctl(pppfd, PPPIO_NPMODE, npi, 2 * sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -985,22 +953,22 @@ sifaddr(u, o, h, m)
     ifr.ifr_addr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_addr) = m;
     if (ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP netmask: %m");
+       error("Couldn't set IP netmask: %m");
     }
     ifr.ifr_addr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_addr) = o;
     if (ioctl(sockfd, SIOCSIFADDR, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set local IP address: %m");
+       error("Couldn't set local IP address: %m");
     }
     ifr.ifr_dstaddr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_dstaddr) = h;
     if (ioctl(sockfd, SIOCSIFDSTADDR, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set remote IP address: %m");
+       error("Couldn't set remote IP address: %m");
     }
 #if 0  /* now done in ppp_send_config */
     ifr.ifr_metric = link_mtu;
     if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+       error("Couldn't set IP MTU: %m");
     }
 #endif
     ifaddrs[0] = o;
@@ -1027,7 +995,7 @@ cifaddr(u, o, h)
     INET_ADDR(rt.rt_gateway) = o;
     rt.rt_flags = RTF_HOST;
     if (ioctl(sockfd, SIOCDELRT, &rt) < 0)
-       syslog(LOG_ERR, "Couldn't delete route through interface: %m");
+       error("Couldn't delete route through interface: %m");
     ifaddrs[0] = 0;
     return 1;
 }
@@ -1050,7 +1018,7 @@ sifdefaultroute(u, l, g)
     rt.rt_flags = RTF_GATEWAY;
 
     if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
-       syslog(LOG_ERR, "Can't add default route: %m");
+       error("Can't add default route: %m");
        return 0;
     }
 
@@ -1076,7 +1044,7 @@ cifdefaultroute(u, l, g)
     rt.rt_flags = RTF_GATEWAY;
 
     if (ioctl(sockfd, SIOCDELRT, &rt) < 0) {
-       syslog(LOG_ERR, "Can't delete default route: %m");
+       error("Can't delete default route: %m");
        return 0;
     }
 
@@ -1102,7 +1070,7 @@ sifproxyarp(unit, hisaddr)
     INET_ADDR(arpreq.arp_pa) = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(sockfd, SIOCSARP, (caddr_t) &arpreq) < 0) {
-       syslog(LOG_ERR, "Couldn't set proxy ARP entry: %m");
+       error("Couldn't set proxy ARP entry: %m");
        return 0;
     }
 
@@ -1124,7 +1092,7 @@ cifproxyarp(unit, hisaddr)
     arpreq.arp_pa.sa_family = AF_INET;
     INET_ADDR(arpreq.arp_pa) = hisaddr;
     if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "Couldn't delete proxy ARP entry: %m");
+       error("Couldn't delete proxy ARP entry: %m");
        return 0;
     }
 
@@ -1153,7 +1121,7 @@ get_ether_addr(ipaddr, hwaddr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+       error("ioctl(SIOCGIFCONF): %m");
        return 0;
     }
 
@@ -1194,19 +1162,19 @@ get_ether_addr(ipaddr, hwaddr)
 
     if (ifr >= ifend)
        return 0;
-    syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+    info("found interface %s for proxy arp", ifr->ifr_name);
 
     /*
      * Grab the physical address for this interface.
      */
     if ((nit_fd = open("/dev/nit", O_RDONLY)) < 0) {
-       syslog(LOG_ERR, "Couldn't open /dev/nit: %m");
+       error("Couldn't open /dev/nit: %m");
        return 0;
     }
     strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name);
     if (ioctl(nit_fd, NIOCBIND, &ifreq) < 0
        || ioctl(nit_fd, SIOCGIFADDR, &ifreq) < 0) {
-       syslog(LOG_ERR, "Couldn't get hardware address for %s: %m",
+       error("Couldn't get hardware address for %s: %m",
               ifreq.ifr_name);
        close(nit_fd);
        return 0;
@@ -1287,7 +1255,7 @@ GetMask(addr)
     if (ifc.ifc_req == 0)
        return mask;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+       warn("Couldn't get system interface list: %m");
        return mask;
     }
     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -1334,7 +1302,7 @@ strioctl(fd, cmd, ptr, ilen, olen)
     if (ioctl(fd, I_STR, &str) == -1)
        return -1;
     if (str.ic_len != olen)
-       syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
+       dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
               olen, str.ic_len, cmd);
     return 0;
 }
@@ -1402,33 +1370,33 @@ lock(dev)
            n = read(fd, &pid, sizeof(pid));
 #endif
            if (n <= 0) {
-               syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+               error("Can't read pid from lock file %s", lock_file);
                close(fd);
            } else {
                if (kill(pid, 0) == -1 && errno == ESRCH) {
                    /* pid no longer exists - remove the lock file */
                    if (unlink(lock_file) == 0) {
                        close(fd);
-                       syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+                       notice("Removed stale lock on %s (pid %d)",
                               dev, pid);
                        continue;
                    } else
-                       syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+                       warn("Couldn't remove stale lock on %s",
                               dev);
                } else
-                   syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+                   notice("Device %s is locked by pid %d",
                           dev, pid);
            }
            close(fd);
        } else
-           syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+           error("Can't create lock file %s: %m", lock_file);
        free(lock_file);
        lock_file = NULL;
        return -1;
     }
 
 #ifdef PIDSTRING
-    sprintf(hdb_lock_buffer, "%10d\n", getpid());
+    slprintf(hdb_lock_buffer, sizeof(hdb_lock_buffer), "%10d\n", getpid());
     write(fd, hdb_lock_buffer, 11);
 #else
     pid = getpid();
@@ -1477,6 +1445,6 @@ strerror(n)
 
     if (n > 0 && n < sys_nerr)
        return sys_errlist[n];
-    sprintf(unknown, "Error %d", n);
+    slprintf(unknown, sizeof(unknown), "Error %d", n);
     return unknown;
 }
index 4173e4d2f4c246e81431403960c3929ad0689d80..efaaef02151b783d02224f5a11fa53ba65980a02 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-svr4.c,v 1.24 1999/03/12 06:07:23 paulus Exp $";
+static char rcsid[] = "$Id: sys-svr4.c,v 1.25 1999/03/16 02:57:07 paulus Exp $";
 #endif
 
 #include <limits.h>
@@ -49,7 +49,6 @@ static char rcsid[] = "$Id: sys-svr4.c,v 1.24 1999/03/12 06:07:23 paulus Exp $";
 #include <sys/stropts.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
-#include <sys/syslog.h>
 #include <sys/sysmacros.h>
 #include <sys/systeminfo.h>
 #include <sys/dlpi.h>
@@ -84,6 +83,10 @@ static pid_t tty_sid;        /* original session ID for terminal */
 
 extern u_char  inpacket_buf[]; /* borrowed from main.c */
 
+#define MAX_POLLFDS    32
+static struct pollfd pollfds[MAX_POLLFDS];
+static int n_pollfds;
+
 static int     link_mtu, link_mru;
 
 #define NMODULES       32
@@ -122,29 +125,23 @@ sys_init()
 #endif
 
     ipfd = open("/dev/ip", O_RDWR, 0);
-    if (ipfd < 0) {
-       syslog(LOG_ERR, "Couldn't open IP device: %m");
-       die(1);
-    }
+    if (ipfd < 0)
+       fatal("Couldn't open IP device: %m");
 
     if (default_device)
        tty_sid = getsid((pid_t)0);
 
     pppfd = open("/dev/ppp", O_RDWR | O_NONBLOCK, 0);
-    if (pppfd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/ppp: %m");
-       die(1);
-    }
+    if (pppfd < 0)
+       fatal("Can't open /dev/ppp: %m");
     if (kdebugflag & 1) {
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(pppfd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
 
     /* Assign a new PPA and get its unit number. */
-    if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0) {
-       syslog(LOG_ERR, "Can't create new PPP interface: %m");
-       die(1);
-    }
+    if (strioctl(pppfd, PPPIO_NEWPPA, &ifunit, 0, sizeof(int)) < 0)
+       fatal("Can't create new PPP interface: %m");
 
     /*
      * Open the ppp device again and link it under the ip multiplexor.
@@ -152,44 +149,38 @@ sys_init()
      * I don't know any way to be certain they will be the same. :-(
      */
     ifd = open("/dev/ppp", O_RDWR, 0);
-    if (ifd < 0) {
-       syslog(LOG_ERR, "Can't open /dev/ppp (2): %m");
-       die(1);
-    }
+    if (ifd < 0)
+       fatal("Can't open /dev/ppp (2): %m");
     if (kdebugflag & 1) {
        x = PPPDBG_LOG + PPPDBG_DRIVER;
        strioctl(ifd, PPPIO_DEBUG, &x, sizeof(int), 0);
     }
 #ifdef sun
     if (ioctl(ifd, I_PUSH, "ip") < 0) {
-       syslog(LOG_ERR, "Can't push IP module: %m");
        close(ifd);
-       die(1);
+       fatal("Can't push IP module: %m");
     }
 #else
     if (dlpi_attach(ifd, ifunit) < 0 ||
        dlpi_get_reply(ifd, &reply.prim, DL_OK_ACK, sizeof(reply)) < 0) {
-       syslog(LOG_ERR, "Can't attach to ppp%d: %m", ifunit);
        close(ifd);
-       die(1);
+       fatal("Can't attach to ppp%d: %m", ifunit);
     }
 #endif
     ipmuxid = ioctl(ipfd, I_LINK, ifd);
     close(ifd);
-    if (ipmuxid < 0) {
-       syslog(LOG_ERR, "Can't link PPP device to IP: %m");
-       die(1);
-    }
+    if (ipmuxid < 0)
+       fatal("Can't link PPP device to IP: %m");
 
 #ifndef sun
     /* Set the interface name for the link. */
-    (void) sprintf (ifr.ifr_name, "ppp%d", ifunit);
+    slprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "ppp%d", ifunit);
     ifr.ifr_metric = ipmuxid;
-    if (strioctl(ipfd, SIOCSIFNAME, (char *)&ifr, sizeof ifr, 0) < 0) {
-       syslog(LOG_ERR, "Can't set interface name %s: %m", ifr.ifr_name);
-       die(1);
-    }
+    if (strioctl(ipfd, SIOCSIFNAME, (char *)&ifr, sizeof ifr, 0) < 0)
+       fatal("Can't set interface name %s: %m", ifr.ifr_name);
 #endif
+
+    n_pollfds = 0;
 }
 
 /*
@@ -283,28 +274,22 @@ establish_ppp(fd)
     tty_nmodules = i;
 
     /* Push the async hdlc module and the compressor module. */
-    if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0) {
-       syslog(LOG_ERR, "Couldn't push PPP Async HDLC module: %m");
-       die(1);
-    }
+    if (ioctl(fd, I_PUSH, "ppp_ahdl") < 0)
+       fatal("Couldn't push PPP Async HDLC module: %m");
     if (kdebugflag & 4) {
        i = PPPDBG_LOG + PPPDBG_AHDLC;
        strioctl(pppfd, PPPIO_DEBUG, &i, sizeof(int), 0);
     }
-    if (ioctl(fd, I_PUSH, "ppp_comp") < 0) {
-       syslog(LOG_ERR, "Couldn't push PPP compression module: %m");
-/*     die(1); */
-    }
+    if (ioctl(fd, I_PUSH, "ppp_comp") < 0)
+       error("Couldn't push PPP compression module: %m");
     if (kdebugflag & 2) {
        i = PPPDBG_LOG + PPPDBG_COMP;
        strioctl(pppfd, PPPIO_DEBUG, &i, sizeof(int), 0);
     }
 
     /* Link the serial port under the PPP multiplexor. */
-    if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) {
-       syslog(LOG_ERR, "Can't link tty to PPP mux: %m");
-       die(1);
-    }
+    if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0)
+       fatal("Can't link tty to PPP mux: %m");
 }
 
 /*
@@ -330,7 +315,7 @@ disestablish_ppp(fd)
     if (fdmuxid >= 0) {
        if (ioctl(pppfd, I_UNLINK, fdmuxid) < 0) {
            if (!hungup)
-               syslog(LOG_ERR, "Can't unlink tty from PPP mux: %m");
+               error("Can't unlink tty from PPP mux: %m");
        }
        fdmuxid = -1;
 
@@ -339,7 +324,7 @@ disestablish_ppp(fd)
                ;
            for (i = tty_nmodules - 1; i >= 0; --i)
                if (ioctl(fd, I_PUSH, tty_modules[i]) < 0)
-                   syslog(LOG_ERR, "Couldn't restore tty module %s: %m",
+                   error("Couldn't restore tty module %s: %m",
                           tty_modules[i]);
        }
        if (hungup && default_device && tty_sid > 0) {
@@ -382,8 +367,8 @@ clean_check()
        break;
     }
     if (s != NULL) {
-       syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-       syslog(LOG_WARNING, "All received characters had %s", s);
+       warn("Serial link is not 8-bit clean:");
+       warn("All received characters had %s", s);
     }
 }
 
@@ -476,7 +461,7 @@ translate_speed(bps)
     for (speedp = speeds; speedp->speed_int; speedp++)
        if (bps == speedp->speed_int)
            return speedp->speed_val;
-    syslog(LOG_WARNING, "speed %d not supported", bps);
+    warn("speed %d not supported", bps);
     return 0;
 }
 
@@ -512,17 +497,15 @@ set_up_tty(fd, local)
     struct termiox tiox;
 #endif
 
-    if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
-       die(1);
-    }
+    if (tcgetattr(fd, &tios) < 0)
+       fatal("tcgetattr: %m");
 
 #ifndef CRTSCTS
     termiox_ok = 1;
     if (ioctl (fd, TCGETX, &tiox) < 0) {
        termiox_ok = 0;
        if (errno != ENOTTY)
-           syslog (LOG_ERR, "TCGETX: %m");
+           error("TCGETX: %m");
     }
 #endif
 
@@ -542,7 +525,7 @@ set_up_tty(fd, local)
        tios.c_cflag &= ~CRTSCTS;
 #else
     if (crtscts != 0 && !termiox_ok) {
-       syslog(LOG_ERR, "Can't set RTS/CTS flow control");
+       error("Can't set RTS/CTS flow control");
     } else if (crtscts > 0) {
        tiox.x_hflag |= RTSXOFF|CTSXON;
     } else if (crtscts < 0) {
@@ -575,21 +558,16 @@ set_up_tty(fd, local)
         * We can't proceed if the serial port speed is 0,
         * since that implies that the serial port is disabled.
         */
-       if (speed == B0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
-                  devnam);
-           die(1);
-       }
+       if (speed == B0)
+           fatal("Baud rate for %s is 0; need explicit baud rate", devnam);
     }
 
-    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
-       die(1);
-    }
+    if (tcsetattr(fd, TCSAFLUSH, &tios) < 0)
+       fatal("tcsetattr: %m");
 
 #ifndef CRTSCTS
     if (termiox_ok && ioctl (fd, TCSETXF, &tiox) < 0){
-       syslog (LOG_ERR, "TCSETXF: %m");
+       error("TCSETXF: %m");
     }
 #endif
 
@@ -616,11 +594,11 @@ restore_tty(fd)
        }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (!hungup && errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
 #ifndef CRTSCTS
        if (ioctl (fd, TCSETXF, &inittermiox) < 0){
            if (!hungup && errno != ENXIO)
-               syslog (LOG_ERR, "TCSETXF: %m");
+               error("TCSETXF: %m");
        }
 #endif
        ioctl(fd, TIOCSWINSZ, &wsinfo);
@@ -665,7 +643,7 @@ output(unit, p, len)
     struct pollfd pfd;
 
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     data.len = len;
     data.buf = (caddr_t) p;
@@ -673,7 +651,7 @@ output(unit, p, len)
     while (putmsg(pppfd, NULL, &data, 0) < 0) {
        if (--retries < 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) {
            if (errno != ENXIO)
-               syslog(LOG_ERR, "Couldn't send packet: %m");
+               error("Couldn't send packet: %m");
            break;
        }
        pfd.fd = pppfd;
@@ -684,7 +662,7 @@ output(unit, p, len)
 
 
 /*
- * wait_input - wait until there is data available on fd,
+ * wait_input - wait until there is data available,
  * for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
@@ -693,17 +671,48 @@ wait_input(timo)
     struct timeval *timo;
 {
     int t;
-    struct pollfd pfd;
 
     t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
-    pfd.fd = pppfd;
-    pfd.events = POLLIN | POLLPRI | POLLHUP;
-    if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "poll: %m");
-       die(1);
+    if (poll(pollfds, n_pollfds, t) < 0 && errno != EINTR)
+       fatal("poll: %m");
+}
+
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n)
+       if (pollfds[n].fd == fd)
+           return;
+    if (n_pollfds < MAX_POLLFDS) {
+       pollfds[n_pollfds].fd = fd;
+       pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP;
+       ++n_pollfds;
+    } else
+       error("Too many inputs!");
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+    int n;
+
+    for (n = 0; n < n_pollfds; ++n) {
+       if (pollfds[n].fd == fd) {
+           while (++n < n_pollfds)
+               pollfds[n-1] = pollfds[n];
+           --n_pollfds;
+           break;
+       }
     }
 }
 
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -727,11 +736,10 @@ wait_time(timo)
     int n;
 
     n = select(0, NULL, NULL, NULL, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
+#endif
 
 
 /*
@@ -755,8 +763,7 @@ read_packet(buf)
        if (len < 0) {
            if (errno == EAGAIN || errno == EINTR)
                return -1;
-           syslog(LOG_ERR, "Error reading packet: %m");
-           die(1);
+           fatal("Error reading packet: %m");
        }
 
        if (ctrl.len <= 0)
@@ -767,7 +774,7 @@ read_packet(buf)
         * as a DLPI primitive??
         */
        if (debug)
-           syslog(LOG_DEBUG, "got dlpi prim 0x%x, len=%d",
+           dbglog("got dlpi prim 0x%x, len=%d",
                   ((union DL_primitives *)ctrlbuf)->dl_primitive, ctrl.len);
 
     }
@@ -808,17 +815,17 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_MTU, &mtu, sizeof(mtu), 0) < 0) {
        if (hungup && errno == ENXIO)
            return;
-       syslog(LOG_ERR, "Couldn't set MTU: %m");
+       error("Couldn't set MTU: %m");
     }
     if (fdmuxid >= 0) {
        /* can't set these if we don't have a stream attached below /dev/ppp */
        if (strioctl(pppfd, PPPIO_XACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't set transmit ACCM: %m");
+           error("Couldn't set transmit ACCM: %m");
        }
        cf[0] = (pcomp? COMP_PROT: 0) + (accomp? COMP_AC: 0);
        cf[1] = COMP_PROT | COMP_AC;
        if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
-           syslog(LOG_ERR, "Couldn't set prot/AC compression: %m");
+           error("Couldn't set prot/AC compression: %m");
        }
     }
 
@@ -827,7 +834,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     ifr.ifr_metric = link_mtu;
     if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+       error("Couldn't set IP MTU: %m");
     }
 }
 
@@ -842,7 +849,7 @@ ppp_set_xaccm(unit, accm)
     if (fdmuxid >= 0
        && strioctl(pppfd, PPPIO_XACCM, accm, sizeof(ext_accm), 0) < 0) {
        if (!hungup || errno != ENXIO)
-           syslog(LOG_WARNING, "Couldn't set extended ACCM: %m");
+           warn("Couldn't set extended ACCM: %m");
     }
 }
 
@@ -862,17 +869,17 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     if (strioctl(pppfd, PPPIO_MRU, &mru, sizeof(mru), 0) < 0) {
        if (hungup && errno == ENXIO)
            return;
-       syslog(LOG_ERR, "Couldn't set MRU: %m");
+       error("Couldn't set MRU: %m");
     }
     if (fdmuxid >= 0) {
        /* can't set these if we don't have a stream attached below /dev/ppp */
        if (strioctl(pppfd, PPPIO_RACCM, &asyncmap, sizeof(asyncmap), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't set receive ACCM: %m");
+           error("Couldn't set receive ACCM: %m");
        }
        cf[0] = (pcomp? DECOMP_PROT: 0) + (accomp? DECOMP_AC: 0);
        cf[1] = DECOMP_PROT | DECOMP_AC;
        if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
-           syslog(LOG_ERR, "Couldn't set prot/AC decompression: %m");
+           error("Couldn't set prot/AC decompression: %m");
        }
     }
 }
@@ -905,7 +912,7 @@ ccp_flags_set(unit, isopen, isup)
     cf[1] = CCP_ISOPEN | CCP_ISUP | CCP_ERROR | CCP_FATALERROR;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (!hungup || errno != ENXIO)
-           syslog(LOG_ERR, "Couldn't set kernel CCP state: %m");
+           error("Couldn't set kernel CCP state: %m");
     }
 }
 
@@ -933,14 +940,14 @@ set_filters(pass, active)
     if (pass->bf_len > 0) {
        if (strioctl(pppfd, PPPIO_PASSFILT, pass,
                     sizeof(struct bpf_program), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't set pass-filter in kernel: %m");
+           error("Couldn't set pass-filter in kernel: %m");
            ret = 0;
        }
     }
     if (active->bf_len > 0) {
        if (strioctl(pppfd, PPPIO_ACTIVEFILT, active,
                     sizeof(struct bpf_program), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't set active-filter in kernel: %m");
+           error("Couldn't set active-filter in kernel: %m");
            ret = 0;
        }
     }
@@ -962,7 +969,7 @@ ccp_fatal_error(unit)
     cf[0] = cf[1] = 0;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (errno != ENXIO && errno != EINVAL)
-           syslog(LOG_ERR, "Couldn't get compression flags: %m");
+           error("Couldn't get compression flags: %m");
        return 0;
     }
     return cf[0] & CCP_FATALERROR;
@@ -982,7 +989,7 @@ sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
        maxcid[0] = xcidcomp;
        maxcid[1] = 15;         /* XXX should be rmaxcid */
        if (strioctl(pppfd, PPPIO_VJINIT, maxcid, sizeof(maxcid), 0) < 0) {
-           syslog(LOG_ERR, "Couldn't initialize VJ compression: %m");
+           error("Couldn't initialize VJ compression: %m");
        }
     }
 
@@ -991,7 +998,7 @@ sifvjcomp(u, vjcomp, xcidcomp, xmaxcid)
     cf[1] = COMP_VJC + DECOMP_VJC + COMP_VJCCID + DECOMP_VJCCID;
     if (strioctl(pppfd, PPPIO_CFLAGS, cf, sizeof(cf), sizeof(int)) < 0) {
        if (vjcomp)
-           syslog(LOG_ERR, "Couldn't enable VJ compression: %m");
+           error("Couldn't enable VJ compression: %m");
     }
 
     return 1;
@@ -1008,12 +1015,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface up (get): %m");
+       error("Couldn't mark interface up (get): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface up (set): %m");
+       error("Couldn't mark interface up (set): %m");
        return 0;
     }
     if_is_up = 1;
@@ -1033,12 +1040,12 @@ sifdown(u)
        return 1;
     strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname);
     if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface down (get): %m");
+       error("Couldn't mark interface down (get): %m");
        return 0;
     }
     ifr.ifr_flags &= ~IFF_UP;
     if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't mark interface down (set): %m");
+       error("Couldn't mark interface down (set): %m");
        return 0;
     }
     if_is_up = 0;
@@ -1059,7 +1066,7 @@ sifnpmode(u, proto, mode)
     npi[0] = proto;
     npi[1] = (int) mode;
     if (strioctl(pppfd, PPPIO_NPMODE, &npi, 2 * sizeof(int), 0) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -1083,13 +1090,13 @@ sifaddr(u, o, h, m)
     ifr.ifr_addr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_addr) = m;
     if (ioctl(ipfd, SIOCSIFNETMASK, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP netmask: %m");
+       error("Couldn't set IP netmask: %m");
        ret = 0;
     }
     ifr.ifr_addr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_addr) = o;
     if (ioctl(ipfd, SIOCSIFADDR, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set local IP address: %m");
+       error("Couldn't set local IP address: %m");
        ret = 0;
     }
 
@@ -1101,20 +1108,20 @@ sifaddr(u, o, h, m)
        && (ifr.ifr_flags & IFF_POINTOPOINT) == 0) {
        ifr.ifr_flags |= IFF_POINTOPOINT;
        if (ioctl(ipfd, SIOCSIFFLAGS, &ifr) < 0) {
-           syslog(LOG_ERR, "Couldn't mark interface pt-to-pt: %m");
+           error("Couldn't mark interface pt-to-pt: %m");
            ret = 0;
        }
     }
     ifr.ifr_dstaddr.sa_family = AF_INET;
     INET_ADDR(ifr.ifr_dstaddr) = h;
     if (ioctl(ipfd, SIOCSIFDSTADDR, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set remote IP address: %m");
+       error("Couldn't set remote IP address: %m");
        ret = 0;
     }
 #if 0  /* now done in ppp_send_config */
     ifr.ifr_metric = link_mtu;
     if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) {
-       syslog(LOG_ERR, "Couldn't set IP MTU: %m");
+       error("Couldn't set IP MTU: %m");
     }
 #endif
 
@@ -1134,9 +1141,9 @@ cifaddr(u, o, h)
 #if defined(__USLC__)          /* was: #if 0 */
     cifroute(unit, ouraddr, hisaddr);
     if (ipmuxid >= 0) {
-       syslog(LOG_NOTICE, "Removing ppp interface unit");
+       notice("Removing ppp interface unit");
        if (ioctl(ipfd, I_UNLINK, ipmuxid) < 0) {
-           syslog(LOG_ERR, "Can't remove ppp interface unit: %m");
+           error("Can't remove ppp interface unit: %m");
            return 0;
        }
        ipmuxid = -1;
@@ -1167,7 +1174,7 @@ sifdefaultroute(u, l, g)
     rt.rt_flags = RTF_GATEWAY;
 
     if (ioctl(ipfd, SIOCADDRT, &rt) < 0) {
-       syslog(LOG_ERR, "Can't add default route: %m");
+       error("Can't add default route: %m");
        return 0;
     }
 
@@ -1196,7 +1203,7 @@ cifdefaultroute(u, l, g)
     rt.rt_flags = RTF_GATEWAY;
 
     if (ioctl(ipfd, SIOCDELRT, &rt) < 0) {
-       syslog(LOG_ERR, "Can't delete default route: %m");
+       error("Can't delete default route: %m");
        return 0;
     }
 
@@ -1222,7 +1229,7 @@ sifproxyarp(unit, hisaddr)
     INET_ADDR(arpreq.arp_pa) = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(ipfd, SIOCSARP, (caddr_t) &arpreq) < 0) {
-       syslog(LOG_ERR, "Couldn't set proxy ARP entry: %m");
+       error("Couldn't set proxy ARP entry: %m");
        return 0;
     }
 
@@ -1244,7 +1251,7 @@ cifproxyarp(unit, hisaddr)
     arpreq.arp_pa.sa_family = AF_INET;
     INET_ADDR(arpreq.arp_pa) = hisaddr;
     if (ioctl(ipfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "Couldn't delete proxy ARP entry: %m");
+       error("Couldn't delete proxy ARP entry: %m");
        return 0;
     }
 
@@ -1280,7 +1287,7 @@ get_ether_addr(ipaddr, hwaddr)
     if (ifc.ifc_buf == 0)
        return 0;
     if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+       warn("Couldn't get system interface list: %m");
        free(ifc.ifc_buf);
        return 0;
     }
@@ -1310,14 +1317,14 @@ get_ether_addr(ipaddr, hwaddr)
     }
 
     if (ifr >= ifend) {
-       syslog(LOG_WARNING, "No suitable interface found for proxy ARP");
+       warn("No suitable interface found for proxy ARP");
        free(ifc.ifc_buf);
        return 0;
     }
 
-    syslog(LOG_INFO, "found interface %s for proxy ARP", ifr->ifr_name);
+    info("found interface %s for proxy ARP", ifr->ifr_name);
     if (!get_hw_addr(ifr->ifr_name, ina, hwaddr)) {
-       syslog(LOG_ERR, "Couldn't get hardware address for %s", ifr->ifr_name);
+       error("Couldn't get hardware address for %s", ifr->ifr_name);
        free(ifc.ifc_buf);
        return 0;
     }
@@ -1347,7 +1354,7 @@ get_hw_addr(name, ina, hwaddr)
     req.arp_pa.sa_family = AF_INET;
     INET_ADDR(req.arp_pa) = ina;
     if (ioctl(s, SIOCGARP, &req) < 0) {
-       syslog(LOG_ERR, "Couldn't get ARP entry for %s: %m", ip_ntoa(ina));
+       error("Couldn't get ARP entry for %s: %m", ip_ntoa(ina));
        return 0;
     }
     *hwaddr = req.arp_ha;
@@ -1379,7 +1386,7 @@ get_hw_addr(name, ina, hwaddr)
      */
     iffd = open(ifdev, O_RDWR);
     if (iffd < 0) {
-       syslog(LOG_ERR, "Can't open %s: %m", ifdev);
+       error("Can't open %s: %m", ifdev);
        return 0;
     }
     if (dlpi_attach(iffd, unit) < 0
@@ -1463,7 +1470,7 @@ dlpi_get_reply(fd, reply, expected_prim, maxlen)
 
     if (buf.len < sizeof(ulong)) {
        if (debug)
-           syslog(LOG_DEBUG, "dlpi response short (len=%d)\n", buf.len);
+           dbglog("dlpi response short (len=%d)\n", buf.len);
        return -1;
     }
 
@@ -1472,11 +1479,11 @@ dlpi_get_reply(fd, reply, expected_prim, maxlen)
 
     if (debug) {
        if (reply->dl_primitive == DL_ERROR_ACK) {
-           syslog(LOG_DEBUG, "dlpi error %d (unix errno %d) for prim %x\n",
+           dbglog("dlpi error %d (unix errno %d) for prim %x\n",
                   reply->error_ack.dl_errno, reply->error_ack.dl_unix_errno,
                   reply->error_ack.dl_error_primitive);
        } else {
-           syslog(LOG_DEBUG, "dlpi unexpected response prim %x\n",
+           dbglog("dlpi unexpected response prim %x\n",
                   reply->dl_primitive);
        }
     }
@@ -1523,7 +1530,7 @@ GetMask(addr)
     if (ifc.ifc_buf == 0)
        return mask;
     if (ioctl(ipfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "Couldn't get system interface list: %m");
+       warn("Couldn't get system interface list: %m");
        free(ifc.ifc_buf);
        return mask;
     }
@@ -1590,7 +1597,7 @@ get_host_seed()
     char buf[32];
 
     if (sysinfo(SI_HW_SERIAL, buf, sizeof(buf)) < 0) {
-       syslog(LOG_ERR, "sysinfo: %m");
+       error("sysinfo: %m");
        return 0;
     }
     return (int) strtoul(buf, NULL, 16);
@@ -1610,7 +1617,7 @@ strioctl(fd, cmd, ptr, ilen, olen)
     if (ioctl(fd, I_STR, &str) == -1)
        return -1;
     if (str.ic_len != olen)
-       syslog(LOG_DEBUG, "strioctl: expected %d bytes, got %d for cmd %x\n",
+       dbglog("strioctl: expected %d bytes, got %d for cmd %x\n",
               olen, str.ic_len, cmd);
     return 0;
 }
@@ -1631,15 +1638,16 @@ lock(dev)
     char ascii_pid[12];
 
     if (stat(dev, &sbuf) < 0) {
-       syslog(LOG_ERR, "Can't get device number for %s: %m", dev);
+       error("Can't get device number for %s: %m", dev);
        return -1;
     }
     if ((sbuf.st_mode & S_IFMT) != S_IFCHR) {
-       syslog(LOG_ERR, "Can't lock %s: not a character device", dev);
+       error("Can't lock %s: not a character device", dev);
        return -1;
     }
-    sprintf(lock_file, "%s%03d.%03d.%03d", LOCK_PREFIX, major(sbuf.st_dev),
-           major(sbuf.st_rdev), minor(sbuf.st_rdev));
+    slprintf(lock_file, sizeof(lock_file), "%s%03d.%03d.%03d",
+            LOCK_PREFIX, major(sbuf.st_dev),
+            major(sbuf.st_rdev), minor(sbuf.st_rdev));
 
     while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) {
        if (errno == EEXIST
@@ -1647,7 +1655,7 @@ lock(dev)
            /* Read the lock file to find out who has the device locked */
            n = read(fd, ascii_pid, 11);
            if (n <= 0) {
-               syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+               error("Can't read pid from lock file %s", lock_file);
                close(fd);
            } else {
                ascii_pid[n] = 0;
@@ -1656,24 +1664,24 @@ lock(dev)
                    /* pid no longer exists - remove the lock file */
                    if (unlink(lock_file) == 0) {
                        close(fd);
-                       syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+                       notice("Removed stale lock on %s (pid %d)",
                               dev, pid);
                        continue;
                    } else
-                       syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+                       warn("Couldn't remove stale lock on %s",
                               dev);
                } else
-                   syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+                   notice("Device %s is locked by pid %d",
                           dev, pid);
            }
            close(fd);
        } else
-           syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+           error("Can't create lock file %s: %m", lock_file);
        lock_file[0] = 0;
        return -1;
     }
 
-    sprintf(ascii_pid, "%10d\n", getpid());
+    slprintf(ascii_pid, sizeof(ascii_pid), "%10d\n", getpid());
     write(fd, ascii_pid, 11);
 
     close(fd);
@@ -1711,7 +1719,7 @@ cifroute(u, our, his)
     rt.rt_flags = RTF_HOST;
 
     if (ioctl(ipfd, SIOCDELRT, &rt) < 0) {
-       syslog(LOG_ERR, "Can't delete route: %m");
+       error("Can't delete route: %m");
        return 0;
     }
 
@@ -1750,7 +1758,7 @@ have_route_to(addr)
 
     fd = open("/dev/ip", O_RDWR);
     if (fd < 0) {
-       syslog(LOG_WARNING, "have_route_to: couldn't open /dev/ip: %m");
+       warn("have_route_to: couldn't open /dev/ip: %m");
        return -1;
     }
 
@@ -1767,7 +1775,7 @@ have_route_to(addr)
     cbuf.len = sizeof(req);
 
     if (putmsg(fd, &cbuf, NULL, 0) == -1) {
-       syslog(LOG_WARNING, "have_route_to: putmsg: %m");
+       warn("have_route_to: putmsg: %m");
        close(fd);
        return -1;
     }
@@ -1780,7 +1788,7 @@ have_route_to(addr)
        flags = 0;
        r = getmsg(fd, &cbuf, &dbuf, &flags);
        if (r == -1) {
-           syslog(LOG_WARNING, "have_route_to: getmsg: %m");
+           warn("have_route_to: getmsg: %m");
            close(fd);
            return -1;
        }
@@ -1789,7 +1797,7 @@ have_route_to(addr)
            || ack.ack.PRIM_type != T_OPTMGMT_ACK
            || ack.ack.MGMT_flags != T_SUCCESS
            || ack.ack.OPT_length < sizeof(struct opthdr)) {
-           syslog(LOG_DEBUG, "have_route_to: bad message len=%d prim=%d",
+           dbglog("have_route_to: bad message len=%d prim=%d",
                   cbuf.len, ack.ack.PRIM_type);
            close(fd);
            return -1;
@@ -1808,7 +1816,7 @@ have_route_to(addr)
            nroutes = dbuf.len / sizeof(mib2_ipRouteEntry_t);
            for (rp = routes, i = 0; i < nroutes; ++i, ++rp) {
                if (rp->ipRouteMask != ~0) {
-                   syslog(LOG_DEBUG, "have_route_to: dest=%x gw=%x mask=%x\n",
+                   dbglog("have_route_to: dest=%x gw=%x mask=%x\n",
                           rp->ipRouteDest, rp->ipRouteNextHop,
                           rp->ipRouteMask);
                    if (((addr ^ rp->ipRouteDest) & rp->ipRouteMask) == 0
index 92d3bd26d771b4351038699ac19cdb6154ee05be..53c8f7cba51470b14e6b42986f73608342a2ceb7 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.25 1999/03/12 06:07:24 paulus Exp $";
+static char rcsid[] = "$Id: sys-ultrix.c,v 1.26 1999/03/16 02:57:08 paulus Exp $";
 #endif
 
 /*
@@ -30,7 +30,6 @@ static char rcsid[] = "$Id: sys-ultrix.c,v 1.25 1999/03/12 06:07:24 paulus Exp $
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <syslog.h>
 #include <string.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -71,6 +70,9 @@ static unsigned char inbuf[512]; /* buffer for chars read from loopback */
 
 static int sockfd;             /* socket for doing interface ioctls */
 
+static fd_set in_fds;          /* set of fds that wait_input waits for */
+static int max_in_fd;          /* highest fd set in in_fds */
+
 static int if_is_up;           /* the interface is currently up */
 static u_int32_t ifaddrs[2];   /* local and remote addresses */
 static u_int32_t default_route_gateway;        /* gateway addr for default route */
@@ -90,9 +92,12 @@ sys_init()
 {
     /* Get an internet socket for doing socket ioctl's on. */
     if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
-       syslog(LOG_ERR, "Couldn't create IP socket: %m");
+       error("Couldn't create IP socket: %m");
        die(1);
     }
+
+    FD_ZERO(&in_fds);
+    max_in_fd = 0;
 }
 
 /*
@@ -211,11 +216,11 @@ establish_ppp(fd)
      * Save the old line discipline of fd, and set it to PPP.
      */
     if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
+       error("ioctl(TIOCGETD): %m");
        die(1);
     }
     if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+       error("ioctl(TIOCSETD): %m");
        die(1);
     }
 
@@ -223,7 +228,7 @@ establish_ppp(fd)
      * Find out which interface we were given.
      */
     if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) { 
-       syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
+       error("ioctl(PPPIOCGUNIT): %m");
        die(1);
     }
 
@@ -234,11 +239,11 @@ establish_ppp(fd)
      */
     if (kdebugflag) {
        if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-           syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
+           warn("ioctl (PPPIOCGFLAGS): %m");
        } else {
            x |= (kdebugflag & 0xFF) * SC_DEBUG;
            if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
-               syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
+               warn("ioctl(PPPIOCSFLAGS): %m");
        }
     }
 
@@ -247,7 +252,7 @@ establish_ppp(fd)
      */
     if ((initfdflags = fcntl(fd, F_GETFL)) == -1
        || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) {
-       syslog(LOG_WARNING, "Couldn't set device to non-blocking mode: %m");
+       warn("Couldn't set device to non-blocking mode: %m");
     }
 }
 
@@ -269,12 +274,12 @@ disestablish_ppp(fd)
 {
     /* Reset non-blocking mode on fd. */
     if (initfdflags != -1 && fcntl(fd, F_SETFL, initfdflags) < 0)
-       syslog(LOG_WARNING, "Couldn't restore device fd flags: %m");
+       warn("Couldn't restore device fd flags: %m");
     initfdflags = -1;
 
     /* Restore old line discipline. */
     if (initdisc >= 0 && ioctl(fd, TIOCSETD, &initdisc) < 0)
-       syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
+       error("ioctl(TIOCSETD): %m");
     initdisc = -1;
 
     if (fd == ppp_fd)
@@ -307,8 +312,8 @@ clean_check()
            break;
        }
        if (s != NULL) {
-           syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
-           syslog(LOG_WARNING, "All received characters had %s", s);
+           warn("Serial link is not 8-bit clean:");
+           warn("All received characters had %s", s);
        }
     }
 }
@@ -403,7 +408,7 @@ translate_speed(bps)
     for (speedp = speeds; speedp->speed_int; speedp++)
        if (bps == speedp->speed_int)
            return speedp->speed_val;
-    syslog(LOG_WARNING, "speed %d not supported", bps);
+    warn("speed %d not supported", bps);
     return 0;
 }
 
@@ -437,7 +442,7 @@ set_up_tty(fd, local)
     struct termios tios;
 
     if (tcgetattr(fd, &tios) < 0) {
-       syslog(LOG_ERR, "tcgetattr: %m");
+       error("tcgetattr: %m");
        die(1);
     }
 
@@ -480,22 +485,22 @@ set_up_tty(fd, local)
         * since that implies that the serial port is disabled.
         */
        if (speed == B0) {
-           syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
+           error("Baud rate for %s is 0; need explicit baud rate",
                   devnam);
            die(1);
        }
     }
 
     if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
-       syslog(LOG_ERR, "tcsetattr: %m");
+       error("tcsetattr: %m");
        die(1);
     }
 
     x = 0;
     if (ioctl(fd, (crtscts > 0 || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0)
-       syslog(LOG_WARNING, "TIOC(N)MODEM: %m");
+       warn("TIOC(N)MODEM: %m");
     if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0)
-       syslog(LOG_WARNING, "TIOC(N)CAR: %m");
+       warn("TIOC(N)CAR: %m");
 
     baud_rate = inspeed = baud_rate_of(speed);
     restore_term = TRUE;
@@ -520,7 +525,7 @@ restore_tty(fd)
        }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (errno != ENXIO)
-               syslog(LOG_WARNING, "tcsetattr: %m");
+               warn("tcsetattr: %m");
        ioctl(fd, TIOCSWINSZ, &wsinfo);
        restore_term = FALSE;
     }
@@ -548,7 +553,7 @@ int fd, on;
 void
 open_ppp_loopback()
 {
-    syslog(LOG_ERR, "open_ppp_loopback called!");
+    error("open_ppp_loopback called!");
     die(1);
 }
 
@@ -563,17 +568,17 @@ output(unit, p, len)
     int len;
 {
     if (debug)
-       log_packet(p, len, "sent ", LOG_DEBUG);
+       dbglog("sent %P", p, len);
 
     if (write(ttyfd, p, len) < 0) {
        if (errno != EIO)
-           syslog(LOG_ERR, "write: %m");
+           error("write: %m");
     }
 }
 
 
 /*
- * wait_input - wait until there is data available on ttyfd,
+ * wait_input - wait until there is data available,
  * for the length of time specified by *timo (indefinite
  * if timo is NULL).
  */
@@ -584,16 +589,32 @@ wait_input(timo)
     fd_set ready;
     int n;
 
-    FD_ZERO(&ready);
-    FD_SET(ttyfd, &ready);
+    ready = in_fds;
     n = select(ttyfd+1, &ready, NULL, &ready, timo);
-    if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
-       die(1);
-    }
+    if (n < 0 && errno != EINTR)
+       fatal("select: %m");
 }
 
 
+/*
+ * add_fd - add an fd to the set that wait_input waits for.
+ */
+void add_fd(int fd)
+{
+    FD_SET(fd, &in_fds);
+    if (fd > max_in_fd)
+       max_in_fd = fd;
+}
+
+/*
+ * remove_fd - remove an fd from the set that wait_input waits for.
+ */
+void remove_fd(int fd)
+{
+    FD_CLR(fd, &in_fds);
+}
+
+#if 0
 /*
  * wait_loop_output - wait until there is data available on the
  * loopback, for the length of time specified by *timo (indefinite
@@ -619,11 +640,11 @@ wait_time(timo)
 
     n = select(0, NULL, NULL, NULL, timo);
     if (n < 0 && errno != EINTR) {
-       syslog(LOG_ERR, "select: %m");
+       error("select: %m");
        die(1);
     }
 }
-
+#endif
 
 /*
  * read_packet - get a PPP packet from the serial device.
@@ -637,7 +658,7 @@ read_packet(buf)
     if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
        if (errno == EWOULDBLOCK || errno == EINTR)
            return -1;
-       syslog(LOG_ERR, "read(fd): %m");
+       error("read(fd): %m");
        die(1);
     }
     return len;
@@ -669,23 +690,23 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
     u_int x;
 
     if (ioctl(ppp_fd, PPPIOCSMTU, &mtu) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSMTU): %m");
+       error("ioctl(PPPIOCSMTU): %m");
        quit();
     }
 
     if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
+       error("ioctl(PPPIOCSASYNCMAP): %m");
        quit();
     }
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       error("ioctl (PPPIOCGFLAGS): %m");
        quit();
     }
     x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
     x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        quit();
     }
 }
@@ -700,7 +721,7 @@ ppp_set_xaccm(unit, accm)
     ext_accm accm;
 {
     if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
-       syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
+       warn("ioctl(set extended ACCM): %m");
 }
 
 
@@ -717,20 +738,20 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
     int x;
 
     if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
+       error("ioctl(PPPIOCSMRU): %m");
        quit();
     }
     if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
+       error("ioctl(PPPIOCSRASYNCMAP): %m");
        quit();
     }
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       error("ioctl (PPPIOCGFLAGS): %m");
        quit();
     }
     x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        quit();
     }
 }
@@ -766,13 +787,13 @@ ccp_flags_set(unit, isopen, isup)
     int x;
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       error("ioctl (PPPIOCGFLAGS): %m");
        return;
     }
     x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
     x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
 }
 
 /*
@@ -787,7 +808,7 @@ ccp_fatal_error(unit)
     int x;
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
+       error("ioctl(PPPIOCGFLAGS): %m");
        return 0;
     }
     return x & SC_DC_FERROR;
@@ -815,17 +836,17 @@ sifvjcomp(u, vjcomp, cidcomp, maxcid)
     u_int x;
 
     if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
+       error("ioctl (PPPIOCGFLAGS): %m");
        return 0;
     }
     x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
     x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
     if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        return 0;
     }
     if (ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
-       syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
+       error("ioctl(PPPIOCSFLAGS): %m");
        return 0;
     }
     return 1;
@@ -842,12 +863,12 @@ sifup(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        return 0;
     }
     ifr.ifr_flags |= IFF_UP;
     if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+       error("ioctl(SIOCSIFFLAGS): %m");
        return 0;
     }
     if_is_up = 1;
@@ -868,7 +889,7 @@ sifnpmode(u, proto, mode)
     npi.protocol = proto;
     npi.mode = mode;
     if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) {
-       syslog(LOG_ERR, "ioctl(set NP %d mode to %d): %m", proto, mode);
+       error("ioctl(set NP %d mode to %d): %m", proto, mode);
        return 0;
     }
     return 1;
@@ -893,12 +914,12 @@ sifdown(u)
 
     strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname);
     if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
-       syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
+       error("ioctl (SIOCGIFFLAGS): %m");
        rv = 0;
     } else {
        ifr.ifr_flags &= ~IFF_UP;
        if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
-           syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
+           error("ioctl(SIOCSIFFLAGS): %m");
            rv = 0;
        } else
            if_is_up = 0;
@@ -930,20 +951,20 @@ sifaddr(u, o, h, m)
     SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
     if (m != 0) {
         ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
-        syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
+        info("Setting interface mask to %s\n", ip_ntoa(m));
         if (ioctl(sockfd, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
-            syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
+            error("ioctl(SIOCSIFNETMASK): %m");
             ret = 0;
         }
     }
     ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
     if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
+        error("ioctl(SIOCSIFADDR): %m");
         ret = 0;
     }
     ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
     if (ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
+        error("ioctl(SIOCSIFDSTADDR): %m");
         ret = 0;
     }
     ifaddrs[0] = o;
@@ -970,7 +991,7 @@ cifaddr(u, o, h)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
     rt.rt_flags = RTF_HOST;
     if (ioctl(sockfd, SIOCDELRT, (caddr_t) &rt) < 0) {
-        syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
+        error("ioctl(SIOCDELRT): %m");
         return 0;
     }
     return 1;
@@ -992,7 +1013,7 @@ sifdefaultroute(u, l, g)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, SIOCADDRT, &rt) < 0) {
-        syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
+        error("default route ioctl(SIOCADDRT): %m");
         return 0;
     }
     default_route_gateway = g;
@@ -1015,7 +1036,7 @@ cifdefaultroute(u, l, g)
     ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
     rt.rt_flags = RTF_GATEWAY;
     if (ioctl(sockfd, SIOCDELRT, &rt) < 0)
-        syslog(LOG_WARNING, "default route ioctl(SIOCDELRT): %m");
+        warn("default route ioctl(SIOCDELRT): %m");
     default_route_gateway = 0;
     return 1;
 }
@@ -1037,7 +1058,7 @@ sifproxyarp(unit, hisaddr)
      * as our local address.
      */
     if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
-       syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
+       error("Cannot determine ethernet address for proxy ARP");
        return 0;
     }
 
@@ -1045,7 +1066,7 @@ sifproxyarp(unit, hisaddr)
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     arpreq.arp_flags = ATF_PERM | ATF_PUBL;
     if (ioctl(sockfd, SIOCSARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_ERR, "Couldn't add proxy arp entry: %m");
+       error("Couldn't add proxy arp entry: %m");
        return 0;
     }
 
@@ -1067,7 +1088,7 @@ cifproxyarp(unit, hisaddr)
     SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
     ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
     if (ioctl(sockfd, SIOCDARP, (caddr_t)&arpreq) < 0) {
-       syslog(LOG_WARNING, "Couldn't delete proxy arp entry: %m");
+       warn("Couldn't delete proxy arp entry: %m");
        return 0;
     }
     proxy_arp_addr = 0;
@@ -1095,7 +1116,7 @@ get_ether_addr(ipaddr, hwaddr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
+       error("ioctl(SIOCGIFCONF): %m");
        return 0;
     }
 
@@ -1134,14 +1155,14 @@ get_ether_addr(ipaddr, hwaddr)
 
     if (ifr >= ifend)
        return 0;
-    syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
+    info("found interface %s for proxy arp", ifr->ifr_name);
 
     /*
      * Grab the physical address for this interface.
      */
     strlcpy(ifdevea.ifr_name, sizeof(ifdevea.ifr_name), ifr->ifr_name);
     if (ioctl(sockfd, SIOCRPHYSADDR, &ifdevea) < 0) {
-       syslog(LOG_ERR, "Couldn't get h/w address for %s: %m", ifr->ifr_name);
+       error("Couldn't get h/w address for %s: %m", ifr->ifr_name);
        return 0;
     }
 
@@ -1183,7 +1204,7 @@ GetMask(addr)
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
     if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
-       syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+       warn("ioctl(SIOCGIFCONF): %m");
        return mask;
     }
     ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
@@ -1328,26 +1349,26 @@ lock(dev)
            /* Read the lock file to find out who has the device locked */
            n = read(fd, &pid, sizeof(pid));
            if (n <= 0) {
-               syslog(LOG_ERR, "Can't read pid from lock file %s", lock_file);
+               error("Can't read pid from lock file %s", lock_file);
                close(fd);
            } else {
                if (kill(pid, 0) == -1 && errno == ESRCH) {
                    /* pid no longer exists - remove the lock file */
                    if (unlink(lock_file) == 0) {
                        close(fd);
-                       syslog(LOG_NOTICE, "Removed stale lock on %s (pid %d)",
+                       notice("Removed stale lock on %s (pid %d)",
                               dev, pid);
                        continue;
                    } else
-                       syslog(LOG_WARNING, "Couldn't remove stale lock on %s",
+                       warn("Couldn't remove stale lock on %s",
                               dev);
                } else
-                   syslog(LOG_NOTICE, "Device %s is locked by pid %d",
+                   notice("Device %s is locked by pid %d",
                           dev, pid);
            }
            close(fd);
        } else
-           syslog(LOG_ERR, "Can't create lock file %s: %m", lock_file);
+           error("Can't create lock file %s: %m", lock_file);
        free(lock_file);
        lock_file = NULL;
        return -1;