diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-06-12 01:24:28 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-06-12 01:24:28 +0000 |
commit | 9b2e67785fb65dd687a1365a1838a1af8aca902a (patch) | |
tree | 1b908d4bbc5e64ba87f81cc3ce09f6cf2839704f /src | |
parent | e785620e70ca5213d4aca91cd48e95b70eca0c81 (diff) | |
download | gnunet-9b2e67785fb65dd687a1365a1838a1af8aca902a.tar.gz gnunet-9b2e67785fb65dd687a1365a1838a1af8aca902a.zip |
more arm, waidpid fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/arm/gnunet-service-arm.c | 87 | ||||
-rw-r--r-- | src/util/os_priority.c | 4 |
2 files changed, 55 insertions, 36 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 3a93c654b..66df86e45 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -396,7 +396,6 @@ free_and_signal (void *cls, struct ServiceList *pos) | |||
396 | { | 396 | { |
397 | struct GNUNET_SERVER_Client *client = cls; | 397 | struct GNUNET_SERVER_Client *client = cls; |
398 | /* find_name will remove "pos" from the list! */ | 398 | /* find_name will remove "pos" from the list! */ |
399 | GNUNET_assert (pos == find_name (pos->name)); | ||
400 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Service `%s' stopped\n", pos->name); | 399 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Service `%s' stopped\n", pos->name); |
401 | signal_result (client, pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); | 400 | signal_result (client, pos->name, GNUNET_MESSAGE_TYPE_ARM_IS_DOWN); |
402 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 401 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -526,6 +525,8 @@ static void | |||
526 | maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 525 | maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
527 | { | 526 | { |
528 | struct ServiceList *pos; | 527 | struct ServiceList *pos; |
528 | struct ServiceList *prev; | ||
529 | struct ServiceList *next; | ||
529 | const char *statstr; | 530 | const char *statstr; |
530 | int statcode; | 531 | int statcode; |
531 | struct stat sbuf; | 532 | struct stat sbuf; |
@@ -552,45 +553,66 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
552 | MAINT_FREQUENCY, &maint, cfg); | 553 | MAINT_FREQUENCY, &maint, cfg); |
553 | 554 | ||
554 | /* check for services that died (WAITPID) */ | 555 | /* check for services that died (WAITPID) */ |
555 | for (pos = running; pos != NULL; pos = pos->next) | 556 | prev = NULL; |
557 | next = running; | ||
558 | while (NULL != (pos = next)) | ||
556 | { | 559 | { |
557 | enum GNUNET_OS_ProcessStatusType statusType; | 560 | enum GNUNET_OS_ProcessStatusType statusType; |
558 | unsigned long statusCode; | 561 | unsigned long statusCode; |
559 | 562 | ||
560 | if (GNUNET_SYSERR == (ret = GNUNET_OS_process_status(pos->pid, &statusType, &statusCode))) | 563 | next = pos->next; |
561 | continue; | 564 | if (pos->pid == 0) |
562 | if ( (ret == GNUNET_NO) || | 565 | { |
563 | (statusType == GNUNET_OS_PROCESS_STOPPED) || | 566 | if (NULL != pos->kill_continuation) |
564 | (statusType == GNUNET_OS_PROCESS_RUNNING) ) | 567 | { |
565 | continue; | 568 | if (prev == NULL) |
569 | running = next; | ||
570 | else | ||
571 | prev->next = next; | ||
572 | pos->kill_continuation (pos->kill_continuation_cls, pos); | ||
573 | } | ||
574 | continue; | ||
575 | } | ||
576 | if ( (GNUNET_SYSERR == (ret = GNUNET_OS_process_status(pos->pid, | ||
577 | &statusType, | ||
578 | &statusCode))) || | ||
579 | ( (ret == GNUNET_NO) || | ||
580 | (statusType == GNUNET_OS_PROCESS_STOPPED) || | ||
581 | (statusType == GNUNET_OS_PROCESS_RUNNING) ) ) | ||
582 | { | ||
583 | prev = pos; | ||
584 | continue; | ||
585 | } | ||
566 | if (statusType == GNUNET_OS_PROCESS_EXITED) | 586 | if (statusType == GNUNET_OS_PROCESS_EXITED) |
567 | { | 587 | { |
568 | statstr = _( /* process termination method */ "exit"); | 588 | statstr = _( /* process termination method */ "exit"); |
569 | statcode = statusCode; | 589 | statcode = statusCode; |
570 | } | 590 | } |
571 | else if (statusType == GNUNET_OS_PROCESS_SIGNALED) | 591 | else if (statusType == GNUNET_OS_PROCESS_SIGNALED) |
572 | { | 592 | { |
573 | statstr = _( /* process termination method */ "signal"); | 593 | statstr = _( /* process termination method */ "signal"); |
574 | statcode = statusCode; | 594 | statcode = statusCode; |
575 | } | 595 | } |
576 | else | 596 | else |
577 | { | 597 | { |
578 | statstr = _( /* process termination method */ "unknown"); | 598 | statstr = _( /* process termination method */ "unknown"); |
579 | statcode = 0; | 599 | statcode = 0; |
580 | } | 600 | } |
581 | if (NULL != pos->kill_continuation) | 601 | if (NULL != pos->kill_continuation) |
582 | { | 602 | { |
583 | pos->kill_continuation (pos->kill_continuation_cls, pos); | 603 | if (prev == NULL) |
584 | } | 604 | running = next; |
585 | else | 605 | else |
586 | { | 606 | prev->next = next; |
587 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 607 | pos->kill_continuation (pos->kill_continuation_cls, pos); |
588 | _ | 608 | continue; |
589 | ("Service `%s' terminated with status %s/%d, will try to restart it!\n"), | ||
590 | pos->name, statstr, statcode); | ||
591 | /* schedule restart */ | ||
592 | pos->pid = 0; | ||
593 | } | 609 | } |
610 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
611 | _("Service `%s' terminated with status %s/%d, will try to restart it!\n"), | ||
612 | pos->name, statstr, statcode); | ||
613 | /* schedule restart */ | ||
614 | pos->pid = 0; | ||
615 | prev = pos; | ||
594 | } | 616 | } |
595 | 617 | ||
596 | /* check for services that need to be restarted due to | 618 | /* check for services that need to be restarted due to |
@@ -601,8 +623,7 @@ maint (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
601 | if ((0 == STAT (pos->config, &sbuf)) && (pos->mtime < sbuf.st_mtime)) | 623 | if ((0 == STAT (pos->config, &sbuf)) && (pos->mtime < sbuf.st_mtime)) |
602 | { | 624 | { |
603 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 625 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
604 | _ | 626 | _("Restarting service `%s' due to configuration file change.\n")); |
605 | ("Restarting service `%s' due to configuration file change.\n")); | ||
606 | if (0 != PLIBC_KILL (pos->pid, SIGTERM)) | 627 | if (0 != PLIBC_KILL (pos->pid, SIGTERM)) |
607 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 628 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
608 | } | 629 | } |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 16537dfcd..4e820b8d5 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -274,9 +274,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, | |||
274 | 274 | ||
275 | GNUNET_assert (0 != proc); | 275 | GNUNET_assert (0 != proc); |
276 | ret = waitpid (proc, &status, WNOHANG); | 276 | ret = waitpid (proc, &status, WNOHANG); |
277 | if ( (0 == ret) || | 277 | if (0 == ret) |
278 | ( (-1 == ret) && | ||
279 | (ECHILD == errno) ) ) | ||
280 | { | 278 | { |
281 | *type = GNUNET_OS_PROCESS_RUNNING; | 279 | *type = GNUNET_OS_PROCESS_RUNNING; |
282 | *code = 0; | 280 | *code = 0; |