Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fencing: Prevent sending SIGTERM to stonithd when stointh operation timed out #334

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions fencing/fence_legacy
Expand Up @@ -190,12 +190,7 @@ $opt_o=lc($opt_o);
fail "failed: unrecognised action: $opt_o"
unless $opt_o =~ /^(on|off|reset|reboot|stat|status|monitor|list|hostlist|poweroff|poweron)$/;

sub term_handler {
local $SIG{TERM} = 'IGNORE';
kill(TERM,-getpgrp($$));
}

setpgrp($$,0);
setpgrp(0,0);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, these two lines are functionally equivalent.

if ( $pid=fork() == 0 )
{
Expand Down Expand Up @@ -229,7 +224,6 @@ if ( $pid=fork() == 0 )
}
}

$SIG{TERM} = \&term_handler;
wait;
$status=$?/256;

Expand Down
8 changes: 1 addition & 7 deletions fencing/fence_pcmk
Expand Up @@ -182,12 +182,7 @@ $opt_o=lc($opt_o);
fail "failed: unrecognised action: $opt_o"
unless $opt_o =~ /^(on|off|reset|reboot|stat|status|monitor|list|hostlist|poweroff|poweron)$/;

sub term_handler {
local $SIG{TERM} = 'IGNORE';
kill(TERM,-getpgrp($$));
}

setpgrp($$,0);
setpgrp(0,0);
$agent_pid=$$;

if ( $pid=fork() == 0 )
Expand All @@ -210,7 +205,6 @@ if ( $pid=fork() == 0 )
exec "stonith_admin $cmd $opt_n --tolerance 5s --tag cman" or die "failed to exec \"stonith_admin $cmd $opt_n\"\n";
}

$SIG{TERM} = \&term_handler;
wait;
$status=$?/256;

Expand Down
6 changes: 3 additions & 3 deletions lib/fencing/st_client.c
Expand Up @@ -506,7 +506,7 @@ st_child_term(gpointer data)
crm_info("Child %d timed out, sending SIGTERM", track->pid);
track->timer_sigterm = 0;
track->last_timeout_signo = SIGTERM;
rc = kill(track->pid, SIGTERM);
rc = kill(-track->pid, SIGTERM);
if (rc < 0) {
crm_perror(LOG_ERR, "Couldn't send SIGTERM to %d", track->pid);
}
Expand All @@ -522,7 +522,7 @@ st_child_kill(gpointer data)
crm_info("Child %d timed out, sending SIGKILL", track->pid);
track->timer_sigkill = 0;
track->last_timeout_signo = SIGKILL;
rc = kill(track->pid, SIGKILL);
rc = kill(-track->pid, SIGKILL);
if (rc < 0) {
crm_perror(LOG_ERR, "Couldn't send SIGKILL to %d", track->pid);
}
Expand Down Expand Up @@ -835,7 +835,7 @@ internal_stonith_action_execute(stonith_action_t * action)
}

if (timeout == 0) {
int killrc = kill(pid, SIGKILL);
int killrc = kill(-pid, SIGKILL);

if (killrc && errno != ESRCH) {
crm_err("kill(%d, KILL) failed: %s (%d)", pid, pcmk_strerror(errno), errno);
Expand Down