aboutsummaryrefslogtreecommitdiff
path: root/misc/daemon.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2000-09-26 07:56:19 +0000
committerUlrich Drepper <drepper@redhat.com>2000-09-26 07:56:19 +0000
commit316ca440b070114ba877455c3dbbcdc1b20e4f33 (patch)
tree4224faacba4731e0b405a79552dde36c31e3eeea /misc/daemon.c
parente5448d7ad2c39a6784894e8e840514b0d88333bc (diff)
downloadglibc-316ca440b070114ba877455c3dbbcdc1b20e4f33.tar
glibc-316ca440b070114ba877455c3dbbcdc1b20e4f33.tar.gz
glibc-316ca440b070114ba877455c3dbbcdc1b20e4f33.tar.bz2
glibc-316ca440b070114ba877455c3dbbcdc1b20e4f33.zip
Update.
* misc/daemon.c (daemon): Fail if !noclose and we cannot open the real /dev/null device. * sysdeps/generic/check_fds.c: Include device-nrs.h. * sysdeps/generic/device-nrs.h: New file. * sysdeps/unix/sysv/linux/device-nrs.h: New file. * misc/Makefile (distribute): Add device-nrs.h. * posix/wordexp.c (exec_comm_child): Likewise. * locale/nl_langinfo.c: Allow use of file for __nl_langinfo_l definition.
Diffstat (limited to 'misc/daemon.c')
-rw-r--r--misc/daemon.c23
1 files changed, 19 insertions, 4 deletions
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);
}