aboutsummaryrefslogtreecommitdiff
path: root/src/arm/gnunet-arm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arm/gnunet-arm.c')
-rw-r--r--src/arm/gnunet-arm.c1044
1 files changed, 632 insertions, 412 deletions
diff --git a/src/arm/gnunet-arm.c b/src/arm/gnunet-arm.c
index 3396a4dbe..0fdb66fa0 100644
--- a/src/arm/gnunet-arm.c
+++ b/src/arm/gnunet-arm.c
@@ -54,6 +54,11 @@ static int delete;
54static int quiet; 54static int quiet;
55 55
56/** 56/**
57 * Set if we should print all services, including stopped ones.
58 */
59static int show_all;
60
61/**
57 * Monitor ARM activity. 62 * Monitor ARM activity.
58 */ 63 */
59static int monitor; 64static int monitor;
@@ -144,25 +149,25 @@ static struct GNUNET_ARM_Operation *op;
144 * were specified when gnunet-arm was run. 149 * were specified when gnunet-arm was run.
145 */ 150 */
146static void 151static void
147delete_files() 152delete_files ()
148{ 153{
149 GNUNET_log( 154 GNUNET_log (
150 GNUNET_ERROR_TYPE_DEBUG, 155 GNUNET_ERROR_TYPE_DEBUG,
151 "Will attempt to remove configuration file %s and service directory %s\n", 156 "Will attempt to remove configuration file %s and service directory %s\n",
152 config_file, 157 config_file,
153 dir); 158 dir);
154 if (0 != unlink(config_file)) 159 if (0 != unlink (config_file))
155 { 160 {
156 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 161 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
157 _("Failed to remove configuration file %s\n"), 162 _ ("Failed to remove configuration file %s\n"),
158 config_file); 163 config_file);
159 } 164 }
160 if (GNUNET_OK != GNUNET_DISK_directory_remove(dir)) 165 if (GNUNET_OK != GNUNET_DISK_directory_remove (dir))
161 { 166 {
162 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 167 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
163 _("Failed to remove servicehome directory %s\n"), 168 _ ("Failed to remove servicehome directory %s\n"),
164 dir); 169 dir);
165 } 170 }
166} 171}
167 172
168 173
@@ -173,37 +178,38 @@ delete_files()
173 * @param cls closure, unused 178 * @param cls closure, unused
174 */ 179 */
175static void 180static void
176shutdown_task(void *cls) 181shutdown_task (void *cls)
177{ 182{
178 (void)cls; 183 (void) cls;
179 if (NULL != al_task) 184 if (NULL != al_task)
180 { 185 {
181 GNUNET_SCHEDULER_cancel(al_task); 186 GNUNET_SCHEDULER_cancel (al_task);
182 al_task = NULL; 187 al_task = NULL;
183 } 188 }
184 if (NULL != op) 189 if (NULL != op)
185 { 190 {
186 GNUNET_ARM_operation_cancel(op); 191 GNUNET_ARM_operation_cancel (op);
187 op = NULL; 192 op = NULL;
188 } 193 }
189 if (NULL != h) 194 if (NULL != h)
190 { 195 {
191 GNUNET_ARM_disconnect(h); 196 GNUNET_ARM_disconnect (h);
192 h = NULL; 197 h = NULL;
193 } 198 }
194 if (NULL != m) 199 if (NULL != m)
195 { 200 {
196 GNUNET_ARM_monitor_stop(m); 201 GNUNET_ARM_monitor_stop (m);
197 m = NULL; 202 m = NULL;
198 } 203 }
199 if (NULL != timeout_task) 204 if (NULL != timeout_task)
200 { 205 {
201 GNUNET_SCHEDULER_cancel(timeout_task); 206 GNUNET_SCHEDULER_cancel (timeout_task);
202 timeout_task = NULL; 207 timeout_task = NULL;
203 } 208 }
204 if ((GNUNET_YES == end) && (GNUNET_YES == delete)) 209 if ( (GNUNET_YES == end) &&
205 delete_files(); 210 (GNUNET_YES == delete) )
206 GNUNET_CONFIGURATION_destroy(cfg); 211 delete_files ();
212 GNUNET_CONFIGURATION_destroy (cfg);
207 cfg = NULL; 213 cfg = NULL;
208} 214}
209 215
@@ -215,17 +221,17 @@ shutdown_task(void *cls)
215 * @return a string interpretation of the request status 221 * @return a string interpretation of the request status
216 */ 222 */
217static const char * 223static const char *
218req_string(enum GNUNET_ARM_RequestStatus rs) 224req_string (enum GNUNET_ARM_RequestStatus rs)
219{ 225{
220 switch (rs) 226 switch (rs)
221 { 227 {
222 case GNUNET_ARM_REQUEST_SENT_OK: 228 case GNUNET_ARM_REQUEST_SENT_OK:
223 return _("Message was sent successfully"); 229 return _ ("Message was sent successfully");
224 230
225 case GNUNET_ARM_REQUEST_DISCONNECTED: 231 case GNUNET_ARM_REQUEST_DISCONNECTED:
226 return _("We disconnected from ARM before we could send a request"); 232 return _ ("We disconnected from ARM before we could send a request");
227 } 233 }
228 return _("Unknown request status"); 234 return _ ("Unknown request status");
229} 235}
230 236
231 237
@@ -236,41 +242,41 @@ req_string(enum GNUNET_ARM_RequestStatus rs)
236 * @return a string interpretation 242 * @return a string interpretation
237 */ 243 */
238static const char * 244static const char *
239ret_string(enum GNUNET_ARM_Result result) 245ret_string (enum GNUNET_ARM_Result result)
240{ 246{
241 switch (result) 247 switch (result)
242 { 248 {
243 case GNUNET_ARM_RESULT_STOPPED: 249 case GNUNET_ARM_RESULT_STOPPED:
244 return _("is stopped"); 250 return _ ("is stopped");
245 251
246 case GNUNET_ARM_RESULT_STARTING: 252 case GNUNET_ARM_RESULT_STARTING:
247 return _("is starting"); 253 return _ ("is starting");
248 254
249 case GNUNET_ARM_RESULT_STOPPING: 255 case GNUNET_ARM_RESULT_STOPPING:
250 return _("is stopping"); 256 return _ ("is stopping");
251 257
252 case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: 258 case GNUNET_ARM_RESULT_IS_STARTING_ALREADY:
253 return _("is starting already"); 259 return _ ("is starting already");
254 260
255 case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: 261 case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY:
256 return _("is stopping already"); 262 return _ ("is stopping already");
257 263
258 case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: 264 case GNUNET_ARM_RESULT_IS_STARTED_ALREADY:
259 return _("is started already"); 265 return _ ("is started already");
260 266
261 case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: 267 case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY:
262 return _("is stopped already"); 268 return _ ("is stopped already");
263 269
264 case GNUNET_ARM_RESULT_IS_NOT_KNOWN: 270 case GNUNET_ARM_RESULT_IS_NOT_KNOWN:
265 return _("service is not known to ARM"); 271 return _ ("service is not known to ARM");
266 272
267 case GNUNET_ARM_RESULT_START_FAILED: 273 case GNUNET_ARM_RESULT_START_FAILED:
268 return _("service failed to start"); 274 return _ ("service failed to start");
269 275
270 case GNUNET_ARM_RESULT_IN_SHUTDOWN: 276 case GNUNET_ARM_RESULT_IN_SHUTDOWN:
271 return _("service cannot be manipulated because ARM is shutting down"); 277 return _ ("service cannot be manipulated because ARM is shutting down");
272 } 278 }
273 return _("Unknown result code."); 279 return _ ("Unknown result code.");
274} 280}
275 281
276 282
@@ -280,7 +286,7 @@ ret_string(enum GNUNET_ARM_Result result)
280 * @param cls closure 286 * @param cls closure
281 */ 287 */
282static void 288static void
283action_loop(void *cls); 289action_loop (void *cls);
284 290
285 291
286/** 292/**
@@ -293,18 +299,20 @@ action_loop(void *cls);
293 * #GNUNET_SYSERR on error. 299 * #GNUNET_SYSERR on error.
294 */ 300 */
295static void 301static void
296conn_status(void *cls, int connected) 302conn_status (void *cls,
303 int connected)
297{ 304{
298 static int once; 305 static int once;
299 306
300 (void)cls; 307 (void) cls;
301 if ((GNUNET_SYSERR == connected) && (0 == once)) 308 if ( (GNUNET_SYSERR == connected) &&
302 { 309 (0 == once) )
303 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 310 {
304 _("Fatal error initializing ARM API.\n")); 311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
305 GNUNET_SCHEDULER_shutdown(); 312 _ ("Fatal error initializing ARM API.\n"));
306 return; 313 GNUNET_SCHEDULER_shutdown ();
307 } 314 return;
315 }
308 once = 1; 316 once = 1;
309} 317}
310 318
@@ -321,32 +329,34 @@ conn_status(void *cls, int connected)
321 * according to ARM 329 * according to ARM
322 */ 330 */
323static void 331static void
324start_callback(void *cls, 332start_callback (void *cls,
325 enum GNUNET_ARM_RequestStatus rs, 333 enum GNUNET_ARM_RequestStatus rs,
326 enum GNUNET_ARM_Result result) 334 enum GNUNET_ARM_Result result)
327{ 335{
328 (void)cls; 336 (void) cls;
329 op = NULL; 337 op = NULL;
330 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 338 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
331 { 339 {
332 fprintf(stdout, 340 fprintf (stdout,
333 _("Failed to start the ARM service: %s\n"), 341 _ ("Failed to start the ARM service: %s\n"),
334 req_string(rs)); 342 req_string (rs));
335 GNUNET_SCHEDULER_shutdown(); 343 GNUNET_SCHEDULER_shutdown ();
336 return; 344 return;
337 } 345 }
338 if ((GNUNET_ARM_RESULT_STARTING != result) && 346 if ((GNUNET_ARM_RESULT_STARTING != result) &&
339 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) 347 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
340 { 348 {
341 fprintf(stdout, 349 fprintf (stdout,
342 _("Failed to start the ARM service: %s\n"), 350 _ ("Failed to start the ARM service: %s\n"),
343 ret_string(result)); 351 ret_string (result));
344 GNUNET_SCHEDULER_shutdown(); 352 GNUNET_SCHEDULER_shutdown ();
345 return; 353 return;
346 } 354 }
347 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ARM service [re]start successful\n"); 355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
356 "ARM service [re]start successful\n");
348 start = 0; 357 start = 0;
349 al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); 358 al_task = GNUNET_SCHEDULER_add_now (&action_loop,
359 NULL);
350} 360}
351 361
352 362
@@ -362,44 +372,47 @@ start_callback(void *cls,
362 * according to ARM 372 * according to ARM
363 */ 373 */
364static void 374static void
365stop_callback(void *cls, 375stop_callback (void *cls,
366 enum GNUNET_ARM_RequestStatus rs, 376 enum GNUNET_ARM_RequestStatus rs,
367 enum GNUNET_ARM_Result result) 377 enum GNUNET_ARM_Result result)
368{ 378{
369 char *msg; 379 char *msg;
370 380
371 (void)cls; 381 (void) cls;
372 op = NULL; 382 op = NULL;
373 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 383 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
374 { 384 {
375 GNUNET_asprintf(&msg, 385 GNUNET_asprintf (&msg,
376 "%s", 386 "%s",
377 _( 387 _ (
378 "Failed to send a stop request to the ARM service: %s\n")); 388 "Failed to send a stop request to the ARM service: %s\n"));
379 fprintf(stdout, msg, req_string(rs)); 389 fprintf (stdout, msg, req_string (rs));
380 GNUNET_free(msg); 390 GNUNET_free (msg);
381 GNUNET_SCHEDULER_shutdown(); 391 GNUNET_SCHEDULER_shutdown ();
382 return; 392 return;
383 } 393 }
384 if ((GNUNET_ARM_RESULT_STOPPING != result) && 394 if ( (GNUNET_ARM_RESULT_STOPPING != result) &&
385 (GNUNET_ARM_RESULT_STOPPED != result) && 395 (GNUNET_ARM_RESULT_STOPPED != result) &&
386 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) 396 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result) )
387 { 397 {
388 fprintf(stdout, 398 fprintf (stdout,
389 _("Failed to stop the ARM service: %s\n"), 399 _ ("Failed to stop the ARM service: %s\n"),
390 ret_string(result)); 400 ret_string (result));
391 GNUNET_SCHEDULER_shutdown(); 401 GNUNET_SCHEDULER_shutdown ();
392 return; 402 return;
393 } 403 }
394 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ARM service shutdown successful\n"); 404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405 "ARM service shutdown successful\n");
395 end = 0; 406 end = 0;
396 if (restart) 407 if (restart)
397 { 408 {
398 restart = 0; 409 restart = 0;
399 start = 1; 410 start = 1;
400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initiating an ARM restart\n"); 411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
401 } 412 "Initiating an ARM restart\n");
402 al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); 413 }
414 al_task = GNUNET_SCHEDULER_add_now (&action_loop,
415 NULL);
403} 416}
404 417
405 418
@@ -415,37 +428,38 @@ stop_callback(void *cls,
415 * according to ARM 428 * according to ARM
416 */ 429 */
417static void 430static void
418init_callback(void *cls, 431init_callback (void *cls,
419 enum GNUNET_ARM_RequestStatus rs, 432 enum GNUNET_ARM_RequestStatus rs,
420 enum GNUNET_ARM_Result result) 433 enum GNUNET_ARM_Result result)
421{ 434{
422 (void)cls; 435 (void) cls;
423 op = NULL; 436 op = NULL;
424 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 437 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
425 { 438 {
426 fprintf(stdout, 439 fprintf (stdout,
427 _("Failed to send a request to start the `%s' service: %s\n"), 440 _ ("Failed to send a request to start the `%s' service: %s\n"),
428 init, 441 init,
429 req_string(rs)); 442 req_string (rs));
430 GNUNET_SCHEDULER_shutdown(); 443 GNUNET_SCHEDULER_shutdown ();
431 return; 444 return;
432 } 445 }
433 if ((GNUNET_ARM_RESULT_STARTING != result) && 446 if ((GNUNET_ARM_RESULT_STARTING != result) &&
434 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result)) 447 (GNUNET_ARM_RESULT_IS_STARTED_ALREADY != result))
435 { 448 {
436 fprintf(stdout, 449 fprintf (stdout,
437 _("Failed to start the `%s' service: %s\n"), 450 _ ("Failed to start the `%s' service: %s\n"),
438 init, 451 init,
439 ret_string(result)); 452 ret_string (result));
440 GNUNET_SCHEDULER_shutdown(); 453 GNUNET_SCHEDULER_shutdown ();
441 return; 454 return;
442 } 455 }
443 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 456 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
444 "Service %s [re]started successfully\n", 457 "Service %s [re]started successfully\n",
445 init); 458 init);
446 GNUNET_free(init); 459 GNUNET_free (init);
447 init = NULL; 460 init = NULL;
448 al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); 461 al_task = GNUNET_SCHEDULER_add_now (&action_loop,
462 NULL);
449} 463}
450 464
451 465
@@ -461,42 +475,45 @@ init_callback(void *cls,
461 * according to ARM 475 * according to ARM
462 */ 476 */
463static void 477static void
464term_callback(void *cls, 478term_callback (void *cls,
465 enum GNUNET_ARM_RequestStatus rs, 479 enum GNUNET_ARM_RequestStatus rs,
466 enum GNUNET_ARM_Result result) 480 enum GNUNET_ARM_Result result)
467{ 481{
468 char *msg; 482 char *msg;
469 483
470 (void)cls; 484 (void) cls;
471 op = NULL; 485 op = NULL;
472 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 486 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
473 { 487 {
474 GNUNET_asprintf(&msg, 488 GNUNET_asprintf (&msg,
475 _( 489 _ (
476 "Failed to send a request to kill the `%s' service: %%s\n"), 490 "Failed to send a request to kill the `%s' service: %%s\n"),
477 term); 491 term);
478 fprintf(stdout, msg, req_string(rs)); 492 fprintf (stdout,
479 GNUNET_free(msg); 493 msg,
480 GNUNET_SCHEDULER_shutdown(); 494 req_string (rs));
481 return; 495 GNUNET_free (msg);
482 } 496 GNUNET_SCHEDULER_shutdown ();
483 if ((GNUNET_ARM_RESULT_STOPPED != result) && 497 return;
484 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result)) 498 }
485 { 499 if ( (GNUNET_ARM_RESULT_STOPPED != result) &&
486 fprintf(stdout, 500 (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY != result) )
487 _("Failed to kill the `%s' service: %s\n"), 501 {
488 term, 502 fprintf (stdout,
489 ret_string(result)); 503 _ ("Failed to kill the `%s' service: %s\n"),
490 GNUNET_SCHEDULER_shutdown(); 504 term,
491 return; 505 ret_string (result));
492 } 506 GNUNET_SCHEDULER_shutdown ();
507 return;
508 }
493 509
494 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "Service %s stopped successfully\n", 511 "Service %s stopped successfully\n",
496 term); 512 term);
497 GNUNET_free(term); 513 GNUNET_free (term);
498 term = NULL; 514 term = NULL;
499 al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); 515 al_task = GNUNET_SCHEDULER_add_now (&action_loop,
516 NULL);
500} 517}
501 518
502 519
@@ -508,42 +525,196 @@ term_callback(void *cls,
508 * @param cls closure (unused) 525 * @param cls closure (unused)
509 * @param rs request status (success, failure, etc.) 526 * @param rs request status (success, failure, etc.)
510 * @param count number of services in the list 527 * @param count number of services in the list
511 * @param list list of services that are running 528 * @param list list of services managed by arm
512 */ 529 */
513static void 530static void
514list_callback(void *cls, 531list_callback (void *cls,
515 enum GNUNET_ARM_RequestStatus rs, 532 enum GNUNET_ARM_RequestStatus rs,
516 unsigned int count, 533 unsigned int count,
517 const char *const *list) 534 const struct GNUNET_ARM_ServiceInfo *list)
518{ 535{
519 (void)cls; 536 unsigned int num_stopped = 0;
537 unsigned int num_started = 0;
538 unsigned int num_stopping = 0;
539 unsigned int num_failed = 0;
540 unsigned int num_finished = 0;
541 (void) cls;
520 op = NULL; 542 op = NULL;
521 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 543 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
544 {
545 char *msg;
546
547 GNUNET_asprintf (&msg,
548 "%s",
549 _ ("Failed to request a list of services: %s\n"));
550 fprintf (stdout,
551 msg,
552 req_string (rs));
553 GNUNET_free (msg);
554 ret = 3;
555 GNUNET_SCHEDULER_shutdown ();
556 }
557 if (NULL == list)
558 {
559 fprintf (stderr,
560 "%s",
561 _ ("Error communicating with ARM. ARM not running?\n"));
562 GNUNET_SCHEDULER_shutdown ();
563 ret = 3;
564 return;
565 }
566 for (unsigned int i = 0; i < count; i++)
567 {
568 switch (list[i].status)
522 { 569 {
523 char *msg; 570 case GNUNET_ARM_SERVICE_STATUS_STOPPED:
524 571 num_stopped++;
525 GNUNET_asprintf(&msg, 572 break;
526 "%s", 573 case GNUNET_ARM_SERVICE_STATUS_FAILED:
527 _("Failed to request a list of services: %s\n")); 574 num_failed++;
528 fprintf(stdout, msg, req_string(rs)); 575 break;
529 GNUNET_free(msg); 576 case GNUNET_ARM_SERVICE_STATUS_FINISHED:
530 ret = 3; 577 num_finished++;
531 GNUNET_SCHEDULER_shutdown(); 578 break;
579 case GNUNET_ARM_SERVICE_STATUS_STARTED:
580 num_started++;
581 break;
582 case GNUNET_ARM_SERVICE_STATUS_STOPPING:
583 num_stopping++;
584 fprintf (stdout,
585 "%s (binary='%s', status=stopping)\n",
586 list[i].name,
587 list[i].binary);
588 break;
589 default:
590 GNUNET_break_op (0);
591 fprintf (stdout,
592 "%s (binary='%s', status=unknown)\n",
593 list[i].name,
594 list[i].binary);
595 break;
532 } 596 }
533 if (NULL == list) 597 }
598 if (! quiet)
599 {
600 if (show_all)
601 fprintf (stdout,
602 "%s",
603 _ ("All services:\n"));
604 else
605 fprintf (stdout,
606 "%s",
607 _ ("Services (excluding stopped services):\n"));
608 if (num_stopped || num_failed || num_finished || num_stopping ||
609 num_started)
534 { 610 {
535 fprintf(stderr, 611 int sep = 0;
536 "%s", 612 fprintf (stdout, "(");
537 _("Error communicating with ARM. ARM not running?\n")); 613 if (0 != num_started)
538 GNUNET_SCHEDULER_shutdown(); 614 {
539 ret = 3; 615 if (sep)
540 return; 616 fprintf (stdout, " / ");
617 fprintf (stdout,
618 "started: %u",
619 num_started);
620 sep = 1;
621 }
622 if (0 != num_failed)
623 {
624 if (sep)
625 fprintf (stdout, " / ");
626 fprintf (stdout,
627 "failed: %u",
628 num_failed);
629 sep = 1;
630 }
631 if (0 != num_stopping)
632 {
633 if (sep)
634 fprintf (stdout, " / ");
635 fprintf (stdout,
636 "stopping: %u",
637 num_stopping);
638 sep = 1;
639 }
640 if (0 != num_stopped)
641 {
642 if (sep)
643 fprintf (stdout, " / ");
644 fprintf (stdout,
645 "stopped: %u",
646 num_stopped);
647 sep = 1;
648 }
649 if (0 != num_finished)
650 {
651 if (sep)
652 fprintf (stdout, " / ");
653 fprintf (stdout,
654 "finished: %u",
655 num_finished);
656 sep = 1;
657 }
658 fprintf (stdout, ")\n");
541 } 659 }
542 if (!quiet) 660 else
543 fprintf(stdout, "%s", _("Running services:\n")); 661 {
662 fprintf (stdout,
663 "%s",
664 _ ("(No services configured.)\n"));
665 }
666 }
544 for (unsigned int i = 0; i < count; i++) 667 for (unsigned int i = 0; i < count; i++)
545 fprintf(stdout, "%s\n", list[i]); 668 {
546 al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); 669 struct GNUNET_TIME_Relative restart_in;
670 switch (list[i].status)
671 {
672 case GNUNET_ARM_SERVICE_STATUS_STOPPED:
673 if (show_all)
674 fprintf (stdout,
675 "%s (binary='%s', status=stopped)\n",
676 list[i].name,
677 list[i].binary);
678 break;
679 case GNUNET_ARM_SERVICE_STATUS_FAILED:
680 restart_in = GNUNET_TIME_absolute_get_remaining (list[i].restart_at);
681 fprintf (stdout,
682 "%s (binary='%s', status=failed, exit_status=%d, restart_delay='%s')\n",
683 list[i].name,
684 list[i].binary,
685 list[i].last_exit_status,
686 GNUNET_STRINGS_relative_time_to_string (restart_in,
687 GNUNET_YES));
688 break;
689 case GNUNET_ARM_SERVICE_STATUS_FINISHED:
690 fprintf (stdout,
691 "%s (binary='%s', status=finished)\n",
692 list[i].name,
693 list[i].binary);
694 break;
695 case GNUNET_ARM_SERVICE_STATUS_STARTED:
696 fprintf (stdout,
697 "%s (binary='%s', status=started)\n",
698 list[i].name,
699 list[i].binary);
700 break;
701 case GNUNET_ARM_SERVICE_STATUS_STOPPING:
702 fprintf (stdout,
703 "%s (binary='%s', status=stopping)\n",
704 list[i].name,
705 list[i].binary);
706 break;
707 default:
708 GNUNET_break_op (0);
709 fprintf (stdout,
710 "%s (binary='%s', status=unknown)\n",
711 list[i].name,
712 list[i].binary);
713 break;
714 }
715 }
716 al_task = GNUNET_SCHEDULER_add_now (&action_loop,
717 NULL);
547} 718}
548 719
549 720
@@ -554,91 +725,115 @@ list_callback(void *cls,
554 * @param cls closure, unused 725 * @param cls closure, unused
555 */ 726 */
556static void 727static void
557action_loop(void *cls) 728action_loop (void *cls)
558{ 729{
559 (void)cls; 730 (void) cls;
560 al_task = NULL; 731 al_task = NULL;
561 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running requested actions\n"); 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
733 "Running requested actions\n");
562 while (1) 734 while (1)
735 {
736 switch (phase++)
563 { 737 {
564 switch (phase++) 738 case 0:
739 if (NULL != term)
740 {
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Termination action\n");
743 op = GNUNET_ARM_request_service_stop (h,
744 term,
745 &term_callback,
746 NULL);
747 return;
748 }
749 break;
750
751 case 1:
752 if (end || restart)
753 {
754 if (GNUNET_YES !=
755 GNUNET_CLIENT_test (cfg,
756 "arm"))
757 {
758 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
759 "GNUnet not running, cannot stop the peer\n");
760 }
761 else
565 { 762 {
566 case 0: 763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
567 if (NULL != term) 764 "End action\n");
568 { 765 op = GNUNET_ARM_request_service_stop (h,
569 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Termination action\n"); 766 "arm",
570 op = GNUNET_ARM_request_service_stop(h, term, &term_callback, NULL); 767 &stop_callback,
571 return; 768 NULL);
572 }
573 break;
574
575 case 1:
576 if (end || restart)
577 {
578 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "End action\n");
579 op = GNUNET_ARM_request_service_stop(h, "arm", &stop_callback, NULL);
580 return;
581 }
582 break;
583
584 case 2:
585 if (start)
586 {
587 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start action\n");
588 op =
589 GNUNET_ARM_request_service_start(h,
590 "arm",
591 (no_stdout
592 ? 0
593 : GNUNET_OS_INHERIT_STD_OUT) |
594 (no_stderr
595 ? 0
596 : GNUNET_OS_INHERIT_STD_ERR),
597 &start_callback,
598 NULL);
599 return;
600 }
601 break;
602
603 case 3:
604 if (NULL != init)
605 {
606 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Initialization action\n");
607 op = GNUNET_ARM_request_service_start(h,
608 init,
609 GNUNET_OS_INHERIT_STD_NONE,
610 &init_callback,
611 NULL);
612 return;
613 }
614 break;
615
616 case 4:
617 if (list)
618 {
619 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
620 "Going to list all running services controlled by ARM.\n");
621 op = GNUNET_ARM_request_service_list(h, &list_callback, &list);
622 return;
623 }
624 break;
625
626 case 5:
627 if (monitor)
628 {
629 if (!quiet)
630 fprintf(stderr, _("Now only monitoring, press CTRL-C to stop.\n"));
631 quiet =
632 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
637 default: /* last phase */
638 GNUNET_SCHEDULER_shutdown();
639 return; 769 return;
640 } 770 }
771 }
772 break;
773
774 case 2:
775 if (start)
776 {
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Start action\n");
779 op =
780 GNUNET_ARM_request_service_start (h,
781 "arm",
782 (no_stdout
783 ? 0
784 : GNUNET_OS_INHERIT_STD_OUT)
785 | (no_stderr
786 ? 0
787 : GNUNET_OS_INHERIT_STD_ERR),
788 &start_callback,
789 NULL);
790 return;
791 }
792 break;
793
794 case 3:
795 if (NULL != init)
796 {
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
798 "Initialization action\n");
799 op = GNUNET_ARM_request_service_start (h,
800 init,
801 GNUNET_OS_INHERIT_STD_NONE,
802 &init_callback,
803 NULL);
804 return;
805 }
806 break;
807
808 case 4:
809 if (list)
810 {
811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
812 "Going to list all running services controlled by ARM.\n");
813 op = GNUNET_ARM_request_service_list (h,
814 &list_callback,
815 &list);
816 return;
817 }
818 break;
819
820 case 5:
821 if (monitor)
822 {
823 if (! quiet)
824 fprintf (stderr,
825 _ ("Now only monitoring, press CTRL-C to stop.\n"));
826 quiet =
827 0; /* does not make sense to stay quiet in monitor mode at this time */
828 return; /* done with tasks, just monitor */
829 }
830 break;
831
832 default: /* last phase */
833 GNUNET_SCHEDULER_shutdown ();
834 return;
641 } 835 }
836 }
642} 837}
643 838
644 839
@@ -650,48 +845,50 @@ action_loop(void *cls)
650 * @param status status of the service 845 * @param status status of the service
651 */ 846 */
652static void 847static void
653srv_status(void *cls, 848srv_status (void *cls,
654 const char *service, 849 const char *service,
655 enum GNUNET_ARM_ServiceStatus status) 850 enum GNUNET_ARM_ServiceMonitorStatus status)
656{ 851{
657 const char *msg; 852 const char *msg;
658 853
659 (void)cls; 854 (void) cls;
660 switch (status) 855 switch (status)
661 { 856 {
662 case GNUNET_ARM_SERVICE_MONITORING_STARTED: 857 case GNUNET_ARM_SERVICE_MONITORING_STARTED:
663 return; /* this should be done silently */ 858 return; /* this should be done silently */
664 859
665 case GNUNET_ARM_SERVICE_STOPPED: 860 case GNUNET_ARM_SERVICE_STOPPED:
666 msg = _("Stopped %s.\n"); 861 msg = _ ("Stopped %s.\n");
667 break; 862 break;
668 863
669 case GNUNET_ARM_SERVICE_STARTING: 864 case GNUNET_ARM_SERVICE_STARTING:
670 msg = _("Starting %s...\n"); 865 msg = _ ("Starting %s...\n");
671 break; 866 break;
672 867
673 case GNUNET_ARM_SERVICE_STOPPING: 868 case GNUNET_ARM_SERVICE_STOPPING:
674 msg = _("Stopping %s...\n"); 869 msg = _ ("Stopping %s...\n");
675 break; 870 break;
676 871
677 default: 872 default:
678 msg = NULL; 873 msg = NULL;
679 break; 874 break;
680 } 875 }
681 if (!quiet) 876 if (! quiet)
682 { 877 {
683 if (NULL != msg) 878 if (NULL != msg)
684 fprintf(stderr, msg, service); 879 fprintf (stderr,
685 else 880 msg,
686 fprintf(stderr, 881 service);
687 _("Unknown status %u for service %s.\n"), 882 else
688 status, 883 fprintf (stderr,
689 service); 884 _ ("Unknown status %u for service %s.\n"),
690 } 885 status,
691 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 886 service);
692 "Got service %s status %d\n", 887 }
693 service, 888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 (int)status); 889 "Got service %s status %d\n",
890 service,
891 (int) status);
695} 892}
696 893
697 894
@@ -699,12 +896,12 @@ srv_status(void *cls,
699 * Task run on timeout (if -T is given). 896 * Task run on timeout (if -T is given).
700 */ 897 */
701static void 898static void
702timeout_task_cb(void *cls) 899timeout_task_cb (void *cls)
703{ 900{
704 (void)cls; 901 (void) cls;
705 timeout_task = NULL; 902 timeout_task = NULL;
706 ret = 2; 903 ret = 2;
707 GNUNET_SCHEDULER_shutdown(); 904 GNUNET_SCHEDULER_shutdown ();
708} 905}
709 906
710 907
@@ -717,34 +914,47 @@ timeout_task_cb(void *cls)
717 * @param c configuration 914 * @param c configuration
718 */ 915 */
719static void 916static void
720run(void *cls, 917run (void *cls,
721 char *const *args, 918 char *const *args,
722 const char *cfgfile, 919 const char *cfgfile,
723 const struct GNUNET_CONFIGURATION_Handle *c) 920 const struct GNUNET_CONFIGURATION_Handle *c)
724{ 921{
725 (void)cls; 922 (void) cls;
726 (void)args; 923 (void) args;
727 (void)cfgfile; 924 (void) cfgfile;
728 cfg = GNUNET_CONFIGURATION_dup(c); 925 cfg = GNUNET_CONFIGURATION_dup (c);
729 if (GNUNET_OK != 926 if (GNUNET_OK !=
730 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_HOME", &dir)) 927 GNUNET_CONFIGURATION_get_value_string (cfg,
731 { 928 "PATHS",
732 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, "PATHS", "GNUNET_HOME"); 929 "GNUNET_HOME",
733 return; 930 &dir))
734 } 931 {
735 (void)GNUNET_CONFIGURATION_get_value_filename(cfg, 932 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
736 "arm", 933 "PATHS",
737 "CONFIG", 934 "GNUNET_HOME");
738 &config_file); 935 return;
739 if (NULL == (h = GNUNET_ARM_connect(cfg, &conn_status, NULL))) 936 }
937 (void) GNUNET_CONFIGURATION_get_value_filename (cfg,
938 "arm",
939 "CONFIG",
940 &config_file);
941 if (NULL == (h = GNUNET_ARM_connect (cfg,
942 &conn_status,
943 NULL)))
740 return; 944 return;
741 if (monitor) 945 if (monitor)
742 m = GNUNET_ARM_monitor_start(cfg, &srv_status, NULL); 946 m = GNUNET_ARM_monitor_start (cfg,
743 al_task = GNUNET_SCHEDULER_add_now(&action_loop, NULL); 947 &srv_status,
744 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); 948 NULL);
949 al_task = GNUNET_SCHEDULER_add_now (&action_loop,
950 NULL);
951 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
952 NULL);
745 if (0 != timeout.rel_value_us) 953 if (0 != timeout.rel_value_us)
746 timeout_task = 954 timeout_task =
747 GNUNET_SCHEDULER_add_delayed(timeout, &timeout_task_cb, NULL); 955 GNUNET_SCHEDULER_add_delayed (timeout,
956 &timeout_task_cb,
957 NULL);
748} 958}
749 959
750 960
@@ -756,88 +966,98 @@ run(void *cls,
756 * @return 0 ok, 1 on error, 2 on timeout 966 * @return 0 ok, 1 on error, 2 on timeout
757 */ 967 */
758int 968int
759main(int argc, char *const *argv) 969main (int argc, char *const *argv)
760{ 970{
761 struct GNUNET_GETOPT_CommandLineOption options[] = 971 struct GNUNET_GETOPT_CommandLineOption options[] = {
762 { GNUNET_GETOPT_option_flag('e', 972 GNUNET_GETOPT_option_flag ('e',
763 "end", 973 "end",
764 gettext_noop("stop all GNUnet services"), 974 gettext_noop ("stop all GNUnet services"),
765 &end), 975 &end),
766 GNUNET_GETOPT_option_string('i', 976 GNUNET_GETOPT_option_string ('i',
767 "init", 977 "init",
768 "SERVICE", 978 "SERVICE",
769 gettext_noop("start a particular service"), 979 gettext_noop ("start a particular service"),
770 &init), 980 &init),
771 GNUNET_GETOPT_option_string('k', 981 GNUNET_GETOPT_option_string ('k',
772 "kill", 982 "kill",
773 "SERVICE", 983 "SERVICE",
774 gettext_noop("stop a particular service"), 984 gettext_noop ("stop a particular service"),
775 &term), 985 &term),
776 GNUNET_GETOPT_option_flag('s', 986 GNUNET_GETOPT_option_flag ('a',
777 "start", 987 "all",
778 gettext_noop( 988 gettext_noop (
779 "start all GNUnet default services"), 989 "also show stopped services (used with -I)"),
780 &start), 990 &show_all),
781 GNUNET_GETOPT_option_flag('r', 991 GNUNET_GETOPT_option_flag ('s',
782 "restart", 992 "start",
783 gettext_noop( 993 gettext_noop (
784 "stop and start all GNUnet default services"), 994 "start all GNUnet default services"),
785 &restart), 995 &start),
786 GNUNET_GETOPT_option_flag('d', 996 GNUNET_GETOPT_option_flag ('r',
787 "delete", 997 "restart",
788 gettext_noop( 998 gettext_noop (
789 "delete config file and directory on exit"), 999 "stop and start all GNUnet default services"),
790 &delete), 1000 &restart),
791 GNUNET_GETOPT_option_flag('m', 1001 GNUNET_GETOPT_option_flag ('d',
792 "monitor", 1002 "delete",
793 gettext_noop("monitor ARM activities"), 1003 gettext_noop (
794 &monitor), 1004 "delete config file and directory on exit"),
795 GNUNET_GETOPT_option_flag('q', 1005 &delete),
796 "quiet", 1006 GNUNET_GETOPT_option_flag ('m',
797 gettext_noop("don't print status messages"), 1007 "monitor",
798 &quiet), 1008 gettext_noop ("monitor ARM activities"),
799 GNUNET_GETOPT_option_relative_time( 1009 &monitor),
1010 GNUNET_GETOPT_option_flag ('q',
1011 "quiet",
1012 gettext_noop ("don't print status messages"),
1013 &quiet),
1014 GNUNET_GETOPT_option_relative_time (
800 'T', 1015 'T',
801 "timeout", 1016 "timeout",
802 "DELAY", 1017 "DELAY",
803 gettext_noop( 1018 gettext_noop (
804 "exit with error status if operation does not finish after DELAY"), 1019 "exit with error status if operation does not finish after DELAY"),
805 &timeout), 1020 &timeout),
806 GNUNET_GETOPT_option_flag('I', 1021 GNUNET_GETOPT_option_flag ('I',
807 "info", 1022 "info",
808 gettext_noop( 1023 gettext_noop (
809 "list currently running services"), 1024 "list currently running services"),
810 &list), 1025 &list),
811 GNUNET_GETOPT_option_flag( 1026 GNUNET_GETOPT_option_flag (
812 'O', 1027 'O',
813 "no-stdout", 1028 "no-stdout",
814 gettext_noop("don't let gnunet-service-arm inherit standard output"), 1029 gettext_noop ("don't let gnunet-service-arm inherit standard output"),
815 &no_stdout), 1030 &no_stdout),
816 GNUNET_GETOPT_option_flag( 1031 GNUNET_GETOPT_option_flag (
817 'E', 1032 'E',
818 "no-stderr", 1033 "no-stderr",
819 gettext_noop("don't let gnunet-service-arm inherit standard error"), 1034 gettext_noop ("don't let gnunet-service-arm inherit standard error"),
820 &no_stderr), 1035 &no_stderr),
821 GNUNET_GETOPT_OPTION_END }; 1036 GNUNET_GETOPT_OPTION_END
1037 };
822 int lret; 1038 int lret;
823 1039
824 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) 1040 if (GNUNET_OK !=
1041 GNUNET_STRINGS_get_utf8_args (argc,
1042 argv,
1043 &argc,
1044 &argv))
825 return 2; 1045 return 2;
826 if (GNUNET_OK == 1046 if (GNUNET_OK ==
827 (lret = GNUNET_PROGRAM_run( 1047 (lret = GNUNET_PROGRAM_run (
828 argc, 1048 argc,
829 argv, 1049 argv,
830 "gnunet-arm", 1050 "gnunet-arm",
831 gettext_noop( 1051 gettext_noop (
832 "Control services and the Automated Restart Manager (ARM)"), 1052 "Control services and the Automated Restart Manager (ARM)"),
833 options, 1053 options,
834 &run, 1054 &run,
835 NULL))) 1055 NULL)))
836 { 1056 {
837 GNUNET_free((void *)argv); 1057 GNUNET_free ((void *) argv);
838 return ret; 1058 return ret;
839 } 1059 }
840 GNUNET_free((void *)argv); 1060 GNUNET_free ((void *) argv);
841 return lret; 1061 return lret;
842} 1062}
843 1063