From: mdw Date: Wed, 15 Oct 2003 09:27:06 +0000 (+0000) Subject: Make sure standard file descriptors are open before starting properly. X-Git-Url: https://git.distorted.org.uk/~mdw/become/commitdiff_plain/1939e189f903d0b635d90b1f8fbd40df03ce6fba Make sure standard file descriptors are open before starting properly. --- diff --git a/src/become.c b/src/become.c index 60cb1f3..7c7c2aa 100644 --- a/src/become.c +++ b/src/become.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: become.c,v 1.23 2003/10/12 10:00:06 mdw Exp $ + * $Id: become.c,v 1.24 2003/10/15 09:27:06 mdw Exp $ * * Main code for `become' * @@ -29,6 +29,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: become.c,v $ + * Revision 1.24 2003/10/15 09:27:06 mdw + * Make sure standard file descriptors are open before starting properly. + * * Revision 1.23 2003/10/12 10:00:06 mdw * Fix for daemon mode. Oops. * @@ -150,6 +153,7 @@ #include #include #include +#include extern char **environ; @@ -558,6 +562,17 @@ int main(int argc, char *argv[]) if (getuid() != geteuid()) flags |= f_setuid; + /* --- Make sure standard file descriptors are open --- */ + + { + int fd; + do { + if ((fd = open("/dev/null", O_RDWR)) < 0) + die(1, "couldn't open /dev/null: %s", strerror(errno)); + } while (fd <= STDERR_FILENO); + close(fd); + } + /* --- Read the environment into a hashtable --- */ { @@ -589,7 +604,7 @@ int main(int argc, char *argv[]) /* --- Group style options --- */ - { "group", gFlag_argReq, 0, 'g' }, + { "group", OPTF_ARGREQ, 0, 'g' }, #ifdef HAVE_SETGROUPS { "keep-groups", 0, 0, 'k' }, { "merge-groups", 0, 0, 'm' }, @@ -598,23 +613,23 @@ int main(int argc, char *argv[]) /* --- Command to run options --- */ - { "command", gFlag_argReq, 0, 'c' }, + { "command", OPTF_ARGREQ, 0, 'c' }, /* --- Server options --- */ #ifndef NONETWORK { "daemon", 0, 0, 'd' }, { "nofork", 0, 0, 'n' }, - { "port", gFlag_argReq, 0, 'p' }, - { "config-file", gFlag_argReq, 0, 'f' }, + { "port", OPTF_ARGREQ, 0, 'p' }, + { "config-file", OPTF_ARGREQ, 0, 'f' }, #endif /* --- Tracing options --- */ #ifndef NTRACE - { "impersonate", gFlag_argReq, 0, 'I' }, - { "trace", gFlag_argOpt, 0, 'T' }, - { "trace-level", gFlag_argOpt, 0, 'L' }, + { "impersonate", OPTF_ARGREQ, 0, 'I' }, + { "trace", OPTF_ARGOPT, 0, 'T' }, + { "trace-level", OPTF_ARGOPT, 0, 'L' }, #endif { 0, 0, 0, 0 }