From 1a829fd76d6a2293f147ea4cf16f01acbcb8f3d0 Mon Sep 17 00:00:00 2001 From: Nikos Ntarmos Date: Sat, 17 Nov 2007 12:35:20 +0200 Subject: [PATCH] Make awesome-client exit with a meaningful value on error As discussed on #awesome, the attached patch makes awesome-client exit with a meaningful value (i.e. that of errno) when it encounters an error. Since the most frequent error with awesome-client is a mismatch in the socket path, there is an explicit case for ENOENT errors. I thought of adding a matching fprintf in awesome.c, but you can tell what socket awesome is listening on by looking at what ~/.awesome_ctl.* file you have. CAVEAT: Exiting on error may break setups such as: while true; do echo "some text" done | /path/to/awesome-client which relied on awesome-client continuing to send to the given socket (although failing) until EOF was encountered on stdin. --- awesome-client.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/awesome-client.c b/awesome-client.c index ee945b5f1..b94e819c0 100644 --- a/awesome-client.c +++ b/awesome-client.c @@ -34,7 +34,7 @@ main(int argc, char **argv) { struct sockaddr_un *addr; char buf[1024]; - int csfd; + int csfd, ret_value = EXIT_SUCCESS; csfd = get_client_socket(); if(argc > 1) @@ -46,12 +46,25 @@ main(int argc, char **argv) return EXIT_FAILURE; while(fgets(buf, sizeof(buf), stdin)) + { if(sendto(csfd, buf, a_strlen(buf), MSG_NOSIGNAL, (const struct sockaddr *) addr, sizeof(struct sockaddr_un)) == -1) - perror("error sending datagram"); + { + switch (errno) + { + case ENOENT: + fprintf(stderr, "Can't write to %s\n", addr->sun_path); + break; + default: + perror("error sending datagram"); + } + ret_value = errno; + break; + } + } p_delete(&addr); - return EXIT_SUCCESS; + return ret_value; } // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99