diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2021-10-21 22:47:35 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-10-22 09:57:05 +0200 |
commit | b223f702500d7cda6336e948062d680f07f34f66 (patch) | |
tree | 96b59cf413046634b6d6a647a35994123356d54a /swaymsg | |
parent | fix: use sane value for json_tokener max_depth (diff) | |
download | sway-b223f702500d7cda6336e948062d680f07f34f66.tar.gz sway-b223f702500d7cda6336e948062d680f07f34f66.tar.zst sway-b223f702500d7cda6336e948062d680f07f34f66.zip |
refactor: use sway_abort instead
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index dcf42cb6..e469319a 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -487,32 +487,33 @@ int main(int argc, char **argv) { | |||
487 | // pretty print the json | 487 | // pretty print the json |
488 | json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); | 488 | json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); |
489 | if (tok == NULL) { | 489 | if (tok == NULL) { |
490 | sway_log(SWAY_ERROR, "failed allocating json_tokener"); | 490 | if (quiet) { |
491 | exit(EXIT_FAILURE); | ||
492 | } | ||
493 | sway_abort("failed allocating json_tokener"); | ||
494 | } | ||
495 | json_object *obj = json_tokener_parse_ex(tok, resp, -1); | ||
496 | enum json_tokener_error err = json_tokener_get_error(tok); | ||
497 | json_tokener_free(tok); | ||
498 | if (obj == NULL || err != json_tokener_success) { | ||
499 | if (!quiet) { | ||
500 | sway_log(SWAY_ERROR, "failed to parse payload as json: %s", | ||
501 | json_tokener_error_desc(err)); | ||
502 | } | ||
491 | ret = 1; | 503 | ret = 1; |
492 | } else { | 504 | } else { |
493 | json_object *obj = json_tokener_parse_ex(tok, resp, -1); | 505 | if (!success(obj, true)) { |
494 | enum json_tokener_error err = json_tokener_get_error(tok); | 506 | ret = 2; |
495 | json_tokener_free(tok); | 507 | } |
496 | if (obj == NULL || err != json_tokener_success) { | 508 | if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) { |
497 | if (!quiet) { | 509 | if (raw) { |
498 | sway_log(SWAY_ERROR, "failed to parse payload as json: %s", | 510 | printf("%s\n", json_object_to_json_string_ext(obj, |
499 | json_tokener_error_desc(err)); | 511 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); |
500 | } | 512 | } else { |
501 | ret = 1; | 513 | pretty_print(type, obj); |
502 | } else { | ||
503 | if (!success(obj, true)) { | ||
504 | ret = 2; | ||
505 | } | ||
506 | if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) { | ||
507 | if (raw) { | ||
508 | printf("%s\n", json_object_to_json_string_ext(obj, | ||
509 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); | ||
510 | } else { | ||
511 | pretty_print(type, obj); | ||
512 | } | ||
513 | } | 514 | } |
514 | json_object_put(obj); | ||
515 | } | 515 | } |
516 | json_object_put(obj); | ||
516 | } | 517 | } |
517 | free(command); | 518 | free(command); |
518 | free(resp); | 519 | free(resp); |
@@ -531,9 +532,10 @@ int main(int argc, char **argv) { | |||
531 | 532 | ||
532 | json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); | 533 | json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); |
533 | if (tok == NULL) { | 534 | if (tok == NULL) { |
534 | sway_log(SWAY_ERROR, "failed allocating json_tokener"); | 535 | if (quiet) { |
535 | ret = 1; | 536 | exit(EXIT_FAILURE); |
536 | break; | 537 | } |
538 | sway_abort("failed allocating json_tokener"); | ||
537 | } | 539 | } |
538 | json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); | 540 | json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); |
539 | enum json_tokener_error err = json_tokener_get_error(tok); | 541 | enum json_tokener_error err = json_tokener_get_error(tok); |