Skip to content

Commit

Permalink
Merge pull request #2394 from pqarmitage/updates
Browse files Browse the repository at this point in the history
core: make startup/shutdown scripts work when not using --dont-fork
  • Loading branch information
pqarmitage authored Mar 19, 2024
2 parents 43a0582 + 7b5c03f commit 45f6beb
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions keepalived/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2781,19 +2781,36 @@ keepalived_main(int argc, char **argv)
}

/* daemonize process */
if (!__test_bit(DONT_FORK_BIT, &debug) && xdaemon() > 0) {
closelog();
FREE_CONST_PTR(config_id);
FREE_PTR(orig_core_dump_pattern);
close_std_fd();
exit(0);
if (!__test_bit(DONT_FORK_BIT, &debug)) {
pid_t old_ppid = getpid();

if (xdaemon() > 0) {
/* Parent process */
closelog();
FREE_CONST_PTR(config_id);
FREE_PTR(orig_core_dump_pattern);
close_std_fd();
exit(0);
}

/* Child process */

/* check_start_stop_script_secure() called below makes a check
* that our parent process hasn't changed, but it can take a while
* for the parent of the fork to exit which is when our parent pid
* changes. We need to loop until that has happened. */
while (old_ppid == getppid())
usleep(10);
}

#ifdef _MEM_CHECK_
enable_mem_log_termination();
#endif

if (global_data->startup_script || global_data->shutdown_script) {
/* This is a workaround for the check in check_start_stop_script_secure() */
main_pid = getppid();

magic = ka_magic_open();
script_flags = 0;
if (global_data->startup_script)
Expand Down

0 comments on commit 45f6beb

Please sign in to comment.