diff options
Diffstat (limited to 'i3-msg/main.c')
-rw-r--r-- | i3-msg/main.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/i3-msg/main.c b/i3-msg/main.c index 239ac46f..e2d27412 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -61,22 +61,24 @@ static int exit_code = 0; static reply_t last_reply; static int reply_boolean_cb(void *params, int val) { - if (strcmp(last_key, "success") == 0) + if (strcmp(last_key, "success") == 0) { last_reply.success = val; + } return 1; } static int reply_string_cb(void *params, const unsigned char *val, size_t len) { char *str = sstrndup((const char *)val, len); - if (strcmp(last_key, "error") == 0) + if (strcmp(last_key, "error") == 0) { last_reply.error = str; - else if (strcmp(last_key, "input") == 0) + } else if (strcmp(last_key, "input") == 0) { last_reply.input = str; - else if (strcmp(last_key, "errorposition") == 0) + } else if (strcmp(last_key, "errorposition") == 0) { last_reply.errorposition = str; - else + } else { free(str); + } return 1; } @@ -147,8 +149,9 @@ static yajl_callbacks config_callbacks = { int main(int argc, char *argv[]) { #if defined(__OpenBSD__) - if (pledge("stdio rpath unix", NULL) == -1) + if (pledge("stdio rpath unix", NULL) == -1) { err(EXIT_FAILURE, "pledge"); + } #endif char *socket_path = NULL; int o, option_index = 0; @@ -244,12 +247,14 @@ int main(int argc, char *argv[]) { optind++; } - if (!payload) + if (!payload) { payload = sstrdup(""); + } int sockfd = ipc_connect(socket_path); - if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1) + if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1) { err(EXIT_FAILURE, "IPC: write()"); + } free(payload); uint32_t reply_length; @@ -257,12 +262,14 @@ int main(int argc, char *argv[]) { uint8_t *reply; int ret; if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) { - if (ret == -1) + if (ret == -1) { err(EXIT_FAILURE, "IPC: read()"); + } exit(1); } - if (reply_type != message_type) + if (reply_type != message_type) { errx(EXIT_FAILURE, "IPC: Received reply of type %d but expected %d", reply_type, message_type); + } /* For the reply of commands, have a look if that command was successful. * If not, nicely format the error message. */ if (reply_type == I3_IPC_REPLY_TYPE_COMMAND) { @@ -303,8 +310,9 @@ int main(int argc, char *argv[]) { do { free(reply); if ((ret = ipc_recv_message(sockfd, &reply_type, &reply_length, &reply)) != 0) { - if (ret == -1) + if (ret == -1) { err(EXIT_FAILURE, "IPC: read()"); + } exit(1); } |