]> git.sur5r.net Git - i3/i3/blobdiff - src/main.c
Merge branch 'master' into next
[i3/i3] / src / main.c
index 65db1711c40845710233535463ab8a465c9cc5ae..6d0f80cb124c44cbd1956d89fb87da56db036eb6 100644 (file)
@@ -232,15 +232,10 @@ static void i3_exit(void) {
  * Unlinks the SHM log and re-raises the signal.
  *
  */
-static void handle_signal(struct ev_loop *loop, ev_signal *w, int revents) {
-    int sig = w->signum;
-    fprintf(stderr, "Received signal %d, terminating\n", sig);
+static void handle_signal(int sig, siginfo_t *info, void *data) {
     if (*shmlogname != '\0') {
-        fprintf(stderr, "Closing SHM log \"%s\"\n", shmlogname);
         shm_unlink(shmlogname);
     }
-    fflush(stderr);
-    ev_signal_stop(loop, w);
     raise(sig);
 }
 
@@ -274,6 +269,7 @@ int main(int argc, char *argv[]) {
         {"get_socketpath", no_argument, 0, 0},
         {"fake_outputs", required_argument, 0, 0},
         {"fake-outputs", required_argument, 0, 0},
+        {"force-old-config-parser-v4.4-only", no_argument, 0, 0},
         {0, 0, 0, 0}
     };
     int option_index = 0, opt;
@@ -377,6 +373,10 @@ int main(int argc, char *argv[]) {
                     LOG("Initializing fake outputs: %s\n", optarg);
                     fake_outputs = sstrdup(optarg);
                     break;
+                } else if (strcmp(long_options[option_index].name, "force-old-config-parser-v4.4-only") == 0) {
+                    LOG("FORCING OLD CONFIG PARSER!\n");
+                    force_old_config_parser = true;
+                    break;
                 }
                 /* fall-through */
             default:
@@ -783,32 +783,31 @@ int main(int argc, char *argv[]) {
     }
     xcb_ungrab_server(conn);
 
+    struct sigaction action;
 
-#define HANDLE_SIGNAL_EV(signum) \
-    do { \
-        struct ev_signal *signal_watcher = scalloc(sizeof(struct ev_signal)); \
-        ev_signal_init(signal_watcher, handle_signal, signum); \
-        ev_signal_start(main_loop, signal_watcher); \
-    } while (0)
+    action.sa_sigaction = handle_signal;
+    action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
+    sigemptyset(&action.sa_mask);
 
     if (!disable_signalhandler)
         setup_signal_handler();
     else {
         /* Catch all signals with default action "Core", see signal(7) */
-        HANDLE_SIGNAL_EV(SIGQUIT);
-        HANDLE_SIGNAL_EV(SIGILL);
-        HANDLE_SIGNAL_EV(SIGABRT);
-        HANDLE_SIGNAL_EV(SIGFPE);
-        HANDLE_SIGNAL_EV(SIGSEGV);
+        if (sigaction(SIGQUIT, &action, NULL) == -1 ||
+            sigaction(SIGILL, &action, NULL) == -1 ||
+            sigaction(SIGABRT, &action, NULL) == -1 ||
+            sigaction(SIGFPE, &action, NULL) == -1 ||
+            sigaction(SIGSEGV, &action, NULL) == -1)
+            ELOG("Could not setup signal handler");
     }
 
     /* Catch all signals with default action "Term", see signal(7) */
-    HANDLE_SIGNAL_EV(SIGHUP);
-    HANDLE_SIGNAL_EV(SIGINT);
-    HANDLE_SIGNAL_EV(SIGALRM);
-    HANDLE_SIGNAL_EV(SIGTERM);
-    HANDLE_SIGNAL_EV(SIGUSR1);
-    HANDLE_SIGNAL_EV(SIGUSR2);
+    if (sigaction(SIGHUP, &action, NULL) == -1 ||
+        sigaction(SIGINT, &action, NULL) == -1 ||
+        sigaction(SIGALRM, &action, NULL) == -1 ||
+        sigaction(SIGUSR1, &action, NULL) == -1 ||
+        sigaction(SIGUSR2, &action, NULL) == -1)
+        ELOG("Could not setup signal handler");
 
     /* Ignore SIGPIPE to survive errors when an IPC client disconnects
      * while we are sending him a message */