/* -*-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'
*
/*----- 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.
*
#include <pwd.h>
#include <syslog.h>
#include <unistd.h>
+#include <fcntl.h>
extern char **environ;
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 --- */
{
/* --- 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' },
/* --- 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 }