Skip to content

Commit

Permalink
drivers/upsdrvctl.c: SIGKILL a driver instance if SIGTERM did not [ne…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimklimov committed May 13, 2022
1 parent f4a3c9e commit 9643988
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions drivers/upsdrvctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void do_upsconf_args(char *upsname, char *var, char *val)
static void stop_driver(const ups_t *ups)
{
char pidfn[SMALLBUF];
int ret;
int ret, i;
struct stat fs;

upsdebugx(1, "Stopping UPS: %s", ups->upsname);
Expand Down Expand Up @@ -176,10 +176,37 @@ static void stop_driver(const ups_t *ups)
ret = sendsignalfn(pidfn, SIGTERM);

if (ret < 0) {
upslog_with_errno(LOG_ERR, "Stopping %s failed", pidfn);
exec_error++;
return;
upsdebugx(2, "SIGTERM to %s failed, retrying with SIGKILL", pidfn);
ret = sendsignalfn(pidfn, SIGKILL);
if (ret < 0) {
upslog_with_errno(LOG_ERR, "Stopping %s failed", pidfn);
exec_error++;
return;
}
}

for (i = 0; i < 5 ; i++) {
if (sendsignalfn(pidfn, 0) != 0) {
upsdebugx(2, "Sending signal to %s failed, driver is finally down or wrongly owned", pidfn);
return;
}
sleep(1);
}

upslog_with_errno(LOG_ERR, "Stopping %s failed, retrying harder", pidfn);
ret = sendsignalfn(pidfn, SIGKILL);
if (ret == 0) {
for (i = 0; i < 5 ; i++) {
if (sendsignalfn(pidfn, 0) != 0) {
upsdebugx(2, "Sending signal to %s failed, driver is finally down or wrongly owned", pidfn);
return;
}
sleep(1);
}
}

upslog_with_errno(LOG_ERR, "Stopping %s failed", pidfn);
exec_error++;
}

static void waitpid_timeout(const int sig)
Expand Down

0 comments on commit 9643988

Please sign in to comment.