From 8f9464256fc06a884bf589b4004262a0549d11b3 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 9 Jul 2012 19:04:19 +0000 Subject: -LRN: Another take on std descriptor inheritance Now descriptors are not inherited by default, you have to pass a set of flags to make it so. When pipes are given, flags have no effect. gnunet-arm now has two options to block stdout and stderr from being passed to gnunet-service-arm --- src/arm/arm_api.c | 14 ++- src/arm/do_start_process.c | 5 +- src/arm/gnunet-arm.c | 18 ++++ src/arm/gnunet-service-arm.c | 4 +- src/arm/test_arm_api.c | 4 +- src/arm/test_exponential_backoff.c | 4 +- src/arm/test_gnunet_service_manager.c | 2 +- src/chat/test_chat.c | 2 +- src/chat/test_chat_private.c | 2 +- src/core/test_core_api.c | 2 +- src/core/test_core_api_reliability.c | 2 +- src/core/test_core_api_start_only.c | 2 +- src/core/test_core_quota_compliance.c | 2 +- src/fs/gnunet-auto-share.c | 2 +- src/hostlist/test_gnunet_daemon_hostlist.c | 2 +- .../test_gnunet_daemon_hostlist_learning.c | 4 +- .../test_gnunet_daemon_hostlist_reconnect.c | 2 +- src/include/gnunet_arm_service.h | 3 + src/include/gnunet_os_lib.h | 53 ++++++++++ src/nat/nat.c | 6 +- src/nat/nat_mini.c | 2 +- src/nat/test_nat_test.c | 2 +- src/statistics/test_statistics_api.c | 4 +- src/statistics/test_statistics_api_loop.c | 2 +- src/statistics/test_statistics_api_watch.c | 2 +- .../test_statistics_api_watch_zero_value.c | 2 +- src/testbed/testbed_api_hosts.c | 4 + src/testing/testing.c | 2 +- src/testing_old/test_testing_large_topology.c | 2 +- src/testing_old/test_testing_topology.c | 2 +- src/testing_old/testing.c | 38 +++---- src/testing_old/testing_group.c | 12 +-- .../gnunet-transport-certificate-creation.c | 4 +- src/transport/gnunet-transport.c | 2 +- src/transport/plugin_transport_http_server.c | 2 +- src/util/crypto_random.c | 2 +- src/util/gnunet-uri.c | 2 +- src/util/helper.c | 2 +- src/util/os_priority.c | 112 ++++++++++++++++++--- src/util/test_common_logging_runtime_loglevels.c | 2 +- src/util/test_os_start_process.c | 6 +- src/util/test_resolver_api.c | 2 +- 42 files changed, 257 insertions(+), 88 deletions(-) diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 1b78d3393..a598a5fea 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -295,6 +295,11 @@ struct RequestContext */ uint16_t type; + /** + * Flags for passing std descriptors to ARM (when starting ARM). + */ + enum GNUNET_OS_InheritStdioFlags std_inheritance; + }; #include "do_start_process.c" @@ -381,14 +386,14 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { /* Means we are ONLY running locally */ /* we're clearly running a test, don't daemonize */ - proc = do_start_process (GNUNET_NO, + proc = do_start_process (GNUNET_NO, pos->std_inheritance, NULL, loprefix, binary, "-c", config, /* no daemonization! */ lopostfix, NULL); } else { - proc = do_start_process (GNUNET_NO, + proc = do_start_process (GNUNET_NO, pos->std_inheritance, NULL, loprefix, binary, "-c", config, "-d", lopostfix, NULL); } @@ -522,6 +527,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name, * * @param h handle to ARM * @param service_name name of the service + * @param std_inheritance inheritance of std streams * @param timeout how long to wait before failing for good * @param cb callback to invoke when service is ready * @param cb_cls closure for callback @@ -529,6 +535,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name, void GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, const char *service_name, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_TIME_Relative timeout, GNUNET_ARM_Callback cb, void *cb_cls) { @@ -547,12 +554,13 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, sctx->callback = cb; sctx->cls = cb_cls; sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); + sctx->std_inheritance = std_inheritance; memcpy (&sctx[1], service_name, slen); GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report, sctx); return; } - if (h->client == NULL) + if (NULL == h->client) { client = GNUNET_CLIENT_connect ("arm", h->cfg); if (client == NULL) diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c index 4554f5729..1bc56d540 100644 --- a/src/arm/do_start_process.c +++ b/src/arm/do_start_process.c @@ -8,13 +8,14 @@ * with spaces to the new process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param lsocks array of listen sockets to dup starting at fd3 (systemd-style), or NULL * @param first_arg first argument for argv (may be an empty string) * @param ... more arguments, NULL terminated * @return handle of the started process, NULL on error */ static struct GNUNET_OS_Process * -do_start_process (int pipe_control, +do_start_process (int pipe_control, unsigned int std_inheritance, const SOCKTYPE * lsocks, const char *first_arg, ...) { va_list ap; @@ -97,7 +98,7 @@ do_start_process (int pipe_control, /* *INDENT-ON* */ va_end (ap); argv[argv_size] = NULL; - proc = GNUNET_OS_start_process_v (pipe_control, lsocks, argv[0], argv); + proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, argv[0], argv); while (argv_size > 0) GNUNET_free (argv[--argv_size]); GNUNET_free (argv); diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index 8ce8375e7..84d91355a 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -126,6 +126,16 @@ static unsigned int phase; static struct GNUNET_TIME_Relative timeout; +/** + * Do we want to give our stdout to gnunet-service-arm? + */ +static unsigned int no_stdout = 0; + +/** + * Do we want to give our stderr to gnunet-service-arm? + */ +static unsigned int no_stderr = 0; + /** * Main continuation-passing-style loop. Runs the various * jobs that we've been asked to do in order. @@ -323,6 +333,8 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (start) { GNUNET_ARM_start_service (h, "arm", + (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | + (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), (0 == timeout.rel_value) ? START_TIMEOUT : timeout, &confirm_cb, "arm"); @@ -333,6 +345,8 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) if (init != NULL) { GNUNET_ARM_start_service (h, init, + (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | + (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), (0 == timeout.rel_value) ? START_TIMEOUT : timeout, &confirm_cb, init); @@ -422,6 +436,10 @@ main (int argc, char *const *argv) GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms}, {'I', "info", NULL, gettext_noop ("List currently running services"), GNUNET_NO, &GNUNET_GETOPT_set_one, &list}, + {'O', "no-stdout", NULL, gettext_noop ("Don't let gnunet-service-arm inherit standard output"), + GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stdout}, + {'E', "no-stderr", NULL, gettext_noop ("Don't let gnunet-service-arm inherit standard error"), + GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stderr}, GNUNET_GETOPT_OPTION_END }; diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index ce9104334..00dda263e 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -320,12 +320,12 @@ start_process (struct ServiceList *sl) GNUNET_assert (NULL == sl->proc); if (GNUNET_YES == use_debug) sl->proc = - do_start_process (sl->pipe_control, + do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, lsocks, loprefix, sl->binary, "-c", sl->config, "-L", "DEBUG", options, NULL); else sl->proc = - do_start_process (sl->pipe_control, + do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, lsocks, loprefix, sl->binary, "-c", sl->config, options, NULL); if (sl->proc == NULL) diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index e4e4510ad..e9bda410b 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c @@ -109,7 +109,7 @@ arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus success) GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); #endif } - GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, + GNUNET_ARM_start_service (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &resolver_notify, NULL); } @@ -121,7 +121,7 @@ task (void *cls, char *const *args, const char *cfgfile, cfg = c; arm = GNUNET_ARM_connect (cfg, NULL); #if START_ARM - GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL); + GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &arm_notify, NULL); #else arm_notify (NULL, GNUNET_YES); #endif diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index 77bd9e2ce..1709dbdba 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c @@ -270,7 +270,7 @@ static void arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus status) { GNUNET_assert (status == GNUNET_ARM_PROCESS_STARTING); - GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify, + GNUNET_ARM_start_service (arm, "do-nothing", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, TIMEOUT, &do_nothing_notify, NULL); } @@ -365,7 +365,7 @@ task (void *cls, char *const *args, const char *cfgfile, arm = GNUNET_ARM_connect (cfg, NULL); #if START_ARM - GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, + GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, &arm_notify, NULL); #else arm_do_nothing (NULL, GNUNET_YES); diff --git a/src/arm/test_gnunet_service_manager.c b/src/arm/test_gnunet_service_manager.c index fe3357161..2abcc9563 100644 --- a/src/arm/test_gnunet_service_manager.c +++ b/src/arm/test_gnunet_service_manager.c @@ -124,7 +124,7 @@ run (void *cls, char *const *args, const char *cfgfile, cfg = c; #if START_ARM arm = GNUNET_ARM_connect (cfg, NULL); - GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL); + GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &arm_notify, NULL); #else arm_notify (NULL, GNUNET_YES); #endif diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c index 370cb04ee..5dcb87966 100644 --- a/src/chat/test_chat.c +++ b/src/chat/test_chat.c @@ -119,7 +119,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/chat/test_chat_private.c b/src/chat/test_chat_private.c index 0aebd8f8b..ec170a1dd 100644 --- a/src/chat/test_chat_private.c +++ b/src/chat/test_chat_private.c @@ -133,7 +133,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index d1591328f..0512c9617 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -319,7 +319,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 682424f89..d4afbc27d 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -429,7 +429,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, NULL); #endif diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index 7704b4387..a502fce6d 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c @@ -139,7 +139,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index bee8c02b4..61fe21626 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -573,7 +573,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, NULL); #endif diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index f7026554d..9e2f45d3e 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c @@ -488,7 +488,7 @@ work (void *cls, _("Publishing `%s'\n"), wi->filename); publish_proc = GNUNET_OS_start_process_vap (GNUNET_YES, - NULL, NULL, + 0, NULL, NULL, "gnunet-publish", argv); if (NULL == publish_proc) diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 5f07ce415..6e9f31a20 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -133,7 +133,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index 6f0ab4c9e..8a0992dda 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -385,7 +385,7 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); @@ -416,7 +416,7 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index ff6e4177d..1b1df9a3a 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c @@ -144,7 +144,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h index 116bfc5b4..0aa916bd4 100644 --- a/src/include/gnunet_arm_service.h +++ b/src/include/gnunet_arm_service.h @@ -37,6 +37,7 @@ extern "C" #include "gnunet_configuration_lib.h" #include "gnunet_scheduler_lib.h" +#include "gnunet_os_lib.h" #include "gnunet_time_lib.h" /** @@ -169,12 +170,14 @@ GNUNET_ARM_disconnect (struct GNUNET_ARM_Handle *h); * * @param h handle to ARM * @param service_name name of the service + * @param std_inheritance flags controlling std descriptors inheritance * @param timeout how long to wait before failing for good * @param cb callback to invoke when service is ready * @param cb_cls closure for callback */ void GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, const char *service_name, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_TIME_Relative timeout, GNUNET_ARM_Callback cb, void *cb_cls); diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index 67b6cce0c..1d4828f48 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h @@ -54,6 +54,51 @@ extern "C" #include "gnunet_configuration_lib.h" #include "gnunet_scheduler_lib.h" + +/** + * Flags that determine which of the standard streams + * should be inherited by the child process. + */ +enum GNUNET_OS_InheritStdioFlags +{ + + /** + * No standard streams should be inherited. + */ + GNUNET_OS_INHERIT_STD_NONE = 0, + + /** + * When this flag is set, the child process will + * inherit stdin of the parent. + */ + GNUNET_OS_INHERIT_STD_IN = 1, + + /** + * When this flag is set, the child process will + * inherit stdout of the parent. + */ + GNUNET_OS_INHERIT_STD_OUT = 2, + + /** + * When this flag is set, the child process will + * inherit stderr of the parent. + */ + GNUNET_OS_INHERIT_STD_ERR = 4, + + /** + * When these flags are set, the child process will + * inherit stdout and stderr of the parent. + */ + GNUNET_OS_INHERIT_STD_OUT_AND_ERR = 6, + + /** + * Use this option to have all of the standard streams + * (stdin, stdout and stderror) be inherited. + */ + GNUNET_OS_INHERIT_STD_ALL = 7 +}; + + /** * Process information (OS-dependent) */ @@ -257,6 +302,7 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -265,6 +311,7 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_vap (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, @@ -275,6 +322,7 @@ GNUNET_OS_start_process_vap (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -283,6 +331,7 @@ GNUNET_OS_start_process_vap (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...); @@ -292,6 +341,7 @@ GNUNET_OS_start_process (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -300,6 +350,7 @@ GNUNET_OS_start_process (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_va (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, va_list va); @@ -308,6 +359,7 @@ GNUNET_OS_start_process_va (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param lsocks array of listen sockets to dup systemd-style (or NULL); * must be NULL on platforms where dup is not supported * @param filename name of the binary @@ -317,6 +369,7 @@ GNUNET_OS_start_process_va (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_v (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, const SOCKTYPE *lsocks, const char *filename, char *const argv[]); diff --git a/src/nat/nat.c b/src/nat/nat.c index 79604da7d..80d0fc2bd 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -835,7 +835,7 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h) "gnunet-helper-nat-server", h->internal_address); /* Start the server process */ h->server_proc = - GNUNET_OS_start_process (GNUNET_NO, NULL, h->server_stdout, + GNUNET_OS_start_process (GNUNET_NO, 0, NULL, h->server_stdout, "gnunet-helper-nat-server", "gnunet-helper-nat-server", h->internal_address, NULL); @@ -1332,8 +1332,8 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, _("Running gnunet-helper-nat-client %s %s %u\n"), h->internal_address, inet4, (unsigned int) h->adv_port); proc = - GNUNET_OS_start_process (GNUNET_NO, - NULL, NULL, "gnunet-helper-nat-client", + GNUNET_OS_start_process (GNUNET_NO, 0, NULL, NULL, + "gnunet-helper-nat-client", "gnunet-helper-nat-client", h->internal_address, inet4, port_as_string, NULL); if (NULL == proc) diff --git a/src/nat/nat_mini.c b/src/nat/nat_mini.c index 82697a971..5dffa8120 100644 --- a/src/nat/nat_mini.c +++ b/src/nat/nat_mini.c @@ -176,7 +176,7 @@ GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout, return NULL; } eh->eip = - GNUNET_OS_start_process (GNUNET_NO, NULL, eh->opipe, "external-ip", "external-ip", + GNUNET_OS_start_process (GNUNET_NO, 0, NULL, eh->opipe, "external-ip", "external-ip", NULL); if (NULL == eh->eip) { diff --git a/src/nat/test_nat_test.c b/src/nat/test_nat_test.c index 891a7633a..c213ffa1e 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c @@ -102,7 +102,7 @@ main (int argc, char *const argv[]) } gns = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-nat-server", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-nat-server", "gnunet-nat-server", "-c", "test_nat_test_data.conf", "12345", NULL); GNUNET_assert (NULL != gns); diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index 11f02b817..ddebfa356 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c @@ -139,7 +139,7 @@ check () struct GNUNET_OS_Process *proc; proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); #endif @@ -162,7 +162,7 @@ check () #if START_SERVICE /* restart to check persistence! */ proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); #endif diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c index 58114f278..ae798b830 100644 --- a/src/statistics/test_statistics_api_loop.c +++ b/src/statistics/test_statistics_api_loop.c @@ -97,7 +97,7 @@ check () struct GNUNET_OS_Process *proc; proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if DEBUG_STATISTICS "-L", "DEBUG", diff --git a/src/statistics/test_statistics_api_watch.c b/src/statistics/test_statistics_api_watch.c index e976bd473..f3524aa7c 100644 --- a/src/statistics/test_statistics_api_watch.c +++ b/src/statistics/test_statistics_api_watch.c @@ -127,7 +127,7 @@ check () struct GNUNET_OS_Process *proc; proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if VERBOSE "-L", "DEBUG", diff --git a/src/statistics/test_statistics_api_watch_zero_value.c b/src/statistics/test_statistics_api_watch_zero_value.c index 9fadf6a6c..fe3974fc9 100644 --- a/src/statistics/test_statistics_api_watch_zero_value.c +++ b/src/statistics/test_statistics_api_watch_zero_value.c @@ -160,7 +160,7 @@ check () struct GNUNET_OS_Process *proc; proc = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if VERBOSE "-L", "DEBUG", diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 326a64924..f42c954ab 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c @@ -385,6 +385,8 @@ GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host, if ((NULL == host) || (0 == host->id)) { h->process = GNUNET_OS_start_process_vap (GNUNET_YES, + GNUNET_OS_INHERIT_STD_OUT | + GNUNET_OS_INHERIT_STD_ERR, h->cpipe, NULL, "gnunet-service-testbed", binary_argv); @@ -414,6 +416,8 @@ GNUNET_TESTBED_host_run_ (const struct GNUNET_TESTBED_Host *host, remote_args[argp++] = NULL; GNUNET_assert (argp == argc + 6 + 1); h->process = GNUNET_OS_start_process_vap (GNUNET_YES, + GNUNET_OS_INHERIT_STD_OUT | + GNUNET_OS_INHERIT_STD_ERR, h->cpipe, NULL, "ssh", remote_args); diff --git a/src/testing/testing.c b/src/testing/testing.c index 3631f7b74..da0526576 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -905,7 +905,7 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) return GNUNET_SYSERR; } GNUNET_assert (NULL != peer->cfgfile); - peer->main_process = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, + peer->main_process = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, peer->main_binary, peer->main_binary, "-c", diff --git a/src/testing_old/test_testing_large_topology.c b/src/testing_old/test_testing_large_topology.c index cd80db195..4b7e1d150 100644 --- a/src/testing_old/test_testing_large_topology.c +++ b/src/testing_old/test_testing_large_topology.c @@ -189,7 +189,7 @@ gather_log_data () GNUNET_asprintf (&peer_number, "%llu", num_peers); GNUNET_asprintf (&connect_number, "%llu", expected_connections); mem_process = - GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl", + GNUNET_OS_start_process (NULL, NULL, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, "./memsize.pl", "memsize.pl", "totals.txt", peer_number, connect_number, NULL); GNUNET_OS_process_wait (mem_process); GNUNET_OS_process_destroy (mem_process); diff --git a/src/testing_old/test_testing_topology.c b/src/testing_old/test_testing_topology.c index 94cbc0df6..62fa89b32 100644 --- a/src/testing_old/test_testing_topology.c +++ b/src/testing_old/test_testing_topology.c @@ -194,7 +194,7 @@ gather_log_data () GNUNET_asprintf (&peer_number, "%llu", num_peers); GNUNET_asprintf (&connect_number, "%llu", expected_connections); mem_process = - GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl", + GNUNET_OS_start_process (NULL, NULL, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, "./memsize.pl", "memsize.pl", "totals.txt", peer_number, connect_number, NULL); GNUNET_OS_process_wait (mem_process); GNUNET_OS_process_destroy (mem_process); diff --git a/src/testing_old/testing.c b/src/testing_old/testing.c index 5456d56cb..1b164aa0f 100644 --- a/src/testing_old/testing.c +++ b/src/testing_old/testing.c @@ -245,7 +245,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, "-sq"); d->proc_arm_peerinfo = - GNUNET_OS_start_process (GNUNET_YES, NULL, d->pipe_stdout, "gnunet-peerinfo", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, d->pipe_stdout, "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, "-sq", NULL); GNUNET_DISK_pipe_close_end (d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); @@ -263,7 +263,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) d->cfgfile, "-sq"); if (d->ssh_port_str == NULL) { - d->proc_arm_peerinfo = GNUNET_OS_start_process (GNUNET_NO, NULL, d->pipe_stdout, "ssh", "ssh", + d->proc_arm_peerinfo = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, d->pipe_stdout, "ssh", "ssh", "-q", dst, "gnunet-peerinfo", "-c", d->cfgfile, "-sq", NULL); @@ -271,7 +271,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else { d->proc_arm_peerinfo = - GNUNET_OS_start_process (GNUNET_NO, NULL, d->pipe_stdout, "ssh", "ssh", "-p", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, d->pipe_stdout, "ssh", "ssh", "-p", d->ssh_port_str, "-q", dst, "gnunet-peerinfo", "-c", d->cfgfile, @@ -414,7 +414,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-s"); d->proc_arm_start = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-s", "-q", "-T", GNUNET_TIME_relative_to_string @@ -434,7 +434,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) "-s", "-q"); if (d->ssh_port_str == NULL) { - d->proc_arm_start = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", + d->proc_arm_start = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-q", dst, "gnunet-arm", "-c", d->cfgfile, "-s", "-q", "-T", @@ -446,7 +446,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { d->proc_arm_start = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-p", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-p", d->ssh_port_str, "-q", dst, "gnunet-arm", @@ -892,7 +892,7 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", + d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-q", arg, "gnunet-arm", "-c", d->cfgfile, "-i", service, "-q", @@ -908,7 +908,7 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); - d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-i", service, "-q", "-T", GNUNET_TIME_relative_to_string (timeout), @@ -960,7 +960,7 @@ GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", + d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-q", arg, "gnunet-arm", "-c", d->cfgfile, "-i", service, "-q", @@ -977,7 +977,7 @@ GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); - d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc_arm_srv_start = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-i", service, "-q", "-T", GNUNET_TIME_relative_to_string (timeout), @@ -1184,7 +1184,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_free (baseservicehome); if (ret->ssh_port_str == NULL) { - ret->proc_arm_copying = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", "-r", + ret->proc_arm_copying = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", "-r", "-q", servicehome, arg, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1194,7 +1194,7 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, else { ret->proc_arm_copying = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", "-r", "-P", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", "-r", "-P", ret->ssh_port_str, "-q", servicehome, arg, NULL); @@ -1304,7 +1304,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", + d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-q", arg, "gnunet-arm", "-c", d->cfgfile, "-e", "-r", NULL); @@ -1316,7 +1316,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); - d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-e", "-r", NULL); } @@ -1377,7 +1377,7 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->proc_arm_srv_stop = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", + d->proc_arm_srv_stop = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-q", arg, "gnunet-arm", "-c", d->cfgfile, "-k", service, "-q", @@ -1393,7 +1393,7 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); - d->proc_arm_srv_stop = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc_arm_srv_stop = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-k", service, "-q", "-T", GNUNET_TIME_relative_to_string (timeout), @@ -1546,7 +1546,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", + d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-q", arg, "gnunet-arm", "-c", d->cfgfile, "-e", "-q", "-T", @@ -1562,7 +1562,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); - d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc_arm_stop = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-e", "-q", "-T", GNUNET_TIME_relative_to_string (timeout), del_arg, NULL); @@ -1626,7 +1626,7 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile); else GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile); - d->proc_arm_copying = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", + d->proc_arm_copying = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", "-q", d->cfgfile, arg, NULL); GNUNET_free (arg); diff --git a/src/testing_old/testing_group.c b/src/testing_old/testing_group.c index 086ce2720..62cc185ce 100644 --- a/src/testing_old/testing_group.c +++ b/src/testing_old/testing_group.c @@ -2904,7 +2904,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) pg->peers[pg_iter].daemon->hostname, temp_service_path); procarr[pg_iter] = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", mytemp, arg, NULL); + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", mytemp, arg, NULL); GNUNET_assert (procarr[pg_iter] != NULL); ret = GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: schedule this, throttle! */ GNUNET_OS_process_destroy (procarr[pg_iter]); @@ -3090,7 +3090,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, pg->peers[pg_iter].daemon->hostname, temp_service_path); procarr[pg_iter] = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", mytemp, arg, NULL); + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "scp", "scp", mytemp, arg, NULL); GNUNET_assert (procarr[pg_iter] != NULL); GNUNET_OS_process_wait (procarr[pg_iter]); /* FIXME: add scheduled blacklist file copy that parallelizes file copying! */ @@ -5693,7 +5693,7 @@ start_peer_helper (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* FIXME: Doesn't support ssh_port option! */ helper->proc = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg, + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", arg, "peerStartHelper.pl", tempdir, NULL); GNUNET_assert (helper->proc != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting peers with cmd ssh %s %s %s\n", @@ -5916,13 +5916,13 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, { GNUNET_asprintf (&ssh_port_str, "%d", pg->hosts[i].sshport); proc = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str, + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str, "-q", arg, "mkdir -p", tmpdir, NULL); } else proc = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg, "mkdir -p", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "ssh", "ssh", arg, "mkdir -p", tmpdir, NULL); GNUNET_assert (proc != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -6141,7 +6141,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, /* FIXME: Doesn't support ssh_port option! */ proc = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "rsync", "rsync", "-r", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "rsync", "rsync", "-r", newservicehome, arg, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "copying directory with command rsync -r %s %s\n", diff --git a/src/transport/gnunet-transport-certificate-creation.c b/src/transport/gnunet-transport-certificate-creation.c index d5a7fcbd1..f7deb1206 100644 --- a/src/transport/gnunet-transport-certificate-creation.c +++ b/src/transport/gnunet-transport-certificate-creation.c @@ -57,7 +57,7 @@ main (int argc, char **argv) /* Create RSA Private Key */ /* openssl genrsa -out $1 1024 2> /dev/null */ openssl = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "openssl", "openssl", "genrsa", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "openssl", "openssl", "genrsa", "-out", argv[1], "1024", NULL); if (openssl == NULL) return 2; @@ -67,7 +67,7 @@ main (int argc, char **argv) /* Create a self-signed certificate in batch mode using rsa key */ /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */ openssl = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "openssl", "openssl", "req", + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "openssl", "openssl", "req", "-batch", "-days", "365", "-out", argv[2], "-new", "-x509", "-key", argv[1], NULL); if (openssl == NULL) diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 42b7f6062..36c02014e 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -284,7 +284,7 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) adv_port = bnd_port; if (NULL == resolver) resolver = - GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-resolver", + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-resolver", "gnunet-service-resolver", NULL); resolver_users++; GNUNET_RESOLVER_connect (cfg); diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 8ac301341..bd7829e6f 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -167,7 +167,7 @@ server_load_certificate (struct Plugin *plugin) "No usable TLS certificate found, creating certificate\n"); errno = 0; cert_creation = - GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-transport-certificate-creation", "gnunet-transport-certificate-creation", key_file, cert_file, NULL); diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index e8522d5e7..dbf71d78a 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -284,7 +284,7 @@ entropy_generator (void *cls, const char *what, int printchar, int current, LOG (GNUNET_ERROR_TYPE_INFO, _("Starting `%s' process to generate entropy\n"), "find"); genproc = - GNUNET_OS_start_process (GNUNET_NO, + GNUNET_OS_start_process (GNUNET_NO, 0, NULL, NULL, "sh", "sh", "-c", "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", NULL); diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 6268360f2..8cc813be5 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c @@ -118,7 +118,7 @@ run (void *cls, char *const *args, const char *cfgfile, GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), &maint_child_death, NULL); - p = GNUNET_OS_start_process (GNUNET_NO, + p = GNUNET_OS_start_process (GNUNET_NO, 0, NULL, NULL, program, program, diff --git a/src/util/helper.c b/src/util/helper.c index 6a84ff3ef..64f082bee 100644 --- a/src/util/helper.c +++ b/src/util/helper.c @@ -314,7 +314,7 @@ start_helper (struct GNUNET_HELPER_Handle *h) h->fh_to_helper = GNUNET_DISK_pipe_handle (h->helper_in, GNUNET_DISK_PIPE_END_WRITE); h->helper_proc = - GNUNET_OS_start_process_vap (GNUNET_NO, + GNUNET_OS_start_process_vap (GNUNET_NO, 0, h->helper_in, h->helper_out, h->binary_name, h->binary_argv); diff --git a/src/util/os_priority.c b/src/util/os_priority.c index c9174dee9..3a10599b5 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -768,6 +768,10 @@ CreateCustomEnvTable (char **vars) * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags controlling which + * std handles of the parent are inherited by the child. + * pipe_stdin and pipe_stdout take priority over std_inheritance + * (when they are non-NULL). * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param lsocks array of listen sockets to dup systemd-style (or NULL); @@ -778,6 +782,7 @@ CreateCustomEnvTable (char **vars) */ static struct GNUNET_OS_Process * start_process (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const SOCKTYPE *lsocks, @@ -870,6 +875,10 @@ start_process (int pipe_control, LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); GNUNET_break (0 == close (fd_stdout_write)); } + else if (!(std_inheritance & GNUNET_OS_INHERIT_STD_OUT)) + { + close (1); + } if (pipe_stdin != NULL) { @@ -878,6 +887,14 @@ start_process (int pipe_control, LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); GNUNET_break (0 == close (fd_stdin_read)); } + else if (!(std_inheritance & GNUNET_OS_INHERIT_STD_IN)) + { + close (0); + } + if (!(std_inheritance & GNUNET_OS_INHERIT_STD_ERR)) + { + close (2); + } if (lscp != NULL) { /* read systemd documentation... */ @@ -961,6 +978,10 @@ start_process (int pipe_control, long lRet; HANDLE stdin_handle; HANDLE stdout_handle; + HANDLE stdih, stdoh, stdeh; + DWORD stdif, stdof, stdef; + BOOL bresult; + DWORD error_code; if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename)) return NULL; /* not executable */ @@ -1083,9 +1104,11 @@ start_process (int pipe_control, memset (&start, 0, sizeof (start)); start.cb = sizeof (start); - if ((pipe_stdin != NULL) || (pipe_stdout != NULL)) + if ((pipe_stdin != NULL) || (pipe_stdout != NULL) || (std_inheritance != 0)) start.dwFlags |= STARTF_USESTDHANDLES; + stdih = GetStdHandle (STD_INPUT_HANDLE); + GetHandleInformation (stdih, &stdif); if (pipe_stdin != NULL) { GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle @@ -1093,7 +1116,21 @@ start_process (int pipe_control, &stdin_handle, sizeof (HANDLE)); start.hStdInput = stdin_handle; } + if (stdih) + { + if (std_inheritance & GNUNET_OS_INHERIT_STD_IN) + { + SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 1); + if (pipe_stdin == NULL) + start.hStdInput = stdih; + } + else + SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 0); + } + + stdoh = GetStdHandle (STD_OUTPUT_HANDLE); + GetHandleInformation (stdoh, &stdof); if (pipe_stdout != NULL) { GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle @@ -1102,6 +1139,30 @@ start_process (int pipe_control, &stdout_handle, sizeof (HANDLE)); start.hStdOutput = stdout_handle; } + if (stdoh) + { + if (std_inheritance & GNUNET_OS_INHERIT_STD_OUT) + { + SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 1); + if (pipe_stdout == NULL) + start.hStdOutput = stdoh; + } + else + SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 0); + } + + stdeh = GetStdHandle (STD_ERROR_HANDLE); + GetHandleInformation (stdeh, &stdef); + if (stdeh) + { + if (std_inheritance & GNUNET_OS_INHERIT_STD_ERR) + { + SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 1); + start.hStdError = stdeh; + } + else + SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 0); + } if (GNUNET_YES == pipe_control) { @@ -1179,24 +1240,36 @@ start_process (int pipe_control, return NULL; } - if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, - DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc)) + bresult = CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, + DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc); + error_code = GetLastError (); + + if ((NULL == pipe_stdin) && (stdih)) + SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, stdif); + + + if ((NULL == pipe_stdout) && (stdoh)) + SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, stdof); + + if (stdeh) + SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, stdef); + + GNUNET_free (env_block); + GNUNET_free (cmd); + free (wpath); + free (wcmd); + + if (!bresult) { - SetErrnoFromWinError (GetLastError ()); + SetErrnoFromWinError (error_code); LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); if (NULL != control_pipe) GNUNET_DISK_file_close (control_pipe); if (NULL != lsocks) GNUNET_DISK_pipe_close (lsocks_pipe); - GNUNET_free (env_block); - GNUNET_free (cmd); - free (wpath); - free (wcmd); return NULL; } - GNUNET_free (env_block); - gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); gnunet_proc->pid = proc.dwProcessId; gnunet_proc->handle = proc.hProcess; @@ -1206,9 +1279,6 @@ start_process (int pipe_control, ResumeThread (proc.hThread); CloseHandle (proc.hThread); - GNUNET_free (cmd); - free (wpath); - free (wcmd); if (lsocks == NULL || lsocks[0] == INVALID_SOCKET) return gnunet_proc; @@ -1300,6 +1370,7 @@ start_process (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -1308,12 +1379,14 @@ start_process (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_vap (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, char *const argv[]) { return start_process (pipe_control, + std_inheritance, pipe_stdin, pipe_stdout, NULL, @@ -1326,6 +1399,7 @@ GNUNET_OS_start_process_vap (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -1334,6 +1408,7 @@ GNUNET_OS_start_process_vap (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_va (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, va_list va) @@ -1355,6 +1430,7 @@ GNUNET_OS_start_process_va (int pipe_control, argc++; va_end (ap); ret = GNUNET_OS_start_process_vap (pipe_control, + std_inheritance, pipe_stdin, pipe_stdout, filename, @@ -1369,6 +1445,7 @@ GNUNET_OS_start_process_va (int pipe_control, * Start a process. * * @param pipe_control should a pipe be used to send signals to the child? + * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags * @param pipe_stdin pipe to use to send input to child process (or NULL) * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary @@ -1379,6 +1456,7 @@ GNUNET_OS_start_process_va (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...) @@ -1387,7 +1465,8 @@ GNUNET_OS_start_process (int pipe_control, va_list ap; va_start (ap, filename); - ret = GNUNET_OS_start_process_va (pipe_control, pipe_stdin, pipe_stdout, filename, ap); + ret = GNUNET_OS_start_process_va (pipe_control, std_inheritance, pipe_stdin, + pipe_stdout, filename, ap); va_end (ap); return ret; } @@ -1405,11 +1484,13 @@ GNUNET_OS_start_process (int pipe_control, */ struct GNUNET_OS_Process * GNUNET_OS_start_process_v (int pipe_control, + enum GNUNET_OS_InheritStdioFlags std_inheritance, const SOCKTYPE *lsocks, const char *filename, char *const argv[]) { return start_process (pipe_control, + std_inheritance, NULL, NULL, lsocks, @@ -1723,7 +1804,8 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls, if (NULL == opipe) return NULL; va_start (ap, binary); - eip = GNUNET_OS_start_process_va (GNUNET_NO, NULL, opipe, binary, ap); + /* redirect stdout, don't inherit stderr/stdin */ + eip = GNUNET_OS_start_process_va (GNUNET_NO, 0, NULL, opipe, binary, ap); va_end (ap); if (NULL == eip) { diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c index d01cd3bce..4c6ae0039 100644 --- a/src/util/test_common_logging_runtime_loglevels.c +++ b/src/util/test_common_logging_runtime_loglevels.c @@ -317,7 +317,7 @@ runone () break; } - proc = GNUNET_OS_start_process (GNUNET_NO, NULL, pipe_stdout, + proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, pipe_stdout, #if MINGW "test_common_logging_dummy", #else diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 3c30c75f3..e24e09500 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c @@ -131,7 +131,7 @@ run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } proc = - GNUNET_OS_start_process (GNUNET_NO, hello_pipe_stdin, hello_pipe_stdout, fn, + GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, "test_gnunet_echo_hello", "-", NULL); GNUNET_free (fn); @@ -200,7 +200,7 @@ check_kill () return 1; } proc = - GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, fn, + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, "gnunet-service-resolver", "-", NULL); sleep (1); /* give process time to start, so we actually use the pipe-kill mechanism! */ if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) @@ -233,7 +233,7 @@ check_instant_kill () return 1; } proc = - GNUNET_OS_start_process (GNUNET_YES, hello_pipe_stdin, hello_pipe_stdout, fn, + GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, "gnunet-service-resolver", "-", NULL); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index f924661dd..b9ca81b0f 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c @@ -370,7 +370,7 @@ main (int argc, char *argv[]) pfx = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); GNUNET_asprintf (&fn, "%s%cgnunet-service-resolver", pfx, DIR_SEPARATOR); GNUNET_free (pfx); - proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, "gnunet-service-resolver", + proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, fn, "gnunet-service-resolver", "-c", "test_resolver_api_data.conf", NULL); GNUNET_assert (NULL != proc); GNUNET_free (fn); -- cgit v1.2.3