Merge pull request #387 from mikkeloscar/handle-term-signal

swaybar: Correct handling of SIGTERM.
master
Drew DeVault 9 years ago
commit 9d09f5e391

@ -5,6 +5,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <sys/select.h> #include <sys/select.h>
#include <sys/wait.h>
#include <errno.h> #include <errno.h>
#include <json-c/json.h> #include <json-c/json.h>
#include <sys/un.h> #include <sys/un.h>
@ -87,7 +88,7 @@ struct colors colors = {
}, },
}; };
void sway_terminate(void) { void swaybar_teardown() {
window_teardown(window); window_teardown(window);
if (registry) { if (registry) {
registry_teardown(registry); registry_teardown(registry);
@ -99,16 +100,31 @@ void sway_terminate(void) {
if (pid) { if (pid) {
// terminate status_command process // terminate status_command process
kill(pid, SIGTERM); int ret = kill(pid, SIGTERM);
if (ret != 0) {
sway_log(L_ERROR, "Unable to terminate status_command [pid: %d]", pid);
} else {
int status;
waitpid(pid, &status, 0);
}
} }
if (pipefd[0]) { if (pipefd[0]) {
close(pipefd[0]); close(pipefd[0]);
} }
}
void sway_terminate(void) {
swaybar_teardown();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
void sig_handler(int signal) {
swaybar_teardown();
exit(0);
}
void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
cairo_set_source_rgba(cairo, cairo_set_source_rgba(cairo,
((color & 0xFF000000) >> 24) / 256.0, ((color & 0xFF000000) >> 24) / 256.0,
@ -525,14 +541,12 @@ int main(int argc, char **argv) {
line[0] = '\0'; line[0] = '\0';
} }
signal(SIGTERM, sig_handler);
poll_for_update(); poll_for_update();
window_teardown(window); // gracefully shutdown swaybar and status_command
registry_teardown(registry); swaybar_teardown();
fclose(command);
// terminate status_command process
kill(pid, SIGTERM);
close(pipefd[0]);
return 0; return 0;
} }

Loading…
Cancel
Save