aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-07-09 19:04:19 +0000
committerChristian Grothoff <christian@grothoff.org>2012-07-09 19:04:19 +0000
commit8f9464256fc06a884bf589b4004262a0549d11b3 (patch)
treea088b8acbebdefe2acf0b41cfed4418830275b78 /src/arm
parent817ee37a75fb8eb5887023d1a5152cb528ee2d5a (diff)
downloadgnunet-8f9464256fc06a884bf589b4004262a0549d11b3.tar.gz
gnunet-8f9464256fc06a884bf589b4004262a0549d11b3.zip
-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
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/arm_api.c14
-rw-r--r--src/arm/do_start_process.c5
-rw-r--r--src/arm/gnunet-arm.c18
-rw-r--r--src/arm/gnunet-service-arm.c4
-rw-r--r--src/arm/test_arm_api.c4
-rw-r--r--src/arm/test_exponential_backoff.c4
-rw-r--r--src/arm/test_gnunet_service_manager.c2
7 files changed, 39 insertions, 12 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
295 */ 295 */
296 uint16_t type; 296 uint16_t type;
297 297
298 /**
299 * Flags for passing std descriptors to ARM (when starting ARM).
300 */
301 enum GNUNET_OS_InheritStdioFlags std_inheritance;
302
298}; 303};
299 304
300#include "do_start_process.c" 305#include "do_start_process.c"
@@ -381,14 +386,14 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381 { 386 {
382 /* Means we are ONLY running locally */ 387 /* Means we are ONLY running locally */
383 /* we're clearly running a test, don't daemonize */ 388 /* we're clearly running a test, don't daemonize */
384 proc = do_start_process (GNUNET_NO, 389 proc = do_start_process (GNUNET_NO, pos->std_inheritance,
385 NULL, loprefix, binary, "-c", config, 390 NULL, loprefix, binary, "-c", config,
386 /* no daemonization! */ 391 /* no daemonization! */
387 lopostfix, NULL); 392 lopostfix, NULL);
388 } 393 }
389 else 394 else
390 { 395 {
391 proc = do_start_process (GNUNET_NO, 396 proc = do_start_process (GNUNET_NO, pos->std_inheritance,
392 NULL, loprefix, binary, "-c", config, 397 NULL, loprefix, binary, "-c", config,
393 "-d", lopostfix, NULL); 398 "-d", lopostfix, NULL);
394 } 399 }
@@ -522,6 +527,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
522 * 527 *
523 * @param h handle to ARM 528 * @param h handle to ARM
524 * @param service_name name of the service 529 * @param service_name name of the service
530 * @param std_inheritance inheritance of std streams
525 * @param timeout how long to wait before failing for good 531 * @param timeout how long to wait before failing for good
526 * @param cb callback to invoke when service is ready 532 * @param cb callback to invoke when service is ready
527 * @param cb_cls closure for callback 533 * @param cb_cls closure for callback
@@ -529,6 +535,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
529void 535void
530GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, 536GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
531 const char *service_name, 537 const char *service_name,
538 enum GNUNET_OS_InheritStdioFlags std_inheritance,
532 struct GNUNET_TIME_Relative timeout, 539 struct GNUNET_TIME_Relative timeout,
533 GNUNET_ARM_Callback cb, void *cb_cls) 540 GNUNET_ARM_Callback cb, void *cb_cls)
534{ 541{
@@ -547,12 +554,13 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
547 sctx->callback = cb; 554 sctx->callback = cb;
548 sctx->cls = cb_cls; 555 sctx->cls = cb_cls;
549 sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout); 556 sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
557 sctx->std_inheritance = std_inheritance;
550 memcpy (&sctx[1], service_name, slen); 558 memcpy (&sctx[1], service_name, slen);
551 GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report, 559 GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
552 sctx); 560 sctx);
553 return; 561 return;
554 } 562 }
555 if (h->client == NULL) 563 if (NULL == h->client)
556 { 564 {
557 client = GNUNET_CLIENT_connect ("arm", h->cfg); 565 client = GNUNET_CLIENT_connect ("arm", h->cfg);
558 if (client == NULL) 566 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 @@
8 * with spaces to the new process. 8 * with spaces to the new process.
9 * 9 *
10 * @param pipe_control should a pipe be used to send signals to the child? 10 * @param pipe_control should a pipe be used to send signals to the child?
11 * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
11 * @param lsocks array of listen sockets to dup starting at fd3 (systemd-style), or NULL 12 * @param lsocks array of listen sockets to dup starting at fd3 (systemd-style), or NULL
12 * @param first_arg first argument for argv (may be an empty string) 13 * @param first_arg first argument for argv (may be an empty string)
13 * @param ... more arguments, NULL terminated 14 * @param ... more arguments, NULL terminated
14 * @return handle of the started process, NULL on error 15 * @return handle of the started process, NULL on error
15 */ 16 */
16static struct GNUNET_OS_Process * 17static struct GNUNET_OS_Process *
17do_start_process (int pipe_control, 18do_start_process (int pipe_control, unsigned int std_inheritance,
18 const SOCKTYPE * lsocks, const char *first_arg, ...) 19 const SOCKTYPE * lsocks, const char *first_arg, ...)
19{ 20{
20 va_list ap; 21 va_list ap;
@@ -97,7 +98,7 @@ do_start_process (int pipe_control,
97/* *INDENT-ON* */ 98/* *INDENT-ON* */
98 va_end (ap); 99 va_end (ap);
99 argv[argv_size] = NULL; 100 argv[argv_size] = NULL;
100 proc = GNUNET_OS_start_process_v (pipe_control, lsocks, argv[0], argv); 101 proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, argv[0], argv);
101 while (argv_size > 0) 102 while (argv_size > 0)
102 GNUNET_free (argv[--argv_size]); 103 GNUNET_free (argv[--argv_size]);
103 GNUNET_free (argv); 104 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
@@ -127,6 +127,16 @@ static struct GNUNET_TIME_Relative timeout;
127 127
128 128
129/** 129/**
130 * Do we want to give our stdout to gnunet-service-arm?
131 */
132static unsigned int no_stdout = 0;
133
134/**
135 * Do we want to give our stderr to gnunet-service-arm?
136 */
137static unsigned int no_stderr = 0;
138
139/**
130 * Main continuation-passing-style loop. Runs the various 140 * Main continuation-passing-style loop. Runs the various
131 * jobs that we've been asked to do in order. 141 * jobs that we've been asked to do in order.
132 * 142 *
@@ -323,6 +333,8 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
323 if (start) 333 if (start)
324 { 334 {
325 GNUNET_ARM_start_service (h, "arm", 335 GNUNET_ARM_start_service (h, "arm",
336 (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
337 (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
326 (0 == 338 (0 ==
327 timeout.rel_value) ? START_TIMEOUT : 339 timeout.rel_value) ? START_TIMEOUT :
328 timeout, &confirm_cb, "arm"); 340 timeout, &confirm_cb, "arm");
@@ -333,6 +345,8 @@ cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
333 if (init != NULL) 345 if (init != NULL)
334 { 346 {
335 GNUNET_ARM_start_service (h, init, 347 GNUNET_ARM_start_service (h, init,
348 (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
349 (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
336 (0 == 350 (0 ==
337 timeout.rel_value) ? START_TIMEOUT : 351 timeout.rel_value) ? START_TIMEOUT :
338 timeout, &confirm_cb, init); 352 timeout, &confirm_cb, init);
@@ -422,6 +436,10 @@ main (int argc, char *const *argv)
422 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms}, 436 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms},
423 {'I', "info", NULL, gettext_noop ("List currently running services"), 437 {'I', "info", NULL, gettext_noop ("List currently running services"),
424 GNUNET_NO, &GNUNET_GETOPT_set_one, &list}, 438 GNUNET_NO, &GNUNET_GETOPT_set_one, &list},
439 {'O', "no-stdout", NULL, gettext_noop ("Don't let gnunet-service-arm inherit standard output"),
440 GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stdout},
441 {'E', "no-stderr", NULL, gettext_noop ("Don't let gnunet-service-arm inherit standard error"),
442 GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stderr},
425 GNUNET_GETOPT_OPTION_END 443 GNUNET_GETOPT_OPTION_END
426 }; 444 };
427 445
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)
320 GNUNET_assert (NULL == sl->proc); 320 GNUNET_assert (NULL == sl->proc);
321 if (GNUNET_YES == use_debug) 321 if (GNUNET_YES == use_debug)
322 sl->proc = 322 sl->proc =
323 do_start_process (sl->pipe_control, 323 do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
324 lsocks, loprefix, sl->binary, "-c", sl->config, "-L", 324 lsocks, loprefix, sl->binary, "-c", sl->config, "-L",
325 "DEBUG", options, NULL); 325 "DEBUG", options, NULL);
326 else 326 else
327 sl->proc = 327 sl->proc =
328 do_start_process (sl->pipe_control, 328 do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
329 lsocks, loprefix, sl->binary, "-c", sl->config, 329 lsocks, loprefix, sl->binary, "-c", sl->config,
330 options, NULL); 330 options, NULL);
331 if (sl->proc == NULL) 331 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)
109 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL); 109 GNUNET_ARM_stop_service (arm, "arm", TIMEOUT, &arm_stopped, NULL);
110#endif 110#endif
111 } 111 }
112 GNUNET_ARM_start_service (arm, "resolver", START_TIMEOUT, &resolver_notify, 112 GNUNET_ARM_start_service (arm, "resolver", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &resolver_notify,
113 NULL); 113 NULL);
114} 114}
115 115
@@ -121,7 +121,7 @@ task (void *cls, char *const *args, const char *cfgfile,
121 cfg = c; 121 cfg = c;
122 arm = GNUNET_ARM_connect (cfg, NULL); 122 arm = GNUNET_ARM_connect (cfg, NULL);
123#if START_ARM 123#if START_ARM
124 GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL); 124 GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &arm_notify, NULL);
125#else 125#else
126 arm_notify (NULL, GNUNET_YES); 126 arm_notify (NULL, GNUNET_YES);
127#endif 127#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
270arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus status) 270arm_notify (void *cls, enum GNUNET_ARM_ProcessStatus status)
271{ 271{
272 GNUNET_assert (status == GNUNET_ARM_PROCESS_STARTING); 272 GNUNET_assert (status == GNUNET_ARM_PROCESS_STARTING);
273 GNUNET_ARM_start_service (arm, "do-nothing", TIMEOUT, &do_nothing_notify, 273 GNUNET_ARM_start_service (arm, "do-nothing", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, TIMEOUT, &do_nothing_notify,
274 NULL); 274 NULL);
275} 275}
276 276
@@ -365,7 +365,7 @@ task (void *cls, char *const *args, const char *cfgfile,
365 365
366 arm = GNUNET_ARM_connect (cfg, NULL); 366 arm = GNUNET_ARM_connect (cfg, NULL);
367#if START_ARM 367#if START_ARM
368 GNUNET_ARM_start_service (arm, "arm", GNUNET_TIME_UNIT_ZERO, &arm_notify, 368 GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, GNUNET_TIME_UNIT_ZERO, &arm_notify,
369 NULL); 369 NULL);
370#else 370#else
371 arm_do_nothing (NULL, GNUNET_YES); 371 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,
124 cfg = c; 124 cfg = c;
125#if START_ARM 125#if START_ARM
126 arm = GNUNET_ARM_connect (cfg, NULL); 126 arm = GNUNET_ARM_connect (cfg, NULL);
127 GNUNET_ARM_start_service (arm, "arm", START_TIMEOUT, &arm_notify, NULL); 127 GNUNET_ARM_start_service (arm, "arm", GNUNET_OS_INHERIT_STD_OUT_AND_ERR, START_TIMEOUT, &arm_notify, NULL);
128#else 128#else
129 arm_notify (NULL, GNUNET_YES); 129 arm_notify (NULL, GNUNET_YES);
130#endif 130#endif