about summary refs log tree commit diff
path: root/misc/daemon.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-25 05:30:41 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-25 05:30:41 +0000
commit267a7a9eca77719b9cee482585d04ad515a4436d (patch)
treeb38cb2e73cf79014b8dc790a2884159b64e3bf06 /misc/daemon.c
parent5fa3cee8e9d0e2a2222ba760b538a6583ccb983c (diff)
downloadglibc-267a7a9eca77719b9cee482585d04ad515a4436d.tar.gz
glibc-267a7a9eca77719b9cee482585d04ad515a4436d.tar.xz
glibc-267a7a9eca77719b9cee482585d04ad515a4436d.zip
(daemon): Define errno in case /dev/null is not the correct device.
Diffstat (limited to 'misc/daemon.c')
-rw-r--r--misc/daemon.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/misc/daemon.c b/misc/daemon.c
index bc93956e85..775ef1aacf 100644
--- a/misc/daemon.c
+++ b/misc/daemon.c
@@ -65,17 +65,26 @@ daemon(nochdir, noclose)
 	    && (fd = open_not_cancel(_PATH_DEVNULL, O_RDWR, 0)) != -1) {
 		struct stat64 st;
 
-		if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) == 0
-		    && __builtin_expect (S_ISCHR (st.st_mode), 1) != 0
+		if (__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;