summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ppp
diff options
context:
space:
mode:
authorbrian <brian@FreeBSD.org>2001-07-04 03:34:20 +0000
committerbrian <brian@FreeBSD.org>2001-07-04 03:34:20 +0000
commit746c94eef49c16fd453841bbf10d856057837480 (patch)
tree7a9a6d5a608388edca4eee1f442419c937608a1b /usr.sbin/ppp
parent33e85623fa7950794d670bf31ce9bde30f6422b5 (diff)
downloadFreeBSD-src-746c94eef49c16fd453841bbf10d856057837480.zip
FreeBSD-src-746c94eef49c16fd453841bbf10d856057837480.tar.gz
Handle any of descriptors 0, 1 or 2 being closed when we're
envoked -- don't use them (as return values from open()), then (say) close(STDIN_FILENO) when daemonising. This is done by grabbing 3 descriptors to /dev/null at startup and releasing them after we've daemonised. MFC after: 1 week
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r--usr.sbin/ppp/main.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c
index c094e9a..968e6d2 100644
--- a/usr.sbin/ppp/main.c
+++ b/usr.sbin/ppp/main.c
@@ -295,11 +295,24 @@ main(int argc, char **argv)
{
char *name;
const char *lastlabel;
- int label, arg;
+ int arg, f, holdfd[3], label;
struct bundle *bundle;
struct prompt *prompt;
struct switches sw;
+ /*
+ * We open 3 descriptors to ensure that STDIN_FILENO, STDOUT_FILENO and
+ * STDERR_FILENO are always open. These are closed before DoLoop(),
+ * but *after* we've avoided the possibility of erroneously closing
+ * an important descriptor with close(STD{IN,OUT,ERR}_FILENO).
+ */
+ if ((holdfd[0] = open(_PATH_DEVNULL, O_RDWR)) == -1) {
+ fprintf(stderr, "Cannot open %s !\n", _PATH_DEVNULL);
+ return 2;
+ }
+ for (f = 1; f < sizeof holdfd / sizeof *holdfd; f++)
+ dup2(holdfd[0], holdfd[f]);
+
name = strrchr(argv[0], '/');
log_Open(name ? name + 1 : argv[0]);
@@ -498,6 +511,10 @@ main(int argc, char **argv)
prompt_Required(prompt);
}
+ /* We can get rid of these now */
+ for (f = 0; f < sizeof holdfd / sizeof *holdfd; f++)
+ close(holdfd[f]);
+
log_Printf(LogPHASE, "PPP Started (%s mode).\n", mode2Nam(sw.mode));
DoLoop(bundle);
AbortProgram(EX_NORMAL);
OpenPOWER on IntegriCloud