i3-msg: check reply in quiet mode

i3-msg currently exits right after sending the IPC message if the quiet
flag is set. This means that if an error occurred when issuing a
command, e.g. "i3-msg -q foobar", it gets silently ignored.

What we really want is to just skip printing but still check the reply.

At the same time, explicitly print the reply when we need to, instead of
using an exit label.
This commit is contained in:
Vivien Didelot 2018-10-02 18:13:06 -04:00
parent 3b73edb511
commit d722d1b0e6
1 changed files with 7 additions and 9 deletions

View File

@ -246,9 +246,6 @@ int main(int argc, char *argv[]) {
err(EXIT_FAILURE, "IPC: write()"); err(EXIT_FAILURE, "IPC: write()");
free(payload); free(payload);
if (quiet)
return 0;
uint32_t reply_length; uint32_t reply_length;
uint32_t reply_type; uint32_t reply_type;
uint8_t *reply; uint8_t *reply;
@ -275,8 +272,9 @@ int main(int argc, char *argv[]) {
errx(EXIT_FAILURE, "IPC: Could not parse JSON reply."); errx(EXIT_FAILURE, "IPC: Could not parse JSON reply.");
} }
/* NB: We still fall-through and print the reply, because even if one if (!quiet) {
* command failed, that doesnt mean that all commands failed. */ printf("%.*s\n", reply_length, reply);
}
} else if (reply_type == I3_IPC_REPLY_TYPE_CONFIG) { } else if (reply_type == I3_IPC_REPLY_TYPE_CONFIG) {
yajl_handle handle = yajl_alloc(&config_callbacks, NULL, NULL); yajl_handle handle = yajl_alloc(&config_callbacks, NULL, NULL);
yajl_status state = yajl_parse(handle, (const unsigned char *)reply, reply_length); yajl_status state = yajl_parse(handle, (const unsigned char *)reply, reply_length);
@ -289,12 +287,12 @@ int main(int argc, char *argv[]) {
case yajl_status_error: case yajl_status_error:
errx(EXIT_FAILURE, "IPC: Could not parse JSON reply."); errx(EXIT_FAILURE, "IPC: Could not parse JSON reply.");
} }
} else {
goto exit; if (!quiet) {
}
printf("%.*s\n", reply_length, reply); printf("%.*s\n", reply_length, reply);
}
}
exit:
free(reply); free(reply);
close(sockfd); close(sockfd);