*/
#define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+/**
+ * Timeout for listing all running services.
+ */
+#define LIST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
+
/**
* Set if we are to shutdown all services (including ARM).
*/
*/
static int quiet;
+/**
+ * Set if we should print a list of currently running services.
+ */
+static int list;
+
/**
* Set to the name of a service to start.
*/
switch (result)
{
case GNUNET_ARM_PROCESS_UNKNOWN:
- fprintf (stderr, _("Service `%s' is unknown to ARM.\n"), service);
+ FPRINTF (stderr, _("Service `%s' is unknown to ARM.\n"), service);
ret = 1;
break;
case GNUNET_ARM_PROCESS_DOWN:
if (quiet != GNUNET_YES)
- fprintf (stdout, _("Service `%s' has been stopped.\n"), service);
+ FPRINTF (stdout, _("Service `%s' has been stopped.\n"), service);
break;
case GNUNET_ARM_PROCESS_ALREADY_RUNNING:
- fprintf (stderr, _("Service `%s' was already running.\n"), service);
+ FPRINTF (stderr, _("Service `%s' was already running.\n"), service);
ret = 1;
break;
case GNUNET_ARM_PROCESS_STARTING:
if (quiet != GNUNET_YES)
- fprintf (stdout, _("Service `%s' has been started.\n"), service);
+ FPRINTF (stdout, _("Service `%s' has been started.\n"), service);
break;
case GNUNET_ARM_PROCESS_ALREADY_STOPPING:
- fprintf (stderr, _("Service `%s' was already being stopped.\n"), service);
+ FPRINTF (stderr, _("Service `%s' was already being stopped.\n"), service);
ret = 1;
break;
case GNUNET_ARM_PROCESS_ALREADY_DOWN:
- fprintf (stderr, _("Service `%s' was already not running.\n"), service);
+ FPRINTF (stderr, _("Service `%s' was already not running.\n"), service);
ret = 1;
break;
case GNUNET_ARM_PROCESS_SHUTDOWN:
- fprintf (stderr, _("Request ignored as ARM is shutting down.\n"));
+ FPRINTF (stderr, "%s", _("Request ignored as ARM is shutting down.\n"));
ret = 1;
break;
case GNUNET_ARM_PROCESS_COMMUNICATION_ERROR:
- fprintf (stderr, _("Error communicating with ARM service.\n"));
+ FPRINTF (stderr, "%s", _("Error communicating with ARM service.\n"));
ret = 1;
break;
case GNUNET_ARM_PROCESS_COMMUNICATION_TIMEOUT:
- fprintf (stderr, _("Timeout communicating with ARM service.\n"));
+ FPRINTF (stderr, "%s", _("Timeout communicating with ARM service.\n"));
ret = 1;
break;
case GNUNET_ARM_PROCESS_FAILURE:
- fprintf (stderr, _("Operation failed.\n"));
+ FPRINTF (stderr, "%s", _("Operation failed.\n"));
ret = 1;
break;
default:
- fprintf (stderr, _("Unknown response code from ARM.\n"));
+ FPRINTF (stderr, "%s", _("Unknown response code from ARM.\n"));
break;
}
GNUNET_SCHEDULER_add_continuation (&cps_loop, NULL,
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.
+ *
+ * @param cls currently not used
+ * @param result result of the operation
+ * @param count number of running services
+ * @param list copy of the list of running services
+ */
+static void
+list_cb (void *cls, int result, unsigned int count, const char *const*list)
+{
+ unsigned int i;
+
+ if ( (result != GNUNET_YES) || (NULL == list) )
+ {
+ FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not running?\n"));
+ return;
+ }
+ FPRINTF (stdout, "%s", _("Running services:\n"));
+ for (i=0; i<count; i++)
+ FPRINTF (stdout, "%s\n", list[i]);
+}
/**
* Main function that will be run by the scheduler.
start = 1;
restart = 0;
h = GNUNET_ARM_connect (cfg, NULL);
- if (h == NULL)
+ if (NULL == h)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Fatal error initializing ARM API.\n"));
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);
{'T', "timeout", NULL,
gettext_noop ("timeout for completing current operation"),
GNUNET_YES, &GNUNET_GETOPT_set_ulong, &temp_timeout_ms},
+ {'I', "info", NULL, gettext_noop ("List currently running services"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &list},
GNUNET_GETOPT_OPTION_END
};