From: Christian Grothoff Date: Mon, 27 Feb 2012 11:00:10 +0000 (+0000) Subject: enabling use of pipes for signal communication also on UNIX to enable future integrat... X-Git-Tag: initial-import-from-subversion-38251~14618 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0238db34853380280ccf164918ebbb28260f4629;p=oweals%2Fgnunet.git enabling use of pipes for signal communication also on UNIX to enable future integration with Java services --- diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index 12395fea9..0f4ae6a4f 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -410,7 +410,8 @@ 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 (NULL, loprefix, binary, "-c", config, + proc = do_start_process (GNUNET_NO, + NULL, loprefix, binary, "-c", config, #if DEBUG_ARM "-L", "DEBUG", #endif @@ -419,7 +420,8 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } else { - proc = do_start_process (NULL, loprefix, binary, "-c", config, + proc = do_start_process (GNUNET_NO, + NULL, loprefix, binary, "-c", config, #if DEBUG_ARM "-L", "DEBUG", #endif diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c index fd7fc17ed..865ea8e7d 100644 --- a/src/arm/do_start_process.c +++ b/src/arm/do_start_process.c @@ -13,7 +13,8 @@ * @return handle of the started process, NULL on error */ static struct GNUNET_OS_Process * -do_start_process (const SOCKTYPE * lsocks, const char *first_arg, ...) +do_start_process (int pipe_control, + const SOCKTYPE * lsocks, const char *first_arg, ...) { va_list ap; char **argv; @@ -95,7 +96,7 @@ do_start_process (const SOCKTYPE * lsocks, const char *first_arg, ...) /* *INDENT-ON* */ va_end (ap); argv[argv_size] = NULL; - proc = GNUNET_OS_start_process_v (lsocks, argv[0], argv); + proc = GNUNET_OS_start_process_v (pipe_control, lsocks, argv[0], argv); while (argv_size > 0) GNUNET_free (argv[--argv_size]); GNUNET_free (argv); diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 064cb9777..f4430ed0c 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -152,6 +152,11 @@ struct ServiceList */ int is_default; + /** + * Should we use pipes to signal this process? (YES for Java binaries and if we + * are on Windoze). + */ + int pipe_control; }; /** @@ -311,11 +316,13 @@ start_process (struct ServiceList *sl) GNUNET_assert (NULL == sl->proc); if (GNUNET_YES == use_debug) sl->proc = - do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config, "-L", + do_start_process (sl->pipe_control, + lsocks, loprefix, sl->binary, "-c", sl->config, "-L", "DEBUG", options, NULL); else sl->proc = - do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config, + do_start_process (sl->pipe_control, + lsocks, loprefix, sl->binary, "-c", sl->config, options, NULL); if (sl->proc == NULL) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start service `%s'\n"), @@ -1070,6 +1077,12 @@ setup_service (void *cls, const char *section) sl->config = config; sl->backoff = GNUNET_TIME_UNIT_MILLISECONDS; sl->restart_at = GNUNET_TIME_UNIT_FOREVER_ABS; +#if WINDOWS + sl->pipe_control = GNUNET_YES; +#else + if (GNUNET_CONFIGURATION_have_value (cfg, section, "PIPECONTROL")) + sl->pipe_control = GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "PIPECONTROL"); +#endif GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl); if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "AUTOSTART")) diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c index 9b09f5a49..a84927d58 100644 --- a/src/ats/test_ats_api_bandwidth_consumption.c +++ b/src/ats/test_ats_api_bandwidth_consumption.c @@ -199,7 +199,7 @@ void start_arm (const char *cfgname) { arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c index 9435a7b6f..892186cd1 100644 --- a/src/ats/test_ats_api_scheduling.c +++ b/src/ats/test_ats_api_scheduling.c @@ -156,7 +156,7 @@ void start_arm (const char *cfgname) { arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/chat/test_chat.c b/src/chat/test_chat.c index 7cf8b19cf..fec5db02a 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 (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, 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 acec5bcf0..cbc90656f 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 (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, 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 7bf091933..271c2ce08 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 (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, 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 94c28fa81..645b27e74 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -442,7 +442,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c index f04f94fac..4fa73d951 100644 --- a/src/core/test_core_api_send_to_self.c +++ b/src/core/test_core_api_send_to_self.c @@ -170,7 +170,7 @@ run (void *cls, char *const *args, const char *cfgfile, core_cfg = GNUNET_CONFIGURATION_create (); arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index 876e3b0f8..2eca57512 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c @@ -148,7 +148,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/core/test_core_defaults.conf b/src/core/test_core_defaults.conf index 82f14a9d9..f91ee42bb 100644 --- a/src/core/test_core_defaults.conf +++ b/src/core/test_core_defaults.conf @@ -47,4 +47,7 @@ AUTOSTART = NO AUTOSTART = NO [dv] -AUTOSTART = NO \ No newline at end of file +AUTOSTART = NO + +[chat] +AUTOSTART = NO diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index f16cc5441..7c16531d8 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -569,7 +569,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index 393972da2..aae152db8 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -343,7 +343,7 @@ check () GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datastore_api_data_%s.conf", plugin_name); proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index c93f5412e..25836ca66 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -526,7 +526,7 @@ check () "test_datastore_api_data_%s.conf", plugin_name); #if START_DATASTORE proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index 2d5cc6bf9..4015c2cb2 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -311,7 +311,7 @@ check () GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datastore_api_data_%s.conf", plugin_name); proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/datastore/test_defaults.conf b/src/datastore/test_defaults.conf index bbc1ad190..bdba91731 100644 --- a/src/datastore/test_defaults.conf +++ b/src/datastore/test_defaults.conf @@ -15,4 +15,7 @@ AUTOSTART = NO AUTOSTART = NO [dv] -AUTOSTART = NO \ No newline at end of file +AUTOSTART = NO + +[chat] +AUTOSTART = NO diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index b31cd1a72..182856a8e 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -263,7 +263,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/fs/test_fs_defaults.conf b/src/fs/test_fs_defaults.conf index 9dd717863..e32213bc3 100644 --- a/src/fs/test_fs_defaults.conf +++ b/src/fs/test_fs_defaults.conf @@ -75,4 +75,7 @@ AUTOSTART = NO AUTOSTART = NO [dv] -AUTOSTART = NO \ No newline at end of file +AUTOSTART = NO + +[chat] +AUTOSTART = NO diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 51020c4a2..570eab909 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -245,7 +245,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_download_indexed.c b/src/fs/test_fs_download_indexed.c index b9b791d1f..e8504f175 100644 --- a/src/fs/test_fs_download_indexed.c +++ b/src/fs/test_fs_download_indexed.c @@ -246,7 +246,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index f0dc6f3a6..bcb1c54b6 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c @@ -295,7 +295,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index 5df503a65..535f8ef58 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -188,7 +188,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index 7ef5d89be..d25fd6f83 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c @@ -67,7 +67,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c index 1ad2fb5ac..44775ac0e 100644 --- a/src/fs/test_fs_namespace_list_updateable.c +++ b/src/fs/test_fs_namespace_list_updateable.c @@ -71,7 +71,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index 1ae3ab451..e52743876 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -173,7 +173,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index 0b7828256..7707eac32 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -236,7 +236,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index e10461534..f6c8f00f8 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c @@ -174,7 +174,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index bb38d92c7..38f88a82a 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c @@ -236,7 +236,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c index c65ad2fc1..0ef0723f9 100644 --- a/src/fs/test_fs_start_stop.c +++ b/src/fs/test_fs_start_stop.c @@ -57,7 +57,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index cede0f5b7..a8b68a3cf 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c @@ -187,7 +187,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index b13378f20..575e1715f 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c @@ -249,7 +249,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 056e56177..da3ab8b58 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -140,7 +140,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index b27710677..9ef8812f6 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -370,7 +370,7 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -406,7 +406,7 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c b/src/hostlist/test_gnunet_daemon_hostlist_reconnect.c index e347673d8..a9915574b 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 (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/hostlist/test_hostlist_defaults.conf b/src/hostlist/test_hostlist_defaults.conf index 08c58b963..b74a6a615 100644 --- a/src/hostlist/test_hostlist_defaults.conf +++ b/src/hostlist/test_hostlist_defaults.conf @@ -50,4 +50,7 @@ AUTOSTART = NO AUTOSTART = NO [dv] -AUTOSTART = NO \ No newline at end of file +AUTOSTART = NO + +[chat] +AUTOSTART = NO diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h index 9c88a163b..18f553576 100644 --- a/src/include/gnunet_disk_lib.h +++ b/src/include/gnunet_disk_lib.h @@ -31,11 +31,6 @@ #define OFF_T off_t #endif -/** - * Opaque handle used to access files. - */ -struct GNUNET_DISK_FileHandle; - /** * Handle used to manage a pipe. */ @@ -759,36 +754,6 @@ GNUNET_DISK_file_unmap (struct GNUNET_DISK_MapHandle *h); int GNUNET_DISK_file_sync (const struct GNUNET_DISK_FileHandle *h); -/** - * Creates a named pipe/FIFO and opens it - * @param fn pointer to the name of the named pipe or to NULL - * @param flags open flags - * @param perm access permissions - * @return pipe handle on success, NULL on error - */ -struct GNUNET_DISK_FileHandle * -GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm); - -/** - * Opens already existing named pipe/FIFO - * - * @param fn name of an existing named pipe - * @param flags open flags - * @param perm access permissions - * @return pipe handle on success, NULL on error - */ -struct GNUNET_DISK_FileHandle * -GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm); - -/** - * Closes a named pipe/FIFO - * @param pipe named pipe - * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe); #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index c56947431..e9e484f78 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h @@ -27,6 +27,16 @@ * @author Ioana Patrascu * @author Tzvetan Horozov * @author Milan + * + * This code manages child processes. We can communicate with child + * processes using signals. Because signals are not supported on W32 + * and Java (at least not nicely), we can alternatively use a pipe + * to send signals to the child processes (if the child process is + * a full-blown GNUnet process that supports reading signals from + * a pipe, of course). Naturally, this also only works for 'normal' + * termination via signals, and not as a replacement for SIGKILL. + * Thus using pipes to communicate signals should only be enabled if + * the child is a Java process OR if we are on Windoze. */ #ifndef GNUNET_OS_LIB_H @@ -201,7 +211,7 @@ GNUNET_OS_process_current (void); /** - * Sends sig to the process + * Sends a signal to the process * * @param proc pointer to process structure * @param sig signal @@ -219,6 +229,7 @@ GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig); void GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); + /** * Get the pid of the process in question * @@ -229,6 +240,7 @@ GNUNET_OS_process_close (struct GNUNET_OS_Process *proc); pid_t GNUNET_OS_process_get_pid (struct GNUNET_OS_Process *proc); + /** * Set process priority * @@ -241,10 +253,10 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, enum GNUNET_SCHEDULER_Priority prio); - /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -252,7 +264,8 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, * @return pointer to process structure of the new process, NULL on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, +GNUNET_OS_start_process_vap (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, char *const argv[]); @@ -261,6 +274,7 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -268,7 +282,8 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @return pointer to process structure of the new process, NULL on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, +GNUNET_OS_start_process (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...); @@ -276,6 +291,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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,13 +299,15 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @return pointer to process structure of the new process, NULL on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, +GNUNET_OS_start_process_va (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, va_list va); /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -298,7 +316,9 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @return pointer to process structure of the new process, NULL on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, const char *filename, +GNUNET_OS_start_process_v (int pipe_control, + const SOCKTYPE *lsocks, + const char *filename, char *const argv[]); @@ -307,6 +327,7 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, const char *filename, */ struct GNUNET_OS_CommandHandle; + /** * Type of a function to process a line of output. * @@ -315,6 +336,7 @@ struct GNUNET_OS_CommandHandle; */ typedef void (*GNUNET_OS_LineProcessor) (void *cls, const char *line); + /** * Stop/kill a command. * @@ -370,7 +392,13 @@ GNUNET_OS_process_wait (struct GNUNET_OS_Process *proc); /** - * Connects this process to its parent via pipe + * Connects this process to its parent via pipe; + * essentially, the parent control handler will read signal numbers + * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment + * variable) and raise those signals. + * + * @param cls closure (unused) + * @param tc scheduler context (unused) */ void GNUNET_OS_install_parent_control_handler (void *cls, diff --git a/src/include/platform.h b/src/include/platform.h index 179503731..7383e48ad 100644 --- a/src/include/platform.h +++ b/src/include/platform.h @@ -107,6 +107,7 @@ #include #include #include +#include #ifdef WINDOWS #include /* for alloca(), on other OSes it's in stdlib.h */ #endif diff --git a/src/mesh/test_mesh_api.c b/src/mesh/test_mesh_api.c index d92c25938..fbc1fbaff 100644 --- a/src/mesh/test_mesh_api.c +++ b/src/mesh/test_mesh_api.c @@ -139,7 +139,7 @@ run (void *cls, char *const *args, const char *cfgfile, #endif NULL); arm_pid = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/mesh/test_mesh_local_1.c b/src/mesh/test_mesh_local_1.c index da65b36c4..73e2bdc13 100644 --- a/src/mesh/test_mesh_local_1.c +++ b/src/mesh/test_mesh_local_1.c @@ -300,7 +300,7 @@ run (void *cls, char *const *args, const char *cfgfile, #endif NULL); arm_pid = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/mesh/test_mesh_local_2.c b/src/mesh/test_mesh_local_2.c index eff15046f..b185f1b84 100644 --- a/src/mesh/test_mesh_local_2.c +++ b/src/mesh/test_mesh_local_2.c @@ -293,7 +293,7 @@ run (void *cls, char *const *args, const char *cfgfile, #endif NULL); arm_pid = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index 3fd84d20f..62cfa808a 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c @@ -40,7 +40,7 @@ static int res; static void start_arm (const char *cfgname) { - arm = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + arm = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, #if VERBOSE_PEERS "-L", "DEBUG", diff --git a/src/nat/nat.c b/src/nat/nat.c index 02ff7547b..744583f3d 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c @@ -843,7 +843,7 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h) #endif /* Start the server process */ h->server_proc = - GNUNET_OS_start_process (NULL, h->server_stdout, + GNUNET_OS_start_process (GNUNET_NO, NULL, h->server_stdout, "gnunet-helper-nat-server", "gnunet-helper-nat-server", h->internal_address, NULL); @@ -1342,7 +1342,8 @@ GNUNET_NAT_run_client (struct GNUNET_NAT_Handle *h, inet4, (unsigned int) h->adv_port); #endif proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-helper-nat-client", + GNUNET_OS_start_process (GNUNET_NO, + 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 6c48f28fe..830fdfd50 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 (NULL, eh->opipe, "external-ip", "external-ip", + GNUNET_OS_start_process (GNUNET_NO, 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 2b9ef0f7c..64617880a 100644 --- a/src/nat/test_nat_test.c +++ b/src/nat/test_nat_test.c @@ -118,7 +118,7 @@ main (int argc, char *const argv[]) } gns = - GNUNET_OS_start_process (NULL, NULL, "gnunet-nat-server", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-nat-server", "gnunet-nat-server", #if VERBOSE "-L", "DEBUG", diff --git a/src/nse/test_nse_api.c b/src/nse/test_nse_api.c index 7e0ab0bbc..f6cde3fe4 100644 --- a/src/nse/test_nse_api.c +++ b/src/nse/test_nse_api.c @@ -110,7 +110,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index fbd12c387..71da46be4 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -179,7 +179,7 @@ check () GNUNET_GETOPT_OPTION_END }; proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-peerinfo", "gnunet-service-peerinfo", #if DEBUG_PEERINFO "-L", "DEBUG", diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index efaf2d2ee..0647a4942 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c @@ -144,7 +144,7 @@ check () struct GNUNET_OS_Process *proc; proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if DEBUG_STATISTICS "-L", "DEBUG", @@ -170,7 +170,7 @@ check () #if START_SERVICE /* restart to check persistence! */ proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if DEBUG_STATISTICS "-L", "DEBUG", diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c index eb739b752..32b176caa 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 (NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, 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 a70b8b311..979b5610e 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 (NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if VERBOSE "-L", "DEBUG", diff --git a/src/stream/test_stream_local.c b/src/stream/test_stream_local.c index 63347d826..4da1258fc 100644 --- a/src/stream/test_stream_local.c +++ b/src/stream/test_stream_local.c @@ -331,7 +331,7 @@ run (void *cls, char *const *args, const char *cfgfile, #endif NULL); arm_pid = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/stream/test_stream_local_halfclose.c b/src/stream/test_stream_local_halfclose.c index 5acaf213a..61e531ae8 100644 --- a/src/stream/test_stream_local_halfclose.c +++ b/src/stream/test_stream_local_halfclose.c @@ -327,7 +327,7 @@ run (void *cls, char *const *args, const char *cfgfile, #endif NULL); arm_pid = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/testing/test_testing_defaults.conf b/src/testing/test_testing_defaults.conf index c4810c303..36a4f76ea 100644 --- a/src/testing/test_testing_defaults.conf +++ b/src/testing/test_testing_defaults.conf @@ -61,3 +61,6 @@ AUTOSTART = NO [dv] AUTOSTART = NO + +[chat] +AUTOSTART = NO diff --git a/src/testing/testing.c b/src/testing/testing.c index 70da138a7..16cee9037 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -97,11 +97,9 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) GNUNET_NO, &test_address, &empty); if (GNUNET_YES == empty) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Skipping empty HELLO address of peer %s\n", GNUNET_i2s (&daemon->id)); -#endif return; } #endif @@ -113,11 +111,9 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) if (daemon->server != NULL) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' from transport service of `%4s', disconnecting core!\n", "HELLO", GNUNET_i2s (&daemon->id)); -#endif GNUNET_CORE_disconnect (daemon->server); daemon->server = NULL; } @@ -135,12 +131,9 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message) GNUNET_TRANSPORT_get_hello_cancel (daemon->ghh); daemon->ghh = NULL; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' from transport service of `%4s'\n", "HELLO", GNUNET_i2s (&daemon->id)); -#endif - GNUNET_free_non_null (daemon->hello); daemon->hello = GNUNET_malloc (msize); memcpy (daemon->hello, message, msize); @@ -192,11 +185,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) char *dst; int bytes_read; -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %s FSM is in phase %u.\n", GNUNET_i2s (&d->id), d->phase); -#endif - d->task = GNUNET_SCHEDULER_NO_TASK; switch (d->phase) { @@ -229,10 +219,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } GNUNET_OS_process_close (d->proc); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully copied configuration file.\n"); -#endif d->phase = SP_COPIED; /* fall-through */ case SP_COPIED: @@ -254,14 +242,12 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } if (NULL == d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting `%s', with command `%s %s %s %s'.\n", "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, "-sq"); -#endif d->proc = - GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", + GNUNET_OS_start_process (GNUNET_YES, 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); @@ -273,15 +259,13 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else dst = GNUNET_strdup (d->hostname); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting `%s', with command `%s %s %s %s %s %s'.\n", "gnunet-peerinfo", "ssh", dst, "gnunet-peerinfo", "-c", d->cfgfile, "-sq"); -#endif if (d->ssh_port_str == NULL) { - d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, d->pipe_stdout, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -291,7 +275,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else { d->proc = - GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", "-p", + GNUNET_OS_start_process (GNUNET_NO, NULL, d->pipe_stdout, "ssh", "ssh", "-p", d->ssh_port_str, #if !DEBUG_TESTING "-q", @@ -317,10 +301,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_DISK_pipe_close (d->pipe_stdout); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started `%s', waiting for hostkey.\n", "gnunet-peerinfo"); -#endif d->phase = SP_HOSTKEY_CREATE; d->task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_absolute_get_remaining @@ -410,9 +392,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { d->phase = SP_TOPOLOGY_SETUP; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); -#endif /* Fall through */ case SP_HOSTKEY_CREATED: /* wait for topology finished */ @@ -435,18 +415,14 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* start GNUnet on remote host */ if (NULL == d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting `%s', with command `%s %s %s %s %s %s'.\n", "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, "-L", "DEBUG", "-s"); -#endif d->proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, -#if DEBUG_TESTING "-L", "DEBUG", -#endif "-s", "-q", "-T", GNUNET_TIME_relative_to_string (GNUNET_TIME_absolute_get_remaining @@ -459,15 +435,13 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else dst = GNUNET_strdup (d->hostname); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Starting `%s', with command `%s %s %s %s %s %s %s %s'.\n", "gnunet-arm", "ssh", dst, "gnunet-arm", "-c", d->cfgfile, "-L", "DEBUG", "-s", "-q"); -#endif if (d->ssh_port_str == NULL) { - d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -484,7 +458,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { d->proc = - GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-p", + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-p", d->ssh_port_str, #if !DEBUG_TESTING "-q", @@ -514,11 +488,9 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) _("Failed to start `ssh' process.\n")); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started `%s', waiting for `%s' to be up.\n", "gnunet-arm", "gnunet-service-core"); -#endif d->phase = SP_START_ARMING; d->task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_EXEC_WAIT, &start_fsm, @@ -561,15 +533,11 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) d); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully started `%s'.\n", "gnunet-arm"); -#endif GNUNET_free (d->proc); d->phase = SP_START_CORE; -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling CORE_connect\n"); -#endif /* Fall through */ case SP_START_CORE: if (d->server != NULL) @@ -588,12 +556,9 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) _("Failed to connect to transport service!\n")); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to transport service `%s', getting HELLO\n", GNUNET_i2s (&d->id)); -#endif - d->ghh = GNUNET_TRANSPORT_get_hello (d->th, &process_hello, d); /* FIXME: store task ID somewhere! */ GNUNET_SCHEDULER_add_now (¬ify_daemon_started, d); @@ -669,9 +634,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } #endif -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service startup complete!\n"); -#endif cb = d->cb; d->cb = NULL; d->phase = SP_START_DONE; @@ -706,9 +669,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } #endif -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n"); -#endif if (NULL != d->dead_cb) d->dead_cb (d->dead_cb_cls, NULL); break; @@ -784,9 +745,7 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_free (d); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer shutdown complete.\n"); -#endif if (d->server != NULL) { GNUNET_CORE_disconnect (d->server); @@ -849,10 +808,8 @@ start_fsm (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) d->update_cb (d->update_cb_cls, _("`scp' did not complete cleanly.\n")); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully copied configuration file.\n"); -#endif if (NULL != d->update_cb) d->update_cb (d->update_cb_cls, NULL); d->phase = SP_START_DONE; @@ -937,18 +894,15 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, /* Check if this is a local or remote process */ if (NULL != d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); -#endif - if (d->username != NULL) GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); else arg = GNUNET_strdup (d->hostname); - d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -967,11 +921,9 @@ GNUNET_TESTING_daemon_start_stopped_service (struct GNUNET_TESTING_Daemon *d, } else { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); -#endif - d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", #endif @@ -1010,29 +962,23 @@ GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, GNUNET_assert (d->running == GNUNET_YES); GNUNET_assert (d->phase == SP_START_DONE); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Starting service %s for peer `%4s'\n"), service, GNUNET_i2s (&d->id)); -#endif - d->phase = SP_SERVICE_START; d->max_timeout = GNUNET_TIME_relative_to_absolute (timeout); /* Check if this is a local or remote process */ if (NULL != d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); -#endif - if (d->username != NULL) GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); else arg = GNUNET_strdup (d->hostname); - d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -1052,11 +998,9 @@ GNUNET_TESTING_daemon_start_service (struct GNUNET_TESTING_Daemon *d, } else { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting gnunet-arm with config `%s' locally.\n", d->cfgfile); -#endif - d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", #endif @@ -1169,10 +1113,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_asprintf (&temp_file_name, "%s/gnunet-testing-config", servicehome); ret->cfgfile = GNUNET_DISK_mktemp (temp_file_name); GNUNET_free (temp_file_name); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer with configuration file `%s'.\n", ret->cfgfile); -#endif if (NULL == ret->cfgfile) { GNUNET_free_non_null (ret->ssh_port_str); @@ -1249,10 +1191,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, /* copy directory to remote host */ if (NULL != hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Copying configuration directory to host `%s'.\n", hostname); -#endif baseservicehome = GNUNET_strdup (servicehome); /* Remove trailing /'s */ while (baseservicehome[strlen (baseservicehome) - 1] == '/') @@ -1270,21 +1210,19 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_free (baseservicehome); if (ret->ssh_port_str == NULL) { - ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", + ret->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", "-r", #if !DEBUG_TESTING "-q", #endif servicehome, arg, NULL); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "copying directory with command scp -r %s %s\n", servicehome, arg); -#endif } else { ret->proc = - GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-r", "-P", + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", "-r", "-P", ret->ssh_port_str, #if !DEBUG_TESTING "-q", @@ -1322,10 +1260,8 @@ GNUNET_TESTING_daemon_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_free (servicehome); return ret; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No need to copy configuration file since we are running locally.\n"); -#endif ret->phase = SP_COPIED; /* FIXME: why add_cont? */ GNUNET_SCHEDULER_add_continuation (&start_fsm, ret, @@ -1383,28 +1319,22 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, /* state clean up and notifications */ GNUNET_free_non_null (d->hello); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); -#endif - d->phase = SP_START_ARMING; /* Check if this is a local or remote process */ if (NULL != d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); -#endif - if (d->username != NULL) GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); else arg = GNUNET_strdup (d->hostname); - d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -1419,11 +1349,9 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, } else { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); -#endif - d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", #endif @@ -1466,10 +1394,8 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, d->phase = SP_START_DONE; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Terminating peer `%4s'\n"), GNUNET_i2s (&d->id)); -#endif if (d->churned_services != NULL) { d->dead_cb (d->dead_cb_cls, "A service has already been turned off!!"); @@ -1481,18 +1407,15 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, /* Check if this is a local or remote process */ if (NULL != d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); -#endif - if (d->username != NULL) GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); else arg = GNUNET_strdup (d->hostname); - d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -1511,11 +1434,9 @@ GNUNET_TESTING_daemon_stop_service (struct GNUNET_TESTING_Daemon *d, } else { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); -#endif - d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", #endif @@ -1556,10 +1477,8 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, if (NULL != d->cb) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Setting d->dead on peer `%4s'\n"), GNUNET_i2s (&d->id)); -#endif d->dead = GNUNET_YES; return; } @@ -1604,10 +1523,8 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, } */ /* shutdown ARM process (will terminate others) */ -#if DEBUG_TESTING - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Terminating peer `%4s'\n"), + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Terminating peer `%4s'\n" , GNUNET_i2s (&d->id)); -#endif d->phase = SP_SHUTDOWN_START; d->running = GNUNET_NO; if (allow_restart == GNUNET_YES) @@ -1622,18 +1539,15 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, /* Check if this is a local or remote process */ if (NULL != d->hostname) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' on host `%s'.\n", d->cfgfile, d->hostname); -#endif - if (d->username != NULL) GNUNET_asprintf (&arg, "%s@%s", d->username, d->hostname); else arg = GNUNET_strdup (d->hostname); - d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -1652,11 +1566,9 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, } else { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); -#endif - d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", #endif @@ -1715,17 +1627,15 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, cb (cb_cls, NULL); return; } -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Copying updated configuration file to remote host `%s'.\n", d->hostname); -#endif d->phase = SP_CONFIG_UPDATE; if (NULL != d->username) GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile); else GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile); - d->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", + d->proc = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "scp", "scp", #if !DEBUG_TESTING "-q", #endif @@ -1915,11 +1825,8 @@ connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, { struct GNUNET_TESTING_ConnectContext *ctx = cls; -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected peer %s to peer %s\n", ctx->d1->shortname, GNUNET_i2s (peer)); -#endif - if (0 != memcmp (&ctx->d2->id, peer, sizeof (struct GNUNET_PeerIdentity))) return; ctx->connected = GNUNET_YES; @@ -1949,18 +1856,14 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { hello = GNUNET_HELLO_get_header (ctx->d2->hello); GNUNET_assert (hello != NULL); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Offering hello of %s to %s\n", ctx->d2->shortname, ctx->d1->shortname); -#endif GNUNET_TRANSPORT_offer_hello (ctx->d1th, hello, NULL, NULL); GNUNET_assert (ctx->d1core != NULL); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending connect request to TRANSPORT of %s for peer %s\n", GNUNET_i2s (&ctx->d1->id), GNUNET_h2s (&ctx->d2->id.hashPubKey)); -#endif GNUNET_TRANSPORT_try_connect (ctx->d1th, &ctx->d2->id); ctx->timeout_hello = GNUNET_TIME_relative_add (ctx->timeout_hello, @@ -1989,13 +1892,10 @@ core_init_notify (void *cls, struct GNUNET_CORE_Handle *server, if (connect_ctx->send_hello == GNUNET_NO) { GNUNET_TRANSPORT_try_connect (connect_ctx->d1th, &connect_ctx->d2->id); -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending connect request to TRANSPORT of %s for peer %s\n", connect_ctx->d1->shortname, connect_ctx->d2->shortname); -#endif } - } @@ -2015,11 +1915,9 @@ reattempt_daemons_connect (void *cls, ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK; if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; -#if DEBUG_TESTING_RECONNECT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "re-attempting connect of peer %s to peer %s\n", ctx->d1->shortname, ctx->d2->shortname); -#endif ctx->connect_attempts--; GNUNET_assert (ctx->d1core == NULL); ctx->d1core_ready = GNUNET_NO; @@ -2040,10 +1938,8 @@ reattempt_daemons_connect (void *cls, /* Don't know reason for initial connect failure, update the HELLO for the second peer */ if (NULL != ctx->d2->hello) { -#if DEBUG_TESTING_RECONNECT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "updating %s's HELLO\n", ctx->d2->shortname); -#endif GNUNET_free (ctx->d2->hello); ctx->d2->hello = NULL; if (NULL != ctx->d2->th) @@ -2059,21 +1955,17 @@ reattempt_daemons_connect (void *cls, ctx->d2->ghh = GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); } -#if DEBUG_TESTING_RECONNECT else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "didn't have %s's HELLO\n", ctx->d2->shortname); } -#endif if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) { -#if DEBUG_TESTING_RECONNECT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "didn't have %s's HELLO, trying to get it now\n", ctx->d2->shortname); -#endif ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); @@ -2090,7 +1982,6 @@ reattempt_daemons_connect (void *cls, ctx->d2->ghh = GNUNET_TRANSPORT_get_hello (ctx->d2->th, &process_hello, ctx->d2); } -#if DEBUG_TESTING_RECONNECT else { if (NULL == ctx->d2->hello) @@ -2100,14 +1991,11 @@ reattempt_daemons_connect (void *cls, ctx->d2->shortname); } } -#endif if (ctx->send_hello == GNUNET_YES) { -#if DEBUG_TESTING_RECONNECT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending %s's HELLO to %s\n", ctx->d1->shortname, ctx->d2->shortname); -#endif ctx->d1th = GNUNET_TRANSPORT_connect (ctx->d1->cfg, &ctx->d1->id, ctx->d1, NULL, NULL, NULL); @@ -2126,10 +2014,8 @@ reattempt_daemons_connect (void *cls, } else { -#if DEBUG_TESTING_RECONNECT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reconnect %s to %s\n", ctx->d1->shortname, ctx->d2->shortname); -#endif GNUNET_TRANSPORT_try_connect (ctx->d1th, &ctx->d2->id); } ctx->timeout_task = @@ -2177,10 +2063,8 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, /* Peer not already connected, need to schedule connect request! */ if (ctx->d1core == NULL) { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers are NOT connected, connecting to core!\n"); -#endif ctx->d1core = GNUNET_CORE_connect (ctx->d1->cfg, 1, ctx, &core_init_notify, &connect_notify, NULL, NULL, GNUNET_NO, NULL, @@ -2195,10 +2079,8 @@ core_initial_iteration (void *cls, const struct GNUNET_PeerIdentity *peer, if ((NULL == ctx->d2->hello) && (ctx->d2->th == NULL)) /* Do not yet have the second peer's hello, set up a task to get it */ { -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Don't have d2's HELLO, trying to get it!\n"); -#endif ctx->d2->th = GNUNET_TRANSPORT_connect (ctx->d2->cfg, &ctx->d2->id, NULL, NULL, NULL, NULL); @@ -2288,11 +2170,8 @@ GNUNET_TESTING_daemons_connect (struct GNUNET_TESTING_Daemon *d1, ctx->connect_attempts = max_connect_attempts; ctx->connected = GNUNET_NO; ctx->send_hello = send_hello; -#if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to connect peer %s to peer %s\n", d1->shortname, d2->shortname); -#endif - /* Core is up! Iterate over all _known_ peers first to check if we are already connected to the peer! */ GNUNET_assert (GNUNET_OK == GNUNET_CORE_is_peer_connected (ctx->d1->cfg, &ctx->d2->id, diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 8a3ec44d4..2d0e9ef79 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -2928,7 +2928,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) { GNUNET_asprintf (&arg, "%s/friends", temp_service_path); procarr[pg_iter] = - GNUNET_OS_start_process (NULL, NULL, "mv", "mv", mytemp, arg, NULL); + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "mv", "mv", mytemp, arg, NULL); GNUNET_assert (procarr[pg_iter] != NULL); #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2950,7 +2950,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 (NULL, NULL, "scp", "scp", mytemp, arg, NULL); + GNUNET_OS_start_process (GNUNET_NO, 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_close (procarr[pg_iter]); @@ -3127,7 +3127,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, { GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); procarr[pg_iter] = - GNUNET_OS_start_process (NULL, NULL, "mv", "mv", mytemp, arg, NULL); + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "mv", "mv", mytemp, arg, NULL); #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Copying file with command cp %s %s\n"), mytemp, arg); @@ -3147,7 +3147,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 (NULL, NULL, "scp", "scp", mytemp, arg, NULL); + GNUNET_OS_start_process (GNUNET_NO, 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! */ @@ -5806,7 +5806,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 (NULL, NULL, "ssh", "ssh", arg, + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg, "peerStartHelper.pl", tempdir, NULL); GNUNET_assert (helper->proc != NULL); #if DEBUG_TESTING @@ -6031,7 +6031,7 @@ 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 (NULL, NULL, "ssh", "ssh", "-P", ssh_port_str, + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", "-P", ssh_port_str, #if !DEBUG_TESTING "-q", #endif @@ -6039,7 +6039,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, } else proc = - GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", arg, "mkdir -p", + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "ssh", "ssh", arg, "mkdir -p", tmpdir, NULL); GNUNET_assert (proc != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -6262,7 +6262,7 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, /* FIXME: Doesn't support ssh_port option! */ proc = - GNUNET_OS_start_process (NULL, NULL, "rsync", "rsync", "-r", + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "rsync", "rsync", "-r", newservicehome, arg, NULL); #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/transport/gnunet-transport-certificate-creation.c b/src/transport/gnunet-transport-certificate-creation.c index 9fd62fc9f..2ec8d36a6 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 (NULL, NULL, "openssl", "openssl", "genrsa", + GNUNET_OS_start_process (GNUNET_NO, 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 (NULL, NULL, "openssl", "openssl", "req", + GNUNET_OS_start_process (GNUNET_NO, 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-connect-running-peers.c b/src/transport/gnunet-transport-connect-running-peers.c index a640f38ab..5a5250920 100644 --- a/src/transport/gnunet-transport-connect-running-peers.c +++ b/src/transport/gnunet-transport-connect-running-peers.c @@ -256,7 +256,7 @@ connect_to_peer (const char *cfgname, GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_DISK_directory_remove (p->servicehome); /* * p->arm_proc = - * GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + * GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", * "gnunet-service-arm", "-c", cfgname, * #if VERBOSE_PEERS * "-L", "DEBUG", diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 5142ee642..ee977f5dc 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c @@ -275,7 +275,7 @@ do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) adv_port = bnd_port; if (NULL == resolver) resolver = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-resolver", + GNUNET_OS_start_process (GNUNET_YES, 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 2e0084ff7..8ec5a5e43 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c @@ -178,7 +178,7 @@ server_load_certificate (struct Plugin *plugin) #endif errno = 0; cert_creation = - GNUNET_OS_start_process (NULL, NULL, + GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, "gnunet-transport-certificate-creation", "gnunet-transport-certificate-creation", key_file, cert_file, NULL); diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 822a6701d..4510ae12c 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -1487,7 +1487,7 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) if (GNUNET_OS_check_helper_binary (filenamehw) == GNUNET_YES) { plugin->server_proc = - GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, + GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout, filenamehw, filenamehw, plugin->interface, NULL); } @@ -1514,7 +1514,7 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) absolute_filename, plugin->interface, plugin->testmode); #endif plugin->server_proc = - GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, + GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout, absolute_filename, absolute_filename, "1", NULL); if (plugin->server_proc == NULL) @@ -1534,7 +1534,7 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) #endif plugin->server_proc = - GNUNET_OS_start_process (plugin->server_stdin, plugin->server_stdout, + GNUNET_OS_start_process (GNUNET_NO, plugin->server_stdin, plugin->server_stdout, absolute_filename, absolute_filename, "2", NULL); if (plugin->server_proc == NULL) diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index 3ef6e4b21..752106bfe 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c @@ -304,7 +304,8 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle } p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, + NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, #if VERBOSE_PEERS "-L", "DEBUG", @@ -420,7 +421,8 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle goto fail; p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, + NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", "-c", cfgname, #if VERBOSE_PEERS "-L", "DEBUG", diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 8f9ba80f6..25226a3b4 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -280,9 +280,10 @@ 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 (NULL, NULL, "sh", "sh", "-c", - "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", - NULL); + GNUNET_OS_start_process (GNUNET_NO, + NULL, NULL, "sh", "sh", "-c", + "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", + NULL); } diff --git a/src/util/disk.c b/src/util/disk.c index e4d9f172a..e4d5ed32b 100644 --- a/src/util/disk.c +++ b/src/util/disk.c @@ -1610,7 +1610,7 @@ GNUNET_DISK_file_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, mode = translate_unix_perms (perm); } - fd = open (expfn, oflags | O_LARGEFILE, mode); + fd = open (expfn, oflags | O_LARGEFILE | O_NONBLOCK, mode); if (fd == -1) { if (0 == (flags & GNUNET_DISK_OPEN_FAILIFEXISTS)) @@ -2454,214 +2454,6 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p) } -/** - * Creates a named pipe/FIFO and opens it - * @param fn pointer to the name of the named pipe or to NULL - * @param flags open flags - * @param perm access permissions - * @return pipe handle on success, NULL on error - */ -struct GNUNET_DISK_FileHandle * -GNUNET_DISK_npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm) -{ -#ifdef MINGW - struct GNUNET_DISK_FileHandle *ret; - HANDLE h = NULL; - DWORD openMode; - char *name; - - openMode = 0; - if (flags & GNUNET_DISK_OPEN_READWRITE) - openMode = PIPE_ACCESS_DUPLEX; - else if (flags & GNUNET_DISK_OPEN_READ) - openMode = PIPE_ACCESS_INBOUND; - else if (flags & GNUNET_DISK_OPEN_WRITE) - openMode = PIPE_ACCESS_OUTBOUND; - - if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) - openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; - - while (h == NULL) - { - DWORD error_code; - - name = NULL; - if (*fn != NULL) - { - GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn); -#if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Trying to create an instance of named pipe `%s'\n", name); -#endif - /* 1) This might work just fine with UTF-8 strings as it is. - * 2) This is only used by GNUnet itself, and only with latin names. - */ - h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, - NULL); - } - else - { - GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu", - GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, - UINT64_MAX)); -#if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named pipe `%s'\n", - *fn); -#endif - h = CreateNamedPipe (*fn, - openMode | FILE_FLAG_OVERLAPPED | - FILE_FLAG_FIRST_PIPE_INSTANCE, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, - NULL); - } - error_code = GetLastError (); - if (name) - GNUNET_free (name); - /* don't re-set name to NULL yet */ - if (h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError (error_code); -#if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Pipe creation have failed because of %d, errno is %d\n", error_code, - errno); -#endif - if (name == NULL) - { -#if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Pipe was to be unique, considering re-creation\n"); -#endif - GNUNET_free (*fn); - *fn = NULL; - if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY) - { - return NULL; - } -#if DEBUG_NPIPE - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Pipe name was not unique, trying again\n"); -#endif - h = NULL; - } - else - return NULL; - } - } - errno = 0; - - ret = GNUNET_malloc (sizeof (*ret)); - ret->h = h; - ret->type = GNUNET_PIPE; - - ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); - ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED)); - - ret->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); - ret->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); - - return ret; -#else - if (*fn == NULL) - { - char dir[] = "/tmp/gnunet-pipe-XXXXXX"; - - if (mkdtemp (dir) == NULL) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp"); - return NULL; - } - GNUNET_asprintf (fn, "%s/child-control", dir); - } - - if (mkfifo (*fn, translate_unix_perms (perm)) == -1) - { - if ((errno != EEXIST) || (0 != (flags & GNUNET_DISK_OPEN_FAILIFEXISTS))) - return NULL; - } - - flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); - return GNUNET_DISK_file_open (*fn, flags, perm); -#endif -} - - -/** - * Opens already existing named pipe/FIFO - * - * @param fn name of an existing named pipe - * @param flags open flags - * @param perm access permissions - * @return pipe handle on success, NULL on error - */ -struct GNUNET_DISK_FileHandle * -GNUNET_DISK_npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, - enum GNUNET_DISK_AccessPermissions perm) -{ -#ifdef MINGW - struct GNUNET_DISK_FileHandle *ret; - HANDLE h; - DWORD openMode; - - openMode = 0; - if (flags & GNUNET_DISK_OPEN_READWRITE) - openMode = GENERIC_WRITE | GENERIC_READ; - else if (flags & GNUNET_DISK_OPEN_READ) - openMode = GENERIC_READ; - else if (flags & GNUNET_DISK_OPEN_WRITE) - openMode = GENERIC_WRITE; - - h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING, - FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); - if (h == INVALID_HANDLE_VALUE) - { - SetErrnoFromWinError (GetLastError ()); - return NULL; - } - - ret = GNUNET_malloc (sizeof (*ret)); - ret->h = h; - ret->type = GNUNET_PIPE; - ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); - ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED)); - ret->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); - ret->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); - - return ret; -#else - flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); - return GNUNET_DISK_file_open (fn, flags, perm); -#endif -} - - -/** - * Closes a named pipe/FIFO - * @param pipe named pipe - * @return GNUNET_OK on success, GNUNET_SYSERR otherwise - */ -int -GNUNET_DISK_npipe_close (struct GNUNET_DISK_FileHandle *pipe) -{ -#ifndef MINGW - return close (pipe->fd) == 0 ? GNUNET_OK : GNUNET_SYSERR; -#else - BOOL ret; - - ret = CloseHandle (pipe->h); - if (!ret) - { - SetErrnoFromWinError (GetLastError ()); - return GNUNET_SYSERR; - } - else - return GNUNET_OK; -#endif -} - - /** * Get the handle to a particular pipe end * diff --git a/src/util/helper.c b/src/util/helper.c index e5d336e2f..43ec23a88 100644 --- a/src/util/helper.c +++ b/src/util/helper.c @@ -306,7 +306,8 @@ 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 (h->helper_in, h->helper_out, + GNUNET_OS_start_process_vap (GNUNET_NO, + h->helper_in, h->helper_out, h->binary_name, h->binary_argv); if (NULL == h->helper_proc) diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 64dce4ba3..18dc4edaa 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -39,21 +39,252 @@ #define GNUNET_OS_CONTROL_PIPE "GNUNET_OS_CONTROL_PIPE" -#define DEBUG_OS GNUNET_EXTRA_LOGGING - struct GNUNET_OS_Process { + /** + * PID of the process. + */ pid_t pid; + #if WINDOWS + /** + * Process handle. + */ HANDLE handle; #endif - int sig; + + /** + * Pipe we use to signal the process (if used). + */ struct GNUNET_DISK_FileHandle *control_pipe; + + /** + * Name of the pipe, NULL for none. + */ + char *childpipename; }; + +/** + * Handle for 'this' process. + */ static struct GNUNET_OS_Process current_process; +/* MinGW version of named pipe API */ +#ifdef MINGW +/** + * Creates a named pipe/FIFO and opens it + * + * @param fn pointer to the name of the named pipe or to NULL + * @param flags open flags + * @param perm access permissions + * @return pipe handle on success, NULL on error + */ +static struct GNUNET_DISK_FileHandle * +npipe_create (char **fn, enum GNUNET_DISK_OpenFlags flags, + enum GNUNET_DISK_AccessPermissions perm) +{ + struct GNUNET_DISK_FileHandle *ret; + HANDLE h = NULL; + DWORD openMode; + char *name; + + openMode = 0; + if (flags & GNUNET_DISK_OPEN_READWRITE) + openMode = PIPE_ACCESS_DUPLEX; + else if (flags & GNUNET_DISK_OPEN_READ) + openMode = PIPE_ACCESS_INBOUND; + else if (flags & GNUNET_DISK_OPEN_WRITE) + openMode = PIPE_ACCESS_OUTBOUND; + if (flags & GNUNET_DISK_OPEN_FAILIFEXISTS) + openMode |= FILE_FLAG_FIRST_PIPE_INSTANCE; + + while (h == NULL) + { + DWORD error_code; + + name = NULL; + if (*fn != NULL) + { + GNUNET_asprintf (&name, "\\\\.\\pipe\\%.246s", fn); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Trying to create an instance of named pipe `%s'\n", name); + /* 1) This might work just fine with UTF-8 strings as it is. + * 2) This is only used by GNUnet itself, and only with latin names. + */ + h = CreateNamedPipe (name, openMode | FILE_FLAG_OVERLAPPED, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, + NULL); + } + else + { + GNUNET_asprintf (fn, "\\\\.\\pipe\\gnunet-%llu", + GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, + UINT64_MAX)); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to create unique named pipe `%s'\n", + *fn); + h = CreateNamedPipe (*fn, + openMode | FILE_FLAG_OVERLAPPED | + FILE_FLAG_FIRST_PIPE_INSTANCE, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 2, 1, 1, 0, + NULL); + } + error_code = GetLastError (); + if (name) + GNUNET_free (name); + /* don't re-set name to NULL yet */ + if (h == INVALID_HANDLE_VALUE) + { + SetErrnoFromWinError (error_code); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Pipe creation have failed because of %d, errno is %d\n", error_code, + errno); + if (name == NULL) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Pipe was to be unique, considering re-creation\n"); + GNUNET_free (*fn); + *fn = NULL; + if (error_code != ERROR_ACCESS_DENIED && error_code != ERROR_PIPE_BUSY) + { + return NULL; + } + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Pipe name was not unique, trying again\n"); + h = NULL; + } + else + return NULL; + } + } + errno = 0; + + ret = GNUNET_malloc (sizeof (*ret)); + ret->h = h; + ret->type = GNUNET_PIPE; + ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); + ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED)); + ret->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); + ret->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); + return ret; +} + + +/** + * Opens already existing named pipe/FIFO + * + * @param fn name of an existing named pipe + * @param flags open flags + * @param perm access permissions + * @return pipe handle on success, NULL on error + */ +static struct GNUNET_DISK_FileHandle * +npipe_open (const char *fn, enum GNUNET_DISK_OpenFlags flags, + enum GNUNET_DISK_AccessPermissions perm) +{ + struct GNUNET_DISK_FileHandle *ret; + HANDLE h; + DWORD openMode; + + openMode = 0; + if (flags & GNUNET_DISK_OPEN_READWRITE) + openMode = GENERIC_WRITE | GENERIC_READ; + else if (flags & GNUNET_DISK_OPEN_READ) + openMode = GENERIC_READ; + else if (flags & GNUNET_DISK_OPEN_WRITE) + openMode = GENERIC_WRITE; + + h = CreateFile (fn, openMode, 0, NULL, OPEN_EXISTING, + FILE_FLAG_OVERLAPPED | FILE_READ_ATTRIBUTES, NULL); + if (h == INVALID_HANDLE_VALUE) + { + SetErrnoFromWinError (GetLastError ()); + return NULL; + } + + ret = GNUNET_malloc (sizeof (*ret)); + ret->h = h; + ret->type = GNUNET_PIPE; + ret->oOverlapRead = GNUNET_malloc (sizeof (OVERLAPPED)); + ret->oOverlapWrite = GNUNET_malloc (sizeof (OVERLAPPED)); + ret->oOverlapRead->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); + ret->oOverlapWrite->hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); + + return ret; +} + +#else +/* UNIX version of named-pipe API */ + +/** + * Clean up a named pipe and the directory it was placed in. + * + * @param fn name of the pipe + */ +static void +cleanup_npipe (const char *fn) +{ + char *dn; + char *dp; + + if (0 != unlink (fn)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); + dn = GNUNET_strdup (fn); + dp = dirname (dn); + if (0 != rmdir (dp)) + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rmdir", dp); + GNUNET_free (dn); +} + + +/** + * Setup a named pipe. + * + * @param fn where to store the name of the new pipe, + * if *fn is non-null, the name of the pipe to setup + * @return GNUNET_OK on success + */ +static int +npipe_setup (char **fn) +{ + if (NULL == *fn) + { + /* FIXME: hardwired '/tmp' path... is bad */ + char dir[] = "/tmp/gnunet-pipe-XXXXXX"; + + if (NULL == mkdtemp (dir)) + { + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "mkdtemp"); + return GNUNET_SYSERR; + } + GNUNET_asprintf (fn, "%s/child-control", dir); + } + if (-1 == mkfifo (*fn, S_IRUSR | S_IWUSR)) + return GNUNET_SYSERR; + return GNUNET_OK; +} + + +/** + * Open an existing named pipe. + * + * @param fn name of the file + * @param flags flags to use + * @param perm permissions to use + * @return NULL on error + */ +static struct GNUNET_DISK_FileHandle * +npipe_open (const char *fn, + enum GNUNET_DISK_OpenFlags flags, + enum GNUNET_DISK_AccessPermissions perm) +{ + flags = flags & (~GNUNET_DISK_OPEN_FAILIFEXISTS); + return GNUNET_DISK_file_open (fn, flags, perm); +} +#endif + + /** * This handler is called when there are control data to be read on the pipe * @@ -64,44 +295,41 @@ static void parent_control_handler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - struct GNUNET_DISK_FileHandle *control_pipe = - (struct GNUNET_DISK_FileHandle *) cls; + struct GNUNET_DISK_FileHandle *control_pipe = cls; int sig; -#if DEBUG_OS LOG (GNUNET_ERROR_TYPE_DEBUG, "`%s' invoked because of %d\n", __FUNCTION__, tc->reason); -#endif if (tc->reason & (GNUNET_SCHEDULER_REASON_SHUTDOWN | GNUNET_SCHEDULER_REASON_TIMEOUT | GNUNET_SCHEDULER_REASON_PREREQ_DONE)) { - GNUNET_DISK_npipe_close (control_pipe); + GNUNET_DISK_file_close (control_pipe); + return; } - else + if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) != + sizeof (sig)) { - if (GNUNET_DISK_file_read (control_pipe, &sig, sizeof (sig)) != - sizeof (sig)) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); - GNUNET_DISK_npipe_close (control_pipe); - } - else - { -#if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig); -#endif - GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, - control_pipe, &parent_control_handler, - control_pipe); - raise (sig); - } + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "GNUNET_DISK_file_read"); + GNUNET_DISK_file_close (control_pipe); + return; } + LOG (GNUNET_ERROR_TYPE_DEBUG, "Got control code %d from parent\n", sig); + GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, + control_pipe, &parent_control_handler, + control_pipe); + raise (sig); } /** - * Task that connects this process to its parent via pipe + * Task that connects this process to its parent via pipe; + * essentially, the parent control handler will read signal numbers + * from the 'GNUNET_OS_CONTROL_PIPE' (as given in an environment + * variable) and raise those signals. + * + * @param cls closure (unused) + * @param tc scheduler context (unused) */ void GNUNET_OS_install_parent_control_handler (void *cls, @@ -112,27 +340,26 @@ GNUNET_OS_install_parent_control_handler (void *cls, struct GNUNET_DISK_FileHandle *control_pipe; env_buf = getenv (GNUNET_OS_CONTROL_PIPE); - if ((env_buf == NULL) || (strlen (env_buf) <= 0)) + if ( (env_buf == NULL) || (strlen (env_buf) <= 0) ) { - LOG (GNUNET_ERROR_TYPE_INFO, _("Not installing a handler because $%s=%s\n"), - GNUNET_OS_CONTROL_PIPE, env_buf); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Not installing a handler because $%s is empty\n", + GNUNET_OS_CONTROL_PIPE); putenv ("GNUNET_OS_CONTROL_PIPE="); return; } control_pipe = - GNUNET_DISK_npipe_open (env_buf, GNUNET_DISK_OPEN_READ, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - if (control_pipe == NULL) + npipe_open (env_buf, GNUNET_DISK_OPEN_READ, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + if (NULL == control_pipe) { LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "open", env_buf); putenv ("GNUNET_OS_CONTROL_PIPE="); return; } -#if DEBUG_OS LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding parent control handler pipe `%s' to the scheduler\n", env_buf); -#endif GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, control_pipe, &parent_control_handler, control_pipe); putenv ("GNUNET_OS_CONTROL_PIPE="); @@ -160,104 +387,64 @@ GNUNET_OS_process_current () } +/** + * Sends a signal to the process + * + * @param proc pointer to process structure + * @param sig signal + * @return 0 on success, -1 on error + */ int GNUNET_OS_process_kill (struct GNUNET_OS_Process *proc, int sig) { -#if ENABLE_WINDOWS_WORKAROUNDS - int res = 0; - int ret = 0; + int ret; +#if !WINDOWS + if ( (NULL == proc->control_pipe) && + (NULL != proc->childpipename) ) + proc->control_pipe = npipe_open (proc->childpipename, + GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); +#endif + if (NULL == proc->control_pipe) + { +#if WINDOWS + /* no pipe and windows? can't do this */ + errno = EINVAL; + return -1; +#else + return kill (proc->pid, sig); +#endif + } ret = GNUNET_DISK_file_write (proc->control_pipe, &sig, sizeof (sig)); - if (ret != sizeof (sig)) + if (ret == sizeof (sig)) + return 0; + /* pipe failed, try other methods */ + switch (sig) { - if (errno == ECOMM) - { - /* Child process is not controllable via pipe */ -#if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Child process is not controllable, will kill it directly\n"); -#endif - } - else if (errno == EPIPE) + case SIGHUP: + case SIGINT: + case SIGKILL: + case SIGTERM: +#if WINDOWS && !defined(__CYGWIN__) + if (0 == TerminateProcess (proc->handle, 0)) { -#if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Failed to write into control pipe, because pipe is invalid (the child is most likely dead)\n"); -#endif + /* FIXME: set 'errno' */ + return -1; } - else - LOG (GNUNET_ERROR_TYPE_WARNING, - "Failed to write into control pipe , errno is %d\n", errno); -#if WINDOWS && !defined(__CYGWIN__) - TerminateProcess (proc->handle, 0); + return 0; #else - PLIBC_KILL (proc->pid, sig); -#endif - } - else - { -#if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Wrote control code into control pipe, now waiting\n"); + return PLIBC_KILL (proc->pid, sig); #endif - + default: #if WINDOWS - /* Give it 3 seconds to die, then kill it in a nice Windows-specific way */ - if (WaitForSingleObject (proc->handle, 3000) != WAIT_OBJECT_0) - TerminateProcess (proc->handle, 0); - res = 0; + errno = EINVAL; + return -1; #else - struct GNUNET_NETWORK_FDSet *rfds; - struct GNUNET_NETWORK_FDSet *efds; - - rfds = GNUNET_NETWORK_fdset_create (); - efds = GNUNET_NETWORK_fdset_create (); - - GNUNET_NETWORK_fdset_handle_set (rfds, proc->control_pipe); - GNUNET_NETWORK_fdset_handle_set (efds, proc->control_pipe); - - /* Ndurner thought this up, and i have no idea what it does. - * There's have never been any code to answer the shutdown call - * (write a single int into the pipe, so that this function can read it). - * On *nix select() will probably tell that pipe is ready - * for reading, once the other process shuts down, - * but the read () call will fail, triggering a kill () - * on the pid that is already dead. This will probably result in non-0 - * return from kill(), and therefore from this function. - */ - while (1) - { - ret = - GNUNET_NETWORK_socket_select (rfds, NULL, efds, - GNUNET_TIME_relative_multiply - (GNUNET_TIME_relative_get_unit (), - 5000)); - - if (ret < 1 || - GNUNET_NETWORK_fdset_handle_isset (efds, proc->control_pipe)) - { - /* Just to be sure */ - PLIBC_KILL (proc->pid, sig); - res = 0; - break; - } - else - { - if (GNUNET_DISK_file_read (proc->control_pipe, &ret, sizeof (ret)) != - GNUNET_OK) - res = PLIBC_KILL (proc->pid, sig); - - /* Child signaled shutdown is in progress */ - continue; - } - } -#endif + return kill (proc->pid, sig); +#endif } - - return res; -#else - return kill (proc->pid, sig); -#endif } /** @@ -279,13 +466,18 @@ GNUNET_OS_process_close (struct GNUNET_OS_Process *proc) { #if ENABLE_WINDOWS_WORKAROUNDS if (proc->control_pipe) - GNUNET_DISK_npipe_close (proc->control_pipe); + GNUNET_DISK_file_close (proc->control_pipe); #endif // FIXME NILS #ifdef WINDOWS if (proc->handle != NULL) CloseHandle (proc->handle); #endif + if (NULL != proc->childpipename) + { + cleanup_npipe (proc->childpipename); + GNUNET_free (proc->childpipename); + } GNUNET_free (proc); } @@ -417,10 +609,8 @@ GNUNET_OS_set_process_priority (struct GNUNET_OS_Process *proc, } } #else -#if DEBUG_OS LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Priority management not availabe for this platform\n"); -#endif #endif return GNUNET_OK; } @@ -531,6 +721,7 @@ CreateCustomEnvTable (char **vars) /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -538,32 +729,25 @@ CreateCustomEnvTable (char **vars) * @return pointer to process structure of the new process, NULL on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, +GNUNET_OS_start_process_vap (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, char *const argv[]) { -#if ENABLE_WINDOWS_WORKAROUNDS +#ifndef MINGW char *childpipename = NULL; - struct GNUNET_DISK_FileHandle *control_pipe = NULL; -#endif struct GNUNET_OS_Process *gnunet_proc = NULL; - -#ifndef MINGW pid_t ret; int fd_stdout_write; int fd_stdout_read; int fd_stdin_read; int fd_stdin_write; -#if ENABLE_WINDOWS_WORKAROUNDS - control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - if (control_pipe == NULL) - return NULL; -#endif + if ( (GNUNET_YES == pipe_control) && + (GNUNET_OK != + npipe_setup (&childpipename)) ) + return NULL; if (pipe_stdout != NULL) { GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle @@ -585,34 +769,24 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, } ret = fork (); - if (ret != 0) + if (-1 == ret) { - if (ret == -1) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); -#if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_DISK_npipe_close (control_pipe); -#endif - } - else - { - gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); - gnunet_proc->pid = ret; -#if ENABLE_WINDOWS_WORKAROUNDS - gnunet_proc->control_pipe = control_pipe; -#endif - } -#if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_free (childpipename); -#endif + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); + GNUNET_free_non_null (childpipename); + return NULL; + } + if (0 != ret) + { + gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); + gnunet_proc->pid = ret; + gnunet_proc->childpipename = childpipename; return gnunet_proc; } - -#if ENABLE_WINDOWS_WORKAROUNDS - setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); - GNUNET_free (childpipename); -#endif - + if (NULL != childpipename) + { + setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); + GNUNET_free (childpipename); + } if (pipe_stdout != NULL) { GNUNET_break (0 == close (fd_stdout_read)); @@ -633,6 +807,8 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); _exit (1); #else + char *childpipename = NULL; + struct GNUNET_OS_Process *gnunet_proc = NULL; char *arg; unsigned int cmdlen; char *cmd, *idx; @@ -749,26 +925,31 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, &stdout_handle, sizeof (HANDLE)); start.hStdOutput = stdout_handle; } - - control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - if (control_pipe == NULL) + if (GNUNET_YES == pipe_control) { - GNUNET_free (cmd); - GNUNET_free (path); - return NULL; + control_pipe = + npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + if (control_pipe == NULL) + { + GNUNET_free (cmd); + GNUNET_free (path); + return NULL; + } + } + if (NULL != childpipename) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", + childpipename); + GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); + GNUNET_asprintf (&our_env[1], "%s", childpipename); + our_env[2] = NULL; + } + else + { + our_env[0] = NULL; } - -#if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", - childpipename); -#endif - - GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); - GNUNET_asprintf (&our_env[1], "%s", childpipename); - our_env[2] = NULL; env_block = CreateCustomEnvTable (our_env); GNUNET_free (our_env[0]); GNUNET_free (our_env[1]); @@ -808,6 +989,7 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -815,7 +997,8 @@ GNUNET_OS_start_process_vap (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @return pointer to process structure of the new process, NULL on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, +GNUNET_OS_start_process_va (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, va_list va) { @@ -835,7 +1018,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, while (NULL != (argv[argc] = va_arg (ap, char *))) argc++; va_end (ap); - ret = GNUNET_OS_start_process_vap (pipe_stdin, + ret = GNUNET_OS_start_process_vap (pipe_control, + pipe_stdin, pipe_stdout, filename, argv); @@ -848,6 +1032,7 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -857,7 +1042,8 @@ GNUNET_OS_start_process_va (struct GNUNET_DISK_PipeHandle *pipe_stdin, * */ struct GNUNET_OS_Process * -GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, +GNUNET_OS_start_process (int pipe_control, + struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...) { @@ -865,7 +1051,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, va_list ap; va_start (ap, filename); - ret = GNUNET_OS_start_process_va (pipe_stdin, pipe_stdout, filename, ap); + ret = GNUNET_OS_start_process_va (pipe_control, pipe_stdin, pipe_stdout, filename, ap); va_end (ap); return ret; } @@ -874,6 +1060,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, /** * Start a process. * + * @param pipe_control should a pipe be used to send signals to the child? * @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 @@ -881,20 +1068,17 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @return process ID of the new process, -1 on error */ struct GNUNET_OS_Process * -GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, +GNUNET_OS_start_process_v (int pipe_control, + const SOCKTYPE *lsocks, const char *filename, char *const argv[]) { -#if ENABLE_WINDOWS_WORKAROUNDS - struct GNUNET_DISK_FileHandle *control_pipe = NULL; - char *childpipename = NULL; -#endif - #ifndef MINGW pid_t ret; char lpid[16]; char fds[16]; struct GNUNET_OS_Process *gnunet_proc = NULL; + char *childpipename = NULL; int i; int j; int k; @@ -903,15 +1087,9 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, int *lscp; unsigned int ls; -#if ENABLE_WINDOWS_WORKAROUNDS - control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - if (control_pipe == NULL) - return NULL; -#endif - + if ( (GNUNET_YES == pipe_control) && + (GNUNET_OK != npipe_setup (&childpipename)) ) + return NULL; lscp = NULL; ls = 0; if (lsocks != NULL) @@ -922,36 +1100,26 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, GNUNET_array_append (lscp, ls, -1); } ret = fork (); - if (ret != 0) + if (-1 == ret) { - if (ret == -1) - { - LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); -#if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_DISK_npipe_close (control_pipe); -#endif - } - else - { - gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); - gnunet_proc->pid = ret; -#if ENABLE_WINDOWS_WORKAROUNDS - gnunet_proc->control_pipe = control_pipe; - -#endif - } + LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); + GNUNET_free_non_null (childpipename); + GNUNET_array_grow (lscp, ls, 0); + return NULL; + } + if (0 != ret) + { + gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); + gnunet_proc->pid = ret; + gnunet_proc->childpipename = childpipename; GNUNET_array_grow (lscp, ls, 0); -#if ENABLE_WINDOWS_WORKAROUNDS - GNUNET_free (childpipename); -#endif return gnunet_proc; } - -#if ENABLE_WINDOWS_WORKAROUNDS - setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); - GNUNET_free (childpipename); -#endif - + if (NULL != childpipename) + { + setenv (GNUNET_OS_CONTROL_PIPE, childpipename, 1); + GNUNET_free (childpipename); + } if (lscp != NULL) { /* read systemd documentation... */ @@ -999,6 +1167,8 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); _exit (1); #else + struct GNUNET_DISK_FileHandle *control_pipe = NULL; + char *childpipename = NULL; char **arg, **non_const_argv; unsigned int cmdlen; char *cmd, *idx; @@ -1006,9 +1176,7 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, PROCESS_INFORMATION proc; int argcount = 0; struct GNUNET_OS_Process *gnunet_proc = NULL; - char path[MAX_PATH + 1]; - char *our_env[5] = { NULL, NULL, NULL, NULL, NULL }; char *env_block = NULL; char *pathbuf; @@ -1023,7 +1191,7 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, HANDLE lsocks_read; HANDLE lsocks_write; wchar_t wpath[MAX_PATH + 1], wcmd[32768]; - + int env_off; int fail; /* Search in prefix dir (hopefully - the directory from which @@ -1130,15 +1298,18 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, memset (&start, 0, sizeof (start)); start.cb = sizeof (start); - control_pipe = - GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, - GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); - if (control_pipe == NULL) + if (GNUNET_YES == pipe_control) { - GNUNET_free (cmd); - GNUNET_free (path); - return NULL; + control_pipe = + npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE, + GNUNET_DISK_PERM_USER_READ | + GNUNET_DISK_PERM_USER_WRITE); + if (control_pipe == NULL) + { + GNUNET_free (cmd); + GNUNET_free (path); + return NULL; + } } if (lsocks != NULL && lsocks[0] != INVALID_SOCKET) { @@ -1160,29 +1331,25 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, &lsocks_read, sizeof (HANDLE)); } -#if DEBUG_OS - LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", - childpipename); -#endif - - GNUNET_asprintf (&our_env[0], "%s=", GNUNET_OS_CONTROL_PIPE); - GNUNET_asprintf (&our_env[1], "%s", childpipename); - GNUNET_free (childpipename); - if (lsocks == NULL || lsocks[0] == INVALID_SOCKET) - our_env[2] = NULL; - else + env_off = 0; + if (NULL != childpipename) + { + LOG (GNUNET_ERROR_TYPE_DEBUG, "Opened the parent end of the pipe `%s'\n", + childpipename); + GNUNET_asprintf (&our_env[env_off++], "%s=", GNUNET_OS_CONTROL_PIPE); + GNUNET_asprintf (&our_env[env_off++], "%s", childpipename); + GNUNET_free (childpipename); + } + if ( (lsocks != NULL) && (lsocks[0] != INVALID_SOCKET)) { /*This will tell the child that we're going to send lsocks over the pipe*/ - GNUNET_asprintf (&our_env[2], "%s=", "GNUNET_OS_READ_LSOCKS"); - GNUNET_asprintf (&our_env[3], "%lu", lsocks_read); - our_env[4] = NULL; + GNUNET_asprintf (&our_env[env_off++], "%s=", "GNUNET_OS_READ_LSOCKS"); + GNUNET_asprintf (&our_env[env_off++], "%lu", lsocks_read); } + our_env[env_off++] = NULL; env_block = CreateCustomEnvTable (our_env); - GNUNET_free_non_null (our_env[0]); - GNUNET_free_non_null (our_env[1]); - GNUNET_free_non_null (our_env[2]); - GNUNET_free_non_null (our_env[3]); - + while (0 > env_off) + GNUNET_free_non_null (our_env[--env_off]); if (ERROR_SUCCESS != plibc_conv_to_win_pathwconv(path, wpath) || ERROR_SUCCESS != plibc_conv_to_win_pathwconv(cmd, wcmd) || !CreateProcessW @@ -1191,8 +1358,9 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, { SetErrnoFromWinError (GetLastError ()); LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); - GNUNET_DISK_npipe_close (control_pipe); - if (lsocks != NULL) + 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); @@ -1286,11 +1454,11 @@ GNUNET_OS_start_process_v (const SOCKTYPE *lsocks, */ TerminateProcess (gnunet_proc->handle, 0); CloseHandle (gnunet_proc->handle); - GNUNET_DISK_npipe_close (gnunet_proc->control_pipe); + if (NULL != gnunet_proc->control_pipe) + GNUNET_DISK_file_close (gnunet_proc->control_pipe); GNUNET_free (gnunet_proc); return NULL; } - return gnunet_proc; #endif } @@ -1599,7 +1767,7 @@ 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 (NULL, opipe, binary, ap); + eip = GNUNET_OS_start_process_va (GNUNET_NO, NULL, opipe, binary, ap); va_end (ap); if (NULL == eip) { diff --git a/src/util/scheduler.c b/src/util/scheduler.c index f1cecd4ef..c54672f5f 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -818,13 +818,11 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *task_cls) current_lifeness = GNUNET_YES; GNUNET_SCHEDULER_add_continuation (task, task_cls, GNUNET_SCHEDULER_REASON_STARTUP); -#if ENABLE_WINDOWS_WORKAROUNDS active_task = (void *) (long) -1; /* force passing of sanity check */ GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, &GNUNET_OS_install_parent_control_handler, NULL); active_task = NULL; -#endif last_tr = 0; busy_wait_warning = 0; while (GNUNET_OK == check_lifeness ()) diff --git a/src/util/test_common_logging_runtime_loglevels.c b/src/util/test_common_logging_runtime_loglevels.c index b6b9d6178..cdf1f660d 100644 --- a/src/util/test_common_logging_runtime_loglevels.c +++ b/src/util/test_common_logging_runtime_loglevels.c @@ -314,7 +314,7 @@ runone () break; } - proc = GNUNET_OS_start_process (NULL, pipe_stdout, + proc = GNUNET_OS_start_process (GNUNET_NO, 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 178a1d9ef..54638c12f 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c @@ -126,7 +126,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } proc = - GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, + GNUNET_OS_start_process (GNUNET_NO, hello_pipe_stdin, hello_pipe_stdout, fn, "test_gnunet_echo_hello", "-", NULL); GNUNET_free (fn); diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c index 4ad5a2cf5..67d5f4640 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c @@ -393,7 +393,7 @@ check () 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 (NULL, NULL, fn, "gnunet-service-resolver", + proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, fn, "gnunet-service-resolver", #if VERBOSE "-L", "DEBUG", #endif diff --git a/src/util/test_strings.c b/src/util/test_strings.c index 88de0b81b..570776a81 100644 --- a/src/util/test_strings.c +++ b/src/util/test_strings.c @@ -97,7 +97,9 @@ check () GNUNET_free (r); b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "ASCII"); WANT ("TEST", b); + GNUNET_log_skip (2, GNUNET_NO); b = GNUNET_STRINGS_to_utf8 ("TEST", 4, "unknown"); + GNUNET_log_skip (0, GNUNET_YES); WANT ("TEST", b); return 0; } diff --git a/src/vpn/test_gnunet_vpn.c b/src/vpn/test_gnunet_vpn.c index 90895e452..005c7bd07 100644 --- a/src/vpn/test_gnunet_vpn.c +++ b/src/vpn/test_gnunet_vpn.c @@ -441,7 +441,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = - GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG",