-ensure external symbols have proper prefix for conversation service
[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 SERVICEHOME
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 (UNLINK (config_file) != 0)
162   {
163     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
164                 _("Failed to remove configuration file %s\n"), config_file);
165   }
166   if (GNUNET_DISK_directory_remove (dir) != GNUNET_OK)
167   {
168     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
169                 _("Failed to remove servicehome directory %s\n"), dir);
170     
171   }
172 }
173
174
175 /**
176  * Main continuation-passing-style loop.  Runs the various
177  * jobs that we've been asked to do in order.
178  *
179  * @param cls closure, unused
180  * @param tc context, unused
181  */
182 static void
183 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 {
185   if (NULL != h)
186   {
187     GNUNET_ARM_disconnect_and_free (h);
188     h = NULL;
189   }
190   if (NULL != m)
191   {
192     GNUNET_ARM_monitor_disconnect_and_free (m);
193     m = NULL;
194   }
195   if ((end == GNUNET_YES) && (delete == GNUNET_YES))
196     delete_files ();    
197   GNUNET_CONFIGURATION_destroy (cfg);
198   cfg = NULL;
199 }
200
201
202 /**
203  * Returns a string interpretation of 'rs'
204  *
205  * @param rs the request status from ARM
206  * @return a string interpretation of the request status
207  */
208 static const char *
209 req_string (enum GNUNET_ARM_RequestStatus rs)
210 {
211   switch (rs)
212   {
213   case GNUNET_ARM_REQUEST_SENT_OK:
214     return _("Message was sent successfully");
215   case GNUNET_ARM_REQUEST_CONFIGURATION_ERROR:
216     return _("Misconfiguration (can not connect to the ARM service)");
217   case GNUNET_ARM_REQUEST_DISCONNECTED:
218     return _("We disconnected from ARM before we could send a request");
219   case GNUNET_ARM_REQUEST_BUSY:
220     return _("ARM API is busy");
221   case GNUNET_ARM_REQUEST_TOO_LONG:
222     return _("Request does not fit into a message");
223   case GNUNET_ARM_REQUEST_TIMEOUT:
224     return _("Request timed out");
225   }
226   return _("Unknown request status");
227 }
228
229
230 /**
231  * Returns a string interpretation of the 'result'
232  *
233  * @param result the arm result
234  * @return a string interpretation
235  */
236 static const char *
237 ret_string (enum GNUNET_ARM_Result result)
238 {
239   switch (result)
240   {
241   case GNUNET_ARM_RESULT_STOPPED:
242     return _("%s is stopped");
243   case GNUNET_ARM_RESULT_STARTING:
244     return _("%s is starting");
245   case GNUNET_ARM_RESULT_STOPPING:
246     return _("%s is stopping");
247   case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
248     return _("%s is starting already");
249   case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
250     return _("%s is stopping already");
251   case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
252     return _("%s is started already");
253   case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
254     return _("%s is stopped already");
255   case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
256     return _("%s service is not known to ARM");
257   case GNUNET_ARM_RESULT_START_FAILED:
258     return _("%s service failed to start");
259   case GNUNET_ARM_RESULT_IN_SHUTDOWN:
260     return _("%s service cannot be started because ARM is shutting down");
261   }
262   return _("%.s Unknown result code.");
263 }
264
265
266 /**
267  * Main task that runs our various operations in order.
268  *
269  * @param cls closure
270  * @param tc scheudler context
271  */
272 static void 
273 action_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
274
275
276 /**
277  * Function called whenever we connect to or disconnect from ARM.
278  * Termiantes the process if we fail to connect to the service on
279  * our first attempt.
280  *
281  * @param cls closure
282  * @param connected GNUNET_YES if connected, GNUNET_NO if disconnected,
283  *                  GNUNET_SYSERR on error.
284  */
285 static void
286 conn_status (void *cls, 
287              int connected)
288 {
289   static int once;
290   
291   if ( (GNUNET_SYSERR == connected) &&
292        (0 == once) )
293   {
294     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
295                 _("Fatal error initializing ARM API.\n"));
296     GNUNET_SCHEDULER_shutdown ();
297     return;
298   }
299   once = 1;
300 }
301
302
303 /**
304  * We have requested ARM to be started, this function
305  * is called with the result of the operation.  Informs the
306  * use of the result; on success, we continue with the event
307  * loop, on failure we terminate the process.
308  *
309  * @param cls closure unused
310  * @param rs what happened to our request
311  * @param service name of the service we tried to start ("arm")
312  * @param result if the request was processed, this is the result
313  *               according to ARM
314  */
315 static void
316 start_callback (void *cls,
317                 enum GNUNET_ARM_RequestStatus rs, const char *service,
318                 enum GNUNET_ARM_Result result)
319 {
320   char *msg;
321
322   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
323   {
324     GNUNET_asprintf (&msg, "%s", _("Failed to start the ARM service: %s\n"));
325     FPRINTF (stdout, msg, req_string (rs));
326     GNUNET_free (msg);
327     GNUNET_SCHEDULER_shutdown ();
328     return;
329   }
330   if ( (GNUNET_ARM_RESULT_STARTING != result) &&
331        (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result) )
332   {
333     GNUNET_asprintf (&msg, "%s", _("Failed to start the ARM service: %s\n"));
334     FPRINTF (stdout, msg, ret_string (result));
335     GNUNET_free (msg);
336     GNUNET_SCHEDULER_shutdown ();
337     return;
338   }  
339   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n");
340   start = 0;
341   GNUNET_SCHEDULER_add_now (action_loop, NULL);
342 }
343
344
345 /**
346  * We have requested ARM to be stopped, this function
347  * is called with the result of the operation.  Informs the
348  * use of the result; on success, we continue with the event
349  * loop, on failure we terminate the process.
350  *
351  * @param cls closure unused
352  * @param rs what happened to our request
353  * @param service name of the service we tried to start ("arm")
354  * @param result if the request was processed, this is the result
355  *               according to ARM
356  */
357 static void
358 stop_callback (void *cls, 
359                enum GNUNET_ARM_RequestStatus rs, const char *service,
360                enum GNUNET_ARM_Result result)
361 {
362   char *msg;
363
364   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
365   {
366     GNUNET_asprintf (&msg, "%s", 
367                      _("Failed to send a stop request to the ARM service: %s\n"));
368     FPRINTF (stdout, msg, req_string (rs));
369     GNUNET_free (msg);
370     GNUNET_SCHEDULER_shutdown ();
371     return;
372   }
373   if ((GNUNET_ARM_RESULT_STOPPING != result) &&
374       (GNUNET_ARM_RESULT_STOPPED != result) &&
375       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
376   {
377     GNUNET_asprintf (&msg, "%s", _("Failed to stop the ARM service: %s\n"));
378     FPRINTF (stdout, msg, ret_string (result));
379     GNUNET_free (msg);
380     GNUNET_SCHEDULER_shutdown ();
381     return;
382   }
383   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
384               "ARM service shutdown successful\n");
385   end = 0;
386   if (restart)
387   {
388     restart = 0;
389     start = 1;
390     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
391                 "Initiating an ARM restart\n");
392   }
393   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
394 }
395
396
397 /**
398  * We have requested a service to be started, this function
399  * is called with the result of the operation.  Informs the
400  * use of the result; on success, we continue with the event
401  * loop, on failure we terminate the process.
402  *
403  * @param cls closure unused
404  * @param rs what happened to our request
405  * @param service name of the service we tried to start
406  * @param result if the request was processed, this is the result
407  *               according to ARM
408  */
409 static void
410 init_callback (void *cls, 
411                enum GNUNET_ARM_RequestStatus rs, const char *service,
412                enum GNUNET_ARM_Result result)
413 {
414   char *msg;
415   
416   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
417   {
418     GNUNET_asprintf (&msg, _("Failed to send a request to start the `%s' service: %%s\n"), init);
419     FPRINTF (stdout, msg, req_string (rs));
420     GNUNET_free (msg);
421     GNUNET_SCHEDULER_shutdown ();
422     return;
423   }
424   if ((GNUNET_ARM_RESULT_STARTING != result) &&
425       (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
426   {
427     GNUNET_asprintf (&msg, _("Failed to start the `%s' service: %s\n"),
428                      init, ret_string (result));
429     FPRINTF (stdout, msg, service);
430     GNUNET_free (msg);
431     GNUNET_SCHEDULER_shutdown ();
432     return;
433   }
434   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
435               "Service %s [re]started successfully\n", 
436               init);
437   init = NULL;
438   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
439 }
440
441
442 /**
443  * We have requested a service to be stopped, this function
444  * is called with the result of the operation.  Informs the
445  * use of the result; on success, we continue with the event
446  * loop, on failure we terminate the process.
447  *
448  * @param cls closure unused
449  * @param rs what happened to our request
450  * @param service name of the service we tried to start
451  * @param result if the request was processed, this is the result
452  *               according to ARM
453  */
454 static void
455 term_callback (void *cls, 
456                enum GNUNET_ARM_RequestStatus rs, const char *service,
457                enum GNUNET_ARM_Result result)
458 {
459   char *msg;
460   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
461   {
462     GNUNET_asprintf (&msg,
463                      _("Failed to send a request to kill the `%s' service: %%s\n"),
464                      term);
465     FPRINTF (stdout, msg, req_string (rs));
466     GNUNET_free (msg);
467     GNUNET_SCHEDULER_shutdown ();
468     return;
469   }
470   if ((GNUNET_ARM_RESULT_STOPPED != result) &&
471       (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result))
472   {
473     GNUNET_asprintf (&msg, 
474                      _("Failed to kill the `%s' service: %s\n"),
475                      term, ret_string (result));
476     FPRINTF (stdout, msg, service);
477     GNUNET_free (msg);
478     GNUNET_SCHEDULER_shutdown ();
479     return;
480   }
481
482   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
483               "Service %s stopped successfully\n", term);
484   term = NULL;
485   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
486 }
487
488
489 /**
490  * Function called with the list of running services. Prints
491  * the list to stdout, then starts the event loop again.
492  * Prints an error message and terminates the process on errors.
493  *
494  * @param cls closure (unused)
495  * @param rs request status (success, failure, etc.)
496  * @param count number of services in the list
497  * @param list list of services that are running
498  */
499 static void
500 list_callback (void *cls, 
501                enum GNUNET_ARM_RequestStatus rs, unsigned int count,
502                const char *const*list)
503 {
504   unsigned int i;
505
506   if (GNUNET_ARM_REQUEST_SENT_OK != rs)
507   {
508     char *msg;
509
510     GNUNET_asprintf (&msg, "%s", _("Failed to request a list of services: %s\n"));
511     FPRINTF (stdout, msg, req_string (rs));
512     GNUNET_free (msg);
513     GNUNET_SCHEDULER_shutdown ();
514   }
515   if (NULL == list)
516   {
517     FPRINTF (stderr, "%s", _("Error communicating with ARM. ARM not running?\n"));
518     GNUNET_SCHEDULER_shutdown ();
519     return;
520   }
521   FPRINTF (stdout, "%s", _("Running services:\n"));
522   for (i = 0; i < count; i++)
523     FPRINTF (stdout, "%s\n", list[i]);
524   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
525 }
526
527
528 /**
529  * Main action loop.  Runs the various jobs that we've been asked to
530  * do, in order.
531  *
532  * @param cls closure, unused
533  * @param tc context, unused
534  */
535 static void
536 action_loop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
537 {
538   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
539     return;
540   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n");
541   while (1)
542   {
543     switch (phase++)
544     {
545     case 0:
546       if (NULL != term)
547       {
548         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Termination action\n");
549         GNUNET_ARM_request_service_stop (h, term, 
550                                          (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
551                                          &term_callback, NULL);
552         return;
553       }
554       break;
555     case 1:
556       if (end || restart)
557       {
558         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "End action\n");
559         GNUNET_ARM_request_service_stop (h, "arm", 
560                                          (0 == timeout.rel_value_us) ? STOP_TIMEOUT_ARM : timeout,
561                                          &stop_callback, NULL);
562         return;
563       }
564       break;
565     case 2:
566       if (start)
567       {
568         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
569         GNUNET_ARM_request_service_start (h, "arm",
570             (no_stdout ? 0 : GNUNET_OS_INHERIT_STD_OUT) |
571             (no_stderr ? 0 : GNUNET_OS_INHERIT_STD_ERR),
572             (0 == timeout.rel_value_us) ? START_TIMEOUT: timeout,
573             start_callback, NULL);
574         return;
575       }
576       break;
577     case 3:
578       if (NULL != init)
579       {
580         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
581         GNUNET_ARM_request_service_start (h, init, GNUNET_OS_INHERIT_STD_NONE,
582                                           (0 == timeout.rel_value_us) ? STOP_TIMEOUT : timeout,
583                                           &init_callback, NULL);
584         return;
585       }
586       break;
587     case 4:
588       if (list) 
589       {
590         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
591                     "Going to list all running services controlled by ARM.\n"); 
592         GNUNET_ARM_request_service_list (h,
593                                          (0 == timeout.rel_value_us) ? LIST_TIMEOUT : timeout,
594                                          &list_callback, &list);
595         return;
596       }    
597       break;
598     case 5:
599       if (monitor) 
600         {
601           if (! quiet)
602             fprintf (stderr,
603                      _("Now only monitoring, press CTRL-C to stop.\n"));
604           quiet = 0; /* does not make sense to stay quiet in monitor mode at this time */
605           return; /* done with tasks, just monitor */
606         }
607       break;
608     default:            /* last phase */
609       GNUNET_SCHEDULER_shutdown ();
610       return;
611     }
612   }
613 }
614
615
616 /**
617  * Function called when a service starts or stops.
618  *
619  * @param cls closure
620  * @param service service name
621  * @param status status of the service
622  */
623 static void
624 srv_status (void *cls, 
625             const char *service, enum GNUNET_ARM_ServiceStatus status)
626 {
627   const char *msg;
628
629   switch (status)
630   {
631   case GNUNET_ARM_SERVICE_MONITORING_STARTED:
632     return; /* this should be done silently */
633   case GNUNET_ARM_SERVICE_STOPPED:
634     msg = _("Stopped %s.\n");
635     break;
636   case GNUNET_ARM_SERVICE_STARTING:
637     msg = _("Starting %s...\n");
638     break;
639   case GNUNET_ARM_SERVICE_STOPPING:
640     msg = _("Stopping %s...\n");
641     break;
642   default:
643     msg = NULL;
644     break;
645   }
646   if (! quiet)
647     {
648       if (NULL != msg)
649         FPRINTF (stderr, msg, service);
650       else
651         FPRINTF (stderr, _("Unknown status %u for service %s.\n"), status, service);
652     }
653   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got service %s status %d\n", service, (int) status);
654 }
655
656
657 /**
658  * Main function that will be run by the scheduler.
659  *
660  * @param cls closure
661  * @param args remaining command-line arguments
662  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
663  * @param c configuration
664  */
665 static void
666 run (void *cls, 
667      char *const *args, 
668      const char *cfgfile,
669      const struct GNUNET_CONFIGURATION_Handle *c)
670 {
671   char *armconfig;
672
673   cfg = GNUNET_CONFIGURATION_dup (c);
674   config_file = cfgfile;
675   if (GNUNET_OK != 
676       GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &dir))
677   {
678     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
679                                "PATHS", "SERVICEHOME");
680     return;
681   }
682   if (NULL != cfgfile)
683   {
684     if (GNUNET_OK !=
685         GNUNET_CONFIGURATION_get_value_filename (cfg, "arm", "CONFIG",
686                                                  &armconfig))
687     {
688       GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG",
689                                              cfgfile);
690     }
691     else
692       GNUNET_free (armconfig);
693   }
694   if (NULL == (h = GNUNET_ARM_connect (cfg, &conn_status, NULL)))
695     return;
696   if (monitor)
697     m = GNUNET_ARM_monitor (cfg, &srv_status, NULL);
698   GNUNET_SCHEDULER_add_now (&action_loop, NULL);
699   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
700                                 &shutdown_task, NULL);
701 }
702
703
704 /**
705  * The main function to obtain arm from gnunetd.
706  *
707  * @param argc number of arguments from the command line
708  * @param argv command line arguments
709  * @return 0 ok, 1 on error
710  */
711 int
712 main (int argc, char *const *argv)
713 {
714   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
715     {'e', "end", NULL, gettext_noop ("stop all GNUnet services"),
716      GNUNET_NO, &GNUNET_GETOPT_set_one, &end},
717     {'i', "init", "SERVICE", gettext_noop ("start a particular service"),
718      GNUNET_YES, &GNUNET_GETOPT_set_string, &init},
719     {'k', "kill", "SERVICE", gettext_noop ("stop a particular service"),
720      GNUNET_YES, &GNUNET_GETOPT_set_string, &term},
721     {'s', "start", NULL, gettext_noop ("start all GNUnet default services"),
722      GNUNET_NO, &GNUNET_GETOPT_set_one, &start},
723     {'r', "restart", NULL,
724      gettext_noop ("stop and start all GNUnet default services"),
725      GNUNET_NO, &GNUNET_GETOPT_set_one, &restart},
726     {'d', "delete", NULL,
727      gettext_noop ("delete config file and directory on exit"),
728      GNUNET_NO, &GNUNET_GETOPT_set_one, &delete},
729     {'m', "monitor", NULL,
730      gettext_noop ("monitor ARM activities"),
731      GNUNET_NO, &GNUNET_GETOPT_set_one, &monitor},
732     {'q', "quiet", NULL, gettext_noop ("don't print status messages"),
733      GNUNET_NO, &GNUNET_GETOPT_set_one, &quiet},
734     {'T', "timeout", "MSECS",
735      gettext_noop ("timeout in MSECS milliseconds for completing current operation"),
736      GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &timeout},
737     {'I', "info", NULL, gettext_noop ("list currently running services"),
738      GNUNET_NO, &GNUNET_GETOPT_set_one, &list},
739     {'O', "no-stdout", NULL, gettext_noop ("don't let gnunet-service-arm inherit standard output"),
740      GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stdout},
741     {'E', "no-stderr", NULL, gettext_noop ("don't let gnunet-service-arm inherit standard error"),
742      GNUNET_NO, &GNUNET_GETOPT_set_one, &no_stderr},
743     GNUNET_GETOPT_OPTION_END
744   };
745
746   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
747     return 2;
748
749   if (GNUNET_OK ==
750       GNUNET_PROGRAM_run (argc, argv, "gnunet-arm",
751                           gettext_noop
752                           ("Control services and the Automated Restart Manager (ARM)"),
753                           options, &run, NULL))
754     {
755       GNUNET_free ((void *) argv);
756       return ret;
757     }
758   GNUNET_free ((void*) argv);
759   return 1;
760 }
761
762 /* end of gnunet-arm.c */