From 24b3c2bc4645d5673d713535b06389d4ea392b6d Mon Sep 17 00:00:00 2001 From: dcp1990 Date: Sun, 19 Jun 2005 00:08:10 +0000 Subject: [PATCH] Friends Don't Let Friends Use perror(). --- phoned/socket.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/phoned/socket.c b/phoned/socket.c index 04c9e44..12472aa 100644 --- a/phoned/socket.c +++ b/phoned/socket.c @@ -75,18 +75,21 @@ void *network(b) cbuf[0] = '\0'; cbuf[1] = '\0'; is = b; if((s = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1) { - perror("socket"); + lprintf(error, "socket: %s\n", strerror(errno)); + shutd(0x1|0x2|0x4|0x10|0x20); exit(-1); } strcpy(it.sun_path, SOCKETFILE); it.sun_family = AF_LOCAL; if(bind(s, (struct sockaddr *)&it, 1 + strlen(it.sun_path) + sizeof(it.sun_family)) == -1) { - perror("bind"); + lprintf(error, "bind: %s\n", strerror(errno)); + shutd(0x1|0x2|0x4|0x10|0x20); exit(-1); } if(listen(s, 5) == -1) { - perror("listen"); + lprintf(error, "listen: %s\n", strerror(errno)); + shutd(0x1|0x2|0x4|0x10|0x20); exit(-1); } sin_size = sizeof(struct sockaddr_in); @@ -95,7 +98,8 @@ void *network(b) FD_SET(s, &fds); switch(select(s + 1, &fds, NULL, NULL, NULL)) { case -1: - perror("select"); + lprintf(error, "select: %s\n", strerror(errno)); + shutd(0x1|0x2|0x4|0x10|0x20); exit(-1); break; case 0: @@ -110,6 +114,7 @@ void *network(b) == -1) { lprintf(error, "accept: %s\n", strerror(errno)); + shutd(0x1|0x2|0x4|0x10|0x20); exit(-3); } pthread_create(&thr, NULL, handclient, (void*)sn);