diff options
author | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-02-26 09:08:05 +0100 |
---|---|---|
committer | Mikkel Oscar Lyderik <mikkeloscar@gmail.com> | 2016-02-26 09:42:21 +0100 |
commit | 5e253fdd9ac5c8733203eec9870aa0ca2cd238fd (patch) | |
tree | 3bfaae22500ddfc326dfd4fa4b81bbab285a4c2f /sway | |
parent | Merge pull request #494 from gpyh/argsegfault (diff) | |
download | sway-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.
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/main.c | 18 |
2 files changed, 12 insertions, 8 deletions
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 | ||
23 | static bool terminate_request = false; | 23 | static bool terminate_request = false; |
24 | static int exit_value = 0; | ||
24 | 25 | ||
25 | void sway_terminate(void) { | 26 | void 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 | ||
31 | void sig_handler(int signal) { | 32 | void 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 | ||
36 | static void wlc_log_handler(enum wlc_log_type type, const char *str) { | 37 | static 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 | ||