aboutsummaryrefslogtreecommitdiff
path: root/swaymsg
diff options
context:
space:
mode:
authorRyan Dwyer <ryandwyer1@gmail.com>2018-05-28 13:33:02 +1000
committerRyan Dwyer <ryandwyer1@gmail.com>2018-05-28 13:33:02 +1000
commit508a76695ca1beed7d02b492f784b8ba4df062d0 (patch)
tree641964e8ddb17d8c21c482d4f50ae2d0ed9e8243 /swaymsg
parentb2c0ba5b180b75a18e622934bbed61b0f14b1661 (diff)
swaymsg: Fix exit code
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/main.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 89af7345..bf56b80d 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -19,13 +19,26 @@ void sway_terminate(int exit_code) {
exit(exit_code);
}
+// Iterate results array and return false if any of them failed
static bool success(json_object *r, bool fallback) {
- json_object *success;
- if (!json_object_object_get_ex(r, "success", &success)) {
+ if (!json_object_is_type(r, json_type_array)) {
return fallback;
- } else {
- return json_object_get_boolean(success);
}
+ size_t results_len = json_object_array_length(r);
+ if (!results_len) {
+ return fallback;
+ }
+ for (size_t i = 0; i < results_len; ++i) {
+ json_object *result = json_object_array_get_idx(r, i);
+ json_object *success;
+ if (!json_object_object_get_ex(result, "success", &success)) {
+ return false;
+ }
+ if (!json_object_get_boolean(success)) {
+ return false;
+ }
+ }
+ return true;
}
static void pretty_print_cmd(json_object *r) {