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/os_priority.c | |
parent | a06237deeec4aed38b09f633d7ebbeabb7da4c03 (diff) | |
download | gnunet-2a35e345a204cb357361406f28e07bf9076cb092.tar.gz gnunet-2a35e345a204cb357361406f28e07bf9076cb092.zip |
Allow redirection of STDERR when starting processes.
Diffstat (limited to 'src/util/os_priority.c')
-rw-r--r-- | src/util/os_priority.c | 42 |
1 files changed, 38 insertions, 4 deletions
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 | { |