aboutsummaryrefslogtreecommitdiff
path: root/src/arm
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-11-03 21:26:40 +0000
committerChristian Grothoff <christian@grothoff.org>2010-11-03 21:26:40 +0000
commit721e49caeea6ba5073f8bc5c6c08359295c02bb5 (patch)
treee06e80ba90af91e9452a48a7a5782913199b4877 /src/arm
parent37ac1b7c9e9e05f93d4100cfb53450ec2d370989 (diff)
downloadgnunet-721e49caeea6ba5073f8bc5c6c08359295c02bb5.tar.gz
gnunet-721e49caeea6ba5073f8bc5c6c08359295c02bb5.zip
original patch from Mantis 1614
Diffstat (limited to 'src/arm')
-rw-r--r--src/arm/arm_api.c8
-rw-r--r--src/arm/do_start_process.c8
-rw-r--r--src/arm/gnunet-service-arm.c50
3 files changed, 36 insertions, 30 deletions
diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c
index fb4f3a02d..81f1c2d5c 100644
--- a/src/arm/arm_api.c
+++ b/src/arm/arm_api.c
@@ -375,7 +375,7 @@ arm_service_report (void *cls,
375 const struct GNUNET_SCHEDULER_TaskContext *tc) 375 const struct GNUNET_SCHEDULER_TaskContext *tc)
376{ 376{
377 struct RequestContext *pos = cls; 377 struct RequestContext *pos = cls;
378 pid_t pid; 378 GNUNET_OS_Process *proc;
379 char *binary; 379 char *binary;
380 char *config; 380 char *config;
381 char *loprefix; 381 char *loprefix;
@@ -454,7 +454,7 @@ arm_service_report (void *cls,
454 ) 454 )
455 { 455 {
456 /* we're clearly running a test, don't daemonize */ 456 /* we're clearly running a test, don't daemonize */
457 pid = do_start_process (NULL, 457 proc = do_start_process (NULL,
458 loprefix, 458 loprefix,
459 binary, 459 binary,
460 "-c", config, 460 "-c", config,
@@ -467,7 +467,7 @@ arm_service_report (void *cls,
467 } 467 }
468 else 468 else
469 { 469 {
470 pid = do_start_process (NULL, 470 proc = do_start_process (NULL,
471 loprefix, 471 loprefix,
472 binary, 472 binary,
473 "-c", config, 473 "-c", config,
@@ -482,7 +482,7 @@ arm_service_report (void *cls,
482 GNUNET_free (config); 482 GNUNET_free (config);
483 GNUNET_free (loprefix); 483 GNUNET_free (loprefix);
484 GNUNET_free (lopostfix); 484 GNUNET_free (lopostfix);
485 if (pid == -1) 485 if (proc == NULL)
486 { 486 {
487 if (pos->callback != NULL) 487 if (pos->callback != NULL)
488 pos->callback (pos->cls, GNUNET_SYSERR); 488 pos->callback (pos->cls, GNUNET_SYSERR);
diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c
index d616ac2b7..7d691ce60 100644
--- a/src/arm/do_start_process.c
+++ b/src/arm/do_start_process.c
@@ -12,7 +12,7 @@
12 * @param ... more arguments, NULL terminated 12 * @param ... more arguments, NULL terminated
13 * @return PID of the started process, -1 on error 13 * @return PID of the started process, -1 on error
14 */ 14 */
15static pid_t 15static GNUNET_OS_Process *
16do_start_process (const int *lsocks, 16do_start_process (const int *lsocks,
17 const char *first_arg, ...) 17 const char *first_arg, ...)
18{ 18{
@@ -24,7 +24,7 @@ do_start_process (const int *lsocks,
24 char *pos; 24 char *pos;
25 char *cp; 25 char *cp;
26 const char *last; 26 const char *last;
27 pid_t pid; 27 GNUNET_OS_Process *proc;
28 28
29 argv_size = 1; 29 argv_size = 1;
30 va_start (ap, first_arg); 30 va_start (ap, first_arg);
@@ -88,9 +88,9 @@ do_start_process (const int *lsocks,
88 while (NULL != (arg = (va_arg (ap, const char*)))); 88 while (NULL != (arg = (va_arg (ap, const char*))));
89 va_end (ap); 89 va_end (ap);
90 argv[argv_size] = NULL; 90 argv[argv_size] = NULL;
91 pid = GNUNET_OS_start_process_v (lsocks, argv[0], argv); 91 proc = GNUNET_OS_start_process_v (lsocks, argv[0], argv);
92 while (argv_size > 0) 92 while (argv_size > 0)
93 GNUNET_free (argv[--argv_size]); 93 GNUNET_free (argv[--argv_size]);
94 GNUNET_free (argv); 94 GNUNET_free (argv);
95 return pid; 95 return proc;
96} 96}
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 2eb21a068..543e65557 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -91,9 +91,9 @@ struct ServiceList
91 struct GNUNET_SERVER_Client *killing_client; 91 struct GNUNET_SERVER_Client *killing_client;
92 92
93 /** 93 /**
94 * Process ID of the child. 94 * Process structure pointer of the child.
95 */ 95 */
96 pid_t pid; 96 GNUNET_OS_Process *proc;
97 97
98 /** 98 /**
99 * Last time the config of this service was 99 * Last time the config of this service was
@@ -199,11 +199,11 @@ config_change_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
199 /* FIXME: this test for config change is a bit too coarse grained */ 199 /* FIXME: this test for config change is a bit too coarse grained */
200 if ( (0 == STAT (pos->config, &sbuf)) && 200 if ( (0 == STAT (pos->config, &sbuf)) &&
201 (pos->mtime < sbuf.st_mtime) && 201 (pos->mtime < sbuf.st_mtime) &&
202 (pos->pid != 0) ) 202 (pos->proc != NULL) )
203 { 203 {
204 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
205 _("Restarting service `%s' due to configuration file change.\n")); 205 _("Restarting service `%s' due to configuration file change.\n"));
206 if (0 != PLIBC_KILL (pos->pid, SIGTERM)) 206 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
207 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 207 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
208 else 208 else
209 pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS; 209 pos->backoff = GNUNET_TIME_UNIT_MILLISECONDS;
@@ -414,7 +414,7 @@ start_process (struct ServiceList *sl,
414 sl->name, sl->binary, sl->config); 414 sl->name, sl->binary, sl->config);
415#endif 415#endif
416 if (GNUNET_YES == use_debug) 416 if (GNUNET_YES == use_debug)
417 sl->pid = do_start_process (lsocks, 417 sl->proc = do_start_process (lsocks,
418 loprefix, 418 loprefix,
419 sl->binary, 419 sl->binary,
420 "-c", sl->config, 420 "-c", sl->config,
@@ -422,19 +422,24 @@ start_process (struct ServiceList *sl,
422 options, 422 options,
423 NULL); 423 NULL);
424 else 424 else
425 sl->pid = do_start_process (lsocks, 425 sl->proc = do_start_process (lsocks,
426 loprefix, 426 loprefix,
427 sl->binary, 427 sl->binary,
428 "-c", sl->config, 428 "-c", sl->config,
429 options, 429 options,
430 NULL); 430 NULL);
431 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 431 if (sl->proc == NULL)
432 _("Starting service `%s' (PID: %d)\n"), 432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
433 sl->name, 433 _("Failed to start service `%s'\n"),
434 (int) sl->pid); 434 sl->name);
435 else
436 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
437 _("Starting service `%s' (PID: %d)\n"),
438 sl->name,
439 (int) GNUNET_OS_process_get_pid (sl->proc));
435 GNUNET_free (loprefix); 440 GNUNET_free (loprefix);
436 GNUNET_free (options); 441 GNUNET_free (options);
437 /* FIXME: should check sl->pid */ 442 /* FIXME: should check sl->proc */
438} 443}
439 444
440 445
@@ -568,7 +573,7 @@ stop_service (struct GNUNET_SERVER_Client *client,
568 running = pos; 573 running = pos;
569 return; 574 return;
570 } 575 }
571 if (pos->pid == 0) 576 if (pos->proc == NULL)
572 { 577 {
573 /* process is in delayed restart, simply remove it! */ 578 /* process is in delayed restart, simply remove it! */
574 free_entry (pos); 579 free_entry (pos);
@@ -581,7 +586,7 @@ stop_service (struct GNUNET_SERVER_Client *client,
581 "Sending kill signal to service `%s', waiting for process to die.\n", 586 "Sending kill signal to service `%s', waiting for process to die.\n",
582 servicename); 587 servicename);
583#endif 588#endif
584 if (0 != PLIBC_KILL (pos->pid, SIGTERM)) 589 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
585 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 590 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
586 pos->next = running; 591 pos->next = running;
587 running = pos; 592 running = pos;
@@ -653,7 +658,7 @@ handle_stop (void *cls,
653 658
654/** 659/**
655 * Remove all entries for tasks that are not running 660 * Remove all entries for tasks that are not running
656 * (pid = 0) from the running list (they will no longer 661 * (proc = NULL) from the running list (they will no longer
657 * be restarted since we are shutting down). 662 * be restarted since we are shutting down).
658 */ 663 */
659static void 664static void
@@ -668,7 +673,7 @@ clean_up_running ()
668 while (NULL != pos) 673 while (NULL != pos)
669 { 674 {
670 next = pos->next; 675 next = pos->next;
671 if (pos->pid == 0) 676 if (pos->proc == NULL)
672 { 677 {
673 if (prev == NULL) 678 if (prev == NULL)
674 running = next; 679 running = next;
@@ -727,13 +732,13 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
727 pos = running; 732 pos = running;
728 while (NULL != pos) 733 while (NULL != pos)
729 { 734 {
730 if (pos->pid != 0) 735 if (pos->proc != NULL)
731 { 736 {
732 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 737 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
733 "Stopping service `%s' (PID: %d)\n", 738 "Stopping service `%s' (PID: %d)\n",
734 pos->name, 739 pos->name,
735 pos->pid); 740 GNUNET_OS_process_get_pid (pos->proc));
736 if (0 != PLIBC_KILL (pos->pid, SIGTERM)) 741 if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
737 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 742 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
738 } 743 }
739 pos = pos->next; 744 pos = pos->next;
@@ -773,7 +778,7 @@ delayed_restart_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
773 pos = running; 778 pos = running;
774 while (pos != NULL) 779 while (pos != NULL)
775 { 780 {
776 if ( (pos->pid == 0) && 781 if ( (pos->proc == NULL) &&
777 (GNUNET_YES != in_shutdown) ) 782 (GNUNET_YES != in_shutdown) )
778 { 783 {
779 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0) 784 if (GNUNET_TIME_absolute_get_remaining (pos->restartAt).rel_value == 0)
@@ -845,12 +850,12 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
845 while (NULL != (pos = next)) 850 while (NULL != (pos = next))
846 { 851 {
847 next = pos->next; 852 next = pos->next;
848 if (pos->pid == 0) 853 if (pos->proc == NULL)
849 { 854 {
850 prev = pos; 855 prev = pos;
851 continue; 856 continue;
852 } 857 }
853 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->pid, 858 if ((GNUNET_SYSERR == (ret = GNUNET_OS_process_status (pos->proc,
854 &statusType, 859 &statusType,
855 &statusCode))) || 860 &statusCode))) ||
856 ( (ret == GNUNET_NO) || 861 ( (ret == GNUNET_NO) ||
@@ -876,7 +881,8 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
876 statstr = _( /* process termination method */ "unknown"); 881 statstr = _( /* process termination method */ "unknown");
877 statcode = 0; 882 statcode = 0;
878 } 883 }
879 pos->pid = 0; 884 GNUNET_OS_process_close (pos->proc);
885 pos->proc = NULL;
880 if (NULL != pos->killing_client) 886 if (NULL != pos->killing_client)
881 { 887 {
882 if (prev == NULL) 888 if (prev == NULL)