Page MenuHomeFreeBSD

D41381.id125987.diff
No OneTemporary

D41381.id125987.diff

diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -388,6 +388,7 @@
SIGCHLD,
};
+static int nulldesc; /* /dev/null descriptor */
static bool Debug; /* debug flag */
static bool Foreground = false; /* Run in foreground, instead of daemonizing */
static bool resolve = true; /* resolve hostname */
@@ -770,6 +771,11 @@
err(1, "cannot open %s", _PATH_CONSOLE);
(void)strlcpy(consfile.fu_fname, _PATH_CONSOLE + sizeof(_PATH_DEV) - 1,
sizeof(consfile.fu_fname));
+
+ nulldesc = open(_PATH_DEVNULL, O_RDWR);
+ if (nulldesc == -1)
+ err(1, "cannot open %s", _PATH_DEVNULL);
+
(void)strlcpy(bootfile, getbootfile(), sizeof(bootfile));
pfh = pidfile_open(PidFile, 0600, &spid);
@@ -3208,7 +3214,6 @@
static int
waitdaemon(int maxwait)
{
- int fd;
int status;
pid_t pid, childpid;
@@ -3239,13 +3244,9 @@
return (-1);
(void)chdir("/");
- if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
- (void)dup2(fd, STDIN_FILENO);
- (void)dup2(fd, STDOUT_FILENO);
- (void)dup2(fd, STDERR_FILENO);
- if (fd > STDERR_FILENO)
- (void)close(fd);
- }
+ (void)dup2(nulldesc, STDIN_FILENO);
+ (void)dup2(nulldesc, STDOUT_FILENO);
+ (void)dup2(nulldesc, STDERR_FILENO);
return (getppid());
}
@@ -3568,20 +3569,16 @@
p_open(const char *prog, int *rpd)
{
sigset_t sigset = { };
- int nulldesc, pfd[2], pd;
+ int pfd[2], pd;
pid_t pid;
char *argv[4]; /* sh -c cmd NULL */
char errmsg[200];
if (pipe(pfd) == -1)
return (-1);
- if ((nulldesc = open(_PATH_DEVNULL, O_RDWR)) == -1)
- /* we are royally screwed anyway */
- return (-1);
switch ((pid = pdfork(&pd, PD_CLOEXEC))) {
case -1:
- close(nulldesc);
return (-1);
case 0:
@@ -3612,7 +3609,6 @@
(void)execvp(_PATH_BSHELL, argv);
_exit(255);
}
- close(nulldesc);
close(pfd[0]);
/*
* Avoid blocking on a hung pipe. With O_NONBLOCK, we are

File Metadata

Mime Type
text/plain
Expires
Wed, May 20, 8:33 PM (5 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33355838
Default Alt Text
D41381.id125987.diff (1 KB)

Event Timeline