SIGTERM again
[handlervirt.git] / node / main.c
blob994351c9eaaae09d9da3125a112137890c5bdf20
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include <avahi-client/client.h>
5 #include <avahi-common/simple-watch.h>
6 #include <signal.h>
7 #include <unistd.h>
9 #include "node.h"
11 void terminate(int sig) {
12 pid_t pid;
14 if (offerServiceBrowser) {
15 avahi_service_browser_free(offerServiceBrowser);
16 offerServiceBrowser = NULL;
19 pid = fork();
21 if (pid == 0) {
22 migrate_everything();
23 // exit(0);
27 int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) {
28 /* Allocate main loop object */
29 if (!(simple_poll = avahi_simple_poll_new())) {
30 fprintf(stderr, "Failed to create simple poll object.\n");
31 goto fail;
34 /* The client that is going to do the work */
35 client_callback(NULL, AVAHI_CLIENT_FAILURE, NULL);
37 signal(SIGTERM, terminate);
39 /* Run the main loop */
40 avahi_simple_poll_loop(simple_poll);
42 fail:
43 /* Cleanup things */
44 if (simple_poll)
45 avahi_simple_poll_free(simple_poll);
47 exit(EXIT_SUCCESS);