summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2004-09-25 07:55:46 +0000
committerJakub Jelinek <jakub@redhat.com>2004-09-25 07:55:46 +0000
commitbd7c3bed543d02fb01f69b29ea1a736e7a0f618d (patch)
tree7e9bf02d1315ce177dd95075686ba769057d04b2 /misc
parent338cc5101b59b64358bab982e1311604fdb64651 (diff)
Updated to fedora-glibc-20040925T0738
Diffstat (limited to 'misc')
-rw-r--r--misc/daemon.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/misc/daemon.c b/misc/daemon.c
index bc93956e85..7597ce9996 100644
--- a/misc/daemon.c
+++ b/misc/daemon.c
@@ -61,21 +61,30 @@ daemon(nochdir, noclose)
if (!nochdir)
(void)__chdir("/");
- if (!noclose
- && (fd = open_not_cancel(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
+ if (!noclose) {
struct stat64 st;
- if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) == 0
- && __builtin_expect (S_ISCHR (st.st_mode), 1) != 0
+ if ((fd = open_not_cancel(_PATH_DEVNULL, O_RDWR, 0)) != -1
+ && (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0)
+ == 0)) {
+ if (__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)
+ && (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);
+ ) {
+ (void)__dup2(fd, STDIN_FILENO);
+ (void)__dup2(fd, STDOUT_FILENO);
+ (void)__dup2(fd, STDERR_FILENO);
+ if (fd > 2)
+ (void)__close (fd);
+ } else {
+ /* We must set an errno value since no
+ function call actually failed. */
+ close_not_cancel_no_status (fd);
+ __set_errno (ENODEV);
+ return -1;
+ }
} else {
close_not_cancel_no_status (fd);
return -1;