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