From 9827cc8e21bef6d8e06ba6924dfc8114622647ba Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 15 Jun 2009 02:44:19 +0000 Subject: better support for daemons --- src/arm/arm_api.c | 3 +++ src/arm/gnunet-service-arm.c | 20 ++++++++++++++++---- src/include/gnunet_arm_service.h | 3 ++- src/include/gnunet_protocols.h | 7 ++++++- 4 files changed, 27 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index c5bb15fd3..7f120e6a6 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -129,6 +129,9 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) case GNUNET_MESSAGE_TYPE_ARM_IS_DOWN: ret = GNUNET_NO; break; + case GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN: + ret = GNUNET_SYSERR; + break; default: GNUNET_break (0); ret = GNUNET_SYSERR; diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 66df86e45..1953bffeb 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -412,6 +412,7 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename) { struct ServiceList *pos; struct GNUNET_CLIENT_Connection *sc; + unsigned long long port; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preparing to stop `%s'\n", servicename); @@ -444,10 +445,21 @@ stop_service (struct GNUNET_SERVER_Client *client, const char *servicename) } else { - sc = GNUNET_CLIENT_connect (sched, servicename, cfg); - GNUNET_CLIENT_service_shutdown (sc); - GNUNET_CLIENT_disconnect (sc); - signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); + if ( (GNUNET_OK == + GNUNET_CONFIGURATION_get_value_number (cfg, + servicename, + "PORT", + &port)) && + (NULL != (sc = GNUNET_CLIENT_connect (sched, servicename, cfg))) ) + { + GNUNET_CLIENT_service_shutdown (sc); + GNUNET_CLIENT_disconnect (sc); + signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); + } + else + { + signal_result (client, servicename, GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN); + } GNUNET_SERVER_receive_done (client, GNUNET_OK); } } diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h index 012c27877..5a929a37e 100644 --- a/src/include/gnunet_arm_service.h +++ b/src/include/gnunet_arm_service.h @@ -51,7 +51,8 @@ extern "C" * @param cls closure * @param success GNUNET_YES if we think the service is running * GNUNET_NO if we think the service is stopped - * GNUNET_SYSERR if we think ARM was not running + * GNUNET_SYSERR if we think ARM was not running or + * if the service status is unknown */ typedef void (*GNUNET_ARM_Callback) (void *cls, int success); diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index c86ad83ce..342014ae1 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -95,10 +95,15 @@ extern "C" /** * Response from ARM: service is now down. - * (failed to start it). + * (failed to start it or shut it down). */ #define GNUNET_MESSAGE_TYPE_ARM_IS_DOWN 11 +/** + * Response from ARM: service status is unknown. + */ +#define GNUNET_MESSAGE_TYPE_ARM_IS_UNKNOWN 12 + /** * HELLO message used for communicating peer addresses. -- cgit v1.2.3