ServerPool *servers = NULL;
volatile bool hupped = false;
+volatile bool stopped = false;
-void hup(int ignored)
+void hup(int signum)
{
hupped = true;
+ if (signum == SIGINT) {
+ stopped = true;
+ }
}
CubemapStateProto collect_state(const timeval &serialize_start,
int main(int argc, char **argv)
{
signal(SIGHUP, hup);
+ signal(SIGINT, hup);
signal(SIGPIPE, SIG_IGN);
// Parse options.
}
servers->stop();
- log(INFO, "Serializing state and re-execing...");
- CubemapStateProto state = collect_state(
- serialize_start, acceptors, inputs, servers);
- string serialized;
- state.SerializeToString(&serialized);
- state_fd = make_tempfile(serialized);
- if (state_fd == -1) {
- exit(1);
+ CubemapStateProto state;
+ if (stopped) {
+ log(INFO, "Shutting down.");
+ } else {
+ log(INFO, "Serializing state and re-execing...");
+ state = collect_state(
+ serialize_start, acceptors, inputs, servers);
+ string serialized;
+ state.SerializeToString(&serialized);
+ state_fd = make_tempfile(serialized);
+ if (state_fd == -1) {
+ exit(1);
+ }
}
delete servers;
shut_down_logging();
+ if (stopped) {
+ exit(0);
+ }
+
+ // OK, so the signal was SIGHUP. Check that the new config is okay, then exec the new binary.
if (!dry_run_config(argv[0], config_filename)) {
open_logs(config.log_destinations);
log(ERROR, "%s --test-config failed. Restarting old version instead of new.", argv[0]);
shut_down_logging();
goto start;
}
-
char buf[16];
sprintf(buf, "%d", state_fd);