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.
This commit is contained in:
parent
1ff5740104
commit
1a829fd76d
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue