]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-str.c
Initial revision
[ppp.git] / pppd / sys-str.c
index ecee95b576ff8b001a92ea4a9d013aa749991631..a088eb79d3e177dd7822e6d7d3d44fced34e60ba 100644 (file)
  * TODO:
  */
 
+#include <stdio.h>
 #include <errno.h>
 #include <syslog.h>
+#include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 #include <sys/stream.h>
 #include <sys/stropts.h>
+#include <sys/wait.h>
 
 #include <net/if.h>
 #include <net/route.h>
@@ -38,7 +41,7 @@
 
 #include "pppd.h"
 #include "ppp.h"
-#include "ppp_str.h"
+#include <net/ppp_str.h>
 
 #ifndef ifr_mtu
 #define ifr_mtu                ifr_metric
@@ -50,7 +53,24 @@ static struct        modlist {
 } str_modules[MAXMODULES];
 static int     str_module_count = 0;
 
-extern int hungup;
+extern int hungup;             /* has the physical layer been disconnected? */
+
+/*
+ * ppp_available - check if this kernel supports PPP.
+ */
+int
+ppp_available()
+{
+    int fd, ret;
+
+    fd = open("/dev/tty", O_RDONLY, 0);
+    if (fd < 0)
+       return 1;               /* can't find out - assume we have ppp */
+    ret = ioctl(fd, I_FIND, "pppasync") >= 0;
+    close(fd);
+    return ret;
+}
+
 
 /*
  * establish_ppp - Turn the serial port into a ppp interface.
@@ -159,6 +179,8 @@ output(unit, p, len)
 
     if (unit != 0)
        MAINDEBUG((LOG_WARNING, "output: unit != 0!"));
+    if (debug)
+       log_packet(p, len, "sent ");
 
     str.len = len;
     str.buf = (caddr_t) p;
@@ -273,7 +295,8 @@ ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
  * sifvjcomp - config tcp header compression
  */
 int
-sifvjcomp(u, vjcomp, cidcomp)
+sifvjcomp(u, vjcomp, cidcomp, maxcid)
+    int u, vjcomp, cidcomp, maxcid;
 {
     char x = vjcomp;
 
@@ -622,3 +645,60 @@ get_ether_addr(ipaddr, hwaddr)
     /* couldn't find one */
     return 0;
 }
+
+
+/*
+ * run-program - execute a program with given arguments,
+ * but don't wait for it.
+ * If the program can't be executed, logs an error unless
+ * must_exist is 0 and the program file doesn't exist.
+ */
+static int n_children;
+
+int
+run_program(prog, args, must_exist)
+    char *prog;
+    char **args;
+    int must_exist;
+{
+    int pid;
+
+    pid = fork();
+    if (pid == -1) {
+       syslog(LOG_ERR, "can't fork to run %s: %m", prog);
+       return -1;
+    }
+    if (pid == 0) {
+       execv(prog, args);
+       if (must_exist || errno != ENOENT)
+           syslog(LOG_WARNING, "can't execute %s: %m", prog);
+       _exit(-1);
+    }
+    MAINDEBUG(("Script %s started; pid = %d", prog, pid));
+    ++n_children;
+    return 0;
+}
+
+
+/*
+ * reap_kids - get status from any dead child processes,
+ * and log a message for abnormal terminations.
+ */
+void
+reap_kids()
+{
+    int pid, status;
+
+    if (n_children == 0)
+       return;
+    if ((pid = waitpid(-1, &status, WNOHANG)) == -1) {
+       if (errno != ECHILD)
+           syslog(LOG_ERR, "waitpid: %m");
+       return;
+    }
+    --n_children;
+    if (WIFSIGNALED(status)) {
+       syslog(LOG_WARNING, "child process %d terminated with signal %d",
+              pid, WTERMSIG(status));
+    }
+}