diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-23 00:45:13 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-23 00:45:13 +0200 |
commit | 7c6a78910429f2fa6cb3f0570e66c782d2f17748 (patch) | |
tree | 1aa33c3a2a61ae5409111dd115dc99ae0a5b8124 /main.c | |
parent | fa25599e90a7535a02641ef03ccfc138cf5c8fd3 (diff) |
Add some more meson options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 50 |
1 files changed, 21 insertions, 29 deletions
@@ -28,18 +28,7 @@ #include "igmp.h" #include "idle.h" #include "ptimer.h" - -#define DEFAULT_HOMEDIR_PATH "/home/david/intest" -#define DEFAULT_MAIN_CONFIG_FILE_PATH "./mcproxy.conf" -#define DEFAULT_ANNOUNCE_INTERVAL 3 -#define DEFAULT_PROXY_CONN_INTERVAL 3 -#define DEFAULT_PROXY_CONN_ATTEMPTS 20 -#define DEFAULT_SOCKET_DEFER true -#define DEFAULT_SOCKET_FREEBIND true -#define DEFAULT_SOCKET_KEEPALIVE true -#define DEFAULT_SOCKET_IPTOS true -#define DEFAULT_SOCKET_NODELAY true - +#include <config.h> /* Global */ struct cfg *cfg = NULL; @@ -196,8 +185,6 @@ cfg_free(struct uring_task *task) systemd_delete(cfg); xfree(cfg->igmp_iface); cfg->igmp_iface = NULL; - xfree(cfg->cfg_path); - cfg->cfg_path = NULL; exiting = true; /* The cfg struct is free:d in main() */ } @@ -276,15 +263,15 @@ cfg_read() assert_return(cfg); - if (cfg->cfg_path) - path = cfg->cfg_path; + if (cfg->cfg_file) + path = cfg->cfg_file; else - path = DEFAULT_MAIN_CONFIG_FILE_PATH; + path = DEFAULT_MAIN_CFG_FILE; cfgfile = fopen(path, "re"); if (!cfgfile) { /* ENOENT is only an error with an explicitly set path */ - if (errno == ENOENT && !cfg->cfg_path) + if (errno == ENOENT && !cfg->cfg_file) return; else if (errno == ENOENT) die("main config file (%s) missing", path); @@ -442,7 +429,7 @@ usage(int argc, char **argv, bool invalid) info("Usage: %s [OPTIONS]\n" "\n" "Valid options:\n" - " -H, --homedir=DIR\tlook for configuration files in DIR\n" + " -c, --cfgdir=DIR\tlook for configuration files in DIR\n" " -u, --user=USER\trun as USER\n" " -D, --daemonize\trun in daemon mode (disables stderr output)\n" " -l, --logfile=FILE\tlog to FILE instead of stderr\n" @@ -471,7 +458,7 @@ cfg_init(int argc, char **argv) uring_task_init(&cfg->task, "main", NULL, cfg_free); list_init(&cfg->servers); - cfg->homedir = DEFAULT_HOMEDIR_PATH; + cfg->cfg_dir = DEFAULT_CFG_DIR; cfg->announce_interval = DEFAULT_ANNOUNCE_INTERVAL; cfg->proxy_connection_interval = DEFAULT_PROXY_CONN_INTERVAL; cfg->proxy_connection_attempts = DEFAULT_PROXY_CONN_ATTEMPTS; @@ -486,7 +473,8 @@ cfg_init(int argc, char **argv) while (true) { int option_index = 0; static struct option long_options[] = { - { "homedir", required_argument, 0, 'H' }, + { "cfgdir", required_argument, 0, 'c' }, + { "cfgfile", required_argument, 0, 'C' }, { "user", required_argument, 0, 'u' }, { "daemonize", no_argument, 0, 'D' }, { "logfile", required_argument, 0, 'l' }, @@ -496,14 +484,18 @@ cfg_init(int argc, char **argv) { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, ":H:u:Dl:hvd:", + c = getopt_long(argc, argv, ":c:C:u:Dl:hvd:", long_options, &option_index); if (c == -1) break; switch (c) { - case 'H': - cfg->homedir = optarg; + case 'c': + cfg->cfg_dir = optarg; + break; + + case 'C': + cfg->cfg_file = optarg; break; case 'v': @@ -619,14 +611,14 @@ cfg_apply() * Do this after caps have been dropped to make sure we're not * accessing a directory we should have permissions to. */ - if (chdir(cfg->homedir)) - die("chdir(%s): %m", cfg->homedir); + if (chdir(cfg->cfg_dir)) + die("chdir(%s): %m", cfg->cfg_dir); if (debug_enabled(DBG_VERBOSE)) { char *wd; wd = get_current_dir_name(); - verbose("Homedir: %s", wd ? wd : "<unknown>"); + verbose("Working directory: %s", wd ? wd : "<unknown>"); free(wd); } } @@ -729,8 +721,8 @@ main(int argc, char **argv) server_count, (unsigned long)getpid()); - info("mcproxy started, %u server configurations loaded", - server_count); + info("mcproxy (%s) started, %u server configurations loaded", + VERSION, server_count); uring_event_loop(); |