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 +- 7 files changed, 39 insertions(+), 12 deletions(-) (limited to 'src/arm') 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 -- cgit v1.2.3