Skip to content

Commit 856d4e7

Browse files
authored
Bug fix: if process is stopped, refrain from signaling PID 0. (#921)
* Bug fix: if process is stopped, refrain from signaling PID 0. * Add missing init for the Postgres expected status file.
1 parent 7efa0a0 commit 856d4e7

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/bin/pg_autoctl/cli_drop_node.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ cli_drop_local_node(KeeperConfig *config, bool dropAndDestroy)
638638
* so we can take over. This can happen either because --force was used
639639
* or because 30 seconds was not enough time for the service to exit.
640640
*/
641-
if (!stopped)
641+
if (!stopped && pid != 0)
642642
{
643643
/* if the service isn't terminated, signal it to quit now */
644644
log_info("Sending signal %s to pg_autoctl process %d",
@@ -670,6 +670,8 @@ cli_drop_local_node(KeeperConfig *config, bool dropAndDestroy)
670670
*/
671671
bool dropped = false;
672672

673+
local_postgres_init(&(keeper.postgres), &(config->pgSetup));
674+
673675
if (keeper_ensure_node_has_been_dropped(&keeper, &dropped) && dropped)
674676
{
675677
log_info("This node with id %lld in formation \"%s\" and group %d "

src/bin/pg_autoctl/pidfile.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,11 @@ pidfile_as_json(JSON_Value *js, const char *pidfile, bool includeStatus)
499499
}
500500

501501

502+
/*
503+
* is_process_stopped reads given pidfile and checks if the included PID
504+
* belongs to a process that's still running, and if not, sets the *stopped
505+
* boolean to true.
506+
*/
502507
bool
503508
is_process_stopped(const char *pidfile, bool *stopped, pid_t *pid)
504509
{
@@ -520,8 +525,8 @@ is_process_stopped(const char *pidfile, bool *stopped, pid_t *pid)
520525

521526

522527
/*
523-
* wait_for_process_to_stop waits until the PID found in the pidfile is not running
524-
* anymore.
528+
* wait_for_process_to_stop waits until the PID found in the pidfile is not
529+
* running anymore.
525530
*/
526531
bool
527532
wait_for_process_to_stop(const char *pidfile, int timeout, bool *stopped, pid_t *pid)
@@ -532,6 +537,12 @@ wait_for_process_to_stop(const char *pidfile, int timeout, bool *stopped, pid_t
532537
return false;
533538
}
534539

540+
/* if the process has stopped already, we're done here */
541+
if (*stopped)
542+
{
543+
return true;
544+
}
545+
535546
log_info("An instance of pg_autoctl is running with PID %d, "
536547
"waiting for it to stop.", *pid);
537548

0 commit comments

Comments
 (0)