#ifndef lint
static char ocopyright[] =
-"$Id: dhclient.c,v 1.134 2006/02/27 23:56:12 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.135 2006/03/27 09:45:47 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
int argc;
char **argv, **envp;
{
+ int fd;
int i;
struct servent *ent;
struct interface_info *ip;
int no_dhclient_script = 0;
char *s;
- /* Make sure we have stdin, stdout and stderr. */
- i = open ("/dev/null", O_RDWR);
- if (i == 0)
- i = open ("/dev/null", O_RDWR);
- if (i == 1) {
- i = open ("/dev/null", O_RDWR);
- log_perror = 0; /* No sense logging to /dev/null. */
- } else if (i != -1)
- close (i);
+ /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
+ 2 (stderr) are open. To do this, we assume that when we
+ open a file the lowest available file decriptor is used. */
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 0)
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 1)
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 2)
+ log_perror = 0; /* No sense logging to /dev/null. */
+ else if (fd != -1)
+ close (fd);
#ifdef SYSLOG_4_2
openlog ("dhclient", LOG_NDELAY);
{
static int state = 0;
int pid;
- int i;
/* Don't become a daemon if the user requested otherwise. */
if (no_daemon) {
close(2);
/* Reopen them on /dev/null. */
- i = open ("/dev/null", O_RDWR);
- if (i == 0)
- i = open ("/dev/null", O_RDWR);
- if (i == 1) {
- i = open ("/dev/null", O_RDWR);
- log_perror = 0; /* No sense logging to /dev/null. */
- } else if (i != -1)
- close (i);
+ open ("/dev/null", O_RDWR);
+ open ("/dev/null", O_RDWR);
+ open ("/dev/null", O_RDWR);
+ log_perror = 0; /* No sense logging to /dev/null. */
write_client_pid_file ();
}
#ifndef lint
static char ocopyright[] =
-"$Id: dhcrelay.c,v 1.55 2006/02/27 23:56:13 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
+"$Id: dhcrelay.c,v 1.56 2006/03/27 09:45:47 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
int argc;
char **argv, **envp;
{
+ int fd;
int i;
struct servent *ent;
struct server_list *sp = (struct server_list *)0;
char *s;
struct interface_info *tmp = (struct interface_info *)0;
- /* Make sure we have stdin, stdout and stderr. */
- i = open ("/dev/null", O_RDWR);
- if (i == 0)
- i = open ("/dev/null", O_RDWR);
- if (i == 1) {
- i = open ("/dev/null", O_RDWR);
- log_perror = 0; /* No sense logging to /dev/null. */
- } else if (i != -1)
- close (i);
+ /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
+ 2 (stderr) are open. To do this, we assume that when we
+ open a file the lowest available file decriptor is used. */
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 0)
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 1)
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 2)
+ log_perror = 0; /* No sense logging to /dev/null. */
+ else if (fd != -1)
+ close (fd);
#ifdef SYSLOG_4_2
openlog ("dhcrelay", LOG_NDELAY);
#ifndef lint
static char ocopyright[] =
-"$Id: dhcpd.c,v 1.117 2005/03/17 20:15:27 dhankins Exp $ Copyright 2004-2005 Internet Systems Consortium.";
+"$Id: dhcpd.c,v 1.118 2006/03/27 09:45:47 shane Exp $ Copyright 2004-2005 Internet Systems Consortium.";
#endif
static char copyright[] =
int argc;
char **argv, **envp;
{
+ int fd;
int i, status;
struct servent *ent;
char *s;
char *traceoutfile = (char *)0;
#endif
- /* Make sure we have stdin, stdout and stderr. */
- status = open ("/dev/null", O_RDWR);
- if (status == 0)
- status = open ("/dev/null", O_RDWR);
- if (status == 1) {
- status = open ("/dev/null", O_RDWR);
- log_perror = 0; /* No sense logging to /dev/null. */
- } else if (status != -1)
- close (status);
+ /* Make sure that file descriptors 0 (stdin), 1, (stdout), and
+ 2 (stderr) are open. To do this, we assume that when we
+ open a file the lowest available file decriptor is used. */
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 0)
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 1)
+ fd = open ("/dev/null", O_RDWR);
+ if (fd == 2)
+ log_perror = 0; /* No sense logging to /dev/null. */
+ else if (fd != -1)
+ close (fd);
/* Set up the client classification system. */
classification_setup ();
if (daemon) {
/* Become session leader and get pid... */
- close (0);
- close (1);
- close (2);
pid = setsid ();
+
+ /* Close standard I/O descriptors. */
+ close (0);
+ close (1);
+ close (2);
+
+ /* Reopen them on /dev/null. */
+ open ("/dev/null", O_RDWR);
+ open ("/dev/null", O_RDWR);
+ open ("/dev/null", O_RDWR);
+ log_perror = 0; /* No sense logging to /dev/null. */
}
/* If we didn't write the pid file earlier because we found a