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