Skip to content

Commit

Permalink
Fix Coverity CID #89536: Unchecked return value from library
Browse files Browse the repository at this point in the history
The daemonizing code in main() failed to check the return value of
open() when redirecting STDIN/STDOUT/STDERR to someplace safe.

Signed-off-by: Joachim Nilsson <[email protected]>
  • Loading branch information
troglobit committed Apr 20, 2015
1 parent 92b90e3 commit 907233f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,17 @@ int main(int argc, char *argv[])
haveterminal = 0;
if (fork())
exit(0);
close(0);
close(1);
close(2);
open("/", 0);
dup2(0, 1);
dup2(0, 2);

close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);

n = open("/dev/null", O_RDWR, 0);
if (n >= 0) {
dup2(n, STDIN_FILENO);
dup2(n, STDOUT_FILENO);
dup2(n, STDERR_FILENO);
}
#ifdef SYSV
setpgrp();
#else
Expand All @@ -499,9 +504,8 @@ int main(int argc, char *argv[])
#endif /* SYSV */
} /* End of child process code */

if (pidfile(NULL)) {
if (pidfile(NULL))
warn("Cannot create pidfile");
}

/*
* Main receive loop.
Expand Down

0 comments on commit 907233f

Please sign in to comment.