aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-05-03 12:49:33 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-05-03 11:09:49 -0600
commitc8e4ca355d80d58160aaeebc8a94b7b67b9143cb (patch)
tree649ad6578230ba09bac2521f5b0dcb467a5f184d
parentsway.5.scd: clarify workspace config commands (diff)
downloadsway-c8e4ca355d80d58160aaeebc8a94b7b67b9143cb.tar.gz
sway-c8e4ca355d80d58160aaeebc8a94b7b67b9143cb.tar.zst
sway-c8e4ca355d80d58160aaeebc8a94b7b67b9143cb.zip
swaymsg: fix quiet error reporting
This makes it so swaymsg still returns the correct successful or failed error code when in quiet mode
-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) {
397 if (!socket_path) { 397 if (!socket_path) {
398 socket_path = get_socketpath(); 398 socket_path = get_socketpath();
399 if (!socket_path) { 399 if (!socket_path) {
400 if (quiet) {
401 exit(EXIT_FAILURE);
402 }
400 sway_abort("Unable to retrieve socket path"); 403 sway_abort("Unable to retrieve socket path");
401 } 404 }
402 } 405 }
@@ -430,13 +433,18 @@ int main(int argc, char **argv) {
430 } else if (strcasecmp(cmdtype, "subscribe") == 0) { 433 } else if (strcasecmp(cmdtype, "subscribe") == 0) {
431 type = IPC_SUBSCRIBE; 434 type = IPC_SUBSCRIBE;
432 } else { 435 } else {
436 if (quiet) {
437 exit(EXIT_FAILURE);
438 }
433 sway_abort("Unknown message type %s", cmdtype); 439 sway_abort("Unknown message type %s", cmdtype);
434 } 440 }
435 441
436 free(cmdtype); 442 free(cmdtype);
437 443
438 if (monitor && type != IPC_SUBSCRIBE) { 444 if (monitor && type != IPC_SUBSCRIBE) {
439 sway_log(SWAY_ERROR, "Monitor can only be used with -t SUBSCRIBE"); 445 if (!quiet) {
446 sway_log(SWAY_ERROR, "Monitor can only be used with -t SUBSCRIBE");
447 }
440 free(socket_path); 448 free(socket_path);
441 return 1; 449 return 1;
442 } 450 }
@@ -454,29 +462,29 @@ int main(int argc, char **argv) {
454 ipc_set_recv_timeout(socketfd, timeout); 462 ipc_set_recv_timeout(socketfd, timeout);
455 uint32_t len = strlen(command); 463 uint32_t len = strlen(command);
456 char *resp = ipc_single_command(socketfd, type, command, &len); 464 char *resp = ipc_single_command(socketfd, type, command, &len);
457 if (!quiet) {
458 // pretty print the json
459 json_object *obj = json_tokener_parse(resp);
460 465
461 if (obj == NULL) { 466 // pretty print the json
467 json_object *obj = json_tokener_parse(resp);
468 if (obj == NULL) {
469 if (!quiet) {
462 fprintf(stderr, "ERROR: Could not parse json response from ipc. " 470 fprintf(stderr, "ERROR: Could not parse json response from ipc. "
463 "This is a bug in sway."); 471 "This is a bug in sway.");
464 printf("%s\n", resp); 472 printf("%s\n", resp);
473 }
474 ret = 1;
475 } else {
476 if (!success(obj, true)) {
465 ret = 1; 477 ret = 1;
466 } else { 478 }
467 if (!success(obj, true)) { 479 if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) {
468 ret = 1; 480 if (raw) {
469 } 481 printf("%s\n", json_object_to_json_string_ext(obj,
470 if (type != IPC_SUBSCRIBE || ret != 0) { 482 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
471 if (raw) { 483 } else {
472 printf("%s\n", json_object_to_json_string_ext(obj, 484 pretty_print(type, obj);
473 JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED));
474 } else {
475 pretty_print(type, obj);
476 }
477 } 485 }
478 json_object_put(obj);
479 } 486 }
487 json_object_put(obj);
480 } 488 }
481 free(command); 489 free(command);
482 free(resp); 490 free(resp);
@@ -495,10 +503,14 @@ int main(int argc, char **argv) {
495 503
496 json_object *obj = json_tokener_parse(reply->payload); 504 json_object *obj = json_tokener_parse(reply->payload);
497 if (obj == NULL) { 505 if (obj == NULL) {
498 fprintf(stderr, "ERROR: Could not parse json response from ipc" 506 if (!quiet) {
499 ". This is a bug in sway."); 507 fprintf(stderr, "ERROR: Could not parse json response from"
500 ret = 1; 508 " ipc. This is a bug in sway.");
509 ret = 1;
510 }
501 break; 511 break;
512 } else if (quiet) {
513 json_object_put(obj);
502 } else { 514 } else {
503 if (raw) { 515 if (raw) {
504 printf("%s\n", json_object_to_json_string(obj)); 516 printf("%s\n", json_object_to_json_string(obj));