]> git.ozlabs.org Git - ppp.git/commitdiff
Added updetach option.
authorPaul Mackerras <paulus@samba.org>
Thu, 26 Mar 1998 04:46:08 +0000 (04:46 +0000)
committerPaul Mackerras <paulus@samba.org>
Thu, 26 Mar 1998 04:46:08 +0000 (04:46 +0000)
pppd/auth.c
pppd/main.c
pppd/options.c
pppd/pppd.h

index 457fa1c6070a67b8dc53f47bcf4cb8dcecad4957..7ada83afc8e56973b5059dc812e7cac3716da326 100644 (file)
@@ -33,7 +33,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: auth.c,v 1.36 1998/03/25 01:26:03 paulus Exp $";
+static char rcsid[] = "$Id: auth.c,v 1.37 1998/03/26 04:46:03 paulus Exp $";
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
@@ -433,6 +433,12 @@ np_up(unit, proto)
         */
        if (maxconnect > 0)
            TIMEOUT(connect_time_expired, 0, maxconnect);
         */
        if (maxconnect > 0)
            TIMEOUT(connect_time_expired, 0, maxconnect);
+
+       /*
+        * Detach now, if the updetach option was given.
+        */
+       if (nodetach == -1)
+           detach();
     }
     ++num_np_up;
 }
     }
     ++num_np_up;
 }
index b11ed66a3a1dbdd1791556a498ce96100ee64ded..eec19c760398d598ca9eb8e7650f295db0d9101a 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: main.c,v 1.45 1998/03/25 01:28:14 paulus Exp $";
+static char rcsid[] = "$Id: main.c,v 1.46 1998/03/26 04:46:04 paulus Exp $";
 #endif
 
 #include <stdio.h>
 #endif
 
 #include <stdio.h>
@@ -85,11 +85,11 @@ int baud_rate;                      /* Actual bits/second for serial device */
 int hungup;                    /* terminal has been hung up */
 int privileged;                        /* we're running as real uid root */
 int need_holdoff;              /* need holdoff period before restarting */
 int hungup;                    /* terminal has been hung up */
 int privileged;                        /* we're running as real uid root */
 int need_holdoff;              /* need holdoff period before restarting */
+int detached;                  /* have detached from terminal */
 
 int phase;                     /* where the link is at */
 int kill_link;
 int open_ccp_flag;
 
 int phase;                     /* where the link is at */
 int kill_link;
 int open_ccp_flag;
-int redirect_stderr;           /* Connector's stderr should go to file */
 
 char **script_env;             /* Env. variable values for scripts */
 int s_env_nalloc;              /* # words avail at script_env */
 
 char **script_env;             /* Env. variable values for scripts */
 int s_env_nalloc;              /* # words avail at script_env */
@@ -256,7 +256,8 @@ main(argc, argv)
      */
     if (!default_device && strcmp(devnam, default_devnam) == 0)
        default_device = 1;
      */
     if (!default_device && strcmp(devnam, default_devnam) == 0)
        default_device = 1;
-    redirect_stderr = !nodetach || default_device;
+    if (default_device)
+       nodetach = 1;
 
     /*
      * Initialize system-dependent stuff and magic number package.
 
     /*
      * Initialize system-dependent stuff and magic number package.
@@ -270,10 +271,8 @@ main(argc, argv)
      * Detach ourselves from the terminal, if required,
      * and identify who is running us.
      */
      * Detach ourselves from the terminal, if required,
      * and identify who is running us.
      */
-    if (!default_device && !nodetach && daemon(0, 0) < 0) {
-       perror("Couldn't detach from controlling terminal");
-       exit(1);
-    }
+    if (nodetach == 0)
+       detach();
     pid = getpid();
     p = getlogin();
     if (p == NULL) {
     pid = getpid();
     p = getlogin();
     if (p == NULL) {
@@ -624,6 +623,21 @@ main(argc, argv)
     return 0;
 }
 
     return 0;
 }
 
+/*
+ * detach - detach us from the controlling terminal.
+ */
+void
+detach()
+{
+    if (detached)
+       return;
+    if (daemon(0, 0) < 0) {
+       perror("Couldn't detach from controlling terminal");
+       die(1);
+    }
+    detached = 1;
+}
+
 /*
  * holdoff_end - called via a timeout when the holdoff period ends.
  */
 /*
  * holdoff_end - called via a timeout when the holdoff period ends.
  */
@@ -1068,7 +1082,7 @@ device_script(program, in, out)
                close(out);
            }
        }
                close(out);
            }
        }
-       if (redirect_stderr) {
+       if (nodetach == 0) {
            close(2);
            errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600);
            if (errfd >= 0 && errfd != 2) {
            close(2);
            errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600);
            if (errfd >= 0 && errfd != 2) {
index ae12981dffdf34681dc4a0ec441687ffda7b09db..5a194b59ea1054511f3ec402601753c529189d7b 100644 (file)
@@ -18,7 +18,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: options.c,v 1.41 1998/03/25 01:29:05 paulus Exp $";
+static char rcsid[] = "$Id: options.c,v 1.42 1998/03/26 04:46:06 paulus Exp $";
 #endif
 
 #include <ctype.h>
 #endif
 
 #include <ctype.h>
@@ -173,6 +173,7 @@ static int setcrtscts __P((char **));
 static int setnocrtscts __P((char **));
 static int setxonxoff __P((char **));
 static int setnodetach __P((char **));
 static int setnocrtscts __P((char **));
 static int setxonxoff __P((char **));
 static int setnodetach __P((char **));
+static int setupdetach __P((char **));
 static int setmodem __P((char **));
 static int setlocal __P((char **));
 static int setlock __P((char **));
 static int setmodem __P((char **));
 static int setlocal __P((char **));
 static int setlock __P((char **));
@@ -275,6 +276,7 @@ static struct cmd {
     {"-d", 0, setdebug},       /* Increase debugging level */
     {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
     {"-detach", 0, setnodetach}, /* don't fork */
     {"-d", 0, setdebug},       /* Increase debugging level */
     {"nodetach", 0, setnodetach}, /* Don't detach from controlling tty */
     {"-detach", 0, setnodetach}, /* don't fork */
+    {"updetach", 0, setupdetach}, /* Detach once an NP has come up */
     {"noip", 0, noip},         /* Disable IP and IPCP */
     {"-ip", 0, noip},          /* Disable IP and IPCP */
     {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
     {"noip", 0, noip},         /* Disable IP and IPCP */
     {"-ip", 0, noip},          /* Disable IP and IPCP */
     {"nomagic", 0, nomagicnumber}, /* Disable magic number negotiation */
@@ -1870,6 +1872,14 @@ setnodetach(argv)
     return (1);
 }
 
     return (1);
 }
 
+static int
+setupdetach(argv)
+    char **argv;
+{
+    nodetach = -1;
+    return (1);
+}
+
 static int
 setdemand(argv)
     char **argv;
 static int
 setdemand(argv)
     char **argv;
index 9ef4a8fd0e735a00185f2d77b85f08e907edb367..46b1f937163c6f4b65526ea14b6464b640fd331d 100644 (file)
@@ -16,7 +16,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * $Id: pppd.h,v 1.20 1998/03/25 01:30:18 paulus Exp $
+ * $Id: pppd.h,v 1.21 1998/03/26 04:46:08 paulus Exp $
  */
 
 /*
  */
 
 /*
@@ -69,6 +69,7 @@ extern char   peer_authname[];/* Authenticated name of peer */
 extern int     privileged;     /* We were run by real-uid root */
 extern int     need_holdoff;   /* Need holdoff period after link terminates */
 extern char    **script_env;   /* Environment variables for scripts */
 extern int     privileged;     /* We were run by real-uid root */
 extern int     need_holdoff;   /* Need holdoff period after link terminates */
 extern char    **script_env;   /* Environment variables for scripts */
+extern int     detached;       /* Have detached from controlling tty */
 
 /*
  * Variables set by command-line options.
 
 /*
  * Variables set by command-line options.
@@ -176,6 +177,7 @@ extern struct protent *protocols[];
  */
 
 /* Procedures exported from main.c. */
  */
 
 /* Procedures exported from main.c. */
+void detach __P((void));       /* Detach from controlling tty */
 void die __P((int));           /* Cleanup and exit */
 void quit __P((void));         /* like die(1) */
 void novm __P((char *));       /* Say we ran out of memory, and die */
 void die __P((int));           /* Cleanup and exit */
 void quit __P((void));         /* like die(1) */
 void novm __P((char *));       /* Say we ran out of memory, and die */