diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-20 13:48:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-20 13:48:47 +0000 |
commit | de9530925391111d24a7806a45040373850747b1 (patch) | |
tree | 2c91a5320d48ff239770f6afee00a7f80003bbf0 /src/exit | |
parent | 03b74eb3aa9c8dfdb2a4f9dd4bc1f699e1d2152f (diff) | |
download | gnunet-de9530925391111d24a7806a45040373850747b1.tar.gz gnunet-de9530925391111d24a7806a45040373850747b1.zip |
give sysctl /dev/null instead of no stdin/stdout
Diffstat (limited to 'src/exit')
-rw-r--r-- | src/exit/gnunet-helper-exit.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/exit/gnunet-helper-exit.c b/src/exit/gnunet-helper-exit.c index 30f5d2569..882778b3f 100644 --- a/src/exit/gnunet-helper-exit.c +++ b/src/exit/gnunet-helper-exit.c | |||
@@ -89,6 +89,32 @@ struct in6_ifreq | |||
89 | #endif | 89 | #endif |
90 | 90 | ||
91 | 91 | ||
92 | /** | ||
93 | * Open '/dev/null' and make the result the given | ||
94 | * file descriptor. | ||
95 | * | ||
96 | * @param target_fd desired FD to point to /dev/null | ||
97 | * @param flags open flags (O_RDONLY, O_WRONLY) | ||
98 | */ | ||
99 | static void | ||
100 | open_dev_null (int target_fd, | ||
101 | int flags) | ||
102 | { | ||
103 | int fd; | ||
104 | |||
105 | fd = open ("/dev/null", flags); | ||
106 | if (-1 == fd) | ||
107 | abort (); | ||
108 | if (fd == target_fd) | ||
109 | return; | ||
110 | if (-1 == dup2 (fd, target_fd)) | ||
111 | { | ||
112 | (void) close (fd); | ||
113 | abort (); | ||
114 | } | ||
115 | (void) close (fd); | ||
116 | } | ||
117 | |||
92 | 118 | ||
93 | /** | 119 | /** |
94 | * Run the given command and wait for it to complete. | 120 | * Run the given command and wait for it to complete. |
@@ -119,7 +145,9 @@ fork_and_exec (const char *file, | |||
119 | /* close stdin/stdout to not cause interference | 145 | /* close stdin/stdout to not cause interference |
120 | with the helper's main protocol! */ | 146 | with the helper's main protocol! */ |
121 | (void) close (0); | 147 | (void) close (0); |
148 | open_dev_null (0, O_RDONLY); | ||
122 | (void) close (1); | 149 | (void) close (1); |
150 | open_dev_null (1, O_WRONLY); | ||
123 | (void) execv (file, cmd); | 151 | (void) execv (file, cmd); |
124 | /* can only get here on error */ | 152 | /* can only get here on error */ |
125 | fprintf (stderr, | 153 | fprintf (stderr, |