From: Paul Mackerras Date: Thu, 26 Mar 1998 04:46:08 +0000 (+0000) Subject: Added updetach option. X-Git-Tag: RELEASE_2_3_6~85 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=8d95b4cae82fe429d2988b3d95d37325e65ea5ad Added updetach option. --- diff --git a/pppd/auth.c b/pppd/auth.c index 457fa1c..7ada83a 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -33,7 +33,7 @@ */ #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 @@ -433,6 +433,12 @@ np_up(unit, proto) */ if (maxconnect > 0) TIMEOUT(connect_time_expired, 0, maxconnect); + + /* + * Detach now, if the updetach option was given. + */ + if (nodetach == -1) + detach(); } ++num_np_up; } diff --git a/pppd/main.c b/pppd/main.c index b11ed66..eec19c7 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -18,7 +18,7 @@ */ #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 @@ -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 detached; /* have detached from terminal */ 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 */ @@ -256,7 +256,8 @@ main(argc, argv) */ 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. @@ -270,10 +271,8 @@ main(argc, argv) * 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) { @@ -624,6 +623,21 @@ main(argc, argv) 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. */ @@ -1068,7 +1082,7 @@ device_script(program, in, 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) { diff --git a/pppd/options.c b/pppd/options.c index ae12981..5a194b5 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -18,7 +18,7 @@ */ #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 @@ -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 setupdetach __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 */ + {"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 */ @@ -1870,6 +1872,14 @@ setnodetach(argv) return (1); } +static int +setupdetach(argv) + char **argv; +{ + nodetach = -1; + return (1); +} + static int setdemand(argv) char **argv; diff --git a/pppd/pppd.h b/pppd/pppd.h index 9ef4a8f..46b1f93 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -16,7 +16,7 @@ * 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 detached; /* Have detached from controlling tty */ /* * Variables set by command-line options. @@ -176,6 +177,7 @@ extern struct protent *protocols[]; */ /* 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 */