aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/main.c
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2015-12-21 11:46:15 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2015-12-21 11:50:56 +0100
commit5c8a3afff92f9d5ca157bdfc03483a805d1b52e8 (patch)
treeb7c7f97a0aaa3b9a046ffe13d2bc161c416ebe5c /swaybar/main.c
parentFix default swaybar font (diff)
downloadsway-5c8a3afff92f9d5ca157bdfc03483a805d1b52e8.tar.gz
sway-5c8a3afff92f9d5ca157bdfc03483a805d1b52e8.tar.zst
sway-5c8a3afff92f9d5ca157bdfc03483a805d1b52e8.zip
swaybar: Correct handling of SIGTERM.
Swaybar did not correctly handle the SIGTERM sent from sway when exiting, ultimately leaving the child status_command behind. This should correctly handle the SIGTERM signal and terminate the status_command. Fix #386
Diffstat (limited to 'swaybar/main.c')
-rw-r--r--swaybar/main.c30
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
90void sway_terminate(void) { 91void 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
118void sway_terminate(void) {
119 swaybar_teardown();
109 exit(EXIT_FAILURE); 120 exit(EXIT_FAILURE);
110} 121}
111 122
123void sig_handler(int signal) {
124 swaybar_teardown();
125 exit(0);
126}
127
112void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { 128void 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}