aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-26 09:08:05 +0100
committerMikkel Oscar Lyderik <mikkeloscar@gmail.com>2016-02-26 09:42:21 +0100
commit5e253fdd9ac5c8733203eec9870aa0ca2cd238fd (patch)
tree3bfaae22500ddfc326dfd4fa4b81bbab285a4c2f /sway
parent40b3215444ed48d2ed9bbaa00f20f266f5318f5a (diff)
downloadsway-5e253fdd9ac5c8733203eec9870aa0ca2cd238fd.tar.xz
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.c2
-rw-r--r--sway/main.c18
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) {
}
// Close all views
close_views(&root_container);
- sway_terminate();
+ sway_terminate(EXIT_SUCCESS);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
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 @@
#include "sway.h"
static bool terminate_request = false;
+static int exit_value = 0;
-void sway_terminate(void) {
+void sway_terminate(int exit_code) {
terminate_request = true;
+ exit_value = exit_code;
wlc_terminate();
- exit(EXIT_FAILURE);
}
void sig_handler(int signal) {
close_views(&root_container);
- sway_terminate();
+ sway_terminate(EXIT_SUCCESS);
}
static void wlc_log_handler(enum wlc_log_type type, const char *str) {
@@ -150,16 +151,19 @@ int main(int argc, char **argv) {
if (optind < argc) { // Behave as IPC client
if(optind != 1) {
- sway_abort("Don't use options with the IPC client");
+ sway_log(L_ERROR, "Don't use options with the IPC client");
+ exit(EXIT_FAILURE);
}
if (getuid() != geteuid() || getgid() != getegid()) {
if (setgid(getgid()) != 0 || setuid(getuid()) != 0) {
- sway_abort("Unable to drop root");
+ sway_log(L_ERROR, "Unable to drop root");
+ exit(EXIT_FAILURE);
}
}
char *socket_path = getenv("SWAYSOCK");
if (!socket_path) {
- sway_abort("Unable to retrieve socket path");
+ sway_log(L_ERROR, "Unable to retrieve socket path");
+ exit(EXIT_FAILURE);
}
char *command = join_args(argv + optind, argc - optind);
run_as_ipc_client(command, socket_path);
@@ -224,6 +228,6 @@ int main(int argc, char **argv) {
ipc_terminate();
- return 0;
+ return exit_value;
}