diff options
-rw-r--r-- | swaybar/main.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/swaybar/main.c b/swaybar/main.c index 88cd1dbe..4323d370 100644 --- a/swaybar/main.c +++ b/swaybar/main.c | |||
@@ -5,6 +5,7 @@ | |||
5 | #include <stdbool.h> | 5 | #include <stdbool.h> |
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <sys/select.h> | 7 | #include <sys/select.h> |
8 | #include <sys/wait.h> | ||
8 | #include <errno.h> | 9 | #include <errno.h> |
9 | #include <json-c/json.h> | 10 | #include <json-c/json.h> |
10 | #include <sys/un.h> | 11 | #include <sys/un.h> |
@@ -87,7 +88,7 @@ struct colors colors = { | |||
87 | }, | 88 | }, |
88 | }; | 89 | }; |
89 | 90 | ||
90 | void sway_terminate(void) { | 91 | void swaybar_teardown() { |
91 | window_teardown(window); | 92 | window_teardown(window); |
92 | if (registry) { | 93 | if (registry) { |
93 | registry_teardown(registry); | 94 | registry_teardown(registry); |
@@ -99,16 +100,31 @@ void sway_terminate(void) { | |||
99 | 100 | ||
100 | if (pid) { | 101 | if (pid) { |
101 | // terminate status_command process | 102 | // terminate status_command process |
102 | kill(pid, SIGTERM); | 103 | int ret = kill(pid, SIGTERM); |
104 | if (ret != 0) { | ||
105 | sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid); | ||
106 | } else { | ||
107 | int status; | ||
108 | waitpid(pid, &status, 0); | ||
109 | } | ||
103 | } | 110 | } |
104 | 111 | ||
105 | if (pipefd[0]) { | 112 | if (pipefd[0]) { |
106 | close(pipefd[0]); | 113 | close(pipefd[0]); |
107 | } | 114 | } |
115 | } | ||
116 | |||
108 | 117 | ||
118 | void sway_terminate(void) { | ||
119 | swaybar_teardown(); | ||
109 | exit(EXIT_FAILURE); | 120 | exit(EXIT_FAILURE); |
110 | } | 121 | } |
111 | 122 | ||
123 | void sig_handler(int signal) { | ||
124 | swaybar_teardown(); | ||
125 | exit(0); | ||
126 | } | ||
127 | |||
112 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { | 128 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { |
113 | cairo_set_source_rgba(cairo, | 129 | cairo_set_source_rgba(cairo, |
114 | ((color & 0xFF000000) >> 24) / 256.0, | 130 | ((color & 0xFF000000) >> 24) / 256.0, |
@@ -525,14 +541,12 @@ int main(int argc, char **argv) { | |||
525 | line[0] = '\0'; | 541 | line[0] = '\0'; |
526 | } | 542 | } |
527 | 543 | ||
544 | signal(SIGTERM, sig_handler); | ||
545 | |||
528 | poll_for_update(); | 546 | poll_for_update(); |
529 | 547 | ||
530 | window_teardown(window); | 548 | // gracefully shutdown swaybar and status_command |
531 | registry_teardown(registry); | 549 | swaybar_teardown(); |
532 | fclose(command); | ||
533 | // terminate status_command process | ||
534 | kill(pid, SIGTERM); | ||
535 | close(pipefd[0]); | ||
536 | 550 | ||
537 | return 0; | 551 | return 0; |
538 | } | 552 | } |