Skip to content

Commit 6079caf

Browse files
authored
Fix supervisor messages about exited services. (#589)
The waitpid() reading of the conditions that lead to a process being reported are more complex than the previous implementation assumed.
1 parent 5ef1078 commit 6079caf

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

src/bin/pg_autoctl/supervisor.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,6 @@ supervisor_shutdown_sequence(Supervisor *supervisor)
619619
static bool
620620
supervisor_restart_service(Supervisor *supervisor, Service *service, int status)
621621
{
622-
char *verb = WIFEXITED(status) ? "exited" : "failed";
623-
int returnCode = WEXITSTATUS(status);
624622
uint64_t now = time(NULL);
625623
int logLevel = LOG_ERROR;
626624

@@ -643,13 +641,34 @@ supervisor_restart_service(Supervisor *supervisor, Service *service, int status)
643641
}
644642

645643
/* when a sub-process has quit and we're not shutting down, warn about it */
646-
else if (returnCode == EXIT_CODE_QUIT)
644+
else if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_CODE_QUIT)
647645
{
648646
logLevel = LOG_WARN;
649647
}
650648

651-
log_level(logLevel, "pg_autoctl service %s %s with exit status %d",
652-
service->name, verb, returnCode);
649+
if (WIFEXITED(status))
650+
{
651+
int returnCode = WEXITSTATUS(status);
652+
653+
log_level(logLevel, "pg_autoctl service %s exited with exit status %d",
654+
service->name, returnCode);
655+
}
656+
else if (WIFSIGNALED(status))
657+
{
658+
int signal = WTERMSIG(status);
659+
660+
log_level(logLevel,
661+
"pg_autoctl service %s exited after receiving signal %s",
662+
service->name, strsignal(signal));
663+
}
664+
else if (WIFSTOPPED(status))
665+
{
666+
/* well that's unexpected, we're not using WUNTRACED */
667+
log_level(logLevel,
668+
"pg_autoctl service %s has been stopped and can be restarted",
669+
service->name);
670+
return false;
671+
}
653672

654673
/*
655674
* We don't restart temporary processes at all: we're done already.
@@ -697,7 +716,9 @@ supervisor_restart_service(Supervisor *supervisor, Service *service, int status)
697716
* pg_autoctl create monitor
698717
* pg_autoctl create postgres
699718
*/
700-
if (service->policy == RP_TRANSIENT && returnCode == EXIT_CODE_QUIT)
719+
if (service->policy == RP_TRANSIENT &&
720+
WIFEXITED(status) &&
721+
WEXITSTATUS(status) == EXIT_CODE_QUIT)
701722
{
702723
/* exit with a happy exit code, and process with shutdown sequence */
703724
supervisor->cleanExit = true;

0 commit comments

Comments
 (0)