diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2014-02-20 10:35:33 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2014-02-20 10:35:33 +0000 |
commit | 2a35e345a204cb357361406f28e07bf9076cb092 (patch) | |
tree | 8c51b5dae07a1f3a3a6a13ac6c623e0b0df2a070 /src/util | |
parent | a06237deeec4aed38b09f633d7ebbeabb7da4c03 (diff) | |
download | gnunet-2a35e345a204cb357361406f28e07bf9076cb092.tar.gz gnunet-2a35e345a204cb357361406f28e07bf9076cb092.zip |
Allow redirection of STDERR when starting processes.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/gnunet-uri.c | 2 | ||||
-rw-r--r-- | src/util/helper.c | 2 | ||||
-rw-r--r-- | src/util/os_priority.c | 42 | ||||
-rw-r--r-- | src/util/test_common_logging_runtime_loglevels.c | 3 | ||||
-rw-r--r-- | src/util/test_os_start_process.c | 11 | ||||
-rw-r--r-- | src/util/test_resolver_api.c | 3 |
6 files changed, 52 insertions, 11 deletions
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 279c5a42e..545b78981 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c | |||
@@ -113,7 +113,7 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
113 | GNUNET_DISK_PIPE_END_READ), | 113 | GNUNET_DISK_PIPE_END_READ), |
114 | &maint_child_death, NULL); | 114 | &maint_child_death, NULL); |
115 | p = GNUNET_OS_start_process (GNUNET_NO, 0, | 115 | p = GNUNET_OS_start_process (GNUNET_NO, 0, |
116 | NULL, NULL, | 116 | NULL, NULL, NULL, |
117 | program, | 117 | program, |
118 | program, | 118 | program, |
119 | args[0], | 119 | args[0], |
diff --git a/src/util/helper.c b/src/util/helper.c index 404dad4fa..105ccf057 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -426,7 +426,7 @@ start_helper (struct GNUNET_HELPER_Handle *h) | |||
426 | GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); | 426 | GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); |
427 | h->helper_proc = | 427 | h->helper_proc = |
428 | GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR, | 428 | GNUNET_OS_start_process_vap (h->with_control_pipe, GNUNET_OS_INHERIT_STD_ERR, |
429 | h->helper_in, h->helper_out, | 429 | h->helper_in, h->helper_out, NULL, |
430 | h->binary_name, | 430 | h->binary_name, |
431 | h->binary_argv); | 431 | h->binary_argv); |
432 | if (NULL == h->helper_proc) | 432 | if (NULL == h->helper_proc) |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 23eb1d168..d0c512363 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -503,6 +503,7 @@ start_process (int pipe_control, | |||
503 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 503 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
504 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 504 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
505 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 505 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
506 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | ||
506 | const SOCKTYPE *lsocks, | 507 | const SOCKTYPE *lsocks, |
507 | const char *filename, | 508 | const char *filename, |
508 | char *const argv[]) | 509 | char *const argv[]) |
@@ -523,6 +524,8 @@ start_process (int pipe_control, | |||
523 | unsigned int ls; | 524 | unsigned int ls; |
524 | int fd_stdout_write; | 525 | int fd_stdout_write; |
525 | int fd_stdout_read; | 526 | int fd_stdout_read; |
527 | int fd_stderr_write; | ||
528 | int fd_stderr_read; | ||
526 | int fd_stdin_read; | 529 | int fd_stdin_read; |
527 | int fd_stdin_write; | 530 | int fd_stdin_write; |
528 | 531 | ||
@@ -583,6 +586,19 @@ start_process (int pipe_control, | |||
583 | (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), | 586 | (pipe_stdin, GNUNET_DISK_PIPE_END_WRITE), |
584 | &fd_stdin_write, sizeof (int))); | 587 | &fd_stdin_write, sizeof (int))); |
585 | } | 588 | } |
589 | if (NULL != pipe_stderr) | ||
590 | { | ||
591 | GNUNET_assert (GNUNET_OK == | ||
592 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle | ||
593 | (pipe_stderr, | ||
594 | GNUNET_DISK_PIPE_END_READ), | ||
595 | &fd_stderr_read, sizeof (int))); | ||
596 | GNUNET_assert (GNUNET_OK == | ||
597 | GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle | ||
598 | (pipe_stderr, | ||
599 | GNUNET_DISK_PIPE_END_WRITE), | ||
600 | &fd_stderr_write, sizeof (int))); | ||
601 | } | ||
586 | lscp = NULL; | 602 | lscp = NULL; |
587 | ls = 0; | 603 | ls = 0; |
588 | if (NULL != lsocks) | 604 | if (NULL != lsocks) |
@@ -659,7 +675,14 @@ start_process (int pipe_control, | |||
659 | GNUNET_break (0 == close (1)); | 675 | GNUNET_break (0 == close (1)); |
660 | open_dev_null (1, O_WRONLY); | 676 | open_dev_null (1, O_WRONLY); |
661 | } | 677 | } |
662 | if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_ERR)) | 678 | if (NULL != pipe_stderr) |
679 | { | ||
680 | GNUNET_break (0 == close (fd_stderr_read)); | ||
681 | if (-1 == dup2 (fd_stderr_write, 2)) | ||
682 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); | ||
683 | GNUNET_break (0 == close (fd_stderr_write)); | ||
684 | } | ||
685 | else if (0 == (std_inheritance & GNUNET_OS_INHERIT_STD_ERR)) | ||
663 | { | 686 | { |
664 | GNUNET_break (0 == close (2)); | 687 | GNUNET_break (0 == close (2)); |
665 | open_dev_null (2, O_WRONLY); | 688 | open_dev_null (2, O_WRONLY); |
@@ -1220,6 +1243,7 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
1220 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 1243 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
1221 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 1244 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
1222 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 1245 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
1246 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | ||
1223 | const char *filename, | 1247 | const char *filename, |
1224 | char *const argv[]) | 1248 | char *const argv[]) |
1225 | { | 1249 | { |
@@ -1227,6 +1251,7 @@ GNUNET_OS_start_process_vap (int pipe_control, | |||
1227 | std_inheritance, | 1251 | std_inheritance, |
1228 | pipe_stdin, | 1252 | pipe_stdin, |
1229 | pipe_stdout, | 1253 | pipe_stdout, |
1254 | pipe_stderr, | ||
1230 | NULL, | 1255 | NULL, |
1231 | filename, | 1256 | filename, |
1232 | argv); | 1257 | argv); |
@@ -1249,6 +1274,7 @@ GNUNET_OS_start_process_va (int pipe_control, | |||
1249 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 1274 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
1250 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 1275 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
1251 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 1276 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
1277 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | ||
1252 | const char *filename, va_list va) | 1278 | const char *filename, va_list va) |
1253 | { | 1279 | { |
1254 | struct GNUNET_OS_Process *ret; | 1280 | struct GNUNET_OS_Process *ret; |
@@ -1271,6 +1297,7 @@ GNUNET_OS_start_process_va (int pipe_control, | |||
1271 | std_inheritance, | 1297 | std_inheritance, |
1272 | pipe_stdin, | 1298 | pipe_stdin, |
1273 | pipe_stdout, | 1299 | pipe_stdout, |
1300 | pipe_stderr, | ||
1274 | filename, | 1301 | filename, |
1275 | argv); | 1302 | argv); |
1276 | GNUNET_free (argv); | 1303 | GNUNET_free (argv); |
@@ -1294,14 +1321,20 @@ GNUNET_OS_start_process (int pipe_control, | |||
1294 | enum GNUNET_OS_InheritStdioFlags std_inheritance, | 1321 | enum GNUNET_OS_InheritStdioFlags std_inheritance, |
1295 | struct GNUNET_DISK_PipeHandle *pipe_stdin, | 1322 | struct GNUNET_DISK_PipeHandle *pipe_stdin, |
1296 | struct GNUNET_DISK_PipeHandle *pipe_stdout, | 1323 | struct GNUNET_DISK_PipeHandle *pipe_stdout, |
1324 | struct GNUNET_DISK_PipeHandle *pipe_stderr, | ||
1297 | const char *filename, ...) | 1325 | const char *filename, ...) |
1298 | { | 1326 | { |
1299 | struct GNUNET_OS_Process *ret; | 1327 | struct GNUNET_OS_Process *ret; |
1300 | va_list ap; | 1328 | va_list ap; |
1301 | 1329 | ||
1302 | va_start (ap, filename); | 1330 | va_start (ap, filename); |
1303 | ret = GNUNET_OS_start_process_va (pipe_control, std_inheritance, pipe_stdin, | 1331 | ret = GNUNET_OS_start_process_va (pipe_control, |
1304 | pipe_stdout, filename, ap); | 1332 | std_inheritance, |
1333 | pipe_stdin, | ||
1334 | pipe_stdout, | ||
1335 | pipe_stderr, | ||
1336 | filename, | ||
1337 | ap); | ||
1305 | va_end (ap); | 1338 | va_end (ap); |
1306 | return ret; | 1339 | return ret; |
1307 | } | 1340 | } |
@@ -1332,6 +1365,7 @@ GNUNET_OS_start_process_v (int pipe_control, | |||
1332 | std_inheritance, | 1365 | std_inheritance, |
1333 | NULL, | 1366 | NULL, |
1334 | NULL, | 1367 | NULL, |
1368 | NULL, | ||
1335 | lsocks, | 1369 | lsocks, |
1336 | filename, | 1370 | filename, |
1337 | argv); | 1371 | argv); |
@@ -1776,7 +1810,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, | |||
1776 | return NULL; | 1810 | return NULL; |
1777 | va_start (ap, binary); | 1811 | va_start (ap, binary); |
1778 | /* redirect stdout, don't inherit stderr/stdin */ | 1812 | /* redirect stdout, don't inherit stderr/stdin */ |
1779 | eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, binary, ap); | 1813 | eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, NULL, binary, ap); |
1780 | va_end (ap); | 1814 | va_end (ap); |
1781 | if (NULL == eip) | 1815 | if (NULL == eip) |
1782 | { | 1816 | { |
diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c index 3361ca1b1..0fe8614d0 100644 --- a/src/util/test_common_logging_runtime_loglevels.c +++ b/src/util/test_common_logging_runtime_loglevels.c | |||
@@ -391,7 +391,8 @@ runone () | |||
391 | break; | 391 | break; |
392 | } | 392 | } |
393 | 393 | ||
394 | proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, pipe_stdout, | 394 | proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
395 | NULL, pipe_stdout, NULL, | ||
395 | #if MINGW | 396 | #if MINGW |
396 | "test_common_logging_dummy", | 397 | "test_common_logging_dummy", |
397 | #else | 398 | #else |
diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 90d8ae101..e76ec5bcf 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c | |||
@@ -135,7 +135,8 @@ run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | 135 | ||
136 | proc = | 136 | proc = |
137 | GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, | 137 | GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, |
138 | hello_pipe_stdin, hello_pipe_stdout, fn, | 138 | hello_pipe_stdin, hello_pipe_stdout, NULL, |
139 | fn, | ||
139 | "test_gnunet_echo_hello", "-", NULL); | 140 | "test_gnunet_echo_hello", "-", NULL); |
140 | GNUNET_free (fn); | 141 | GNUNET_free (fn); |
141 | 142 | ||
@@ -203,7 +204,9 @@ check_kill () | |||
203 | } | 204 | } |
204 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | 205 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); |
205 | proc = | 206 | proc = |
206 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, | 207 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, |
208 | hello_pipe_stdin, hello_pipe_stdout, NULL, | ||
209 | fn, | ||
207 | "gnunet-service-resolver", "-", NULL); | 210 | "gnunet-service-resolver", "-", NULL); |
208 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ | 211 | sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ |
209 | GNUNET_free (fn); | 212 | GNUNET_free (fn); |
@@ -234,7 +237,9 @@ check_instant_kill () | |||
234 | } | 237 | } |
235 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | 238 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); |
236 | proc = | 239 | proc = |
237 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, | 240 | GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, |
241 | hello_pipe_stdin, hello_pipe_stdout, NULL, | ||
242 | fn, | ||
238 | "gnunet-service-resolver", "-", NULL); | 243 | "gnunet-service-resolver", "-", NULL); |
239 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) | 244 | if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) |
240 | { | 245 | { |
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index c94990415..acc3ae6ae 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c | |||
@@ -367,7 +367,8 @@ main (int argc, char *argv[]) | |||
367 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); | 367 | fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); |
368 | proc = GNUNET_OS_start_process (GNUNET_YES, | 368 | proc = GNUNET_OS_start_process (GNUNET_YES, |
369 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 369 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
370 | NULL, NULL, fn, | 370 | NULL, NULL, NULL, |
371 | fn, | ||
371 | "gnunet-service-resolver", | 372 | "gnunet-service-resolver", |
372 | "-c", "test_resolver_api_data.conf", NULL); | 373 | "-c", "test_resolver_api_data.conf", NULL); |
373 | GNUNET_assert (NULL != proc); | 374 | GNUNET_assert (NULL != proc); |