Skip to content

Commit

Permalink
campaignd: Reload configuration on SIGHUP
Browse files Browse the repository at this point in the history
It's a bit tricky right now because whoever changes the configuration
must make sure to do it within the flush interval or their changes may
be lost before they get to send SIGHUP to campaignd. Another issue is
that the campaigns list may change (new uploads, bumped download counts,
etc.) between editing the config file and sending SIGHUP, and any
changes in the on-memory version of the list will be irreversibly lost.

Hopefully soon I'll add some socket commands to address these
limitations.
  • Loading branch information
irydacea committed Apr 20, 2015
1 parent 4b2935b commit 911f59f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -62,11 +62,17 @@ static lg::log_domain log_campaignd("campaignd");

namespace {

void exit_sighup(int signal)
/**
* Whether to reload the server configuration as soon as possible
* (e.g. after SIGHUP).
*/
sig_atomic_t need_reload = 0;

void flag_sighup(int signal)
{
assert(signal == SIGHUP);
LOG_CS << "SIGHUP caught, exiting without cleanup immediately.\n";
exit(128 + SIGHUP);
LOG_CS << "SIGHUP caught, scheduling config reload.\n";
need_reload = 1;
}

void exit_sigint(int signal)
Expand Down Expand Up @@ -114,7 +120,7 @@ server::server(const std::string& cfg_file, size_t min_threads, size_t max_threa
, server_manager_(load_config())
{
#ifndef _MSC_VER
signal(SIGHUP, exit_sighup);
signal(SIGHUP, flag_sighup);
#endif
signal(SIGINT, exit_sigint);
signal(SIGTERM, exit_sigterm);
Expand Down Expand Up @@ -269,6 +275,15 @@ void server::run()

for(;;)
{
if(need_reload) {
load_config(); // TODO: handle port number config changes

need_reload = 0;
last_ts = 0;

LOG_CS << "Reloaded configuration\n";
}

try {
std::string admin_cmd;

Expand Down

0 comments on commit 911f59f

Please sign in to comment.