From: Christian Grothoff Date: Fri, 4 Nov 2011 13:52:33 +0000 (+0000) Subject: close stdin before dup-ing, check return value of dup2 X-Git-Tag: initial-import-from-subversion-38251~16048 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ea9a077ced7eac09a3a6813428aad7e0395f966d;p=oweals%2Fgnunet.git close stdin before dup-ing, check return value of dup2 --- diff --git a/src/transport/gnunet_wlan_sender.c b/src/transport/gnunet_wlan_sender.c index 89bfa0820..3aa32fb1c 100644 --- a/src/transport/gnunet_wlan_sender.c +++ b/src/transport/gnunet_wlan_sender.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "gnunet_protocols.h" #include "plugin_transport_wlan.h" @@ -216,13 +217,18 @@ int main(int argc, char *argv[]){ } else{ /* A zero PID indicates that this is the child process */ - dup2(commpipe[0],0); /* Replace stdin with the in side of the pipe */ - close(commpipe[1]); /* Close unused side of pipe (out side) */ + (void) close(0); + if (-1 == dup2(commpipe[0],0)) /* Replace stdin with the in side of the pipe */ + fprintf (stderr, + "dup2 failed: %s\n", + strerror (errno)); + (void) close(commpipe[1]); /* Close unused side of pipe (out side) */ /* Replace the child fork with a new process */ - if(execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1){ - fprintf(stderr,"Could not start gnunet-transport-wlan-helper!"); - exit(1); - } + if (execl("gnunet-transport-wlan-helper","gnunet-transport-wlan-helper", argv[1], NULL) == -1) + { + fprintf(stderr,"Could not start gnunet-transport-wlan-helper!"); + _exit(1); + } } return 0; }