aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/Makefile4
-rw-r--r--misc/daemon.c23
2 files changed, 22 insertions, 5 deletions
diff --git a/misc/Makefile b/misc/Makefile
index e64451fe22..98d6942fda 100644
--- a/misc/Makefile
+++ b/misc/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991,92,93,94,95,96,97,98,99 Free Software Foundation, Inc.
+# Copyright (C) 1991-1999, 2000 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -59,6 +59,8 @@ routines := brk sbrk sstk ioctl \
getsysstats dirname regexp \
getloadavg
+distribute := device-nrs.h
+
include ../Makeconfig
aux := init-misc
diff --git a/misc/daemon.c b/misc/daemon.c
index bfa5f2edd3..dddb765daf 100644
--- a/misc/daemon.c
+++ b/misc/daemon.c
@@ -34,6 +34,9 @@ static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93";
#include <fcntl.h>
#include <paths.h>
#include <unistd.h>
+#include <sys/stat.h>
+
+#include <device-nrs.h>
int
daemon(nochdir, noclose)
@@ -57,11 +60,23 @@ daemon(nochdir, noclose)
(void)__chdir("/");
if (!noclose && (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 > 2)
+ struct stat64 st;
+
+ if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) == 0
+ && __builtin_expect (S_ISCHR (st.st_mode), 1) != 0
+#if defined DEV_NULL_MAJOR && defined DEV_NULL_MINOR
+ && st.st_rdev == makedev (DEV_NULL_MAJOR, DEV_NULL_MINOR)
+#endif
+ ) {
+ (void)__dup2(fd, STDIN_FILENO);
+ (void)__dup2(fd, STDOUT_FILENO);
+ (void)__dup2(fd, STDERR_FILENO);
+ if (fd > 2)
+ (void)__close (fd);
+ } else {
(void)__close (fd);
+ return -1;
+ }
}
return (0);
}