Skip to content

Commit

Permalink
Feature: sbd-inquisitor: don't fork if no pid-file given
Browse files Browse the repository at this point in the history
  • Loading branch information
wenningerk committed Jun 16, 2023
1 parent 5ec38cf commit 3ba9640
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
32 changes: 20 additions & 12 deletions src/sbd-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1160,11 +1160,28 @@ sbd_cdtocoredir(void)
return rc;
}

void
sbd_detach(void)
{
const char *devnull = "/dev/null";

maximize_priority();
sysrq_init();

umask(022);
close(0);
(void)open(devnull, O_RDONLY);
close(1);
(void)open(devnull, O_WRONLY);
close(2);
(void)open(devnull, O_WRONLY);
sbd_cdtocoredir();
}

pid_t
make_daemon(void)
{
pid_t pid;
const char * devnull = "/dev/null";

pid = fork();
if (pid < 0) {
Expand All @@ -1179,17 +1196,8 @@ make_daemon(void)
qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_FALSE);

/* This is the child; ensure privileges have not been lost. */
maximize_priority();
sysrq_init();

umask(022);
close(0);
(void)open(devnull, O_RDONLY);
close(1);
(void)open(devnull, O_WRONLY);
close(2);
(void)open(devnull, O_WRONLY);
sbd_cdtocoredir();
sbd_detach();

return 0;
}

Expand Down
9 changes: 8 additions & 1 deletion src/sbd-inquisitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,14 @@ int main(int argc, char **argv, char **envp)

cl_log(LOG_NOTICE, "%s flush + write \'%c\' to sysrq in case of timeout",
do_flush?"Do":"Skip", timeout_sysrq_char);
exit_status = inquisitor();
if (pidfile) {
exit_status = inquisitor();
} else {
sbd_detach();
inquisitor_child();
/* not reached */
exit(0);
}
} else {
exit_status = -2;
}
Expand Down
1 change: 1 addition & 0 deletions src/sbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void do_reset(void);
void do_off(void);
void do_timeout_action(void);
pid_t make_daemon(void);
void sbd_detach(void);
void maximize_priority(void);
void sbd_get_uname(void);
void sbd_set_format_string(int method, const char *daemon);
Expand Down

0 comments on commit 3ba9640

Please sign in to comment.