From bd427117a36715cc602e85869cd7d6db6415a945 Mon Sep 17 00:00:00 2001 From: Gediminas Jakutis Date: Sun, 19 May 2019 16:15:11 +0300 Subject: daemon: handle the daemonize flag now. The flag is now successfully read from the config file and is honored. Logic does not handle leading or trailing whitespace yet. Signed-off-by: Gediminas Jakutis --- src/daemon/settings.c | 31 ++++++++++++++++++++++++++++--- src/daemon/settings_private.h | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/daemon/settings.c b/src/daemon/settings.c index acbf40d..355fe1d 100644 --- a/src/daemon/settings.c +++ b/src/daemon/settings.c @@ -129,8 +129,33 @@ static int setting_readconf(const char * const path) /* TODO: stub! */ static int setting_handle_config_entry(const char * const entry, const char * const value) { - printf( "key: %s\n" - "value: %s\n", entry, value); + size_t i; - return 0; + for (i = 0; i < sizeof(ent_table)/sizeof(*ent_table); ++i) { + if (!(strcmp(entry, ent_table[i].name))) { + ent_table[0].set(value); + return 0; + } + } + + return 1; +} + +static void set_daemonize(const void * const arg) +{ + const char * const a = arg; + + atoi(a) ? set_flag(flag_daemonize) : unset_flag(flag_daemonize); +} + +/* TODO: stub! */ +static void set_port(const void * const arg) +{ + (void) arg; +} + +/* TODO: stub! */ +static void set_verbosity(const void * const arg) +{ + (void) arg; } diff --git a/src/daemon/settings_private.h b/src/daemon/settings_private.h index 42c1fa5..2d97bdd 100644 --- a/src/daemon/settings_private.h +++ b/src/daemon/settings_private.h @@ -34,10 +34,24 @@ static struct settings { enum verbosity verboselevel; } settings; +struct entry_description { + const char * const name; + void (*set)(const void * const); +}; + + int test_flag(unsigned int flag); void set_flag(unsigned int flag); void unset_flag(unsigned int flag); static int setting_readconf(const char * const path); static int setting_handle_config_entry(const char * const entry, const char * const value); +static void set_daemonize(const void * const arg); +static void set_port(const void * const arg); +static void set_verbosity(const void * const arg); + +struct entry_description ent_table[] = {{ "daemonize", set_daemonize }, + { "port", set_port }, + { "verbosity", set_verbosity }}; + #endif /* USURPATION_SETTINGS_PRIVATE_H */ -- cgit v1.2.3