From 721e49caeea6ba5073f8bc5c6c08359295c02bb5 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 3 Nov 2010 21:26:40 +0000 Subject: [PATCH] original patch from Mantis 1614 --- src/arm/arm_api.c | 8 +- src/arm/do_start_process.c | 8 +- src/arm/gnunet-service-arm.c | 50 ++-- src/core/test_core_api.c | 12 +- src/core/test_core_api_reliability.c | 12 +- src/core/test_core_api_start_only.c | 12 +- src/core/test_core_quota_compliance.c | 6 +- src/datastore/perf_datastore_api.c | 10 +- src/datastore/test_datastore_api.c | 10 +- src/datastore/test_datastore_api_management.c | 10 +- src/dht/test_dht_api.c | 10 +- src/fs/test_fs.c | 5 +- src/fs/test_fs_download.c | 12 +- src/fs/test_fs_download_indexed.c | 12 +- src/fs/test_fs_download_persistence.c | 12 +- src/fs/test_fs_download_recursive.c | 8 +- src/fs/test_fs_list_indexed.c | 12 +- src/fs/test_fs_namespace.c | 12 +- src/fs/test_fs_namespace_list_updateable.c | 12 +- src/fs/test_fs_publish.c | 12 +- src/fs/test_fs_publish_persistence.c | 12 +- src/fs/test_fs_search.c | 12 +- src/fs/test_fs_search_persistence.c | 12 +- src/fs/test_fs_search_ranking.c | 6 +- src/fs/test_fs_start_stop.c | 12 +- src/fs/test_fs_unindex.c | 12 +- src/fs/test_fs_unindex_persistence.c | 12 +- src/hostlist/test_gnunet_daemon_hostlist.c | 12 +- .../test_gnunet_daemon_hostlist_learning.c | 22 +- src/include/gnunet_os_lib.h | 108 ++++++++- src/include/gnunet_testing_lib.h | 2 +- src/monkey/test_gnunet_monkey.c | 9 +- src/peerinfo/perf_peerinfo_api.c | 11 +- src/peerinfo/test_peerinfo_api.c | 10 +- src/statistics/test_statistics_api.c | 20 +- src/statistics/test_statistics_api_loop.c | 10 +- src/testing/test_testing_topology.c | 6 +- src/testing/testing.c | 56 ++--- src/testing/testing_group.c | 34 +-- src/transport/plugin_transport_tcp.c | 20 +- src/transport/plugin_transport_udp.c | 20 +- src/transport/plugin_transport_wlan.c | 6 +- src/transport/test_quota_compliance.c | 10 +- src/transport/test_transport_api.c | 10 +- .../test_transport_api_reliability.c | 10 +- src/util/crypto_random.c | 24 +- src/util/os_priority.c | 225 ++++++++++++++---- src/util/scheduler.c | 2 +- src/util/test_os_priority.c | 12 +- src/util/test_os_start_process.c | 10 +- src/util/test_resolver_api.c | 10 +- src/vpn/gnunet-daemon-vpn.c | 16 +- src/vpn/gnunet-service-dns.c | 4 +- 53 files changed, 665 insertions(+), 337 deletions(-) diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index fb4f3a02d..81f1c2d5c 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -375,7 +375,7 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct RequestContext *pos = cls; - pid_t pid; + GNUNET_OS_Process *proc; char *binary; char *config; char *loprefix; @@ -454,7 +454,7 @@ arm_service_report (void *cls, ) { /* we're clearly running a test, don't daemonize */ - pid = do_start_process (NULL, + proc = do_start_process (NULL, loprefix, binary, "-c", config, @@ -467,7 +467,7 @@ arm_service_report (void *cls, } else { - pid = do_start_process (NULL, + proc = do_start_process (NULL, loprefix, binary, "-c", config, @@ -482,7 +482,7 @@ arm_service_report (void *cls, GNUNET_free (config); GNUNET_free (loprefix); GNUNET_free (lopostfix); - if (pid == -1) + if (proc == NULL) { if (pos->callback != NULL) pos->callback (pos->cls, GNUNET_SYSERR); diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c index d616ac2b7..7d691ce60 100644 --- a/src/arm/do_start_process.c +++ b/src/arm/do_start_process.c @@ -12,7 +12,7 @@ * @param ... more arguments, NULL terminated * @return PID of the started process, -1 on error */ -static pid_t +static GNUNET_OS_Process * do_start_process (const int *lsocks, const char *first_arg, ...) { @@ -24,7 +24,7 @@ do_start_process (const int *lsocks, char *pos; char *cp; const char *last; - pid_t pid; + GNUNET_OS_Process *proc; argv_size = 1; va_start (ap, first_arg); @@ -88,9 +88,9 @@ do_start_process (const int *lsocks, while (NULL != (arg = (va_arg (ap, const char*)))); va_end (ap); argv[argv_size] = NULL; - pid = GNUNET_OS_start_process_v (lsocks, argv[0], argv); + proc = GNUNET_OS_start_process_v (lsocks, argv[0], argv); while (argv_size > 0) GNUNET_free (argv[--argv_size]); GNUNET_free (argv); - return pid; + return proc; } diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 2eb21a068..543e65557 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -91,9 +91,9 @@ struct ServiceList struct GNUNET_SERVER_Client *killing_client; /** - * Process ID of the child. + * Process structure pointer of the child. */ - pid_t pid; + GNUNET_OS_Process *proc; /** * Last time the config of this service was @@ -199,11 +199,11 @@ config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) /* FIXME: this test for config change is a bit too coarse grained */ if ( (0 == STAT (pos->config, &sbuf)) && (pos->mtime < sbuf.st_mtime) && - (pos->pid != 0) ) + (pos->proc != NULL) ) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Restarting service `%s' due to configuration file change.\n")); - if (0 != PLIBC_KILL (pos->pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); else pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS; @@ -414,7 +414,7 @@ start_process (struct ServiceList *sl, sl->name, sl->binary, sl->config); #endif if (GNUNET_YES == use_debug) - sl->pid = do_start_process (lsocks, + sl->proc = do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config, @@ -422,19 +422,24 @@ start_process (struct ServiceList *sl, options, NULL); else - sl->pid = do_start_process (lsocks, + sl->proc = do_start_process (lsocks, loprefix, sl->binary, "-c", sl->config, options, NULL); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Starting service `%s' (PID: %d)\n"), - sl->name, - (int) sl->pid); + if (sl->proc == NULL) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Failed to start service `%s'\n"), + sl->name); + else + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Starting service `%s' (PID: %d)\n"), + sl->name, + (int) GNUNET_OS_process_get_pid (sl->proc)); GNUNET_free (loprefix); GNUNET_free (options); - /* FIXME: should check sl->pid */ + /* FIXME: should check sl->proc */ } @@ -568,7 +573,7 @@ stop_service (struct GNUNET_SERVER_Client *client, running = pos; return; } - if (pos->pid == 0) + if (pos->proc == NULL) { /* process is in delayed restart, simply remove it! */ free_entry (pos); @@ -581,7 +586,7 @@ stop_service (struct GNUNET_SERVER_Client *client, "Sending kill signal to service `%s', waiting for process to die.\n", servicename); #endif - if (0 != PLIBC_KILL (pos->pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); pos->next = running; running = pos; @@ -653,7 +658,7 @@ handle_stop (void *cls, /** * Remove all entries for tasks that are not running - * (pid = 0) from the running list (they will no longer + * (proc = NULL) from the running list (they will no longer * be restarted since we are shutting down). */ static void @@ -668,7 +673,7 @@ clean_up_running () while (NULL != pos) { next = pos->next; - if (pos->pid == 0) + if (pos->proc == NULL) { if (prev == NULL) running = next; @@ -727,13 +732,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) pos = running; while (NULL != pos) { - if (pos->pid != 0) + if (pos->proc != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s' (PID: %d)\n", pos->name, - pos->pid); - if (0 != PLIBC_KILL (pos->pid, SIGTERM)) + GNUNET_OS_process_get_pid (pos->proc)); + if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } pos = pos->next; @@ -773,7 +778,7 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) pos = running; while (pos != NULL) { - if ( (pos->pid == 0) && + if ( (pos->proc == NULL) && (GNUNET_YES != in_shutdown) ) { if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0) @@ -845,12 +850,12 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) while (NULL != (pos = next)) { next = pos->next; - if (pos->pid == 0) + if (pos->proc == NULL) { prev = pos; continue; } - if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->pid, + if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc, &statusType, &statusCode))) || ( (ret == GNUNET_NO) || @@ -876,7 +881,8 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) statstr = _( /* process termination method */ "unknown"); statcode = 0; } - pos->pid = 0; + GNUNET_OS_process_close (pos->proc); + pos->proc = NULL; if (NULL != pos->killing_client) { if (prev == NULL) diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index b04430eea..a4c3b0a78 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -54,7 +54,7 @@ struct PeerContext struct GNUNET_MessageHeader *hello; int connect_status; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -289,7 +289,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -332,12 +332,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_pid)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index b25cb89f2..0b3be2f82 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -74,7 +74,7 @@ struct PeerContext struct GNUNET_MessageHeader *hello; int connect_status; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -436,7 +436,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -479,12 +479,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c index b55d3c972..e82f12ed3 100644 --- a/src/core/test_core_api_start_only.c +++ b/src/core/test_core_api_start_only.c @@ -49,7 +49,7 @@ struct PeerContext struct GNUNET_CORE_Handle *ch; struct GNUNET_PeerIdentity id; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -153,7 +153,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -193,12 +193,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index d4df96611..99d9ed4ad 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -479,7 +479,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -539,10 +539,12 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM process %u stopped\n", p->arm_pid); #endif diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c index bb4f88cf3..07bb16016 100644 --- a/src/datastore/perf_datastore_api.c +++ b/src/datastore/perf_datastore_api.c @@ -372,7 +372,7 @@ run (void *cls, static int check () { - pid_t pid; + GNUNET_OS_Process *proc; char cfg_name[128]; char *const argv[] = { "perf-datastore-api", @@ -391,7 +391,7 @@ check () sizeof (cfg_name), "test_datastore_api_data_%s.conf", plugin_name); - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -400,12 +400,14 @@ check () GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "perf-datastore-api", "nohelp", options, &run, NULL); - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; return ok; } diff --git a/src/datastore/test_datastore_api.c b/src/datastore/test_datastore_api.c index ae7782d6c..feba0b7ac 100644 --- a/src/datastore/test_datastore_api.c +++ b/src/datastore/test_datastore_api.c @@ -641,7 +641,7 @@ check () { char cfg_name[128]; #if START_DATASTORE - pid_t pid; + GNUNET_OS_Process *proc; #endif char *const argv[] = { "test-datastore-api", @@ -660,7 +660,7 @@ check () "test_datastore_api_data_%s.conf", plugin_name); #if START_DATASTORE - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -671,12 +671,14 @@ check () argv, "test-datastore-api", "nohelp", options, &run, NULL); #if START_DATASTORE - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; #endif if (ok != 0) fprintf (stderr, "Missed some testcases: %u\n", ok); diff --git a/src/datastore/test_datastore_api_management.c b/src/datastore/test_datastore_api_management.c index 72760de7a..fbb8795a6 100644 --- a/src/datastore/test_datastore_api_management.c +++ b/src/datastore/test_datastore_api_management.c @@ -350,7 +350,7 @@ run (void *cls, static int check () { - pid_t pid; + GNUNET_OS_Process *proc; char cfg_name[128]; char *const argv[] = { "test-datastore-api-management", @@ -368,7 +368,7 @@ check () sizeof (cfg_name), "test_datastore_api_data_%s.conf", plugin_name); - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -377,12 +377,14 @@ check () GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-datastore-api", "nohelp", options, &run, NULL); - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; if (ok != 0) fprintf (stderr, "Missed some testcases: %u\n", ok); return ok; diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index 2145be843..5ef70407c 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -85,7 +85,7 @@ struct PeerContext struct GNUNET_DHT_FindPeerHandle *find_peer_handle; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -121,9 +121,11 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (p->arm_pid); + GNUNET_OS_process_wait (p->arm_proc); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } @@ -453,7 +455,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/fs/test_fs.c b/src/fs/test_fs.c index f9621949e..a97faf94f 100644 --- a/src/fs/test_fs.c +++ b/src/fs/test_fs.c @@ -104,7 +104,7 @@ int main (int argc, char *argv[]) { #if START_DAEMON - pid_t daemon; + GNUNET_OS_Process *daemon; #endif int ok; struct GNUNET_ECRS_URI *uri; @@ -132,7 +132,7 @@ main (int argc, char *argv[]) } #if START_DAEMON daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); - GNUNET_GE_ASSERT (NULL, daemon > 0); + GNUNET_GE_ASSERT (NULL, daemon != NULL); CHECK (GNUNET_OK == GNUNET_wait_for_daemon_running (NULL, cfg, 60 * GNUNET_CRON_SECONDS)); @@ -250,6 +250,7 @@ FAILURE: #if START_DAEMON GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); + GNUNET_OS_process_close (daemon); #endif GNUNET_GC_free (cfg); diff --git a/src/fs/test_fs_download.c b/src/fs/test_fs_download.c index 848c95954..305dee07e 100644 --- a/src/fs/test_fs_download.c +++ b/src/fs/test_fs_download.c @@ -52,7 +52,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -249,7 +249,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -264,12 +264,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_download_indexed.c b/src/fs/test_fs_download_indexed.c index ac4f57bb9..b55f2221b 100644 --- a/src/fs/test_fs_download_indexed.c +++ b/src/fs/test_fs_download_indexed.c @@ -52,7 +52,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -251,7 +251,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -266,12 +266,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c index 4560985c9..6bb4ab865 100644 --- a/src/fs/test_fs_download_persistence.c +++ b/src/fs/test_fs_download_persistence.c @@ -52,7 +52,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -310,7 +310,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -325,12 +325,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_download_recursive.c b/src/fs/test_fs_download_recursive.c index 20f681f11..a60a2da9a 100644 --- a/src/fs/test_fs_download_recursive.c +++ b/src/fs/test_fs_download_recursive.c @@ -29,7 +29,7 @@ #include "gnunet_util.h" #include "gnunet_fsui_lib.h" -#define DEBUG_VERBOSE GNUNET_NO +#define DEBUG_VERBOSE GNUNET_YES #define CHECK(a) if (!(a)) { ok = GNUNET_NO; GNUNET_GE_BREAK(ectx, 0); goto FAILURE; } @@ -256,7 +256,7 @@ int main (int argc, char *argv[]) { #if START_DAEMON - pid_t daemon; + GNUNET_OS_Process *daemon; #endif int ok; char *fn = NULL; @@ -284,7 +284,7 @@ main (int argc, char *argv[]) GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-recursive_download_test/"); daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); - GNUNET_GE_ASSERT (NULL, daemon > 0); + GNUNET_GE_ASSERT (NULL, daemon != NULL); CHECK (GNUNET_OK == GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS)); @@ -372,6 +372,8 @@ FAILURE: #if START_DAEMON GNUNET_GE_BREAK (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); + GNUNET_OS_process_close (daemon); + daemon = NULL; #endif GNUNET_GC_free (cfg); return (ok == GNUNET_YES) ? 0 : 1; diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c index dd2b30417..1221ff6c4 100644 --- a/src/fs/test_fs_list_indexed.c +++ b/src/fs/test_fs_list_indexed.c @@ -56,7 +56,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -199,7 +199,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -214,12 +214,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index f197b4749..efe44af0b 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c @@ -59,7 +59,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -69,7 +69,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -84,12 +84,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_namespace_list_updateable.c b/src/fs/test_fs_namespace_list_updateable.c index fc6b1537a..1cf8653bb 100644 --- a/src/fs/test_fs_namespace_list_updateable.c +++ b/src/fs/test_fs_namespace_list_updateable.c @@ -55,7 +55,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -73,7 +73,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -88,12 +88,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif if (uri_this != NULL) GNUNET_FS_uri_destroy (uri_this); diff --git a/src/fs/test_fs_publish.c b/src/fs/test_fs_publish.c index f5b835259..4e65e7590 100644 --- a/src/fs/test_fs_publish.c +++ b/src/fs/test_fs_publish.c @@ -53,7 +53,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -184,7 +184,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -199,12 +199,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_publish_persistence.c b/src/fs/test_fs_publish_persistence.c index b4b9b58ba..afbee2ec8 100644 --- a/src/fs/test_fs_publish_persistence.c +++ b/src/fs/test_fs_publish_persistence.c @@ -52,7 +52,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -243,7 +243,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -258,12 +258,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 98315ac5c..515730689 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c @@ -53,7 +53,7 @@ struct PeerContext struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_PeerIdentity id; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -191,7 +191,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -206,12 +206,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_search_persistence.c b/src/fs/test_fs_search_persistence.c index 97b7f656b..c2af22de4 100644 --- a/src/fs/test_fs_search_persistence.c +++ b/src/fs/test_fs_search_persistence.c @@ -53,7 +53,7 @@ struct PeerContext struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_PeerIdentity id; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -262,7 +262,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -277,12 +277,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_search_ranking.c b/src/fs/test_fs_search_ranking.c index 8c75bc1b1..06a069a32 100644 --- a/src/fs/test_fs_search_ranking.c +++ b/src/fs/test_fs_search_ranking.c @@ -126,7 +126,7 @@ int main (int argc, char *argv[]) { #if START_DAEMON - pid_t daemon; + GNUNET_OS_Process *daemon; #endif int ok; char *fn = NULL; @@ -153,7 +153,7 @@ main (int argc, char *argv[]) #if START_DAEMON GNUNET_disk_directory_remove (NULL, "/tmp/gnunet-fsui-searchranktest/"); daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); - GNUNET_GE_ASSERT (NULL, daemon > 0); + GNUNET_GE_ASSERT (NULL, daemon != NULL); CHECK (GNUNET_OK == GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS)); @@ -242,6 +242,8 @@ FAILURE: #if START_DAEMON GNUNET_GE_ASSERT (NULL, GNUNET_OK == GNUNET_daemon_stop (NULL, daemon)); + GNUNET_OS_process_close (daemon); + daemon = NULL; #endif GNUNET_GC_free (cfg); return (ok == GNUNET_YES) ? 0 : 1; diff --git a/src/fs/test_fs_start_stop.c b/src/fs/test_fs_start_stop.c index 7558ac46a..22fb64ae7 100644 --- a/src/fs/test_fs_start_stop.c +++ b/src/fs/test_fs_start_stop.c @@ -41,7 +41,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -59,7 +59,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -74,12 +74,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_unindex.c b/src/fs/test_fs_unindex.c index 6fe47a6c4..0afed8f06 100644 --- a/src/fs/test_fs_unindex.c +++ b/src/fs/test_fs_unindex.c @@ -52,7 +52,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -196,7 +196,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -211,12 +211,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/fs/test_fs_unindex_persistence.c b/src/fs/test_fs_unindex_persistence.c index cbe08913f..d33ecb5fc 100644 --- a/src/fs/test_fs_unindex_persistence.c +++ b/src/fs/test_fs_unindex_persistence.c @@ -51,7 +51,7 @@ struct PeerContext { struct GNUNET_CONFIGURATION_Handle *cfg; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -266,7 +266,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -281,12 +281,14 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index 899a2eb44..a13f58a65 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -49,7 +49,7 @@ struct PeerContext struct GNUNET_TRANSPORT_Handle *th; struct GNUNET_MessageHeader *hello; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -135,7 +135,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -159,12 +159,14 @@ waitpid_task (void *cls, #if START_ARM GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n"); - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(p->arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "ARM process %u stopped\n", p->arm_pid); + "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc)); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index 7fd291375..b5e6ca0bf 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -71,7 +71,7 @@ struct PeerContext struct GNUNET_CORE_Handle *core; struct GNUNET_STATISTICS_Handle *stats; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -144,24 +144,28 @@ static void shutdown_testcase() #if START_ARM GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing hostlist server ARM process.\n"); - if (0 != PLIBC_KILL (adv_peer.arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(adv_peer.arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(adv_peer.arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist server ARM process %u stopped\n", adv_peer.arm_pid); + "Hostlist server ARM process %u stopped\n", GNUNET_OS_process_get_pid (adv_peer.arm_proc)); + GNUNET_OS_process_close (adv_peer->arm_proc); + adv_peer->arm_proc = NULL; #endif #if START_ARM GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing hostlist client ARM process.\n"); - if (0 != PLIBC_KILL (learn_peer.arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (learn_peer.arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait(learn_peer.arm_pid) != GNUNET_OK) + if (GNUNET_OS_process_wait(learn_peer.arm_proc) != GNUNET_OK) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist client ARM process %u stopped\n", learn_peer.arm_pid); + "Hostlist client ARM process %u stopped\n", GNUNET_OS_process_get_pid (learn_peer.arm_proc)); + GNUNET_OS_process_close (learn_peer->arm_proc); + learn_peer->arm_proc = NULL; #endif GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down scheduler\n"); @@ -354,7 +358,7 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname) unsigned int result; p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", @@ -397,7 +401,7 @@ setup_adv_peer (struct PeerContext *p, const char *cfgname) p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index 701aae593..2152b279c 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h @@ -44,6 +44,11 @@ extern "C" #include "gnunet_configuration_lib.h" #include "gnunet_scheduler_lib.h" +/** + * Process information (OS-dependent) + */ +typedef struct _GNUNET_OS_Process GNUNET_OS_Process; + /** * Possible installation paths to request @@ -170,15 +175,93 @@ void GNUNET_OS_network_interfaces_list (GNUNET_OS_NetworkInterfaceProcessor #define GNUNET_OS_get_hostname_max_length() 255 #endif +/** + * Allocates new process structure + * + * Should be made internal? + * + * @return pointer to allocated structure + */ +GNUNET_OS_Process *GNUNET_OS_process_alloc (); + + +/** + * Get process structure for current process + * + * The pointer it returns points to static memory location and must not be + * deallocated/closed + * + * @return pointer to the process sturcutre for this process + */ +GNUNET_OS_Process *GNUNET_OS_process_current (); + + +/** + * Sends @sig to the process + * + * @param proc pointer to process structure + * @param sig signal + * @return 0 on success, -1 on error + */ +int GNUNET_OS_process_kill (GNUNET_OS_Process *proc, int sig); + +/** + * Get process ID + * + * Should be made internal? + * + * @param proc pointer to process structure + * @return process ID + */ +pid_t GNUNET_OS_process_get_pid (GNUNET_OS_Process *proc); + +/** + * Set process ID + * + * Should be made internal? + * + * @param proc pointer to process structure + * @param pid process ID + */ +void GNUNET_OS_process_set_pid (GNUNET_OS_Process *proc, pid_t pid); + +#if WINDOWS +/** + * Get process handle + * + * Should be made internal? + * + * @param proc pointer to process structure + * @return process handle + */ +HANDLE GNUNET_OS_process_get_handle (GNUNET_OS_Process *proc); + +/** + * Set process handle + * + * Should be made internal? + * + * @param proc pointer to process structure + * @param handle process handle + */ +void GNUNET_OS_process_set_handle(GNUNET_OS_Process *proc, HANDLE handle); +#endif + +/** + * Cleans up process structure contents (OS-dependent) and deallocates it + * + * @param proc pointer to process structure + */ +void GNUNET_OS_process_close (GNUNET_OS_Process *proc); /** * Set process priority * - * @param proc id of the process + * @param proc pointer to process structure * @param prio priority value * @return GNUNET_OK on success, GNUNET_SYSERR on error */ -int GNUNET_OS_set_process_priority (pid_t proc, +int GNUNET_OS_set_process_priority (GNUNET_OS_Process *proc, enum GNUNET_SCHEDULER_Priority prio); @@ -189,9 +272,9 @@ int GNUNET_OS_set_process_priority (pid_t proc, * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary * @param ... NULL-terminated list of arguments to the process - * @return process ID of the new process, -1 on error + * @return pointer to process structure of the new process, NULL on error */ -pid_t +GNUNET_OS_Process * GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...); @@ -205,29 +288,30 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @param filename name of the binary * @param argv NULL-terminated list of arguments to the process, * including the process name as the first argument - * @return process ID of the new process, -1 on error + * @return pointer to process structure of the new process, NULL on error */ -pid_t GNUNET_OS_start_process_v (const int *lsocks, - const char *filename, char *const argv[]); +GNUNET_OS_Process * +GNUNET_OS_start_process_v (const int *lsocks, const char *filename, + char *const argv[]); /** * Retrieve the status of a process - * @param proc process ID + * @param proc pointer to process structure * @param type status type * @param code return code/signal number * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise */ -int GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, - unsigned long *code); +int GNUNET_OS_process_status (GNUNET_OS_Process *proc, + enum GNUNET_OS_ProcessStatusType *type, unsigned long *code); /** * Wait for a process - * @param proc process ID to wait for + * @param proc pointer to process structure of the process to wait for * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ -int GNUNET_OS_process_wait (pid_t proc); +int GNUNET_OS_process_wait (GNUNET_OS_Process *proc); #if 0 /* keep Emacsens' auto-indent happy */ diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h index a377e1d1c..3fee527b8 100644 --- a/src/include/gnunet_testing_lib.h +++ b/src/include/gnunet_testing_lib.h @@ -301,7 +301,7 @@ struct GNUNET_TESTING_Daemon /** * PID of the process that we started last. */ - pid_t pid; + GNUNET_OS_Process *proc; /** * In which phase are we during the start of diff --git a/src/monkey/test_gnunet_monkey.c b/src/monkey/test_gnunet_monkey.c index ba832f137..d1d4155d0 100644 --- a/src/monkey/test_gnunet_monkey.c +++ b/src/monkey/test_gnunet_monkey.c @@ -42,9 +42,12 @@ static int check () { - GNUNET_OS_start_process (NULL, NULL, "gnunet-monkey", - "gnunet-monkey", - "./bug_null_pointer_exception", NULL); + GNUNET_OS_process_close (GNUNET_OS_start_process (NULL, NULL, + "gnunet-monkey", + "gnunet-monkey", + "./bug_null_pointer_exception", + NULL)); + return 0; } diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c index ea21b0fae..eea2eb973 100755 --- a/src/peerinfo/perf_peerinfo_api.c +++ b/src/peerinfo/perf_peerinfo_api.c @@ -166,11 +166,11 @@ check () NULL }; #if START_SERVICE - pid_t pid; + GNUNET_OS_Process *proc; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", "gnunet-service-peerinfo", #if DEBUG_PEERINFO "-L", "DEBUG", @@ -185,12 +185,15 @@ check () numpeers, NUM_REQUESTS * NUM_REQUESTS / 2); #if START_SERVICE - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; + #endif return ok; } diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 34655c893..b2e95d767 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -165,7 +165,7 @@ static int check () { int ok = 3; - pid_t pid; + GNUNET_OS_Process *proc; char *const argv[] = { "test-peerinfo-api", "-c", "test_peerinfo_api_data.conf", @@ -177,7 +177,7 @@ check () struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", "gnunet-service-peerinfo", #if DEBUG_PEERINFO "-L", "DEBUG", @@ -186,12 +186,14 @@ check () GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-peerinfo-api", "nohelp", options, &run, &ok); - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; return ok; } diff --git a/src/statistics/test_statistics_api.c b/src/statistics/test_statistics_api.c index 5c55a11a6..6a45e3b10 100644 --- a/src/statistics/test_statistics_api.c +++ b/src/statistics/test_statistics_api.c @@ -29,7 +29,7 @@ #include "gnunet_scheduler_lib.h" #include "gnunet_statistics_service.h" -#define DEBUG_STATISTICS GNUNET_NO +#define DEBUG_STATISTICS GNUNET_YES #define START_SERVICE GNUNET_YES @@ -157,8 +157,8 @@ check () GNUNET_GETOPT_OPTION_END }; #if START_SERVICE - pid_t pid; - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_Process *proc; + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if DEBUG_STATISTICS "-L", "DEBUG", @@ -168,19 +168,21 @@ check () GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run, &ok); #if START_SERVICE - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; #endif if (ok != 0) return ok; ok = 1; #if START_SERVICE /* restart to check persistence! */ - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if DEBUG_STATISTICS "-L", "DEBUG", @@ -190,12 +192,14 @@ check () GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run_more, &ok); #if START_SERVICE - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; #endif return ok; } diff --git a/src/statistics/test_statistics_api_loop.c b/src/statistics/test_statistics_api_loop.c index 289e8f09f..b4e7ae7ab 100644 --- a/src/statistics/test_statistics_api_loop.c +++ b/src/statistics/test_statistics_api_loop.c @@ -96,8 +96,8 @@ check () GNUNET_GETOPT_OPTION_END }; #if START_SERVICE - pid_t pid; - pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", + GNUNET_OS_Process *proc; + proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-statistics", "gnunet-service-statistics", #if DEBUG_STATISTICS "-L", "DEBUG", @@ -107,12 +107,14 @@ check () GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run, &ok); #if START_SERVICE - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; #endif return ok; } diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c index bb1455e60..ed1f2d591 100644 --- a/src/testing/test_testing_topology.c +++ b/src/testing/test_testing_topology.c @@ -179,12 +179,14 @@ static void gather_log_data () { char *peer_number; char *connect_number; - pid_t mem_process; + GNUNET_OS_Process *mem_process; GNUNET_asprintf(&peer_number, "%llu", num_peers); GNUNET_asprintf(&connect_number, "%llu", expected_connections); mem_process = GNUNET_OS_start_process (NULL, NULL, "./memsize.pl", "memsize.pl", "totals.txt", peer_number, connect_number, NULL); - GNUNET_OS_process_wait(mem_process); + GNUNET_OS_process_wait (mem_process); + GNUNET_OS_process_close (mem_process); + mem_process = NULL; } #endif diff --git a/src/testing/testing.c b/src/testing/testing.c index 7143ba684..89272f3c2 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -205,7 +205,7 @@ start_fsm (void *cls, { case SP_COPYING: /* confirm copying complete */ - if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) + if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) { if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) { @@ -264,7 +264,7 @@ start_fsm (void *cls, "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, "-sq"); #endif - d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", + d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "gnunet-peerinfo", "gnunet-peerinfo", "-c", d->cfgfile, "-sq", NULL); @@ -285,7 +285,7 @@ start_fsm (void *cls, #endif if (d->ssh_port_str == NULL) { - d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", + d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", #if !DEBUG_TESTING "-q", @@ -296,7 +296,7 @@ start_fsm (void *cls, } else { - d->pid = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", + d->proc = GNUNET_OS_start_process (NULL, d->pipe_stdout, "ssh", "ssh", "-p", d->ssh_port_str, #if !DEBUG_TESTING "-q", @@ -308,7 +308,7 @@ start_fsm (void *cls, GNUNET_DISK_pipe_close_end(d->pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); GNUNET_free (dst); } - if (-1 == d->pid) + if (NULL == d->proc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not start `%s' process to create hostkey.\n"), @@ -378,9 +378,10 @@ start_fsm (void *cls, d->cb = NULL; GNUNET_DISK_pipe_close(d->pipe_stdout); d->pipe_stdout = NULL; - (void) PLIBC_KILL (d->pid, SIGKILL); - GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->pid)); - d->pid = 0; + (void) GNUNET_OS_process_kill (d->proc, SIGKILL); + GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); + GNUNET_OS_process_close (d->proc); + d->proc = NULL; if (NULL != cb) cb (d->cb_cls, NULL, @@ -391,9 +392,10 @@ start_fsm (void *cls, } GNUNET_DISK_pipe_close(d->pipe_stdout); d->pipe_stdout = NULL; - (void) PLIBC_KILL (d->pid, SIGKILL); - GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->pid)); - d->pid = 0; + (void) GNUNET_OS_process_kill (d->proc, SIGKILL); + GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (d->proc)); + GNUNET_OS_process_close (d->proc); + d->proc = NULL; #if DEBUG_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully got hostkey!\n"); @@ -439,7 +441,7 @@ start_fsm (void *cls, "-L", "DEBUG", "-s"); #endif - d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", + d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", "-c", d->cfgfile, #if DEBUG_TESTING @@ -462,7 +464,7 @@ start_fsm (void *cls, #endif if (d->ssh_port_str == NULL) { - d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", + d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", @@ -477,7 +479,7 @@ start_fsm (void *cls, else { - d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", + d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", "-p", d->ssh_port_str, #if !DEBUG_TESTING "-q", @@ -491,7 +493,7 @@ start_fsm (void *cls, } GNUNET_free (dst); } - if (-1 == d->pid) + if (NULL == d->proc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not start `%s' process to start GNUnet.\n"), @@ -520,7 +522,7 @@ start_fsm (void *cls, &start_fsm, d); break; case SP_START_ARMING: - if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) + if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) { if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) { @@ -565,7 +567,7 @@ start_fsm (void *cls, break; case SP_SHUTDOWN_START: /* confirm copying complete */ - if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) + if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) { if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) { @@ -645,7 +647,7 @@ start_fsm (void *cls, break; case SP_CONFIG_UPDATE: /* confirm copying complete */ - if (GNUNET_OK != GNUNET_OS_process_status (d->pid, &type, &code)) + if (GNUNET_OK != GNUNET_OS_process_status (d->proc, &type, &code)) { if (GNUNET_TIME_absolute_get_remaining(d->max_timeout).rel_value == 0) /* FIXME: config update should take timeout parameter! */ { @@ -856,7 +858,7 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, if (ret->ssh_port_str == NULL) { - ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp", + ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", #if !DEBUG_TESTING "-q", @@ -865,7 +867,7 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, } else { - ret->pid = GNUNET_OS_start_process (NULL, NULL, "scp", + ret->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", "-P", ret->ssh_port_str, #if !DEBUG_TESTING "-q", @@ -873,7 +875,7 @@ GNUNET_TESTING_daemon_start (struct GNUNET_SCHEDULER_Handle *sched, ret->cfgfile, arg, NULL); } GNUNET_free (arg); - if (-1 == ret->pid) + if (NULL == ret->proc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ @@ -972,7 +974,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -991,7 +993,7 @@ GNUNET_TESTING_daemon_restart (struct GNUNET_TESTING_Daemon *d, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); #endif - d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", + d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", @@ -1107,7 +1109,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, else arg = GNUNET_strdup (d->hostname); - d->pid = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", + d->proc = GNUNET_OS_start_process (NULL, NULL, "ssh", "ssh", #if !DEBUG_TESTING "-q", #endif @@ -1127,7 +1129,7 @@ GNUNET_TESTING_daemon_stop (struct GNUNET_TESTING_Daemon *d, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping gnunet-arm with config `%s' locally.\n", d->cfgfile); #endif - d->pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", + d->proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-arm", "gnunet-arm", #if DEBUG_TESTING "-L", "DEBUG", @@ -1194,13 +1196,13 @@ GNUNET_TESTING_daemon_reconfigure (struct GNUNET_TESTING_Daemon *d, GNUNET_asprintf (&arg, "%s@%s:%s", d->username, d->hostname, d->cfgfile); else GNUNET_asprintf (&arg, "%s:%s", d->hostname, d->cfgfile); - d->pid = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", + d->proc = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", #if !DEBUG_TESTING "-q", #endif d->cfgfile, arg, NULL); GNUNET_free (arg); - if (-1 == d->pid) + if (NULL == d->proc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _ diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 4c123a980..4b34a21de 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -1937,7 +1937,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) FILE *temp_friend_handle; unsigned int pg_iter; char *temp_service_path; - pid_t *pidarr; + GNUNET_OS_Process **procarr; char *arg; char * mytemp; enum GNUNET_OS_ProcessStatusType type; @@ -1946,7 +1946,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) int ret; int max_wait = 10; - pidarr = GNUNET_malloc(sizeof(pid_t) * pg->total); + procarr = GNUNET_malloc(sizeof(GNUNET_OS_Process *) * pg->total); for (pg_iter = 0; pg_iter < pg->total; pg_iter++) { mytemp = GNUNET_DISK_mktemp("friends"); @@ -1972,7 +1972,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ { GNUNET_asprintf (&arg, "%s/friends", temp_service_path); - pidarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", + procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", mytemp, arg, NULL); #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -1987,7 +1987,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) GNUNET_asprintf (&arg, "%s@%s:%s/friends", pg->peers[pg_iter].daemon->username, pg->peers[pg_iter].daemon->hostname, temp_service_path); else GNUNET_asprintf (&arg, "%s:%s/friends", pg->peers[pg_iter].daemon->hostname, temp_service_path); - pidarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", + procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, NULL); #if VERBOSE_TESTING @@ -2011,9 +2011,9 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Checking copy status of file %d\n"), pg_iter); #endif - if (pidarr[pg_iter] != 0) /* Check for already completed! */ + if (procarr[pg_iter] != NULL) /* Check for already completed! */ { - if (GNUNET_OS_process_status(pidarr[pg_iter], &type, &return_code) != GNUNET_OK) + if (GNUNET_OS_process_status(procarr[pg_iter], &type, &return_code) != GNUNET_OK) { ret = GNUNET_SYSERR; } @@ -2023,7 +2023,8 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) } else { - pidarr[pg_iter] = 0; + GNUNET_OS_process_close (procarr[pg_iter]); + procarr[pg_iter] = NULL; #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("File %d copied\n"), pg_iter); @@ -2043,7 +2044,7 @@ create_and_copy_friend_files (struct GNUNET_TESTING_PeerGroup *pg) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Finished copying all friend files!\n")); #endif - GNUNET_free(pidarr); + GNUNET_free(procarr); return ret; } @@ -2063,7 +2064,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char static struct BlacklistContext blacklist_ctx; unsigned int pg_iter; char *temp_service_path; - pid_t *pidarr; + GNUNET_OS_Process **procarr; char *arg; char *mytemp; enum GNUNET_OS_ProcessStatusType type; @@ -2076,7 +2077,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char char *pos; char *temp_transports; - pidarr = GNUNET_malloc(sizeof(pid_t) * pg->total); + procarr = GNUNET_malloc(sizeof(GNUNET_OS_Process *) * pg->total); for (pg_iter = 0; pg_iter < pg->total; pg_iter++) { mytemp = GNUNET_DISK_mktemp("blacklist"); @@ -2124,7 +2125,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char if (pg->peers[pg_iter].daemon->hostname == NULL) /* Local, just copy the file */ { GNUNET_asprintf (&arg, "%s/blacklist", temp_service_path); - pidarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", + procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "mv", "mv", mytemp, arg, NULL); #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2139,7 +2140,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char GNUNET_asprintf (&arg, "%s@%s:%s/blacklist", pg->peers[pg_iter].daemon->username, pg->peers[pg_iter].daemon->hostname, temp_service_path); else GNUNET_asprintf (&arg, "%s:%s/blacklist", pg->peers[pg_iter].daemon->hostname, temp_service_path); - pidarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", + procarr[pg_iter] = GNUNET_OS_start_process (NULL, NULL, "scp", "scp", mytemp, arg, NULL); #if VERBOSE_TESTING @@ -2163,9 +2164,9 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Checking copy status of file %d\n"), pg_iter); #endif - if (pidarr[pg_iter] != 0) /* Check for already completed! */ + if (procarr[pg_iter] != NULL) /* Check for already completed! */ { - if (GNUNET_OS_process_status(pidarr[pg_iter], &type, &return_code) != GNUNET_OK) + if (GNUNET_OS_process_status(procarr[pg_iter], &type, &return_code) != GNUNET_OK) { ret = GNUNET_SYSERR; } @@ -2175,7 +2176,8 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char } else { - pidarr[pg_iter] = 0; + GNUNET_OS_process_close (procarr[pg_iter]); + procarr[pg_iter] = NULL; #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("File %d copied\n"), pg_iter); @@ -2195,7 +2197,7 @@ create_and_copy_blacklist_files (struct GNUNET_TESTING_PeerGroup *pg, const char GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Finished copying all blacklist files!\n")); #endif - GNUNET_free(pidarr); + GNUNET_free(procarr); return ret; } diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 7ac31ecb6..d39787900 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -345,7 +345,7 @@ struct Plugin /** * The process id of the server process (if behind NAT) */ - pid_t server_pid; + GNUNET_OS_Process *server_proc; /** * List of open TCP sessions. @@ -958,7 +958,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) char inet4[INET_ADDRSTRLEN]; char *address_as_string; char *port_as_string; - pid_t pid; + GNUNET_OS_Process *proc; const struct sockaddr *sa = (const struct sockaddr *)addr; #if DEBUG_TCP_NAT @@ -995,10 +995,12 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) #endif /* Start the client process */ - pid = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL); + proc = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL); GNUNET_free(address_as_string); GNUNET_free(port_as_string); - GNUNET_OS_process_wait (pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; } @@ -2201,8 +2203,8 @@ tcp_transport_start_nat_server(struct Plugin *plugin) "Starting gnunet-nat-server process cmd: %s %s\n", "gnunet-nat-server", plugin->internal_address); #endif /* Start the server process */ - plugin->server_pid = GNUNET_OS_start_process(NULL, plugin->server_stdout, "gnunet-nat-server", "gnunet-nat-server", plugin->internal_address, NULL); - if (plugin->server_pid == GNUNET_SYSERR) + plugin->server_proc = GNUNET_OS_start_process(NULL, plugin->server_stdout, "gnunet-nat-server", "gnunet-nat-server", plugin->internal_address, NULL); + if (plugin->server_proc == NULL) { #if DEBUG_TCP_NAT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2603,9 +2605,11 @@ libgnunet_plugin_transport_tcp_done (void *cls) if (plugin->behind_nat == GNUNET_YES) { - if (0 != PLIBC_KILL (plugin->server_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (plugin->server_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (plugin->server_pid); + GNUNET_OS_process_wait (plugin->server_proc); + GNUNET_OS_process_close (plugin->server_proc); + plugin->server_proc = NULL; } GNUNET_free_non_null(plugin->bind_address); GNUNET_free (plugin); diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 1f7aca59a..0f53719fe 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -471,7 +471,7 @@ struct Plugin /** * The process id of the server process (if behind NAT) */ - pid_t server_pid; + GNUNET_OS_Process *server_proc; }; @@ -528,9 +528,11 @@ udp_transport_server_stop (void *cls) } if (plugin->behind_nat == GNUNET_YES) { - if (0 != PLIBC_KILL (plugin->server_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (plugin->server_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (plugin->server_pid); + GNUNET_OS_process_wait (plugin->server_proc); + GNUNET_OS_process_close (plugin->server_proc); + plugin->server_proc = NULL; } return GNUNET_OK; } @@ -700,7 +702,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) char addr_buf[INET_ADDRSTRLEN]; char *address_as_string; char *port_as_string; - pid_t pid; + GNUNET_OS_Process *proc; const struct IPv4UdpAddress *t4; GNUNET_assert(addrlen == sizeof(struct IPv4UdpAddress)); @@ -721,10 +723,12 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen) #endif /* Start the server process */ - pid = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL); + proc = GNUNET_OS_start_process(NULL, NULL, "gnunet-nat-client", "gnunet-nat-client", plugin->external_address, address_as_string, port_as_string, NULL); GNUNET_free(address_as_string); GNUNET_free(port_as_string); - GNUNET_OS_process_wait (pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; } /** @@ -1637,12 +1641,12 @@ udp_transport_server_start (void *cls) plugin->internal_address); #endif /* Start the server process */ - plugin->server_pid = GNUNET_OS_start_process(NULL, + plugin->server_proc = GNUNET_OS_start_process(NULL, plugin->server_stdout, "gnunet-nat-server", "gnunet-nat-server", plugin->internal_address, NULL); - if (plugin->server_pid == GNUNET_SYSERR) + if (plugin->server_proc == NULL) { #if DEBUG_UDP GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 54cc3f864..e53e4f3b4 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c @@ -135,7 +135,7 @@ struct Plugin /** * The process id of the server process (if behind NAT) */ - pid_t server_pid; + GNUNET_OS_Process *server_proc; /** * The interface of the wlan card given to us by the user. @@ -1245,8 +1245,8 @@ wlan_transport_start_wlan_helper (struct Plugin *plugin) "Starting gnunet-wlan-helper process cmd: %s %s\n", "gnunet-wlan-helper", plugin->interface); #endif /* Start the server process */ - plugin->server_pid = GNUNET_OS_start_process(plugin->server_stdin, plugin->server_stdout, "gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper", plugin->interface, NULL); - if (plugin->server_pid == GNUNET_SYSERR) + plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, plugin->server_stdout, "gnunet-transport-wlan-helper", "gnunet-transport-wlan-helper", plugin->interface, NULL); + if (plugin->server_proc == NULL) { #if DEBUG_TCP_NAT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 4c4a025f2..39319f8d7 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c @@ -65,7 +65,7 @@ struct PeerContext struct GNUNET_TRANSPORT_Handle *th; struct GNUNET_PeerIdentity id; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -197,9 +197,11 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (p->arm_pid); + GNUNET_OS_process_wait (p->arm_proc); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } @@ -576,7 +578,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 789a97f3d..7a45ea0f0 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c @@ -60,7 +60,7 @@ struct PeerContext struct GNUNET_TRANSPORT_Handle *th; struct GNUNET_PeerIdentity id; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -118,9 +118,11 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (p->arm_pid); + GNUNET_OS_process_wait (p->arm_proc); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } @@ -220,7 +222,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM "-L", "DEBUG", diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 0625230a4..d9e88fe49 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c @@ -62,7 +62,7 @@ struct PeerContext struct GNUNET_TRANSPORT_Handle *th; struct GNUNET_PeerIdentity id; #if START_ARM - pid_t arm_pid; + GNUNET_OS_Process *arm_proc; #endif }; @@ -141,9 +141,11 @@ static void stop_arm (struct PeerContext *p) { #if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (p->arm_pid); + GNUNET_OS_process_wait (p->arm_proc); + GNUNET_OS_process_close (p->arm_proc); + p->arm_proc = NULL; #endif GNUNET_CONFIGURATION_destroy (p->cfg); } @@ -381,7 +383,7 @@ setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM - p->arm_pid = GNUNET_OS_start_process (NULL, NULL, + p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE_ARM diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c index 4fcb157d9..75435a5e6 100644 --- a/src/util/crypto_random.c +++ b/src/util/crypto_random.c @@ -188,7 +188,7 @@ GNUNET_CRYPTO_random_disable_entropy_gathering () * Process ID of the "find" process that we use for * entropy gathering. */ -static pid_t genproc; +static GNUNET_OS_Process *genproc; /** * Function called by libgcrypt whenever we are @@ -206,16 +206,17 @@ entropy_generator (void *cls, return; if (current == total) { - if (genproc != 0) + if (genproc != NULL) { - if (0 != PLIBC_KILL (genproc, SIGTERM)) + if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); - genproc = 0; + GNUNET_OS_process_close (genproc); + genproc = NULL; } return; } - if (genproc != 0) + if (genproc != NULL) { ret = GNUNET_OS_process_status (genproc, &type, &code); if (ret == GNUNET_NO) @@ -225,10 +226,11 @@ entropy_generator (void *cls, GNUNET_break (0); return; } - if (0 != PLIBC_KILL (genproc, SIGTERM)) + if (0 != GNUNET_OS_process_kill (genproc, SIGTERM)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill"); GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); - genproc = 0; + GNUNET_OS_process_close (genproc); + genproc = NULL; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Starting `%s' process to generate entropy\n"), "find"); @@ -243,10 +245,11 @@ entropy_generator (void *cls, static void killfind () { - if (genproc != 0) + if (genproc != NULL) { - PLIBC_KILL (genproc, SIGKILL); - genproc = 0; + GNUNET_OS_process_kill (genproc, SIGKILL); + GNUNET_OS_process_close (genproc); + genproc = NULL; } } @@ -279,3 +282,4 @@ void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini () /* end of crypto_random.c */ + diff --git a/src/util/os_priority.c b/src/util/os_priority.c index e2e170cb9..b9e5f010b 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -29,6 +29,112 @@ #include "gnunet_os_lib.h" #include "disk.h" +struct _GNUNET_OS_Process +{ + pid_t pid; +#if WINDOWS + HANDLE handle; +#endif +}; + +static GNUNET_OS_Process current_process; + +GNUNET_OS_Process * +GNUNET_OS_process_alloc () +{ + GNUNET_OS_Process *ret = GNUNET_malloc (sizeof (GNUNET_OS_Process)); + ret->pid = 0; +#if WINDOWS + ret->handle = NULL; +#endif + return ret; +} + +/** + * Get process structure for current process + * + * The pointer it returns points to static memory location and must not be + * deallocated/closed + * + * @return pointer to the process sturcutre for this process + */ +GNUNET_OS_Process * +GNUNET_OS_process_current () +{ +#if WINDOWS + current_process.pid = GetCurrentProcessId (); + current_process.handle = GetCurrentProcess (); +#else + current_process.pid = 0; +#endif + return ¤t_process; +} + +int +GNUNET_OS_process_kill (GNUNET_OS_Process *proc, int sig) +{ +#if WINDOWS + if (sig == SIGKILL || sig == SIGTERM) + { + HANDLE h = GNUNET_OS_process_get_handle (proc); + if (NULL == h) + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", GNUNET_OS_process_get_pid (proc), h); + return -1; + } + if (!TerminateProcess (h, 0)) + { + SetErrnoFromWinError (GetLastError ()); + return -1; + } + else + return 0; + } + errno = EINVAL; + return -1; +#else + return kill (GNUNET_OS_process_get_pid (proc), sig); +#endif +} + +pid_t +GNUNET_OS_process_get_pid (GNUNET_OS_Process *proc) +{ + return proc->pid; +} + +void +GNUNET_OS_process_set_pid (GNUNET_OS_Process *proc, pid_t pid) +{ + proc->pid = pid; +} + +#if WINDOWS +HANDLE +GNUNET_OS_process_get_handle (GNUNET_OS_Process *proc) +{ + return proc->handle; +} + +void +GNUNET_OS_process_set_handle(GNUNET_OS_Process *proc, HANDLE handle) +{ + if (proc->handle != NULL) + CloseHandle (proc->handle); + proc->handle = handle; +} +#endif + +void +GNUNET_OS_process_close (GNUNET_OS_Process *proc) +{ +#if WINDOWS + if (proc->handle != NULL) + CloseHandle (proc->handle); +#endif + GNUNET_free (proc); +} + #if WINDOWS #include "gnunet_signal_lib.h" @@ -36,17 +142,17 @@ extern GNUNET_SIGNAL_Handler w32_sigchld_handler; /** * @brief Waits for a process to terminate and invokes the SIGCHLD handler - * @param h handle to the process + * @param proc pointer to process structure */ static DWORD WINAPI -ChildWaitThread (HANDLE h) +ChildWaitThread (void *arg) { - WaitForSingleObject (h, INFINITE); + GNUNET_OS_Process *proc = (GNUNET_OS_Process *) arg; + WaitForSingleObject (proc->handle, INFINITE); if (w32_sigchld_handler) w32_sigchld_handler (); - CloseHandle (h); return 0; } #endif @@ -54,19 +160,21 @@ ChildWaitThread (HANDLE h) /** * Set process priority * - * @param proc id of the process + * @param proc pointer to process structure * @param prio priority value * @return GNUNET_OK on success, GNUNET_SYSERR on error */ int -GNUNET_OS_set_process_priority (pid_t proc, +GNUNET_OS_set_process_priority (GNUNET_OS_Process *proc, enum GNUNET_SCHEDULER_Priority prio) { int rprio; + pid_t pid; GNUNET_assert (prio < GNUNET_SCHEDULER_PRIORITY_COUNT); if (prio == GNUNET_SCHEDULER_PRIORITY_KEEP) return GNUNET_OK; + /* convert to MINGW/Unix values */ switch (prio) { @@ -114,12 +222,19 @@ GNUNET_OS_set_process_priority (pid_t proc, GNUNET_assert (0); return GNUNET_SYSERR; } + + pid = GNUNET_OS_process_get_pid (proc); + /* Set process priority */ #ifdef MINGW - SetPriorityClass (GetCurrentProcess (), rprio); + { + HANDLE h = GNUNET_OS_process_get_handle (proc); + GNUNET_assert (h != NULL); + SetPriorityClass (h, rprio); + } #elif LINUX - if ( (0 == proc) || - (proc == getpid () ) ) + if ( (0 == pid) || + (pid == getpid () ) ) { int have = nice (0); int delta = rprio - have; @@ -135,7 +250,7 @@ GNUNET_OS_set_process_priority (pid_t proc, } else { - if (0 != setpriority (PRIO_PROCESS, proc, rprio)) + if (0 != setpriority (PRIO_PROCESS, pid, rprio)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | @@ -157,18 +272,18 @@ GNUNET_OS_set_process_priority (pid_t proc, * @param pipe_stdout pipe to use to get output from child process (or NULL) * @param filename name of the binary * @param ... NULL-terminated list of arguments to the process - * @return process ID of the new process, -1 on error + * @return pointer to process structure of the new process, NULL on error */ -pid_t +GNUNET_OS_Process * GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...) { - /* FIXME: Make this work on windows!!! */ va_list ap; #ifndef MINGW pid_t ret; + GNUNET_OS_Process *gnunet_proc = NULL; char **argv; int argc; int fd_stdout_write; @@ -227,9 +342,11 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, GNUNET_DISK_pipe_close_end(pipe_stdin, GNUNET_DISK_PIPE_END_READ); sleep (1); #endif + gnunet_proc = GNUNET_OS_process_alloc (); + GNUNET_OS_process_set_pid (gnunet_proc, ret); } GNUNET_free (argv); - return ret; + return gnunet_proc; } if (pipe_stdout != NULL) @@ -258,6 +375,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, int findresult; STARTUPINFO start; PROCESS_INFORMATION proc; + GNUNET_OS_Process *gnunet_proc = NULL; HANDLE stdin_handle; HANDLE stdout_handle; @@ -299,7 +417,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, { SetErrnoFromWinError (GetLastError ()); GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "FindExecutable", filename); - return (pid_t) -1; + return NULL; } if (!CreateProcessA @@ -308,16 +426,20 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, { SetErrnoFromWinError (GetLastError ()); GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path); - return (pid_t) -1; + return NULL; } - CreateThread (NULL, 64000, ChildWaitThread, proc.hProcess, 0, NULL); + gnunet_proc = GNUNET_OS_process_alloc (); + GNUNET_OS_process_set_pid (gnunet_proc, proc.dwProcessId); + GNUNET_OS_process_set_handle (gnunet_proc, proc.hProcess); + + CreateThread (NULL, 64000, ChildWaitThread, (void *) gnunet_proc, 0, NULL); CloseHandle (proc.hThread); GNUNET_free (cmd); - return proc.dwProcessId; + return gnunet_proc; #endif } @@ -333,7 +455,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, * @param argv NULL-terminated list of arguments to the process * @return process ID of the new process, -1 on error */ -pid_t +GNUNET_OS_Process * GNUNET_OS_start_process_v (const int *lsocks, const char *filename, char *const argv[]) { @@ -341,6 +463,7 @@ GNUNET_OS_start_process_v (const int *lsocks, pid_t ret; char lpid[16]; char fds[16]; + GNUNET_OS_Process *gnunet_proc = NULL; int i; int j; int k; @@ -382,9 +505,11 @@ GNUNET_OS_start_process_v (const int *lsocks, be plenty in practice */ sleep (1); #endif + gnunet_proc = GNUNET_OS_process_alloc (); + GNUNET_OS_process_set_pid (gnunet_proc, ret); } GNUNET_array_grow (lscp, ls, 0); - return ret; + return gnunet_proc; } if (lscp != NULL) { @@ -441,6 +566,7 @@ GNUNET_OS_start_process_v (const int *lsocks, int argcount = 0; char *non_const_filename = NULL; int filenamelen = 0; + GNUNET_OS_Process *gnunet_proc = NULL; GNUNET_assert (lsocks == NULL); /* Count the number of arguments */ @@ -504,11 +630,15 @@ GNUNET_OS_start_process_v (const int *lsocks, &proc)) { SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); - return -1; + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); + return NULL; } - CreateThread (NULL, 64000, ChildWaitThread, proc.hProcess, 0, NULL); + gnunet_proc = GNUNET_OS_process_alloc (); + GNUNET_OS_process_set_pid (gnunet_proc, proc.dwProcessId); + GNUNET_OS_process_set_handle (gnunet_proc, proc.hProcess); + + CreateThread (NULL, 64000, ChildWaitThread, (void *) gnunet_proc, 0, NULL); CloseHandle (proc.hThread); GNUNET_free (cmd); @@ -517,7 +647,7 @@ GNUNET_OS_start_process_v (const int *lsocks, GNUNET_free (non_const_argv[--argcount]); GNUNET_free (non_const_argv); - return proc.dwProcessId; + return gnunet_proc; #endif } @@ -529,7 +659,7 @@ GNUNET_OS_start_process_v (const int *lsocks, * @return GNUNET_OK on success, GNUNET_NO if the process is still running, GNUNET_SYSERR otherwise */ int -GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, +GNUNET_OS_process_status (GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code) { #ifndef MINGW @@ -537,7 +667,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, int ret; GNUNET_assert (0 != proc); - ret = waitpid (proc, &status, WNOHANG); + ret = waitpid (GNUNET_OS_process_get_pid (proc), &status, WNOHANG); if (ret < 0) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); @@ -549,7 +679,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, *code = 0; return GNUNET_NO; } - if (proc != ret) + if (GNUNET_OS_process_get_pid (proc) != ret) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); return GNUNET_SYSERR; @@ -583,27 +713,35 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, } #else HANDLE h; - DWORD c; + DWORD c, error_code, ret; - h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); - if (INVALID_HANDLE_VALUE == h) + h = GNUNET_OS_process_get_handle (proc); + ret = GNUNET_OS_process_get_pid (proc); + if (h == NULL || ret == 0) { - SetErrnoFromWinError (GetLastError ()); - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess"); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", ret, h); return GNUNET_SYSERR; } + if (h == NULL) + h = GetCurrentProcess (); - c = GetExitCodeProcess (h, &c); + SetLastError (0); + ret = GetExitCodeProcess (h, &c); + error_code = GetLastError (); + if (ret == 0 || error_code != NO_ERROR) + { + SetErrnoFromWinError (error_code); + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "GetExitCodeProcess"); + return GNUNET_SYSERR; + } if (STILL_ACTIVE == c) { *type = GNUNET_OS_PROCESS_RUNNING; *code = 0; - CloseHandle (h); return GNUNET_NO; } *type = GNUNET_OS_PROCESS_EXITED; *code = c; - CloseHandle (h); #endif return GNUNET_OK; @@ -611,14 +749,15 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, /** * Wait for a process - * @param proc process ID to wait for + * @param proc pointer to process structure * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ int -GNUNET_OS_process_wait (pid_t proc) +GNUNET_OS_process_wait (GNUNET_OS_Process *proc) { + pid_t pid = GNUNET_OS_process_get_pid (proc); #ifndef MINGW - if (proc != waitpid (proc, NULL, 0)) + if (pid != waitpid (pid, NULL, 0)) return GNUNET_SYSERR; return GNUNET_OK; @@ -626,12 +765,14 @@ GNUNET_OS_process_wait (pid_t proc) HANDLE h; int ret; - h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); - if (INVALID_HANDLE_VALUE == h) + h = GNUNET_OS_process_get_handle (proc); + if (NULL == h) { - SetErrnoFromWinError (GetLastError ()); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid process information {%d, %08X}\n", pid, h); return GNUNET_SYSERR; } + if (h == NULL) + h = GetCurrentProcess (); if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) { @@ -641,8 +782,6 @@ GNUNET_OS_process_wait (pid_t proc) else ret = GNUNET_OK; - CloseHandle (h); - return ret; #endif } diff --git a/src/util/scheduler.c b/src/util/scheduler.c index 67406e21c..35e0a70c9 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c @@ -633,7 +633,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched, if (sched->current_priority != pos->priority) { sched->current_priority = pos->priority; - (void) GNUNET_OS_set_process_priority (0, pos->priority); + (void) GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), pos->priority); } sched->active_task = pos; #if PROFILE_DELAYS diff --git a/src/util/test_os_priority.c b/src/util/test_os_priority.c index c2fdcc6f5..17874a6ee 100644 --- a/src/util/test_os_priority.c +++ b/src/util/test_os_priority.c @@ -32,27 +32,27 @@ testprio () { pid_t child; if (GNUNET_OK != - GNUNET_OS_set_process_priority (getpid (), + GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), GNUNET_SCHEDULER_PRIORITY_DEFAULT)) return 1; if (GNUNET_OK != - GNUNET_OS_set_process_priority (getpid (), + GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), GNUNET_SCHEDULER_PRIORITY_UI)) return 1; if (GNUNET_OK != - GNUNET_OS_set_process_priority (getpid (), + GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), GNUNET_SCHEDULER_PRIORITY_IDLE)) return 1; if (GNUNET_OK != - GNUNET_OS_set_process_priority (getpid (), + GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), GNUNET_SCHEDULER_PRIORITY_BACKGROUND)) return 1; if (GNUNET_OK != - GNUNET_OS_set_process_priority (getpid (), + GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), GNUNET_SCHEDULER_PRIORITY_HIGH)) return 1; if (GNUNET_OK != - GNUNET_OS_set_process_priority (getpid (), + GNUNET_OS_set_process_priority (GNUNET_OS_process_current (), GNUNET_SCHEDULER_PRIORITY_HIGH)) return 1; #ifndef MINGW diff --git a/src/util/test_os_start_process.c b/src/util/test_os_start_process.c index 0b8860c7d..bd2eb2b09 100644 --- a/src/util/test_os_start_process.c +++ b/src/util/test_os_start_process.c @@ -38,7 +38,7 @@ static char *test_phrase = "HELLO WORLD"; static int ok; -static pid_t pid; +static GNUNET_OS_Process *proc; /* Pipe to write to started processes stdin (on write end) */ static struct GNUNET_DISK_PipeHandle *hello_pipe_stdin; /* Pipe to read from started processes stdout (on read end) */ @@ -50,11 +50,13 @@ static void end_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - if (0 != PLIBC_KILL (pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } - GNUNET_OS_process_wait (pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; GNUNET_DISK_pipe_close(hello_pipe_stdout); GNUNET_DISK_pipe_close(hello_pipe_stdin); } @@ -119,7 +121,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) return; } - pid = GNUNET_OS_start_process (hello_pipe_stdin, hello_pipe_stdout, fn, + proc = GNUNET_OS_start_process (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 2c3f95367..7321ed587 100644 --- a/src/util/test_resolver_api.c +++ b/src/util/test_resolver_api.c @@ -360,7 +360,7 @@ check() int ok = 1 + 2 + 4 + 8; char *fn; char *pfx; - pid_t pid; + GNUNET_OS_Process *proc; char * const argv[] = { "test-resolver-api", "-c", "test_resolver_api_data.conf", #if VERBOSE @@ -372,7 +372,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); - pid = GNUNET_OS_start_process(NULL, NULL, fn, "gnunet-service-resolver", + proc = GNUNET_OS_start_process(NULL, NULL, fn, "gnunet-service-resolver", #if VERBOSE "-L", "DEBUG", #endif @@ -380,12 +380,14 @@ check() GNUNET_free(fn); GNUNET_assert(GNUNET_OK == GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv, "test-resolver-api", "nohelp", options, &run, &ok)); - if (0 != PLIBC_KILL(pid, SIGTERM)) + if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } - GNUNET_OS_process_wait(pid); + GNUNET_OS_process_wait (proc); + GNUNET_OS_process_close (proc); + proc = NULL; if (ok != 0) fprintf(stderr, "Missed some resolutions: %u\n", ok); return ok; diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index f231ed782..a6f78d707 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -94,7 +94,7 @@ static unsigned char restart_hijack; /** * The process id of the helper */ -static pid_t helper_pid; +static GNUNET_OS_Process *helper_proc; /** * a list of outgoing dns-query-packets @@ -177,8 +177,10 @@ cleanup(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { GNUNET_assert (0 != (tskctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)); /* stop the helper */ - PLIBC_KILL(helper_pid, SIGTERM); - GNUNET_OS_process_wait(helper_pid); + GNUNET_OS_process_kill (helper_proc, SIGTERM); + GNUNET_OS_process_wait (helper_proc); + GNUNET_OS_process_close (helper_proc); + helper_proc = NULL; /* close the connection to the service-dns */ if (dns_connection != NULL) @@ -202,7 +204,7 @@ start_helper_and_schedule(void *cls, if (helper_in == NULL || helper_out == NULL) return; - helper_pid = GNUNET_OS_start_process(helper_in, helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); + helper_proc = GNUNET_OS_start_process(helper_in, helper_out, "gnunet-helper-vpn", "gnunet-helper-vpn", NULL); fh_from_helper = GNUNET_DISK_pipe_handle (helper_out, GNUNET_DISK_PIPE_END_READ); fh_to_helper = GNUNET_DISK_pipe_handle (helper_in, GNUNET_DISK_PIPE_END_WRITE); @@ -219,8 +221,10 @@ start_helper_and_schedule(void *cls, static void restart_helper(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tskctx) { // Kill the helper - PLIBC_KILL(helper_pid, SIGKILL); - GNUNET_OS_process_wait(helper_pid); + GNUNET_OS_process_kill (helper_proc, SIGKILL); + GNUNET_OS_process_wait (helper_proc); + GNUNET_OS_process_close (helper_proc); + helper_proc = NULL; /* Tell the dns-service to rehijack the dns-port * The routing-table gets flushed if an interface disappears. diff --git a/src/vpn/gnunet-service-dns.c b/src/vpn/gnunet-service-dns.c index 6c95c7789..8dda2fffa 100644 --- a/src/vpn/gnunet-service-dns.c +++ b/src/vpn/gnunet-service-dns.c @@ -112,12 +112,12 @@ hijack(unsigned short port) { GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Hijacking, port is %d\n", port); snprintf(port_s, 6, "%d", port); - GNUNET_OS_start_process(NULL, + GNUNET_OS_process_close (GNUNET_OS_start_process(NULL, NULL, "gnunet-helper-hijack-dns", "gnunet-hijack-dns", port_s, - NULL); + NULL)); } /** -- 2.25.1