unix-server: some error checking

This commit is contained in:
Vincent Penquerc'h 2013-12-28 06:25:12 -05:00 committed by Marek Marczykowski-Górecki
parent 9192aa041d
commit 21154a3e6b

View File

@ -32,9 +32,16 @@ int get_server_socket(char *socket_address)
struct sockaddr_un sockname; struct sockaddr_un sockname;
int s; int s;
unlink(socket_address); if (unlink(socket_address) < 0) {
printf("unlink(%s) failed\n", socket_address);
exit(1);
}
s = socket(AF_UNIX, SOCK_STREAM, 0); s = socket(AF_UNIX, SOCK_STREAM, 0);
if (s < 0) {
printf("socket() failed\n");
exit(1);
}
memset(&sockname, 0, sizeof(sockname)); memset(&sockname, 0, sizeof(sockname));
sockname.sun_family = AF_UNIX; sockname.sun_family = AF_UNIX;
memcpy(sockname.sun_path, socket_address, strlen(socket_address)); memcpy(sockname.sun_path, socket_address, strlen(socket_address));