Skip to content

Commit

Permalink
Fixes #6604: handle SIGHUP for cf-serverd and cf-execd.
Browse files Browse the repository at this point in the history
cf-monitord doesn't have the same reloading framework, so will leave
that one for now.

Based on a patch by Nicolas CHARLES <nicolas.charles@normation.com>.
  • Loading branch information
kacf committed Mar 27, 2015
1 parent 0549eaa commit d0547c2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
19 changes: 16 additions & 3 deletions cf-execd/cf-execd.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void StartServer(EvalContext *ctx, Policy *policy, GenericAgentConfig *config, E
WritePID("cf-execd.pid");
signal(SIGINT, HandleSignalsForDaemon);
signal(SIGTERM, HandleSignalsForDaemon);
signal(SIGHUP, SIG_IGN);
signal(SIGHUP, HandleSignalsForDaemon);
signal(SIGPIPE, SIG_IGN);
signal(SIGUSR1, HandleSignalsForDaemon);
signal(SIGUSR2, HandleSignalsForDaemon);
Expand Down Expand Up @@ -474,13 +474,26 @@ static Reload CheckNewPromises(GenericAgentConfig *config)

time_t validated_at = ReadTimestampFromPolicyValidatedFile(config, NULL);

bool reload_config = false;

if (config->agent_specific.daemon.last_validated_at < validated_at)
{
Log(LOG_LEVEL_VERBOSE, "New promises detected...");
reload_config = true;
}
if (ReloadConfigRequested())
{
Log(LOG_LEVEL_VERBOSE, "Force reload of inputs files...");
reload_config = true;
}

if (reload_config)
{
ClearRequestReloadConfig();

/* Rereading policies now, so update timestamp. */
config->agent_specific.daemon.last_validated_at = validated_at;

Log(LOG_LEVEL_VERBOSE, "New promises detected...");

if (GenericAgentArePromisesValid(config))
{
return RELOAD_FULL;
Expand Down
19 changes: 16 additions & 3 deletions cf-serverd/cf-serverd-functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,26 @@ static void CheckFileChanges(EvalContext *ctx, Policy **policy, GenericAgentConf

time_t validated_at = ReadTimestampFromPolicyValidatedFile(config, NULL);

bool reload_config = false;

if (config->agent_specific.daemon.last_validated_at < validated_at)
{
Log(LOG_LEVEL_VERBOSE, "New promises detected...");
reload_config = true;
}
if (ReloadConfigRequested())
{
Log(LOG_LEVEL_VERBOSE, "Force reload of inputs files...");
reload_config = true;
}

if (reload_config)
{
ClearRequestReloadConfig();

/* Rereading policies now, so update timestamp. */
config->agent_specific.daemon.last_validated_at = validated_at;

Log(LOG_LEVEL_VERBOSE, "New promises detected...");

if (GenericAgentArePromisesValid(config))
{
Log(LOG_LEVEL_NOTICE, "Rereading policy file '%s'",
Expand Down Expand Up @@ -563,7 +576,7 @@ static void InitSignals()

signal(SIGINT, HandleSignalsForDaemon);
signal(SIGTERM, HandleSignalsForDaemon);
signal(SIGHUP, SIG_IGN);
signal(SIGHUP, HandleSignalsForDaemon);
signal(SIGPIPE, SIG_IGN);
signal(SIGUSR1, HandleSignalsForDaemon);
signal(SIGUSR2, HandleSignalsForDaemon);
Expand Down
15 changes: 14 additions & 1 deletion libpromises/signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,24 @@

static bool PENDING_TERMINATION = false; /* GLOBAL_X */

static bool RELOAD_CONFIG = false; /* GLOBAL_X */
/********************************************************************/

bool IsPendingTermination(void)
{
return PENDING_TERMINATION;
}

bool ReloadConfigRequested(void)
{
return RELOAD_CONFIG;
}

void ClearRequestReloadConfig()
{
RELOAD_CONFIG = false;
}

/********************************************************************/

static int SIGNAL_PIPE[2] = { -1, -1 }; /* GLOBAL_C */
Expand Down Expand Up @@ -160,7 +171,6 @@ void HandleSignalsForDaemon(int signum)
{
case SIGTERM:
case SIGINT:
case SIGHUP:
case SIGSEGV:
case SIGKILL:
PENDING_TERMINATION = true;
Expand All @@ -171,6 +181,9 @@ void HandleSignalsForDaemon(int signum)
case SIGUSR2:
LogSetGlobalLevel(LOG_LEVEL_NOTICE);
break;
case SIGHUP:
RELOAD_CONFIG = true;
break;
case SIGPIPE:
default:
/* No action */
Expand Down
3 changes: 3 additions & 0 deletions libpromises/signals.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
// check whether the running daemon should terminate after having received a signal.
bool IsPendingTermination(void);

bool ReloadConfigRequested(void);
void ClearRequestReloadConfig();

void MakeSignalPipe(void);
int GetSignalPipe(void);
void HandleSignalsForDaemon(int signum);
Expand Down

0 comments on commit d0547c2

Please sign in to comment.