Use explicit serverMode enum values everywhere

This commit is contained in:
Andrew Bettison 2018-06-01 17:40:09 +09:30
parent bbe7a87904
commit f91033820b
8 changed files with 29 additions and 26 deletions

View File

@ -155,7 +155,7 @@ dna_helper_close_pipes()
static void dna_helper_start()
{
dna_helper_shutdown();
if (!serverMode)
if (serverMode == SERVER_NOT_RUNNING)
return;
if (!config.dna.helper.executable[0]) {

View File

@ -607,7 +607,7 @@ static void set_mdp_packet_rules(struct packet_rule *rules)
int reload_mdp_packet_rules()
{
if (!config.mdp.filter_rules_path[0]) {
if (packet_rules_meta.mtime.tv_sec != -1 && serverMode)
if (packet_rules_meta.mtime.tv_sec != -1 && serverMode != SERVER_NOT_RUNNING)
INFOF("no packet rules file configured");
clear_mdp_packet_rules();
packet_rules_meta = FILE_META_UNKNOWN;
@ -624,7 +624,7 @@ int reload_mdp_packet_rules()
DEBUGF(mdp_filter, "packet_rules_meta=%s", alloca_file_meta(&packet_rules_meta));
if (cmp_file_meta(&meta, &packet_rules_meta) == 0)
return 0; // no change since last load
if (packet_rules_meta.mtime.tv_sec != -1 && serverMode)
if (packet_rules_meta.mtime.tv_sec != -1 && serverMode != SERVER_NOT_RUNNING)
INFOF("packet rules file %s -- detected new version", rules_path);
int ret = 1;
if (meta.mtime.tv_sec == -1) {

View File

@ -120,7 +120,7 @@ struct profile_total client_stats;
static void monitor_setup_sockets()
{
if (serverMode==0)
if (serverMode == SERVER_NOT_RUNNING)
return;
int sock = -1;
@ -148,7 +148,7 @@ static void monitor_setup_sockets()
error:
if (sock != -1)
close(sock);
serverMode=0;
serverMode = SERVER_NOT_RUNNING;
}
DEFINE_TRIGGER(startup, monitor_setup_sockets);
@ -182,7 +182,7 @@ void monitor_poll(struct sched_ent *alarm)
static void monitor_close(struct monitor_context *c){
INFOF("Tearing down monitor client fd=%d", c->alarm.poll.fd);
if (serverMode && (c->flags & MONITOR_QUIT_ON_DISCONNECT)){
if (serverMode != SERVER_NOT_RUNNING && (c->flags & MONITOR_QUIT_ON_DISCONNECT)){
INFOF("Stopping server due to client disconnecting");
server_close();
}

View File

@ -62,7 +62,7 @@ static __thread struct subscriber *my_subscriber = NULL;
struct subscriber *get_my_subscriber(bool_t create)
{
if (!serverMode)
if (serverMode == SERVER_NOT_RUNNING)
return NULL;
if (my_subscriber && my_subscriber->reachable != REACHABLE_SELF)
my_subscriber = NULL;
@ -140,7 +140,7 @@ void free_subscribers()
{
// don't attempt to free anything if we're running as a server
// who knows where subscriber ptr's may have leaked to.
if (serverMode)
if (serverMode != SERVER_NOT_RUNNING)
FATAL("Freeing subscribers from a running daemon is not supported");
tree_walk(&root, NULL, 0, free_node, NULL);
}

View File

@ -1546,7 +1546,7 @@ static void rescan_soon(time_ms_t run_at){
static void overlay_interface_config_change()
{
if (!serverMode)
if (serverMode == SERVER_NOT_RUNNING)
return;
// bring down all interfaces that no longer match any configuration

View File

@ -249,7 +249,7 @@ DEFINE_TRIGGER(shutdown, overlay_mdp_shutdown);
static void overlay_mdp_setup_sockets()
{
if (serverMode==0)
if (serverMode == SERVER_NOT_RUNNING)
return;
/* Delete stale socket files from instance directory. */
@ -258,7 +258,7 @@ static void overlay_mdp_setup_sockets()
if (mdp_sock.poll.fd == -1) {
mdp_sock.poll.fd = mdp_bind_socket("mdp.socket");
if (mdp_sock.poll.fd == -1){
serverMode=0;
serverMode = SERVER_NOT_RUNNING;
return;
}
mdp_sock.poll.events = POLLIN;
@ -268,7 +268,7 @@ static void overlay_mdp_setup_sockets()
if (mdp_sock2.poll.fd == -1) {
mdp_sock2.poll.fd = mdp_bind_socket("mdp.2.socket");
if (mdp_sock2.poll.fd == -1){
serverMode=0;
serverMode = SERVER_NOT_RUNNING;
return;
}
mdp_sock2.poll.events = POLLIN;
@ -312,7 +312,7 @@ static void overlay_mdp_setup_sockets()
if (fd!=-1){
close(fd);
serverMode=0;
serverMode = SERVER_NOT_RUNNING;
return;
}
}

View File

@ -455,7 +455,7 @@ int rhizome_opendb()
if (config.rhizome.clean_on_open)
rhizome_cleanup(NULL);
if (serverMode){
if (serverMode != SERVER_NOT_RUNNING) {
sqlite_exec_uint64_retry(&retry, &max_rowid,
"SELECT max(rowid) "
"FROM manifests", END);
@ -546,8 +546,11 @@ static void rhizome_on_cmd_cleanup()
sqlite_retry_state sqlite_retry_state_init(int serverLimit, int serverSleep, int otherLimit, int otherSleep)
{
return (sqlite_retry_state){
.limit = rhizomeRetryLimit >= 0 ? rhizomeRetryLimit : serverMode ? (serverLimit < 0 ? 50 : serverLimit) : (otherLimit < 0 ? 5000 : otherLimit),
.sleep = serverMode ? (serverSleep < 0 ? 10 : serverSleep) : (otherSleep < 0 ? 100 : otherSleep),
.limit = rhizomeRetryLimit >= 0 ? rhizomeRetryLimit :
serverMode != SERVER_NOT_RUNNING ? (serverLimit < 0 ? 50 : serverLimit)
: (otherLimit < 0 ? 5000 : otherLimit),
.sleep = serverMode != SERVER_NOT_RUNNING ? (serverSleep < 0 ? 10 : serverSleep)
: (otherSleep < 0 ? 100 : otherSleep),
.elapsed = 0,
.start = -1,
.busytries = 0
@ -573,7 +576,7 @@ int _sqlite_retry(struct __sourceloc __whence, sqlite_retry_state *retry, const
if (retry->elapsed >= retry->limit) {
// reset ready for next query
retry->busytries = 0;
if (!serverMode)
if (serverMode == SERVER_NOT_RUNNING)
retry->start = -1;
return 0; // tell caller to stop trying
}
@ -596,7 +599,7 @@ void _sqlite_retry_done(struct __sourceloc __whence, sqlite_retry_state *retry,
}
// reset ready for next query
retry->busytries = 0;
if (!serverMode)
if (serverMode == SERVER_NOT_RUNNING)
retry->start = -1;
}
@ -1558,7 +1561,7 @@ enum rhizome_bundle_status rhizome_add_manifest_to_store(rhizome_manifest *m, rh
alloca_tohex_rhizome_bid_t(m->keypair.public_key),
m->version
);
if (serverMode){
if (serverMode != SERVER_NOT_RUNNING) {
assert(max_rowid < m->rowid);
// detect any bundles added by the CLI
// due to potential race conditions, we have to do this here
@ -2030,7 +2033,7 @@ end:
// Detect bundles added from the cmdline, and call trigger functions.
void rhizome_process_added_bundles(uint64_t up_to_rowid) {
assert(serverMode);
assert(serverMode != SERVER_NOT_RUNNING);
sqlite_retry_state retry = SQLITE_RETRY_STATE_DEFAULT;
sqlite3_stmt *statement = sqlite_prepare_bind(&retry,
"SELECT id, manifest, version, inserttime, author, rowid FROM manifests WHERE rowid > ? AND rowid < ?"

View File

@ -259,12 +259,12 @@ int server_bind()
// Any CPU or IO heavy initialisation should be performed in a config changed trigger
CALL_TRIGGER(startup);
if (serverMode == 0)
if (serverMode == SERVER_NOT_RUNNING)
return -1;
// start the HTTP server if enabled
if (httpd_server_start(config.rhizome.http.port, config.rhizome.http.port + HTTPD_PORT_RANGE)==-1) {
serverMode = 0;
serverMode = SERVER_NOT_RUNNING;
return -1;
}
@ -280,7 +280,7 @@ int server_bind()
/* record PID file so that servald start can return */
if (server_write_pid()) {
serverMode = 0;
serverMode = SERVER_NOT_RUNNING;
return -1;
}
@ -633,9 +633,9 @@ void rhizome_clean_db(struct sched_ent *alarm)
static void server_on_config_change()
{
if (!serverMode)
if (serverMode == SERVER_NOT_RUNNING)
return;
time_ms_t now = gettime_ms();
if (config.server.watchdog.executable[0])
@ -773,7 +773,7 @@ static void signal_handler(int signum)
kill(getpid(), signum);
// Just in case...
FATALF("Sending %s to self (pid=%d) did not cause exit", alloca_signal_name(signum));
FATALF("Sending %s to self (pid=%d) did not cause exit", alloca_signal_name(signum), getpid());
}
static void cli_server_details(struct cli_context *context, const struct pid_tid *id)