summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c
index 71c2d83..cdcec31 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
#include <yopt.h>
static fcgy_app *app; /* TODO: Needs to be a global array of apps */
+static ev_signal termsig, intsig;
static const yopt_opt_t cli_options[] = {
@@ -78,15 +79,33 @@ static int parse_args(int argc, char **argv) {
}
+static void shutdown_sig(EV_P_ ev_signal *w, int revents) {
+ ev_signal_stop(EV_DEFAULT_UC_ &termsig);
+ ev_signal_stop(EV_DEFAULT_UC_ &intsig);
+ app_destroy(app);
+}
+
+
int main(int argc, char **argv) {
app = app_create();
if(parse_args(argc, argv) < 0)
return 1;
ev_default_loop(0);
- app_bind(app);
+
+ char ebuff[256];
+ if(app_bind(app, ebuff, sizeof(ebuff)) < 0) {
+ fprintf(stderr, "fcgy: %s\n", ebuff);
+ return 1;
+ }
app_run(app);
+
+ ev_signal_init(&termsig, shutdown_sig, SIGTERM);
+ ev_signal_init(&intsig, shutdown_sig, SIGINT);
+ ev_signal_start(EV_DEFAULT_UC_ &termsig);
+ ev_signal_start(EV_DEFAULT_UC_ &intsig);
+
ev_run(EV_DEFAULT_UC_ 0);
- app_destroy(app);
+ fprintf(stderr, "Clean shutdown.\n");
return 0;
}