aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2006-07-19 15:28:30 +0000
committerYang Tse <yangsita@gmail.com>2006-07-19 15:28:30 +0000
commitab4256d53a1afdf02fa8b4e7236dc1f6c986d5f4 (patch)
tree204eccc5613a75b2376a99e1b8a520983b0903f7
parent46c5e562bfb5ce530f7f9d0ea9d686ca6e341d2a (diff)
Abort if unable to write pid file, and close socket when aborting.
-rw-r--r--tests/server/sockfilt.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c
index 415bb3576..2e12a03d7 100644
--- a/tests/server/sockfilt.c
+++ b/tests/server/sockfilt.c
@@ -445,7 +445,12 @@ static curl_socket_t sockdaemon(curl_socket_t sock,
}
/* start accepting connections */
- listen(sock, 4);
+ rc = listen(sock, 4);
+ if(0 != rc) {
+ logmsg("listen() failed with error: %d", errno);
+ sclose(sock);
+ return CURL_SOCKET_BAD;
+ }
return sock;
}
@@ -464,10 +469,9 @@ static curl_socket_t mksock(bool use_ipv6)
sock = socket(AF_INET6, SOCK_STREAM, 0);
#endif
- if (sock < 0) {
+ if (CURL_SOCKET_BAD == sock) {
perror("opening stream socket");
logmsg("Error opening socket");
- return CURL_SOCKET_BAD;
}
return sock;
@@ -565,6 +569,10 @@ int main(int argc, char *argv[])
sock = mksock(use_ipv6);
+ if (CURL_SOCKET_BAD == sock) {
+ logmsg("Error opening socket: %d", errno);
+ return 1;
+ }
if(connectport) {
/* Active mode, we should connect to the given port number */
@@ -593,6 +601,7 @@ int main(int argc, char *argv[])
if(rc) {
perror("connecting stream socket");
logmsg("Error connecting to port %d", port);
+ sclose(sock);
return 1;
}
logmsg("====> Client connect");
@@ -621,8 +630,11 @@ int main(int argc, char *argv[])
fclose(pidfile);
logmsg("Wrote pid %d to %s", pid, pidname);
}
- else
+ else {
fprintf(stderr, "Couldn't write pid file\n");
+ sclose(sock);
+ return 1;
+ }
while(juggle(&msgsock, sock, &mode));