summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2018-12-19 18:14:46 +0000
committerFrediano Ziglio <fziglio@redhat.com>2019-01-07 18:15:42 +0000
commit41ad267d8125d1bf4880388083bc13faeecb1fae (patch)
tree230c46a376092b970af6718270d7fa9f6d9c1d0a /src
parent77ef2213aaa00eb63dceedbee91e5bf8c58fda3c (diff)
Check errors setting standard file descriptors
Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Christophe Fergeau <cfergeau@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/vdagent/vdagent.c16
-rw-r--r--src/vdagentd/vdagentd.c16
2 files changed, 24 insertions, 8 deletions
diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 9642a30..90247f9 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -280,7 +280,6 @@ static void wait_and_exit(int s)
static int daemonize(void)
{
- int x;
int fd[2];
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fd)) {
@@ -295,9 +294,18 @@ static int daemonize(void)
close(STDOUT_FILENO);
close(STDERR_FILENO);
setsid();
- x = open("/dev/null", O_RDWR);
- x = dup(x);
- x = dup(x);
+ // coverity[leaked_handle] just opening standard file descriptors
+ if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
+ exit(1);
+ }
+ // coverity[leaked_handle] just opening standard file descriptors
+ if (dup(STDIN_FILENO) != STDOUT_FILENO) {
+ exit(1);
+ }
+ // coverity[leaked_handle] just opening standard file descriptors
+ if (dup(STDOUT_FILENO) != STDERR_FILENO) {
+ exit(1);
+ }
close(fd[0]);
return fd[1];
case -1:
diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index 5ed29cc..f5ba3c2 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -941,7 +941,6 @@ static void agent_read_complete(struct udscs_connection **connp,
static void daemonize(void)
{
- int x;
FILE *pidfile;
/* detach from terminal */
@@ -951,9 +950,18 @@ static void daemonize(void)
close(STDOUT_FILENO);
close(STDERR_FILENO);
setsid();
- x = open("/dev/null", O_RDWR);
- x = dup(x);
- x = dup(x);
+ // coverity[leaked_handle] just opening standard file descriptors
+ if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
+ exit(1);
+ }
+ // coverity[leaked_handle] just opening standard file descriptors
+ if (dup(STDIN_FILENO) != STDOUT_FILENO) {
+ exit(1);
+ }
+ // coverity[leaked_handle] just opening standard file descriptors
+ if (dup(STDOUT_FILENO) != STDERR_FILENO) {
+ exit(1);
+ }
pidfile = fopen(pidfilename, "w");
if (pidfile) {
fprintf(pidfile, "%d\n", (int)getpid());