X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fmain.c;h=eec19c760398d598ca9eb8e7650f295db0d9101a;hb=8d95b4cae82fe429d2988b3d95d37325e65ea5ad;hp=b11ed66a3a1dbdd1791556a498ce96100ee64ded;hpb=ed8ac3e1efc938c3832b84d585a2a7d5a2422cbc;p=ppp.git 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) {