summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 1d0d788..f80b605 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,11 +1,20 @@
+#include <signal.h>
+#include <assert.h>
#include <libdaemon/dlog.h>
#include "main.h"
+#include "exec.h"
+#include "modemman.h"
-#define CHANNELS (2)
+#define CHANNELS 1
oop_source* event_source = NULL;
+static void *oop_exit_cb(oop_source *source, int sig, void *user) {
+ daemon_log(LOG_ERR, "Recieved signal %s", sig == SIGINT ? "SIGINT" : (sig == SIGTERM ? "SIGTERM" : "UNKNWON"));
+ return OOP_HALT;
+}
+
int main_loop(void) {
int r = -1;
oop_source_sys *sys = NULL;
@@ -24,6 +33,9 @@ int main_loop(void) {
if (modem_manager_init(CHANNELS) < 0)
goto finish;
+ event_source->on_signal(event_source, SIGINT, oop_exit_cb, NULL);
+ event_source->on_signal(event_source, SIGTERM, oop_exit_cb, NULL);
+
if (oop_sys_run(sys) == OOP_ERROR) {
daemon_log(LOG_ERR, "oop_sys_new() returned OOP_ERROR");
goto finish;
@@ -32,6 +44,9 @@ int main_loop(void) {
r = 0;
finish:
+ event_source->cancel_signal(event_source, SIGTERM, oop_exit_cb, NULL);
+ event_source->cancel_signal(event_source, SIGINT, oop_exit_cb, NULL);
+
modem_manager_done();
child_process_done();
@@ -44,5 +59,5 @@ finish:
}
int main(int argc, char*argv[]) {
- return main_loop() < 0 : 1 : 0;
+ return main_loop() < 0 ? 1 : 0;
}