diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-27 19:01:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-27 19:01:04 +0000 |
commit | 383eec1895fff4a83f26bb8244d86571dd5baef9 (patch) | |
tree | dc6eccf68932c71785ee86d688ebebeda2ac4025 /src/arm | |
parent | 195267a6ac380d106d9409aa296885251d102c8e (diff) |
reducing error messages about missing configuration options by introducing new helper functions to print them uniformly
Diffstat (limited to 'src/arm')
-rw-r--r-- | src/arm/arm_api.c | 54 | ||||
-rw-r--r-- | src/arm/gnunet-arm.c | 208 | ||||
-rw-r--r-- | src/arm/gnunet-service-arm.c | 11 |
3 files changed, 129 insertions, 144 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c index a598a5fead..7c18c617e4 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c @@ -349,10 +349,8 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "BINARY", &binary)) { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Configuration failes to specify option `%s' in section `%s'!\n"), - "BINARY", "arm"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, + "arm", "BINARY"); if (pos->callback != NULL) pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN); GNUNET_free (pos); @@ -364,9 +362,8 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, "arm", "CONFIG", &config)) { - LOG (GNUNET_ERROR_TYPE_WARNING, - _("Configuration fails to specify option `%s' in section `%s'!\n"), - "CONFIG", "arm"); + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, + "arm", "CONFIG"); if (pos->callback != NULL) pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN); GNUNET_free (binary); @@ -432,11 +429,7 @@ handle_response (void *cls, const struct GNUNET_MessageHeader *msg) if ((msg == NULL) || (ntohs (msg->size) != sizeof (struct GNUNET_ARM_ResultMessage))) { - LOG (GNUNET_ERROR_TYPE_WARNING, - _ - ("Error receiving response to `%s' request from ARM for service `%s'\n"), - (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP", - (const char *) &sc[1]); + GNUNET_break (0); GNUNET_CLIENT_disconnect (sc->h->client); sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg); GNUNET_assert (NULL != sc->h->client); @@ -487,8 +480,8 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name, LOG (GNUNET_ERROR_TYPE_DEBUG, (type == GNUNET_MESSAGE_TYPE_ARM_START) ? - _("Requesting start of service `%s'.\n") : - _("Requesting termination of service `%s'.\n"), service_name); + "Requesting start of service `%s'.\n" : + "Requesting termination of service `%s'.\n", service_name); sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen); sctx->h = h; sctx->callback = cb; @@ -506,12 +499,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name, (sctx->timeout), GNUNET_YES, &handle_response, sctx)) { - LOG (GNUNET_ERROR_TYPE_WARNING, - (type == - GNUNET_MESSAGE_TYPE_ARM_START) - ? _("Error while trying to transmit request to start `%s' to ARM\n") - : _("Error while trying to transmit request to stop `%s' to ARM\n"), - (const char *) &service_name); + GNUNET_break (0); if (cb != NULL) cb (cb_cls, GNUNET_SYSERR); GNUNET_free (sctx); @@ -544,8 +532,8 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h, size_t slen; LOG (GNUNET_ERROR_TYPE_DEBUG, - _("Asked to start service `%s' within %llu ms\n"), service_name, - (unsigned long long) timeout.rel_value); + "Asked to start service `%s' within %s\n", service_name, + GNUNET_STRINGS_relative_time_to_string (timeout)); if (0 == strcasecmp ("arm", service_name)) { slen = strlen ("arm") + 1; @@ -594,7 +582,6 @@ arm_shutdown_callback (void *cls, enum GNUNET_ARM_ProcessStatus reason) if (arm_shutdown_ctx->cb != NULL) arm_shutdown_ctx->cb (arm_shutdown_ctx->cb_cls, reason); - GNUNET_free (arm_shutdown_ctx); } @@ -617,8 +604,10 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h, struct ARM_ShutdownContext *arm_shutdown_ctx; struct GNUNET_CLIENT_Connection *client; - LOG (GNUNET_ERROR_TYPE_INFO, _("Stopping service `%s' within %llu ms\n"), - service_name, (unsigned long long) timeout.rel_value); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Stopping service `%s' within %s\n", + service_name, + GNUNET_STRINGS_relative_time_to_string (timeout)); if (h->client == NULL) { client = GNUNET_CLIENT_connect ("arm", h->cfg); @@ -690,8 +679,7 @@ handle_list_response (void *cls, const struct GNUNET_MessageHeader *msg) if (NULL == msg) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Error receiving response to LIST request from ARM\n"); + GNUNET_break (0); GNUNET_CLIENT_disconnect (sc->h->client); sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg); GNUNET_assert (NULL != sc->h->client); @@ -766,13 +754,10 @@ GNUNET_ARM_list_running_services (struct GNUNET_ARM_Handle *h, client = GNUNET_CLIENT_connect ("arm", h->cfg); if (client == NULL) { - LOG (GNUNET_ERROR_TYPE_DEBUG, - "arm_api, GNUNET_CLIENT_connect returned NULL\n"); + GNUNET_break (0); cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR, 0, NULL); return; } - LOG (GNUNET_ERROR_TYPE_DEBUG, - "arm_api, GNUNET_CLIENT_connect returned non-NULL\n"); h->client = client; } @@ -785,8 +770,8 @@ GNUNET_ARM_list_running_services (struct GNUNET_ARM_Handle *h, msg.type = htons (GNUNET_MESSAGE_TYPE_ARM_LIST); LOG (GNUNET_ERROR_TYPE_DEBUG, - "Requesting LIST from ARM service with timeout: %llu ms\n", - (unsigned long long)timeout.rel_value); + "Requesting LIST from ARM service with timeout: %s\n", + GNUNET_STRINGS_relative_time_to_string (timeout)); if (GNUNET_OK != GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, @@ -797,8 +782,7 @@ GNUNET_ARM_list_running_services (struct GNUNET_ARM_Handle *h, &handle_list_response, sctx)) { - LOG (GNUNET_ERROR_TYPE_WARNING, - "Error while trying to transmit request to list services to ARM\n"); + GNUNET_break (0); if (cb != NULL) cb (cb_cls, GNUNET_SYSERR, 0, NULL); GNUNET_free (sctx); diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c index d84de1c7ab..c155577d0e 100644 --- a/src/arm/gnunet-arm.c +++ b/src/arm/gnunet-arm.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2009 Christian Grothoff (and other contributing authors) + (C) 2009, 2012 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -125,7 +125,6 @@ static unsigned int phase; */ static struct GNUNET_TIME_Relative timeout; - /** * Do we want to give our stdout to gnunet-service-arm? */ @@ -136,6 +135,7 @@ static unsigned int no_stdout = 0; */ static unsigned int no_stderr = 0; + /** * Main continuation-passing-style loop. Runs the various * jobs that we've been asked to do in order. @@ -210,6 +210,7 @@ confirm_cb (void *cls, GNUNET_SCHEDULER_REASON_PREREQ_DONE); } + /** * Callback invoked with the list of running services. * Reports to the user and then runs the next phase in the FSM. @@ -234,6 +235,7 @@ list_cb (void *cls, int result, unsigned int count, const char *const*list) FPRINTF (stdout, "%s\n", list[i]); } + /** * Main function that will be run by the scheduler. * @@ -250,25 +252,23 @@ run (void *cls, char *const *args, const char *cfgfile, config_file = cfgfile; if (GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &dir) != GNUNET_OK) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ - ("Fatal configuration error: `%s' option in section `%s' missing.\n"), - "SERVICEHOME", "PATHS"); - return; - } - h = GNUNET_ARM_connect (cfg, NULL); - if (h == NULL) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Fatal error initializing ARM API.\n")); - ret = 1; - return; + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "PATHS", "SERVICEHOME"); + return; } + if (NULL == (h = GNUNET_ARM_connect (cfg, NULL))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Fatal error initializing ARM API.\n")); + ret = 1; + return; + } GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL, GNUNET_SCHEDULER_REASON_PREREQ_DONE); } + /** * Attempts to delete configuration file and SERVICEHOME * on arm shutdown provided the end and delete options @@ -295,6 +295,7 @@ delete_files () } } + /** * Main continuation-passing-style loop. Runs the various * jobs that we've been asked to do in order. @@ -306,99 +307,98 @@ static void cps_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { while (1) + { + switch (phase++) { - switch (phase++) + case 0: + if (NULL != term) + { + GNUNET_ARM_stop_service (h, term, + (0 == + timeout.rel_value) ? STOP_TIMEOUT : + timeout, &confirm_cb, term); + return; + } + break; + case 1: + if ((end) || (restart)) + { + GNUNET_ARM_stop_service (h, "arm", + (0 == + timeout.rel_value) ? STOP_TIMEOUT_ARM + : timeout, &confirm_cb, "arm"); + return; + } + break; + case 2: + if (start) + { + GNUNET_ARM_start_service (h, "arm", + (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | + (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), + (0 == + timeout.rel_value) ? START_TIMEOUT : + timeout, &confirm_cb, "arm"); + return; + } + break; + case 3: + if (NULL != init) + { + GNUNET_ARM_start_service (h, init, + (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | + (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), + (0 == + timeout.rel_value) ? START_TIMEOUT : + timeout, &confirm_cb, init); + return; + } + break; + case 4: + if (restart) + { + GNUNET_ARM_disconnect (h); + phase = 0; + end = 0; + start = 1; + restart = 0; + if (NULL == (h = GNUNET_ARM_connect (cfg, NULL))) { - case 0: - if (term != NULL) - { - GNUNET_ARM_stop_service (h, term, - (0 == - timeout.rel_value) ? STOP_TIMEOUT : - timeout, &confirm_cb, term); - return; - } - break; - case 1: - if ((end) || (restart)) - { - GNUNET_ARM_stop_service (h, "arm", - (0 == - timeout.rel_value) ? STOP_TIMEOUT_ARM - : timeout, &confirm_cb, "arm"); - return; - } - break; - case 2: - if (start) - { - GNUNET_ARM_start_service (h, "arm", - (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | - (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), - (0 == - timeout.rel_value) ? START_TIMEOUT : - timeout, &confirm_cb, "arm"); - return; - } - break; - case 3: - if (init != NULL) - { - GNUNET_ARM_start_service (h, init, - (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) | - (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR), - (0 == - timeout.rel_value) ? START_TIMEOUT : - timeout, &confirm_cb, init); - return; - } - break; - case 4: - if (restart) - { - GNUNET_ARM_disconnect (h); - phase = 0; - end = 0; - start = 1; - restart = 0; - h = GNUNET_ARM_connect (cfg, NULL); - if (NULL == h) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Fatal error initializing ARM API.\n")); - ret = 1; - return; - } - GNUNET_SCHEDULER_add_now (&cps_loop, NULL); - return; - } - break; - case 5: - if (list) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Going to list all running services controlled by ARM.\n"); - - if (NULL == h) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Fatal error initializing ARM API.\n")); - return; - } - - GNUNET_ARM_list_running_services (h, - (0 == - timeout.rel_value) ? LIST_TIMEOUT : - timeout, &list_cb, NULL); - return; - } - /* Fall through */ - default: /* last phase */ - GNUNET_ARM_disconnect (h); - if ((end == GNUNET_YES) && (delete == GNUNET_YES)) - delete_files (); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Fatal error initializing ARM API.\n")); + ret = 1; return; } + GNUNET_SCHEDULER_add_now (&cps_loop, NULL); + return; + } + break; + case 5: + if (list) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Going to list all running services controlled by ARM.\n"); + + if (NULL == h) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _("Fatal error initializing ARM API.\n")); + return; + } + GNUNET_ARM_list_running_services (h, + (0 == + timeout.rel_value) ? LIST_TIMEOUT : + timeout, &list_cb, NULL); + return; + } + /* Fall through */ + default: /* last phase */ + GNUNET_ARM_disconnect (h); + if ((end == GNUNET_YES) && (delete == GNUNET_YES)) + delete_files (); + return; } + } } diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 00dda263eb..dab38eaf37 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c @@ -1122,11 +1122,12 @@ setup_service (void *cls, const char *section) &config)) || (0 != STAT (config, &sbuf))) { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _ - ("Configuration file `%s' for service `%s' not valid: %s\n"), - config, section, - (config == NULL) ? _("option missing") : STRERROR (errno)); + if (NULL == config) + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, section, "CONFIG"); + else + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, + section, "CONFIG", + STRERROR (errno)); GNUNET_free (binary); GNUNET_free_non_null (config); return; |