diff options
author | 2015-08-13 00:44:56 -0700 | |
---|---|---|
committer | 2015-08-13 00:44:56 -0700 | |
commit | 5df5b0098971e4d7e278bd7dfc8d5a611a97f467 (patch) | |
tree | 99da2609292f7fbec57fb76893d3d29d052517d6 | |
parent | moved fd modifying stuff to log.c (diff) | |
download | sway-5df5b0098971e4d7e278bd7dfc8d5a611a97f467.tar.gz sway-5df5b0098971e4d7e278bd7dfc8d5a611a97f467.tar.zst sway-5df5b0098971e4d7e278bd7dfc8d5a611a97f467.zip |
moved signal handling to main
-rw-r--r-- | sway/commands.c | 13 | ||||
-rw-r--r-- | sway/main.c | 12 |
2 files changed, 12 insertions, 13 deletions
diff --git a/sway/commands.c b/sway/commands.c index edf9db7a..e82462bf 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -5,7 +5,6 @@ | |||
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <unistd.h> | 7 | #include <unistd.h> |
8 | #include <sys/wait.h> | ||
9 | #include <ctype.h> | 8 | #include <ctype.h> |
10 | #include "stringop.h" | 9 | #include "stringop.h" |
11 | #include "layout.h" | 10 | #include "layout.h" |
@@ -109,19 +108,7 @@ static bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
109 | return true; | 108 | return true; |
110 | } | 109 | } |
111 | 110 | ||
112 | static void cmd_exec_cleanup(int signal) { | ||
113 | while (waitpid((pid_t)-1, 0, WNOHANG) > 0){}; | ||
114 | } | ||
115 | |||
116 | static bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { | 111 | static bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { |
117 | /* setup signal handler to cleanup dead proccesses */ | ||
118 | /* TODO: replace this with a function that has constructor attribute? */ | ||
119 | static bool cleanup = false; | ||
120 | if (cleanup == false) { | ||
121 | signal(SIGCHLD, cmd_exec_cleanup); | ||
122 | cleanup = true; | ||
123 | } | ||
124 | |||
125 | if (checkarg(argc, "exec_always", EXPECTED_MORE_THEN, 0) == false) { | 112 | if (checkarg(argc, "exec_always", EXPECTED_MORE_THEN, 0) == false) { |
126 | return false; | 113 | return false; |
127 | } | 114 | } |
diff --git a/sway/main.c b/sway/main.c index 7661551d..7477b08c 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -2,16 +2,23 @@ | |||
2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include <sys/wait.h> | ||
6 | #include <signal.h> | ||
5 | #include "layout.h" | 7 | #include "layout.h" |
6 | #include "config.h" | 8 | #include "config.h" |
7 | #include "log.h" | 9 | #include "log.h" |
8 | #include "handlers.h" | 10 | #include "handlers.h" |
9 | 11 | ||
12 | static void sigchld_handle(int signal); | ||
10 | 13 | ||
11 | int main(int argc, char **argv) { | 14 | int main(int argc, char **argv) { |
12 | init_log(L_DEBUG); // TODO: Control this with command line arg | 15 | init_log(L_DEBUG); // TODO: Control this with command line arg |
13 | init_layout(); | 16 | init_layout(); |
14 | 17 | ||
18 | /* Signal handling */ | ||
19 | signal(SIGCHLD, sigchld_handle); | ||
20 | |||
21 | |||
15 | setenv("WLC_DIM", "0", 0); | 22 | setenv("WLC_DIM", "0", 0); |
16 | if (!wlc_init(&interface, argc, argv)) { | 23 | if (!wlc_init(&interface, argc, argv)) { |
17 | return 1; | 24 | return 1; |
@@ -25,3 +32,8 @@ int main(int argc, char **argv) { | |||
25 | wlc_run(); | 32 | wlc_run(); |
26 | return 0; | 33 | return 0; |
27 | } | 34 | } |
35 | |||
36 | static void sigchld_handle(int signal) { | ||
37 | (void) signal; | ||
38 | while (waitpid((pid_t)-1, 0, WNOHANG) > 0); | ||
39 | } | ||