aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-26 09:08:05 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-26 09:42:21 +0100
commit5e253fdd9ac5c8733203eec9870aa0ca2cd238fd (patch)
tree3bfaae22500ddfc326dfd4fa4b81bbab285a4c2f
parentMerge pull request #494 from gpyh/argsegfault (diff)
downloadsway-5e253fdd9ac5c8733203eec9870aa0ca2cd238fd.tar.gz
sway-5e253fdd9ac5c8733203eec9870aa0ca2cd238fd.tar.zst
sway-5e253fdd9ac5c8733203eec9870aa0ca2cd238fd.zip
Correctly exit sway on errors.
Calling `exit` in sway_terminate prevents sway from correctly shutting down (freeing data, cleanly terminating the ipc server, etc.). A better way is to exit straight away if the failure occurs before `wlc_run` and use sway_abort as usual if it occur when wlc is running.
-rw-r--r--common/log.c2
-rw-r--r--include/sway.h2
-rw-r--r--sway/commands.c2
-rw-r--r--sway/main.c18
-rw-r--r--swaybar/main.c4
-rw-r--r--swaybg/main.c4
-rw-r--r--swaygrab/main.c4
-rw-r--r--swaylock/main.c4
-rw-r--r--swaymsg/main.c4
9 files changed, 24 insertions, 20 deletions
diff --git a/common/log.c b/common/log.c
index adba0021..6d958db2 100644
--- a/common/log.c
+++ b/common/log.c
@@ -58,7 +58,7 @@ void sway_abort(const char *format, ...) {
58 vfprintf(stderr, format, args); 58 vfprintf(stderr, format, args);
59 va_end(args); 59 va_end(args);
60 fprintf(stderr, "\n"); 60 fprintf(stderr, "\n");
61 sway_terminate(); 61 sway_terminate(EXIT_FAILURE);
62} 62}
63 63
64#ifndef NDEBUG 64#ifndef NDEBUG
diff --git a/include/sway.h b/include/sway.h
index 6499c81d..b5cfb668 100644
--- a/include/sway.h
+++ b/include/sway.h
@@ -1,6 +1,6 @@
1#ifndef _SWAY_SWAY_H 1#ifndef _SWAY_SWAY_H
2#define _SWAY_SWAY_H 2#define _SWAY_SWAY_H
3 3
4void sway_terminate(void); 4void sway_terminate(int exit_code);
5 5
6#endif 6#endif
diff --git a/sway/commands.c b/sway/commands.c
index 055473d5..c4b7f6ab 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -450,7 +450,7 @@ static struct cmd_results *cmd_exit(int argc, char **argv) {
450 } 450 }
451 // Close all views 451 // Close all views
452 close_views(&root_container); 452 close_views(&root_container);
453 sway_terminate(); 453 sway_terminate(EXIT_SUCCESS);
454 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 454 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
455} 455}
456 456
diff --git a/sway/main.c b/sway/main.c
index 6adbf89d..7ea392b6 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -21,16 +21,17 @@
21#include "sway.h" 21#include "sway.h"
22 22
23static bool terminate_request = false; 23static bool terminate_request = false;
24static int exit_value = 0;
24 25
25void sway_terminate(void) { 26void sway_terminate(int exit_code) {
26 terminate_request = true; 27 terminate_request = true;
28 exit_value = exit_code;
27 wlc_terminate(); 29 wlc_terminate();
28 exit(EXIT_FAILURE);
29} 30}
30 31
31void sig_handler(int signal) { 32void sig_handler(int signal) {
32 close_views(&root_container); 33 close_views(&root_container);
33 sway_terminate(); 34 sway_terminate(EXIT_SUCCESS);
34} 35}
35 36
36static void wlc_log_handler(enum wlc_log_type type, const char *str) { 37static void wlc_log_handler(enum wlc_log_type type, const char *str) {
@@ -150,16 +151,19 @@ int main(int argc, char **argv) {
150 151
151 if (optind < argc) { // Behave as IPC client 152 if (optind < argc) { // Behave as IPC client
152 if(optind != 1) { 153 if(optind != 1) {
153 sway_abort("Don't use options with the IPC client"); 154 sway_log(L_ERROR, "Don't use options with the IPC client");
155 exit(EXIT_FAILURE);
154 } 156 }
155 if (getuid() != geteuid() || getgid() != getegid()) { 157 if (getuid() != geteuid() || getgid() != getegid()) {
156 if (setgid(getgid()) != 0 || setuid(getuid()) != 0) { 158 if (setgid(getgid()) != 0 || setuid(getuid()) != 0) {
157 sway_abort("Unable to drop root"); 159 sway_log(L_ERROR, "Unable to drop root");
160 exit(EXIT_FAILURE);
158 } 161 }
159 } 162 }
160 char *socket_path = getenv("SWAYSOCK"); 163 char *socket_path = getenv("SWAYSOCK");
161 if (!socket_path) { 164 if (!socket_path) {
162 sway_abort("Unable to retrieve socket path"); 165 sway_log(L_ERROR, "Unable to retrieve socket path");
166 exit(EXIT_FAILURE);
163 } 167 }
164 char *command = join_args(argv + optind, argc - optind); 168 char *command = join_args(argv + optind, argc - optind);
165 run_as_ipc_client(command, socket_path); 169 run_as_ipc_client(command, socket_path);
@@ -224,6 +228,6 @@ int main(int argc, char **argv) {
224 228
225 ipc_terminate(); 229 ipc_terminate();
226 230
227 return 0; 231 return exit_value;
228} 232}
229 233
diff --git a/swaybar/main.c b/swaybar/main.c
index 737ee647..c6bbc7a5 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -10,9 +10,9 @@
10/* global bar state */ 10/* global bar state */
11struct bar swaybar; 11struct bar swaybar;
12 12
13void sway_terminate(void) { 13void sway_terminate(int exit_code) {
14 bar_teardown(&swaybar); 14 bar_teardown(&swaybar);
15 exit(EXIT_FAILURE); 15 exit(exit_code);
16} 16}
17 17
18void sig_handler(int signal) { 18void sig_handler(int signal) {
diff --git a/swaybg/main.c b/swaybg/main.c
index b936be2b..fbd0d16b 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -21,7 +21,7 @@ enum scaling_mode {
21 SCALING_MODE_TILE, 21 SCALING_MODE_TILE,
22}; 22};
23 23
24void sway_terminate(void) { 24void sway_terminate(int exit_code) {
25 int i; 25 int i;
26 for (i = 0; i < surfaces->length; ++i) { 26 for (i = 0; i < surfaces->length; ++i) {
27 struct window *window = surfaces->items[i]; 27 struct window *window = surfaces->items[i];
@@ -29,7 +29,7 @@ void sway_terminate(void) {
29 } 29 }
30 list_free(surfaces); 30 list_free(surfaces);
31 registry_teardown(registry); 31 registry_teardown(registry);
32 exit(EXIT_FAILURE); 32 exit(exit_code);
33} 33}
34 34
35int main(int argc, const char **argv) { 35int main(int argc, const char **argv) {
diff --git a/swaygrab/main.c b/swaygrab/main.c
index 82d623e7..6ba8fb3e 100644
--- a/swaygrab/main.c
+++ b/swaygrab/main.c
@@ -11,8 +11,8 @@
11#include "ipc-client.h" 11#include "ipc-client.h"
12#include "util.h" 12#include "util.h"
13 13
14void sway_terminate(void) { 14void sway_terminate(int exit_code) {
15 exit(EXIT_FAILURE); 15 exit(exit_code);
16} 16}
17 17
18void grab_and_apply_magick(const char *file, const char *output, 18void grab_and_apply_magick(const char *file, const char *output,
diff --git a/swaylock/main.c b/swaylock/main.c
index 9b14086d..b20883af 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -24,7 +24,7 @@ enum scaling_mode {
24 SCALING_MODE_TILE, 24 SCALING_MODE_TILE,
25}; 25};
26 26
27void sway_terminate(void) { 27void sway_terminate(int exit_code) {
28 int i; 28 int i;
29 for (i = 0; i < surfaces->length; ++i) { 29 for (i = 0; i < surfaces->length; ++i) {
30 struct window *window = surfaces->items[i]; 30 struct window *window = surfaces->items[i];
@@ -32,7 +32,7 @@ void sway_terminate(void) {
32 } 32 }
33 list_free(surfaces); 33 list_free(surfaces);
34 registry_teardown(registry); 34 registry_teardown(registry);
35 exit(EXIT_FAILURE); 35 exit(exit_code);
36} 36}
37 37
38char *password; 38char *password;
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 22572b6f..88a8fab0 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -11,8 +11,8 @@
11#include "readline.h" 11#include "readline.h"
12#include "log.h" 12#include "log.h"
13 13
14void sway_terminate(void) { 14void sway_terminate(int exit_code) {
15 exit(EXIT_FAILURE); 15 exit(exit_code);
16} 16}
17 17
18int main(int argc, char **argv) { 18int main(int argc, char **argv) {