aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFurkan Sahin <furkan-dev@proton.me>2023-12-12 22:54:31 +0100
committerFurkan Sahin <furkan-dev@proton.me>2023-12-12 22:54:31 +0100
commit5fa1bf1fd9c04f51237de5e5bd2a030a2c6e10ec (patch)
treeb4ce4c3e352a8948f74316596a0345218a69513c
parent1a994af9e3cc89e471a5bbb71bdb3452ff12c6ad (diff)
sway/output: Improve logging of swaybg execvp failure and more checks
This doesn't catch the error if a background changing command is executed via swaymsg, but improves logging. The additional checks at least propagate if e.g. forking failed. (cherry picked from commit c8676fad54bb0f4152947a6781626872bfa6ad64)
-rw-r--r--sway/commands/output.c5
-rw-r--r--sway/config/output.c9
2 files changed, 10 insertions, 4 deletions
diff --git a/sway/commands/output.c b/sway/commands/output.c
index df32c673..462dffd2 100644
--- a/sway/commands/output.c
+++ b/sway/commands/output.c
@@ -111,7 +111,10 @@ struct cmd_results *cmd_output(int argc, char **argv) {
if (!config->reloading && !config->validating) {
apply_output_config_to_outputs(output);
if (background) {
- spawn_swaybg();
+ if (!spawn_swaybg()) {
+ return cmd_results_new(CMD_FAILURE,
+ "Failed to apply background configuration");
+ }
}
}
diff --git a/sway/config/output.c b/sway/config/output.c
index 3316085a..3c1822d8 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -825,7 +825,9 @@ static bool _spawn_swaybg(char **command) {
setenv("WAYLAND_SOCKET", wayland_socket_str, true);
execvp(command[0], command);
- sway_log_errno(SWAY_ERROR, "execvp failed");
+ sway_log_errno(SWAY_ERROR, "failed to execute '%s' "
+ "(background configuration probably not applied)",
+ command[0]);
_exit(EXIT_FAILURE);
}
_exit(EXIT_SUCCESS);
@@ -835,12 +837,13 @@ static bool _spawn_swaybg(char **command) {
sway_log_errno(SWAY_ERROR, "close failed");
return false;
}
- if (waitpid(pid, NULL, 0) < 0) {
+ int fork_status = 0;
+ if (waitpid(pid, &fork_status, 0) < 0) {
sway_log_errno(SWAY_ERROR, "waitpid failed");
return false;
}
- return true;
+ return WIFEXITED(fork_status) && WEXITSTATUS(fork_status) == EXIT_SUCCESS;
}
bool spawn_swaybg(void) {