Skip to content

Commit

Permalink
Make report_child_status() check for vrrp and checker child processes
Browse files Browse the repository at this point in the history
report_child_status() checks for exit status KEEPALIVED_EXIT_FATAL
and KEEPALIVED_EXIT_CONFIG, but these are only relevant for the vrrp
and checker child processes, and not for track scripts etc. This commit
adds a check that the terminating process is the vrrp or checker process
before checking those exit statuses.

Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
  • Loading branch information
pqarmitage committed Oct 4, 2016
1 parent b25ae9c commit ca955a7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
20 changes: 20 additions & 0 deletions keepalived/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,23 @@ make_pidfile_name(const char* start, const char* instance, const char* extn)
return name;
}

static bool
find_keepalived_child(pid_t pid, char const **prog_name)
{
#ifdef _WITH_LVS_
if (pid == checkers_child)
*prog_name = PROG_CHECK;
#endif
#ifdef _WITH_VRRP_
else if (pid == vrrp_child)
*prog_name = PROG_VRRP;
#endif
else
return false;

return true;
}

#if HAVE_DECL_CLONE_NEWNET
static vector_t *
global_init_keywords(void)
Expand Down Expand Up @@ -712,6 +729,9 @@ keepalived_main(int argc, char **argv)
/* Init debugging level */
debug = 0;

/* Initialise pointer to child finding function */
set_child_finder(find_keepalived_child);

/* Initialise daemon_mode */
#ifdef _WITH_VRRP_
__set_bit(DAEMON_VRRP, &daemon_mode);
Expand Down
36 changes: 30 additions & 6 deletions lib/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,53 @@
#include "logger.h"
#include "bitops.h"


/* global vars */
thread_master_t *master = NULL;

#ifdef _WITH_LVS_
#include "../keepalived/include/check_daemon.h"
#endif
#ifdef _WITH_VRRP_
#include "../keepalived/include/vrrp_daemon.h"
#endif
#include "../keepalived/include/main.h"

/* Function that returns if pid is a known child, and sets *prog_name accordingly */
static bool (*child_finder)(pid_t pid, char const **prog_name);

void
set_child_finder(bool (*func)(pid_t, char const **))
{
child_finder = func;
}

/* report_child_status returns true if the exit is a hard error, so unable to continue */
bool
report_child_status(int status, pid_t pid, const char *prog_name)
report_child_status(int status, pid_t pid, char const *prog_name)
{
const char *prog_id;
char const *prog_id = NULL;
char pid_buf[10]; /* "pid 32767" + '\0' */
int exit_status ;
bool keepalived_child_process = false;

if (prog_name)
if (prog_name) {
prog_id = prog_name;
keepalived_child_process = true;
}
else if (child_finder && child_finder(pid, &prog_id))
keepalived_child_process = true;
else {
snprintf(pid_buf, sizeof(pid_buf), "pid %d", pid);
prog_id = pid_buf;
}

if (WIFEXITED(status)) {
exit_status = WEXITSTATUS(status);
if (exit_status == KEEPALIVED_EXIT_FATAL ||
exit_status == KEEPALIVED_EXIT_CONFIG) {

/* Handle exit codes of vrrp or checker child */
if (keepalived_child_process &&
(exit_status == KEEPALIVED_EXIT_FATAL ||
exit_status == KEEPALIVED_EXIT_CONFIG)) {
log_message(LOG_INFO, "%s exited with permanent error %s. Terminating", prog_id, exit_status == KEEPALIVED_EXIT_CONFIG ? "CONFIG" : "FATAL" );
return true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ typedef struct _thread_master {
extern thread_master_t *master;

/* Prototypes. */
extern void set_child_finder(bool (*)(pid_t, char const **));
extern bool report_child_status(int, pid_t, const char *);
extern thread_master_t *thread_make_master(void);
extern thread_t *thread_add_terminate_event(thread_master_t *);
Expand Down

0 comments on commit ca955a7

Please sign in to comment.