From bb736d606a28d4ab7d6d8d9f939c003fdf273274 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Sun, 31 Mar 2019 04:16:24 +0300 Subject: daemon: employ a flags settings variable. We now have a settings variable for holding various flags. Turn the daemonize setting to a flag. NOTE: the project should not have compiled since commit de18684a25cdc1e310636c5f74d4e901881b5710 but due to some unexplained circumstances, no pre-commit build testing failed. This have been fixed. This commit closes Ticket 25. Signed-off-by: Gediminas Jakutis --- src/daemon/settings.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/daemon/settings.c') diff --git a/src/daemon/settings.c b/src/daemon/settings.c index 3777f23..9c4011f 100644 --- a/src/daemon/settings.c +++ b/src/daemon/settings.c @@ -19,11 +19,7 @@ */ #include "settings.h" - -static struct settings { - int daemonize; - unsigned short int port; -} settings; +#include "settings_private.h" /* TODO: should be, in this order: looking at options provided via command * line arguments, looking at at /etc/conf.d/usurpation.conf or @@ -31,16 +27,37 @@ static struct settings { */ void settings_init(void) { - settings.daemonize =0; - settings.port = 6996 + unset_flag(flag_daemonize); + settings.port = 6996; } int setting_detach(void) { - return settings.daemonize; + return test_flag(flag_daemonize); } unsigned short int setting_port(void) { return settings.port; } + +/* could be a one-liner, but let's make the logic more obvious */ +int test_flag(unsigned int flag) +{ + int ret; + + ret = settings.flags & flag; + ret = !!ret; + + return ret; +} + +void set_flag(unsigned int flag) +{ + settings.flags |= flag; +} + +void unset_flag(unsigned int flag) +{ + settings.flags &= ~flag; +} -- cgit v1.2.3