aboutsummaryrefslogtreecommitdiff
path: root/swaymsg
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-05-03 12:49:33 -0400
committerDrew DeVault <sir@cmpwn.com>2019-05-03 11:09:49 -0600
commitc8e4ca355d80d58160aaeebc8a94b7b67b9143cb (patch)
tree649ad6578230ba09bac2521f5b0dcb467a5f184d /swaymsg
parentc1186182785d15eb205bac4b49d0888e1a6601ee (diff)
swaymsg: fix quiet error reporting
This makes it so swaymsg still returns the correct successful or failed error code when in quiet mode
Diffstat (limited to 'swaymsg')
-rw-r--r--swaymsg/main.c52
1 files changed, 32 insertions, 20 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c
index 518993af..7ee553e7 100644
--- a/swaymsg/main.c
+++ b/swaymsg/main.c
@@ -397,6 +397,9 @@ int main(int argc, char **argv) {
if (!socket_path) {
socket_path = get_socketpath();
if (!socket_path) {
+ if (quiet) {
+ exit(EXIT_FAILURE);
+ }
sway_abort("Unable to retrieve socket path");
}
}
@@ -430,13 +433,18 @@ int main(int argc, char **argv) {
} else if (strcasecmp(cmdtype, "subscribe") == 0) {
type = IPC_SUBSCRIBE;
} else {
+ if (quiet) {
+ exit(EXIT_FAILURE);
+ }
sway_abort("Unknown message type %s", cmdtype);
}
free(cmdtype);
if (monitor && type != IPC_SUBSCRIBE) {
- sway_log(SWAY_ERROR, "Monitor can only be used with -t SUBSCRIBE");
+ if (!quiet) {
+ sway_log(SWAY_ERROR, "Monitor can only be used with -t SUBSCRIBE");
+ }
free(socket_path);
return 1;
}
@@ -454,29 +462,29 @@ int main(int argc, char **argv) {
ipc_set_recv_timeout(socketfd, timeout);
uint32_t len = strlen(command);
char *resp = ipc_single_command(socketfd, type, command, &len);
- if (!quiet) {
- // pretty print the json
- json_object *obj = json_tokener_parse(resp);
- if (obj == NULL) {
+ // pretty print the json
+ json_object *obj = json_tokener_parse(resp);
+ if (obj == NULL) {
+ if (!quiet) {
fprintf(stderr, "ERROR: Could not parse json response from ipc. "
"This is a bug in sway.");
printf("%s\n", resp);
+ }
+ ret = 1;
+ } else {
+ if (!success(obj, true)) {
ret = 1;
- } else {
- if (!success(obj, true)) {
- ret = 1;
- }
- if (type != IPC_SUBSCRIBE || ret != 0) {
- if (raw) {
- printf("%s\n", json_object_to_json_string_ext(obj,
- JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
- } else {
- pretty_print(type, obj);
- }
+ }
+ if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) {
+ if (raw) {
+ printf("%s\n", json_object_to_json_string_ext(obj,
+ JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
+ } else {
+ pretty_print(type, obj);
}
- json_object_put(obj);
}
+ json_object_put(obj);
}
free(command);
free(resp);
@@ -495,10 +503,14 @@ int main(int argc, char **argv) {
json_object *obj = json_tokener_parse(reply->payload);
if (obj == NULL) {
- fprintf(stderr, "ERROR: Could not parse json response from ipc"
- ". This is a bug in sway.");
- ret = 1;
+ if (!quiet) {
+ fprintf(stderr, "ERROR: Could not parse json response from"
+ " ipc. This is a bug in sway.");
+ ret = 1;
+ }
break;
+ } else if (quiet) {
+ json_object_put(obj);
} else {
if (raw) {
printf("%s\n", json_object_to_json_string(obj));