aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2008-02-28 10:13:07 +0000
committerYang Tse <yangsita@gmail.com>2008-02-28 10:13:07 +0000
commit22e84d92b78ec845a6ce6446273ceb9d04dc825d (patch)
tree665cfeb28a6023f0f78f8d0f2b788b78a5888312
parent3d74649908cfe0d397b24d966674415bc54f0fff (diff)
when terminating do it falling through cleanup code
-rw-r--r--tests/server/sockfilt.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/tests/server/sockfilt.c b/tests/server/sockfilt.c
index c54734a52..2d1a47ba2 100644
--- a/tests/server/sockfilt.c
+++ b/tests/server/sockfilt.c
@@ -280,6 +280,7 @@ static bool juggle(curl_socket_t *sockfdp,
ssize_t nread_socket;
ssize_t bytes_written;
ssize_t buffer_len;
+ int error;
/* 'buffer' is this excessively large only to be able to support things like
test 1003 which tests exceedingly large server response lines */
@@ -358,10 +359,13 @@ static bool juggle(curl_socket_t *sockfdp,
rc = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, &timeout);
- } while((rc == -1) && (SOCKERRNO == EINTR));
+ } while((rc == -1) && ((error = SOCKERRNO) == EINTR));
- if(rc < 0)
+ if(rc < 0) {
+ logmsg("select() failed with error: (%d) %s",
+ error, strerror(error));
return FALSE;
+ }
if(rc == 0)
/* timeout */
@@ -620,8 +624,9 @@ int main(int argc, char *argv[])
#ifdef ENABLE_IPV6
struct sockaddr_in6 me6;
#endif /* ENABLE_IPV6 */
- curl_socket_t sock;
- curl_socket_t msgsock;
+ curl_socket_t sock = CURL_SOCKET_BAD;
+ curl_socket_t msgsock = CURL_SOCKET_BAD;
+ int wrotepidfile = 0;
char *pidname= (char *)".sockfilt.pid";
int rc;
int error;
@@ -732,7 +737,7 @@ int main(int argc, char *argv[])
error = SOCKERRNO;
logmsg("Error creating socket: (%d) %s",
error, strerror(error));
- return 1;
+ goto sockfilt_cleanup;
}
if(connectport) {
@@ -767,8 +772,7 @@ int main(int argc, char *argv[])
error = SOCKERRNO;
logmsg("Error connecting to port %d: (%d) %s",
port, error, strerror(error));
- sclose(sock);
- return 1;
+ goto sockfilt_cleanup;
}
logmsg("====> Client connect");
msgsock = sock; /* use this as stream */
@@ -777,7 +781,7 @@ int main(int argc, char *argv[])
/* passive daemon style */
sock = sockdaemon(sock, &port);
if(CURL_SOCKET_BAD == sock)
- return 1;
+ goto sockfilt_cleanup;
msgsock = CURL_SOCKET_BAD; /* no stream socket yet */
}
@@ -789,17 +793,24 @@ int main(int argc, char *argv[])
else
logmsg("Listening on port %d", port);
- if(!write_pidfile(pidname)) {
- sclose(sock);
- return 1;
- }
+ wrotepidfile = write_pidfile(pidname);
+ if(!wrotepidfile)
+ goto sockfilt_cleanup;
while(juggle(&msgsock, sock, &mode));
+sockfilt_cleanup:
+
+ if((msgsock != sock) && (msgsock != CURL_SOCKET_BAD))
+ sclose(msgsock);
+
+ if(sock != CURL_SOCKET_BAD)
sclose(sock);
+
+ if(wrotepidfile)
unlink(pidname);
- logmsg("sockfilt exits");
+ logmsg("============> sockfilt quits");
return 0;
}