Skip to content

Commit

Permalink
Bug fix: if process is stopped, refrain from signaling PID 0. (#921)
Browse files Browse the repository at this point in the history
* Bug fix: if process is stopped, refrain from signaling PID 0.

* Add missing init for the Postgres expected status file.
  • Loading branch information
DimCitus committed Aug 18, 2022
1 parent 7efa0a0 commit 856d4e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/bin/pg_autoctl/cli_drop_node.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ cli_drop_local_node(KeeperConfig *config, bool dropAndDestroy)
* so we can take over. This can happen either because --force was used
* or because 30 seconds was not enough time for the service to exit.
*/
if (!stopped)
if (!stopped && pid != 0)
{
/* if the service isn't terminated, signal it to quit now */
log_info("Sending signal %s to pg_autoctl process %d",
Expand Down Expand Up @@ -670,6 +670,8 @@ cli_drop_local_node(KeeperConfig *config, bool dropAndDestroy)
*/
bool dropped = false;

local_postgres_init(&(keeper.postgres), &(config->pgSetup));

if (keeper_ensure_node_has_been_dropped(&keeper, &dropped) && dropped)
{
log_info("This node with id %lld in formation \"%s\" and group %d "
Expand Down
15 changes: 13 additions & 2 deletions src/bin/pg_autoctl/pidfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ pidfile_as_json(JSON_Value *js, const char *pidfile, bool includeStatus)
}


/*
* is_process_stopped reads given pidfile and checks if the included PID
* belongs to a process that's still running, and if not, sets the *stopped
* boolean to true.
*/
bool
is_process_stopped(const char *pidfile, bool *stopped, pid_t *pid)
{
Expand All @@ -520,8 +525,8 @@ is_process_stopped(const char *pidfile, bool *stopped, pid_t *pid)


/*
* wait_for_process_to_stop waits until the PID found in the pidfile is not running
* anymore.
* wait_for_process_to_stop waits until the PID found in the pidfile is not
* running anymore.
*/
bool
wait_for_process_to_stop(const char *pidfile, int timeout, bool *stopped, pid_t *pid)
Expand All @@ -532,6 +537,12 @@ wait_for_process_to_stop(const char *pidfile, int timeout, bool *stopped, pid_t
return false;
}

/* if the process has stopped already, we're done here */
if (*stopped)
{
return true;
}

log_info("An instance of pg_autoctl is running with PID %d, "
"waiting for it to stop.", *pid);

Expand Down

0 comments on commit 856d4e7

Please sign in to comment.