diff options
author | 2019-05-29 13:03:49 +0300 | |
---|---|---|
committer | 2019-05-29 13:03:49 +0300 | |
commit | 187fe61700fc97fff565ec53aac65c664042feae (patch) | |
tree | 498d0c00af96c4f666b4ef4dbb6db0966a485852 /src/daemon/main.c | |
parent | aef4eba5572d6b42f8ef2913ec41c0e778731960 (diff) | |
download | usurpation-187fe61700fc97fff565ec53aac65c664042feae.tar.gz usurpation-187fe61700fc97fff565ec53aac65c664042feae.tar.bz2 usurpation-187fe61700fc97fff565ec53aac65c664042feae.zip |
daemon: get ready to use messaging interfaces.
Signed-off-by: Gediminas Jakutis <gediminas@varciai.lt>
Diffstat (limited to 'src/daemon/main.c')
-rw-r--r-- | src/daemon/main.c | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/daemon/main.c b/src/daemon/main.c index 94e59fd..37b1a51 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -23,31 +23,46 @@ #include <time.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> #include "settings.h" #include "net.h" #include "purple.h" +#include "proto_stdio.h" static struct _state { int nd; -} _progstate; +} __progstate; -void cleanup(void); +static void cleanup(void); +static int __main_loop(const struct timespec * const iter_len); /* the logic is a placeholder right now */ int main(int argc, char **argv) { extern const char * const version; - struct timespec t = {3600, 0}; /* one hour */ + static const struct timespec t = {0, 250 * 1000 * 1000}; /* 250ms */ + char *proto; printf("Usurpation daemon version %s starting\n", version); atexit(cleanup); settings_init(); - _progstate.nd = net_init(setting_port()); - if (purple_init() && setting_verbose()) { - fprintf(stderr, "libpurple initialization failed\n"); + __progstate.nd = net_init(setting_port()); + proto = setting_im_proto(); + + if (strcmp(proto, "null")) { + if (purple_init() && setting_verbose()) { + fprintf(stderr, "libpurple initialization failed\n"); + } + } else { + if (proto_stdio_init() && setting_verbose()) { + fprintf(stderr, "libpurple initialization failed\n"); + } } + free(proto); + proto = NULL; + /* by default and if running by as a system service, the init system * needs to keep control of the process and thus only detach if * requested when ran manually by a user. @@ -56,17 +71,28 @@ int main(int argc, char **argv) daemon(0, 0); } - while(!(nanosleep(&t, NULL))) { - /* noop */ + return __main_loop(&t); +} + +/* TODO: semi-stub */ +static int __main_loop(const struct timespec * const iter_len) +{ + struct timespec t; + int ret = A_OK; + + t = *iter_len; + while (!ret) { + nanosleep(&t, NULL); } - return 0; + return ret; } -void cleanup(void) +static void cleanup(void) { purple_close(); - net_close(_progstate.nd); + proto_stdio_close(); + net_close(__progstate.nd); settings_cleanup(); } |