From c56dc0f966624aa3279b298134585b791c043ab4 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 28 Jul 2009 21:29:23 +0200 Subject: [PATCH] i3-msg: more error handling, more comments --- i3-msg/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/i3-msg/main.c b/i3-msg/main.c index 8404be3e..ebeca7d5 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -27,6 +27,11 @@ #include #include +/* + * Formats a message (payload) of the given size and type and sends it to i3 via + * the given socket file descriptor. + * + */ static void ipc_send_message(int sockfd, uint32_t message_size, uint32_t message_type, uint8_t *payload) { int buffer_size = strlen("i3-ipc") + sizeof(uint32_t) + sizeof(uint32_t) + message_size; @@ -90,12 +95,15 @@ int main(int argc, char *argv[]) { } int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0); + if (sockfd == -1) + err(EXIT_FAILURE, "Could not create socket"); + struct sockaddr_un addr; memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_LOCAL; strcpy(addr.sun_path, socket_path); if (connect(sockfd, &addr, sizeof(struct sockaddr_un)) < 0) - err(-1, "Could not connect to i3"); + err(EXIT_FAILURE, "Could not connect to i3"); ipc_send_message(sockfd, strlen(argv[optind]), 0, (uint8_t*)argv[optind]); -- 2.39.5