- doc clarification (identity manages egos, not identities)
[oweals/gnunet.git] / src / arm / gnunet-arm.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009, 2012, 2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file arm/gnunet-arm.c
23  * @brief arm for writing a tool
24  * @author Christian Grothoff
25  */
26 #include "platform.h"
27 #include "gnunet_arm_service.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_util_lib.h"
30
31 /**
32  * Timeout for stopping services.  Long to give some services a real chance.
33  */
34 #define STOP_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
35
36 /**
37  * Timeout for stopping ARM.  Extra-long since ARM needs to stop everyone else.
38  */
39 #define STOP_TIMEOUT_ARM GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
40
41 /**
42  * Timeout for starting services, very short because of the strange way start works
43  * (by checking if running before starting, so really this time is always waited on
44  * startup (annoying)).
45  */
46 #define START_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
47
48 /**
49  * Timeout for listing all running services.
50  */
51 #define LIST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2)
52
53 /**
54  * Set if we are to shutdown all services (including ARM).
55  */
56 static int end;
57
58 /**
59  * Set if we are to start default services (including ARM).
60  */
61 static int start;
62
63 /**
64  * Set if we are to stop/start default services (including ARM).
65  */
66 static int restart;
67
68 /**
69  * Set if we should delete configuration and temp directory on exit.
70  */
71 static int delete;
72
73 /**
74  * Set if we should not print status messages.
75  */
76 static int quiet;
77
78 /**
79  * Monitor ARM activity.
80  */
81 static int monitor;
82
83 /**
84  * Set if we should print a list of currently running services.
85  */
86 static int list;
87
88 /**
89  * Set to the name of a service to start.
90  */
91 static char *init;
92
93 /**
94  * Set to the name of a service to kill.
95  */
96 static char *term;
97
98 /**
99  * Set to the name of the config file used.
100  */
101 static const char *config_file;
102
103 /**
104  * Set to the directory where runtime files are stored.
105  */
106 static char *dir;
107
108 /**
109  * Final status code.
110  */
111 static int ret;
112
113 /**
114  * Connection with ARM.
115  */
116 static struct GNUNET_ARM_Handle *h;
117
118 /**
119  * Monitor connection with ARM.
120  */
121 static struct GNUNET_ARM_MonitorHandle *m;
122
123 /**
124  * Our configuration.
125  */
126 static struct GNUNET_CONFIGURATION_Handle *cfg;
127
128 /**
129  * Processing stage that we are in.  Simple counter.
130  */
131 static unsigned int phase;
132
133 /**
134  * User defined timestamp for completing operations.
135  */
136 static struct GNUNET_TIME_Relative timeout;
137
138 /**
139  * Do we want to give our stdout to gnunet-service-arm?
140  */
141 static unsigned int no_stdout;
142
143 /**
144  * Do we want to give our stderr to gnunet-service-arm?
145  */
146 static unsigned int no_stderr;
147
148
149 /**
150  * Attempts to delete configuration file and GNUNET_HOME
151  * on ARM shutdown provided the end and delete options
152  * were specified when gnunet-arm was run.
153  */
154 static void
155 delete_files ()
156 {
157   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158               "Will attempt to remove configuration file %s and service directory %s\n",
159               config_file, dir);
160
161   if (0 != UNLINK (config_file))
162   {
163     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
164                 _("Failed to remove configuration file %s\n"),
165                 config_file);
166   }
167   if (GNUNET_OK != GNUNET_DISK_directory_remove (dir))
168   {
169     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
170                 _("Failed to remove servicehome directory %s\n"),
171                 dir);
172
173   }
174 }
175
176
177 /**
178  * Main continuation-passing-style loop.  Runs the various
179  * jobs that we've been asked to do in order.
180  *
181  * @param cls closure, unused
182  * @param tc context, unused
183  */
184 static void
185 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
186 {
187   if (NULL != h)
188   {
189     GNUNET_ARM_disconnect_and_free (h);
190     h = NULL;
191   }
192   if (NULL != m)
193   {
194     GNUNET_ARM_monitor_disconnect_and_free (m);
195     m = NULL;
196   }
197   if ((GNUNET_YES == end) && (GNUNET_YES == delete))
198     delete_files ();
199   GNUNET_CONFIGURATION_destroy (cfg);
200   cfg = NULL;
201 }
202
203
204 /**
205  * Returns a string interpretation of 'rs'
206  *
207  * @param rs the request status from ARM
208  * @return a string interpretation of the request status
209  */
210 static const char *
211 req_string (enum GNUNET_ARM_RequestStatus rs)
212 {
213   switch (rs)
214   {
215   case GNUNET_ARM_REQUEST_SENT_OK:
216     return _("Message was sent successfully");
217   case GNUNET_ARM_REQUEST_CONFIGURATION_ERROR:
218     return _("Misconfiguration (can not connect to the ARM service)");
219   case GNUNET_ARM_REQUEST_DISCONNECTED:
220     return _("We disconnected from ARM before we could send a request");
221   case GNUNET_ARM_REQUEST_BUSY:
222     return _("ARM API is busy");
223   case GNUNET_ARM_REQUEST_TOO_LONG:
224     return _("Request does not fit into a message");
225   case GNUNET_ARM_REQUEST_TIMEOUT:
226     return _("Request timed out");
227   }
228   return _("Unknown request status");
229 }
230
231
232 /**
233  * Returns a string interpretation of the 'result'
234  *
235  * @param result the arm result
236  * @return a string interpretation
237  */
238 static const char *
239 ret_string (enum GNUNET_ARM_Result result)
240 {
241   switch (result)
242   {
243   case GNUNET_ARM_RESULT_STOPPED:
244     return _("%s is stopped");
245   case GNUNET_ARM_RESULT_STARTING:
246     return _("%s is starting");
247   case GNUNET_ARM_RESULT_STOPPING:
248     return _("%s is stopping");
249   case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
250     return _("%s is starting already");
251   case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
252     return _("%s is stopping already");
253   case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
254     return _("%s is started already");
255   case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
256     return _("%s is stopped already");
257   case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
258     return _("%s service is not known to ARM");
259   case GNUNET_ARM_RESULT_START_FAILED:
260     return _("%s service failed to start");
261   case GNUNET_ARM_RESULT_IN_SHUTDOWN:
262     return _("%s service cannot be started because ARM is shutting down");
263   }
264   return _("%.s Unknown result code.");
265 }
266
267
268 /**
269  * Main task that runs our various operations in order.
270  *
271  * @param cls closure
272  * @param tc scheudler context
273  */
274 static void
275 action_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
276
277
278 /**
279  * Function called whenever we connect to or disconnect from ARM.
280  * Termiantes the process if we fail to connect to the service on
281  * our first attempt.
282  *
283  * @param cls closure
284  * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
285  *                  GNUNET_SYSERR on error.
286  */
287 static void
288 conn_status (void *cls,
289              int connected)
290 {
291   static int once;
292
293   if ( (GNUNET_SYSERR == connected) &&
294        (0 == once) )
295   {
296     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
297                 _("Fatal error initializing ARM API.\n"));
298     GNUNET_SCHEDULER_shutdown ();
299     return;
300   }
301   once = 1;
302 }
303
304
305 /**
306  * We have requested ARM to be started, this function
307  * is called with the result of the operation.  Informs the
308  * use of the result; on success, we continue with the event
309  * loop, on failure we terminate the process.
310  *
311  * @param cls closure unused
312  * @param rs what happened to our request
313  * @param service name of the service we tried to start ("arm")
314  * @param result if the request was processed, this is the result
315  *               according to ARM
316  */
317 static void
318 start_callback (void *cls,
319                 enum GNUNET_ARM_RequestStatus rs, const char *service,
320                 enum GNUNET_ARM_Result result)
321 {
322   char *msg;
323
324   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
325   {
326     GNUNET_asprintf (&msg, "%s", _("Failed to start the ARM service: %s\n"));
327     FPRINTF (stdout, msg, req_string (rs));
328     GNUNET_free (msg);
329     GNUNET_SCHEDULER_shutdown ();
330     return;
331   }
332   if ( (GNUNET_ARM_RESULT_STARTING != result) &&
333        (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result) )
334   {
335     GNUNET_asprintf (&msg, "%s", _("Failed to start the ARM service: %s\n"));
336     FPRINTF (stdout, msg, ret_string (result));
337     GNUNET_free (msg);
338     GNUNET_SCHEDULER_shutdown ();
339     return;
340   }
341   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
342   start = 0;
343   GNUNET_SCHEDULER_add_now (action_loop, NULL);
344 }
345
346
347 /**
348  * We have requested ARM to be stopped, this function
349  * is called with the result of the operation.  Informs the
350  * use of the result; on success, we continue with the event
351  * loop, on failure we terminate the process.
352  *
353  * @param cls closure unused
354  * @param rs what happened to our request
355  * @param service name of the service we tried to start ("arm")
356  * @param result if the request was processed, this is the result
357  *               according to ARM
358  */
359 static void
360 stop_callback (void *cls,
361                enum GNUNET_ARM_RequestStatus rs, const char *service,
362                enum GNUNET_ARM_Result result)
363 {
364   char *msg;
365
366   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
367   {
368     GNUNET_asprintf (&msg, "%s",
369                      _("Failed to send a stop request to the ARM service: %s\n"));
370     FPRINTF (stdout, msg, req_string (rs));
371     GNUNET_free (msg);
372     GNUNET_SCHEDULER_shutdown ();
373     return;
374   }
375   if ((GNUNET_ARM_RESULT_STOPPING != result) &&
376       (GNUNET_ARM_RESULT_STOPPED != result) &&
377       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
378   {
379     GNUNET_asprintf (&msg, "%s", _("Failed to stop the ARM service: %s\n"));
380     FPRINTF (stdout, msg, ret_string (result));
381     GNUNET_free (msg);
382     GNUNET_SCHEDULER_shutdown ();
383     return;
384   }
385   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386               "ARM service shutdown successful\n");
387   end = 0;
388   if (restart)
389   {
390     restart = 0;
391     start = 1;
392     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393                 "Initiating an ARM restart\n");
394   }
395   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
396 }
397
398
399 /**
400  * We have requested a service to be started, this function
401  * is called with the result of the operation.  Informs the
402  * use of the result; on success, we continue with the event
403  * loop, on failure we terminate the process.
404  *
405  * @param cls closure unused
406  * @param rs what happened to our request
407  * @param service name of the service we tried to start
408  * @param result if the request was processed, this is the result
409  *               according to ARM
410  */
411 static void
412 init_callback (void *cls,
413                enum GNUNET_ARM_RequestStatus rs, const char *service,
414                enum GNUNET_ARM_Result result)
415 {
416   char *msg;
417
418   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
419   {
420     GNUNET_asprintf (&msg, _("Failed to send a request to start the `%s' service: %%s\n"), init);
421     FPRINTF (stdout, msg, req_string (rs));
422     GNUNET_free (msg);
423     GNUNET_SCHEDULER_shutdown ();
424     return;
425   }
426   if ((GNUNET_ARM_RESULT_STARTING != result) &&
427       (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
428   {
429     GNUNET_asprintf (&msg, _("Failed to start the `%s' service: %s\n"),
430                      init, ret_string (result));
431     FPRINTF (stdout, msg, service);
432     GNUNET_free (msg);
433     GNUNET_SCHEDULER_shutdown ();
434     return;
435   }
436   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437               "Service %s [re]started successfully\n",
438               init);
439   init = NULL;
440   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
441 }
442
443
444 /**
445  * We have requested a service to be stopped, this function
446  * is called with the result of the operation.  Informs the
447  * use of the result; on success, we continue with the event
448  * loop, on failure we terminate the process.
449  *
450  * @param cls closure unused
451  * @param rs what happened to our request
452  * @param service name of the service we tried to start
453  * @param result if the request was processed, this is the result
454  *               according to ARM
455  */
456 static void
457 term_callback (void *cls,
458                enum GNUNET_ARM_RequestStatus rs, const char *service,
459                enum GNUNET_ARM_Result result)
460 {
461   char *msg;
462   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
463   {
464     GNUNET_asprintf (&msg,
465                      _("Failed to send a request to kill the `%s' service: %%s\n"),
466                      term);
467     FPRINTF (stdout, msg, req_string (rs));
468     GNUNET_free (msg);
469     GNUNET_SCHEDULER_shutdown ();
470     return;
471   }
472   if ((GNUNET_ARM_RESULT_STOPPED != result) &&
473       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
474   {
475     GNUNET_asprintf (&msg,
476                      _("Failed to kill the `%s' service: %s\n"),
477                      term, ret_string (result));
478     FPRINTF (stdout, msg, service);
479     GNUNET_free (msg);
480     GNUNET_SCHEDULER_shutdown ();
481     return;
482   }
483
484   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485               "Service %s stopped successfully\n", term);
486   term = NULL;
487   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
488 }
489
490
491 /**
492  * Function called with the list of running services. Prints
493  * the list to stdout, then starts the event loop again.
494  * Prints an error message and terminates the process on errors.
495  *
496  * @param cls closure (unused)
497  * @param rs request status (success, failure, etc.)
498  * @param count number of services in the list
499  * @param list list of services that are running
500  */
501 static void
502 list_callback (void *cls,
503                enum GNUNET_ARM_RequestStatus rs, unsigned int count,
504                const char *const*list)
505 {
506   unsigned int i;
507
508   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
509   {
510     char *msg;
511
512     GNUNET_asprintf (&msg, "%s", _("Failed to request a list of services: %s\n"));
513     FPRINTF (stdout, msg, req_string (rs));
514     GNUNET_free (msg);
515     GNUNET_SCHEDULER_shutdown ();
516   }
517   if (NULL == list)
518   {
519     FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not running?\n"));
520     GNUNET_SCHEDULER_shutdown ();
521     return;
522   }
523   FPRINTF (stdout, "%s", _("Running services:\n"));
524   for (i = 0; i < count; i++)
525     FPRINTF (stdout, "%s\n", list[i]);
526   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
527 }
528
529
530 /**
531  * Main action loop.  Runs the various jobs that we've been asked to
532  * do, in order.
533  *
534  * @param cls closure, unused
535  * @param tc context, unused
536  */
537 static void
538 action_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
539 {
540   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
541     return;
542   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
543   while (1)
544   {
545     switch (phase++)
546     {
547     case 0:
548       if (NULL != term)
549       {
550         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
551         GNUNET_ARM_request_service_stop (h, term,
552                                          (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
553                                          &term_callback, NULL);
554         return;
555       }
556       break;
557     case 1:
558       if (end || restart)
559       {
560         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n");
561         GNUNET_ARM_request_service_stop (h, "arm",
562                                          (0 == timeout.rel_value_us) ? STOP_TIMEOUT_ARM : timeout,
563                                          &stop_callback, NULL);
564         return;
565       }
566       break;
567     case 2:
568       if (start)
569       {
570         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
571         GNUNET_ARM_request_service_start (h, "arm",
572             (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
573             (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
574             (0 == timeout.rel_value_us) ? START_TIMEOUT: timeout,
575             start_callback, NULL);
576         return;
577       }
578       break;
579     case 3:
580       if (NULL != init)
581       {
582         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
583         GNUNET_ARM_request_service_start (h, init, GNUNET_OS_INHERIT_STD_NONE,
584                                           (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
585                                           &init_callback, NULL);
586         return;
587       }
588       break;
589     case 4:
590       if (list)
591       {
592         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
593                     "Going to list all running services controlled by ARM.\n");
594         GNUNET_ARM_request_service_list (h,
595                                          (0 == timeout.rel_value_us) ? LIST_TIMEOUT : timeout,
596                                          &list_callback, &list);
597         return;
598       }
599       break;
600     case 5:
601       if (monitor)
602         {
603           if (! quiet)
604             fprintf (stderr,
605                      _("Now only monitoring, press CTRL-C to stop.\n"));
606           quiet = 0; /* does not make sense to stay quiet in monitor mode at this time */
607           return; /* done with tasks, just monitor */
608         }
609       break;
610     default:            /* last phase */
611       GNUNET_SCHEDULER_shutdown ();
612       return;
613     }
614   }
615 }
616
617
618 /**
619  * Function called when a service starts or stops.
620  *
621  * @param cls closure
622  * @param service service name
623  * @param status status of the service
624  */
625 static void
626 srv_status (void *cls,
627             const char *service, enum GNUNET_ARM_ServiceStatus status)
628 {
629   const char *msg;
630
631   switch (status)
632   {
633   case GNUNET_ARM_SERVICE_MONITORING_STARTED:
634     return; /* this should be done silently */
635   case GNUNET_ARM_SERVICE_STOPPED:
636     msg = _("Stopped %s.\n");
637     break;
638   case GNUNET_ARM_SERVICE_STARTING:
639     msg = _("Starting %s...\n");
640     break;
641   case GNUNET_ARM_SERVICE_STOPPING:
642     msg = _("Stopping %s...\n");
643     break;
644   default:
645     msg = NULL;
646     break;
647   }
648   if (! quiet)
649     {
650       if (NULL != msg)
651         FPRINTF (stderr, msg, service);
652       else
653         FPRINTF (stderr, _("Unknown status %u for service %s.\n"), status, service);
654     }
655   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got service %s status %d\n", service, (int) status);
656 }
657
658
659 /**
660  * Main function that will be run by the scheduler.
661  *
662  * @param cls closure
663  * @param args remaining command-line arguments
664  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
665  * @param c configuration
666  */
667 static void
668 run (void *cls,
669      char *const *args,
670      const char *cfgfile,
671      const struct GNUNET_CONFIGURATION_Handle *c)
672 {
673   char *armconfig;
674
675   cfg = GNUNET_CONFIGURATION_dup (c);
676   config_file = cfgfile;
677   if (GNUNET_OK !=
678       GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "GNUNET_HOME", &dir))
679   {
680     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
681                                "PATHS", "GNUNET_HOME");
682     return;
683   }
684   if (NULL != cfgfile)
685   {
686     if (GNUNET_OK !=
687         GNUNET_CONFIGURATION_get_value_filename (cfg, "arm", "CONFIG",
688                                                  &armconfig))
689     {
690       GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
691                                              cfgfile);
692     }
693     else
694       GNUNET_free (armconfig);
695   }
696   if (NULL == (h = GNUNET_ARM_connect (cfg, &conn_status, NULL)))
697     return;
698   if (monitor)
699     m = GNUNET_ARM_monitor (cfg, &srv_status, NULL);
700   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
701   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
702                                 &shutdown_task, NULL);
703 }
704
705
706 /**
707  * The main function to obtain arm from gnunetd.
708  *
709  * @param argc number of arguments from the command line
710  * @param argv command line arguments
711  * @return 0 ok, 1 on error
712  */
713 int
714 main (int argc, char *const *argv)
715 {
716   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
717     {'e', "end", NULL, gettext_noop ("stop all GNUnet services"),
718      GNUNET_NO, &GNUNET_GETOPT_set_one, &end},
719     {'i', "init", "SERVICE", gettext_noop ("start a particular service"),
720      GNUNET_YES, &GNUNET_GETOPT_set_string, &init},
721     {'k', "kill", "SERVICE", gettext_noop ("stop a particular service"),
722      GNUNET_YES, &GNUNET_GETOPT_set_string, &term},
723     {'s', "start", NULL, gettext_noop ("start all GNUnet default services"),
724      GNUNET_NO, &GNUNET_GETOPT_set_one, &start},
725     {'r', "restart", NULL,
726      gettext_noop ("stop and start all GNUnet default services"),
727      GNUNET_NO, &GNUNET_GETOPT_set_one, &restart},
728     {'d', "delete", NULL,
729      gettext_noop ("delete config file and directory on exit"),
730      GNUNET_NO, &GNUNET_GETOPT_set_one, &delete},
731     {'m', "monitor", NULL,
732      gettext_noop ("monitor ARM activities"),
733      GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor},
734     {'q', "quiet", NULL, gettext_noop ("don't print status messages"),
735      GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet},
736     {'T', "timeout", "MSECS",
737      gettext_noop ("timeout in MSECS milliseconds for completing current operation"),
738      GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout},
739     {'I', "info", NULL, gettext_noop ("list currently running services"),
740      GNUNET_NO, &GNUNET_GETOPT_set_one, &list},
741     {'O', "no-stdout", NULL, gettext_noop ("don't let gnunet-service-arm inherit standard output"),
742      GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stdout},
743     {'E', "no-stderr", NULL, gettext_noop ("don't let gnunet-service-arm inherit standard error"),
744      GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stderr},
745     GNUNET_GETOPT_OPTION_END
746   };
747
748   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
749     return 2;
750
751   if (GNUNET_OK ==
752       GNUNET_PROGRAM_run (argc, argv, "gnunet-arm",
753                           gettext_noop
754                           ("Control services and the Automated Restart Manager (ARM)"),
755                           options, &run, NULL))
756     {
757       GNUNET_free ((void *) argv);
758       return ret;
759     }
760   GNUNET_free ((void*) argv);
761   return 1;
762 }
763
764 /* end of gnunet-arm.c */