Skip to content

Commit

Permalink
(daemon): Define errno in case /dev/null is not the correct device.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulrich Drepper committed Sep 25, 2004
1 parent 5fa3cee commit 267a7a9
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions misc/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 267a7a9

Please sign in to comment.