From: Michael Stapelberg Date: Tue, 28 Jul 2009 19:29:23 +0000 (+0200) Subject: i3-msg: more error handling, more comments X-Git-Tag: 3.c~39 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c56dc0f966624aa3279b298134585b791c043ab4;p=i3%2Fi3 i3-msg: more error handling, more comments --- 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]);