diff options
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index 5f7854f5..3698294a 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c | |||
@@ -482,28 +482,33 @@ int main(int argc, char **argv) { | |||
482 | 482 | ||
483 | // pretty print the json | 483 | // pretty print the json |
484 | json_tokener *tok = json_tokener_new_ex(INT_MAX); | 484 | json_tokener *tok = json_tokener_new_ex(INT_MAX); |
485 | json_object *obj = json_tokener_parse_ex(tok, resp, -1); | 485 | if (tok == NULL) { |
486 | enum json_tokener_error err = json_tokener_get_error(tok); | 486 | sway_log(SWAY_ERROR, "failed allocating json_tokener"); |
487 | json_tokener_free(tok); | ||
488 | if (obj == NULL || err != json_tokener_success) { | ||
489 | if (!quiet) { | ||
490 | sway_log(SWAY_ERROR, "failed to parse payload as json: %s", | ||
491 | json_tokener_error_desc(err)); | ||
492 | } | ||
493 | ret = 1; | 487 | ret = 1; |
494 | } else { | 488 | } else { |
495 | if (!success(obj, true)) { | 489 | json_object *obj = json_tokener_parse_ex(tok, resp, -1); |
496 | ret = 2; | 490 | enum json_tokener_error err = json_tokener_get_error(tok); |
497 | } | 491 | json_tokener_free(tok); |
498 | if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) { | 492 | if (obj == NULL || err != json_tokener_success) { |
499 | if (raw) { | 493 | if (!quiet) { |
500 | printf("%s\n", json_object_to_json_string_ext(obj, | 494 | sway_log(SWAY_ERROR, "failed to parse payload as json: %s", |
501 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); | 495 | json_tokener_error_desc(err)); |
502 | } else { | ||
503 | pretty_print(type, obj); | ||
504 | } | 496 | } |
497 | ret = 1; | ||
498 | } else { | ||
499 | if (!success(obj, true)) { | ||
500 | ret = 2; | ||
501 | } | ||
502 | if (!quiet && (type != IPC_SUBSCRIBE || ret != 0)) { | ||
503 | if (raw) { | ||
504 | printf("%s\n", json_object_to_json_string_ext(obj, | ||
505 | JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED)); | ||
506 | } else { | ||
507 | pretty_print(type, obj); | ||
508 | } | ||
509 | } | ||
510 | json_object_put(obj); | ||
505 | } | 511 | } |
506 | json_object_put(obj); | ||
507 | } | 512 | } |
508 | free(command); | 513 | free(command); |
509 | free(resp); | 514 | free(resp); |
@@ -521,6 +526,11 @@ int main(int argc, char **argv) { | |||
521 | } | 526 | } |
522 | 527 | ||
523 | json_tokener *tok = json_tokener_new_ex(INT_MAX); | 528 | json_tokener *tok = json_tokener_new_ex(INT_MAX); |
529 | if (tok == NULL) { | ||
530 | sway_log(SWAY_ERROR, "failed allocating json_tokener"); | ||
531 | ret = 1; | ||
532 | break; | ||
533 | } | ||
524 | json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); | 534 | json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); |
525 | enum json_tokener_error err = json_tokener_get_error(tok); | 535 | enum json_tokener_error err = json_tokener_get_error(tok); |
526 | json_tokener_free(tok); | 536 | json_tokener_free(tok); |