summaryrefslogtreecommitdiffstats
path: root/src/daemon/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/main.c')
-rw-r--r--src/daemon/main.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 302a9ce..94e59fd 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -21,9 +21,17 @@
#include <unistd.h>
#include <time.h>
+#include <stdlib.h>
#include <stdio.h>
#include "settings.h"
#include "net.h"
+#include "purple.h"
+
+static struct _state {
+ int nd;
+} _progstate;
+
+void cleanup(void);
/* the logic is a placeholder right now */
int main(int argc, char **argv)
@@ -33,8 +41,12 @@ int main(int argc, char **argv)
printf("Usurpation daemon version %s starting\n", version);
+ atexit(cleanup);
settings_init();
- net_init(setting_port()); /* TODO: get port from settings. */
+ _progstate.nd = net_init(setting_port());
+ if (purple_init() && setting_verbose()) {
+ fprintf(stderr, "libpurple initialization failed\n");
+ }
/* 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
@@ -48,4 +60,13 @@ int main(int argc, char **argv)
/* noop */
}
+
+ return 0;
+}
+
+void cleanup(void)
+{
+ purple_close();
+ net_close(_progstate.nd);
+ settings_cleanup();
}