summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-23 00:45:13 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-23 00:45:13 +0200
commit7c6a78910429f2fa6cb3f0570e66c782d2f17748 (patch)
tree1aa33c3a2a61ae5409111dd115dc99ae0a5b8124
parentfa25599e90a7535a02641ef03ccfc138cf5c8fd3 (diff)
Add some more meson options
-rw-r--r--config.h.in25
-rw-r--r--main.c50
-rw-r--r--main.h4
-rw-r--r--meson.build74
-rw-r--r--meson_options.txt4
-rw-r--r--server-config.c2
6 files changed, 107 insertions, 52 deletions
diff --git a/config.h.in b/config.h.in
new file mode 100644
index 0000000..98fc655
--- /dev/null
+++ b/config.h.in
@@ -0,0 +1,25 @@
+/* Autogenerated */
+
+#pragma once
+
+#define DEFAULT_CFG_DIR @DEFAULT_CFG_DIR@
+
+#define DEFAULT_MAIN_CFG_FILE @DEFAULT_MAIN_CFG_FILE@
+
+#define VERSION @VERSION@
+
+#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
diff --git a/main.c b/main.c
index 2cdf5d6..047e70e 100644
--- a/main.c
+++ b/main.c
@@ -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();
diff --git a/main.h b/main.h
index d405e84..256ddae 100644
--- a/main.h
+++ b/main.h
@@ -144,8 +144,8 @@ struct cfg {
/* Options */
uid_t uid;
gid_t gid;
- const char *homedir;
- char *cfg_path;
+ const char *cfg_dir;
+ const char *cfg_file;
bool do_igmp;
char *igmp_iface;
bool splice_supported;
diff --git a/meson.build b/meson.build
index d58cb36..34ad7b6 100644
--- a/meson.build
+++ b/meson.build
@@ -1,29 +1,63 @@
-project('mcproxy', 'c', default_options : ['c_std=gnu18'])
+project('mcproxy',
+ 'c',
+ version: '0.1.0',
+ license: 'GPL2+',
+ default_options : ['c_std=gnu18']
+)
-liburing = dependency('liburing')
+sysconfdir = join_paths(get_option('prefix'), get_option('sysconfdir'), meson.project_name())
+mainconfname = meson.project_name() + '.conf'
+
+conf = configuration_data()
+conf.set_quoted('VERSION', '@0@-@VCS_TAG@'.format(meson.project_version()))
+conf.set_quoted('DEFAULT_CFG_DIR', sysconfdir)
+conf.set_quoted('DEFAULT_MAIN_CFG_FILE', mainconfname)
+
+config_h = declare_dependency(
+ sources: vcs_tag(
+ command: ['git', 'rev-parse', '--short', 'HEAD'],
+ fallback: get_option('profile') != 'default' ? 'devel' : 'stable',
+ input: configure_file (
+ output: 'config.h.in',
+ input: 'config.h.in',
+ configuration: conf
+ ),
+ output: 'config.h'
+ )
+)
+
+configuration_inc = include_directories('.')
+
+liburing = dependency('liburing')
libsystemd = dependency('libsystemd')
-libcapng = dependency('libcap-ng')
+libcapng = dependency('libcap-ng')
mcproxy_sources = [
- 'main.c',
- 'uring.c',
- 'signal-handler.c',
- 'server.c',
- 'server-proxy.c',
- 'server-config.c',
- 'announce.c',
- 'config-parser.c',
- 'rcon.c',
- 'idle.c',
- 'ptimer.c',
- 'igmp.c',
- 'systemd.c',
- 'utils.c']
+ 'main.c',
+ 'uring.c',
+ 'signal-handler.c',
+ 'server.c',
+ 'server-proxy.c',
+ 'server-config.c',
+ 'announce.c',
+ 'config-parser.c',
+ 'rcon.c',
+ 'idle.c',
+ 'ptimer.c',
+ 'igmp.c',
+ 'systemd.c',
+ 'utils.c'
+]
executable('mcproxy',
mcproxy_sources,
link_args: [ '-lanl' ],
- dependencies : [liburing,
- libsystemd,
- libcapng])
+ include_directories : configuration_inc,
+ dependencies: [
+ liburing,
+ libsystemd,
+ libcapng,
+ config_h
+ ],
+)
diff --git a/meson_options.txt b/meson_options.txt
new file mode 100644
index 0000000..a379ce7
--- /dev/null
+++ b/meson_options.txt
@@ -0,0 +1,4 @@
+option ('profile',
+ type: 'combo',
+ choices: [ 'default', 'development'],
+ value: 'default')
diff --git a/server-config.c b/server-config.c
index fb390ac..549cf16 100644
--- a/server-config.c
+++ b/server-config.c
@@ -562,7 +562,7 @@ server_cfg_monitor_init()
dir = opendir(".");
if (!dir)
- die("opendir(%s): %m", cfg->homedir);
+ die("opendir(%s): %m", cfg->cfg_dir);
while ((dent = readdir(dir)) != NULL) {
if (dent->d_type != DT_REG && dent->d_type != DT_UNKNOWN)