/** * @brief Load the configuration file. * * This function will read the configuration JSON file and parse it into the * application wide @ref appconf structure. After this function is called the * configuration struct must be deleted with the @ref config_destroy function. * * The config file has the following structure: * @code * { * "daemonize" : true/false, * "ssh_poll_time" : 0-100, * "bluecherry_address" : "url.to.iot.server", * "ssh_path" : "/usr/bin/ssh", * "ssh_keygen_path" : "/usr/bin/ssh-keygen", * "loglevel" : "NONE/ERROR/WARNING/INFO/DEBUG", * "logfile" : "/tmp/path/to/logfile", * "pid_file" : "/path/to/pidfile.pid", * "identity_file" : "/path/to/id_rsa", * "ipc_path" : "/path/to/ipc_file" * } * @endcode * * @param path The path where to find the configuration JSON file. * * @return True if the configuration could be parsed successfully. */ bool config_load(const char *path) { appconf = (struct config*) malloc(sizeof(struct config)); if(appconf == NULL) { log_basic(stderr, LG_ERROR, "There was not enough memory to reserve the configuration memory\n"); return false; } return config_reload(path); }
int _main(config_t *config) { pthread_t server_tid= 0; signal(SIGTERM, sig_handler); signal(SIGINT, sig_handler); signal(SIGPIPE, sig_handler); signal(SIGHUP, sig_handler); setproctitle("starting"); s_listen = mallocz_or_die(sizeof(*s_listen)); worker_pool_init_static(config); server_tid= setup_listener(config); graphite_worker= mallocz_or_die(sizeof(graphite_worker_t)); pthread_create(&graphite_worker->tid, NULL, graphite_worker_thread, graphite_worker); for (;;) { int abort; abort= get_abort_val(); if (abort & STOP) { break; } else if (abort & RELOAD) { if (config_reload(config)) { stop_listener(server_tid); server_tid= setup_listener(config); worker_pool_reload_static(config); /* XXX: check me */ /* check and see if we need to stop the old graphite processor and replace it */ graphite_worker_destroy(graphite_worker); pthread_create(&graphite_worker->tid, NULL, graphite_worker_thread, graphite_worker); } unset_abort_bits(RELOAD); } mark_second_elapsed(); sleep(1); } final_shutdown(server_tid); SAY("bye"); closelog(); return(0); }
static void signal_handler(int signum) { /* * On some implementations (i.e. linuxthreads), signals are delivered * to all threads. We only want to handle each signal once for the * entire box, and we let the gwthread wrapper take care of choosing * one. */ if (!gwthread_shouldhandlesignal(signum)) return; switch (signum) { case SIGINT: case SIGTERM: if (program_status != shutting_down) { error(0, "SIGINT or SIGTERM received, let's die."); program_status = shutting_down; break; } break; case SIGHUP: warning(0, "SIGHUP received, catching and re-opening logs"); config_reload(1); log_reopen(); alog_reopen(); break; /* * It would be more proper to use SIGUSR1 for this, but on some * platforms that's reserved by the pthread support. */ case SIGQUIT: warning(0, "SIGQUIT received, reporting memory usage."); gw_check_leaks(); break; } }
static Cfg *init_wapbox(Cfg *cfg) { CfgGroup *grp; Octstr *s; Octstr *logfile; int lf, m; long value; lf = m = 1; cfg_dump(cfg); /* * Extract info from the core group. */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) panic(0, "No 'core' group in configuration."); if (cfg_get_integer(&bearerbox_port,grp,octstr_imm("wapbox-port")) == -1) panic(0, "No 'wapbox-port' in core group"); #ifdef HAVE_LIBSSL cfg_get_bool(&bearerbox_ssl, grp, octstr_imm("wapbox-port-ssl")); #endif /* HAVE_LIBSSL */ /* load parameters that could be later reloaded */ config_reload(0); conn_config_ssl(grp); /* * And the rest of the pull info comes from the wapbox group. */ grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) panic(0, "No 'wapbox' group in configuration."); bearerbox_host = cfg_get(grp, octstr_imm("bearerbox-host")); if (cfg_get_integer(&timer_freq, grp, octstr_imm("timer-freq")) == -1) timer_freq = DEFAULT_TIMER_FREQ; logfile = cfg_get(grp, octstr_imm("log-file")); if (logfile != NULL) { log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL); info(0, "Starting to log to file %s level %ld", octstr_get_cstr(logfile), logfilelevel); } octstr_destroy(logfile); if ((s = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) { long level; Octstr *facility; if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) { log_set_syslog_facility(octstr_get_cstr(facility)); octstr_destroy(facility); } if (octstr_compare(s, octstr_imm("none")) == 0) { log_set_syslog(NULL, 0); debug("wap", 0, "syslog parameter is none"); } else if (octstr_parse_long(&level, s, 0, 10) > 0) { log_set_syslog("wapbox", level); debug("wap", 0, "syslog parameter is %ld", level); } octstr_destroy(s); } else { log_set_syslog(NULL, 0); debug("wap", 0, "no syslog parameter"); } /* determine which timezone we use for access logging */ if ((s = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(s, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(s); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* open access-log file */ if ((s = cfg_get(grp, octstr_imm("access-log"))) != NULL) { info(0, "Logging accesses to '%s'.", octstr_get_cstr(s)); alog_open(octstr_get_cstr(s), lf, m ? 0 : 1); octstr_destroy(s); } if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0) http_set_client_timeout(value); /* configure the 'wtls' group */ #if (HAVE_WTLS_OPENSSL) /* Load up the necessary keys */ grp = cfg_get_single_group(cfg, octstr_imm("wtls")); if (grp != NULL) { if ((s = cfg_get(grp, octstr_imm("certificate-file"))) != NULL) { if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "certificate file not set"); } else { /* Load the certificate into the necessary parameter */ get_cert_from_file(s, &x509_cert); gw_assert(x509_cert != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } octstr_destroy(s); } else panic(0, "No 'certificate-file' in wtls group"); if ((s = cfg_get(grp, octstr_imm("privatekey-file"))) != NULL) { Octstr *password; password = cfg_get(grp, octstr_imm("privatekey-password")); if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "privatekey-file not set"); } else { /* Load the private key into the necessary parameter */ get_privkey_from_file(s, &private_key, password); gw_assert(private_key != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } if (password != NULL) octstr_destroy(password); octstr_destroy(s); } else panic(0, "No 'privatekey-file' in wtls group"); } #endif /* * Check if we have a 'radius-acct' proxy group and start the * corresponding thread for the proxy. */ grp = cfg_get_single_group(cfg, octstr_imm("radius-acct")); if (grp) { radius_acct_init(grp); } /* * We pass ppg configuration groups to the ppg module. */ grp = cfg_get_single_group(cfg, octstr_imm("ppg")); if (grp == NULL) { cfg_destroy(cfg); return NULL; } return cfg; }
/** * Relaod the configuration data from the config file * * @param dcb DCB to use to send output */ static void reload_config(DCB *dcb) { dcb_printf(dcb, "Reloading configuration from file.\n"); config_reload(); }