test servers: fix errno, ERRNO and SOCKERRNO usage for W32/W64

This commit is contained in:
Yang Tse
2013-01-09 15:10:23 +01:00
parent a9ca5e61e5
commit a6848250d2
6 changed files with 112 additions and 78 deletions

View File

@@ -6,7 +6,7 @@
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2010, Mandy Wu, <mandy.wu@intel.com> * Copyright (C) 2010, Mandy Wu, <mandy.wu@intel.com>
* Copyright (C) 2011 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2011 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -184,7 +184,7 @@ int main(int argc, char *argv[])
filename = test2file(testnum); filename = test2file(testnum);
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum); logmsg("Couldn't open test file %ld", testnum);
@@ -202,7 +202,7 @@ int main(int argc, char *argv[])
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum); logmsg("Couldn't open test file %ld", testnum);
@@ -222,7 +222,7 @@ int main(int argc, char *argv[])
if(strcmp(buf, type1_input) == 0) { if(strcmp(buf, type1_input) == 0) {
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum); logmsg("Couldn't open test file %ld", testnum);
@@ -243,7 +243,7 @@ int main(int argc, char *argv[])
else if(strncmp(buf, type3_input, strlen(type3_input)) == 0) { else if(strncmp(buf, type3_input, strlen(type3_input)) == 0) {
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", testnum); logmsg("Couldn't open test file %ld", testnum);

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -54,6 +54,13 @@
/* include memdebug.h last */ /* include memdebug.h last */
#include "memdebug.h" #include "memdebug.h"
#ifdef USE_WINSOCK
#undef EINTR
#define EINTR 4 /* errno.h value */
#undef ERANGE
#define ERANGE 34 /* errno.h value */
#endif
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
static bool use_ipv6 = FALSE; static bool use_ipv6 = FALSE;
#endif #endif
@@ -236,13 +243,13 @@ static volatile int exit_signal = 0;
static RETSIGTYPE exit_signal_handler(int signum) static RETSIGTYPE exit_signal_handler(int signum)
{ {
int old_errno = ERRNO; int old_errno = errno;
if(got_exit_signal == 0) { if(got_exit_signal == 0) {
got_exit_signal = 1; got_exit_signal = 1;
exit_signal = signum; exit_signal = signum;
} }
(void)signal(signum, exit_signal_handler); (void)signal(signum, exit_signal_handler);
SET_ERRNO(old_errno); errno = old_errno;
} }
static void install_signal_handlers(void) static void install_signal_handlers(void)
@@ -250,29 +257,29 @@ static void install_signal_handlers(void)
#ifdef SIGHUP #ifdef SIGHUP
/* ignore SIGHUP signal */ /* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR) if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO)); logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
/* ignore SIGPIPE signal */ /* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO)); logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif #endif
#ifdef SIGALRM #ifdef SIGALRM
/* ignore SIGALRM signal */ /* ignore SIGALRM signal */
if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR) if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGALRM handler: %s", strerror(errno));
#endif #endif
#ifdef SIGINT #ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */ /* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR) if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO)); logmsg("cannot install SIGINT handler: %s", strerror(errno));
else else
siginterrupt(SIGINT, 1); siginterrupt(SIGINT, 1);
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */ /* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR) if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else else
siginterrupt(SIGTERM, 1); siginterrupt(SIGTERM, 1);
#endif #endif
@@ -395,7 +402,7 @@ static int ProcessRequest(struct httprequest *req)
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", req->testno); logmsg("Couldn't open test file %ld", req->testno);
@@ -575,9 +582,9 @@ static int ProcessRequest(struct httprequest *req)
while(*ptr && ISSPACE(*ptr)) while(*ptr && ISSPACE(*ptr))
ptr++; ptr++;
endptr = ptr; endptr = ptr;
SET_ERRNO(0); errno = 0;
clen = strtoul(ptr, &endptr, 10); clen = strtoul(ptr, &endptr, 10);
if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == ERRNO)) { if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
/* this assumes that a zero Content-Length is valid */ /* this assumes that a zero Content-Length is valid */
logmsg("Found invalid Content-Length: (%s) in the request", ptr); logmsg("Found invalid Content-Length: (%s) in the request", ptr);
req->open = FALSE; /* closes connection */ req->open = FALSE; /* closes connection */
@@ -709,7 +716,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
do { do {
dump = fopen(REQUEST_DUMP, "ab"); dump = fopen(REQUEST_DUMP, "ab");
} while ((dump == NULL) && ((error = ERRNO) == EINTR)); } while ((dump == NULL) && ((error = errno) == EINTR));
if (dump == NULL) { if (dump == NULL) {
logmsg("Error opening file %s error: %d %s", logmsg("Error opening file %s error: %d %s",
REQUEST_DUMP, error, strerror(error)); REQUEST_DUMP, error, strerror(error));
@@ -725,7 +732,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
goto storerequest_cleanup; goto storerequest_cleanup;
if(written > 0) if(written > 0)
writeleft -= written; writeleft -= written;
} while ((writeleft > 0) && ((error = ERRNO) == EINTR)); } while ((writeleft > 0) && ((error = errno) == EINTR));
if(writeleft == 0) if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to " REQUEST_DUMP, totalsize); logmsg("Wrote request (%zu bytes) input to " REQUEST_DUMP, totalsize);
@@ -740,7 +747,7 @@ storerequest_cleanup:
do { do {
res = fclose(dump); res = fclose(dump);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = errno) == EINTR));
if(res) if(res)
logmsg("Error closing file %s error: %d %s", logmsg("Error closing file %s error: %d %s",
REQUEST_DUMP, error, strerror(error)); REQUEST_DUMP, error, strerror(error));
@@ -954,7 +961,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file"); logmsg("Couldn't open test file");
@@ -979,7 +986,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
/* re-open the same file again */ /* re-open the same file again */
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file"); logmsg("Couldn't open test file");
@@ -1024,7 +1031,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
dump = fopen(RESPONSE_DUMP, "ab"); dump = fopen(RESPONSE_DUMP, "ab");
if(!dump) { if(!dump) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", RESPONSE_DUMP); logmsg("Error opening file: %s", RESPONSE_DUMP);
logmsg("couldn't create logfile: " RESPONSE_DUMP); logmsg("couldn't create logfile: " RESPONSE_DUMP);
@@ -1082,7 +1089,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
do { do {
res = fclose(dump); res = fclose(dump);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = errno) == EINTR));
if(res) if(res)
logmsg("Error closing file %s error: %d %s", logmsg("Error closing file %s error: %d %s",
RESPONSE_DUMP, error, strerror(error)); RESPONSE_DUMP, error, strerror(error));
@@ -1128,7 +1135,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
break; break;
if(res) { if(res) {
/* should not happen */ /* should not happen */
error = SOCKERRNO; error = errno;
logmsg("wait_ms() failed with error: (%d) %s", logmsg("wait_ms() failed with error: (%d) %s",
error, strerror(error)); error, strerror(error));
break; break;

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -109,6 +109,17 @@
/* include memdebug.h last */ /* include memdebug.h last */
#include "memdebug.h" #include "memdebug.h"
#ifdef USE_WINSOCK
#undef EINTR
#define EINTR 4 /* errno.h value */
#undef EAGAIN
#define EAGAIN 11 /* errno.h value */
#undef ENOMEM
#define ENOMEM 12 /* errno.h value */
#undef EINVAL
#define EINVAL 22 /* errno.h value */
#endif
#define DEFAULT_PORT 8999 #define DEFAULT_PORT 8999
#ifndef DEFAULT_LOGFILE #ifndef DEFAULT_LOGFILE
@@ -178,13 +189,13 @@ static volatile int exit_signal = 0;
static RETSIGTYPE exit_signal_handler(int signum) static RETSIGTYPE exit_signal_handler(int signum)
{ {
int old_errno = ERRNO; int old_errno = errno;
if(got_exit_signal == 0) { if(got_exit_signal == 0) {
got_exit_signal = 1; got_exit_signal = 1;
exit_signal = signum; exit_signal = signum;
} }
(void)signal(signum, exit_signal_handler); (void)signal(signum, exit_signal_handler);
SET_ERRNO(old_errno); errno = old_errno;
} }
static void install_signal_handlers(void) static void install_signal_handlers(void)
@@ -192,29 +203,29 @@ static void install_signal_handlers(void)
#ifdef SIGHUP #ifdef SIGHUP
/* ignore SIGHUP signal */ /* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR) if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO)); logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
/* ignore SIGPIPE signal */ /* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO)); logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif #endif
#ifdef SIGALRM #ifdef SIGALRM
/* ignore SIGALRM signal */ /* ignore SIGALRM signal */
if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR) if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGALRM handler: %s", strerror(errno));
#endif #endif
#ifdef SIGINT #ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */ /* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR) if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO)); logmsg("cannot install SIGINT handler: %s", strerror(errno));
else else
siginterrupt(SIGINT, 1); siginterrupt(SIGINT, 1);
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */ /* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR) if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else else
siginterrupt(SIGTERM, 1); siginterrupt(SIGTERM, 1);
#endif #endif
@@ -266,7 +277,7 @@ static ssize_t fullread(int filedes, void *buffer, size_t nbytes)
} }
if(rc < 0) { if(rc < 0) {
error = ERRNO; error = errno;
if((error == EINTR) || (error == EAGAIN)) if((error == EINTR) || (error == EAGAIN))
continue; continue;
logmsg("unrecoverable read() failure: (%d) %s", logmsg("unrecoverable read() failure: (%d) %s",
@@ -311,7 +322,7 @@ static ssize_t fullwrite(int filedes, const void *buffer, size_t nbytes)
} }
if(wc < 0) { if(wc < 0) {
error = ERRNO; error = errno;
if((error == EINTR) || (error == EAGAIN)) if((error == EINTR) || (error == EAGAIN))
continue; continue;
logmsg("unrecoverable write() failure: (%d) %s", logmsg("unrecoverable write() failure: (%d) %s",
@@ -435,7 +446,7 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
/* check if the input value is valid */ /* check if the input value is valid */
if(nfds < 0) { if(nfds < 0) {
SET_SOCKERRNO(EINVAL); errno = EINVAL;
return -1; return -1;
} }
@@ -448,28 +459,28 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
/* allocate internal array for the original input handles */ /* allocate internal array for the original input handles */
fdarr = malloc(nfds * sizeof(curl_socket_t)); fdarr = malloc(nfds * sizeof(curl_socket_t));
if(fdarr == NULL) { if(fdarr == NULL) {
SET_SOCKERRNO(ENOMEM); errno = ENOMEM;
return -1; return -1;
} }
/* allocate internal array for the internal event handles */ /* allocate internal array for the internal event handles */
handles = malloc(nfds * sizeof(HANDLE)); handles = malloc(nfds * sizeof(HANDLE));
if(handles == NULL) { if(handles == NULL) {
SET_SOCKERRNO(ENOMEM); errno = ENOMEM;
return -1; return -1;
} }
/* allocate internal array for the internal socket handles */ /* allocate internal array for the internal socket handles */
wsasocks = malloc(nfds * sizeof(curl_socket_t)); wsasocks = malloc(nfds * sizeof(curl_socket_t));
if(wsasocks == NULL) { if(wsasocks == NULL) {
SET_SOCKERRNO(ENOMEM); errno = ENOMEM;
return -1; return -1;
} }
/* allocate internal array for the internal WINSOCK2 events */ /* allocate internal array for the internal WINSOCK2 events */
wsaevents = malloc(nfds * sizeof(WSAEVENT)); wsaevents = malloc(nfds * sizeof(WSAEVENT));
if(wsaevents == NULL) { if(wsaevents == NULL) {
SET_SOCKERRNO(ENOMEM); errno = ENOMEM;
return -1; return -1;
} }
@@ -743,7 +754,7 @@ static bool juggle(curl_socket_t *sockfdp,
return FALSE; return FALSE;
} }
} while((rc == -1) && ((error = SOCKERRNO) == EINTR)); } while((rc == -1) && ((error = errno) == EINTR));
if(rc < 0) { if(rc < 0) {
logmsg("select() failed with error: (%d) %s", logmsg("select() failed with error: (%d) %s",
@@ -933,7 +944,7 @@ static curl_socket_t sockdaemon(curl_socket_t sock,
rc = wait_ms(delay); rc = wait_ms(delay);
if(rc) { if(rc) {
/* should not happen */ /* should not happen */
error = SOCKERRNO; error = errno;
logmsg("wait_ms() failed with error: (%d) %s", logmsg("wait_ms() failed with error: (%d) %s",
error, strerror(error)); error, strerror(error));
sclose(sock); sclose(sock);

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -56,6 +56,15 @@
/* include memdebug.h last */ /* include memdebug.h last */
#include "memdebug.h" #include "memdebug.h"
#ifdef USE_WINSOCK
#undef EINTR
#define EINTR 4 /* errno.h value */
#undef EAGAIN
#define EAGAIN 11 /* errno.h value */
#undef ERANGE
#define ERANGE 34 /* errno.h value */
#endif
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
static bool use_ipv6 = FALSE; static bool use_ipv6 = FALSE;
#endif #endif
@@ -239,13 +248,13 @@ static volatile int exit_signal = 0;
static RETSIGTYPE exit_signal_handler(int signum) static RETSIGTYPE exit_signal_handler(int signum)
{ {
int old_errno = ERRNO; int old_errno = errno;
if(got_exit_signal == 0) { if(got_exit_signal == 0) {
got_exit_signal = 1; got_exit_signal = 1;
exit_signal = signum; exit_signal = signum;
} }
(void)signal(signum, exit_signal_handler); (void)signal(signum, exit_signal_handler);
SET_ERRNO(old_errno); errno = old_errno;
} }
static void install_signal_handlers(void) static void install_signal_handlers(void)
@@ -253,29 +262,29 @@ static void install_signal_handlers(void)
#ifdef SIGHUP #ifdef SIGHUP
/* ignore SIGHUP signal */ /* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR) if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO)); logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
/* ignore SIGPIPE signal */ /* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO)); logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif #endif
#ifdef SIGALRM #ifdef SIGALRM
/* ignore SIGALRM signal */ /* ignore SIGALRM signal */
if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR) if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGALRM handler: %s", strerror(errno));
#endif #endif
#ifdef SIGINT #ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */ /* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR) if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO)); logmsg("cannot install SIGINT handler: %s", strerror(errno));
else else
siginterrupt(SIGINT, 1); siginterrupt(SIGINT, 1);
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */ /* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR) if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else else
siginterrupt(SIGTERM, 1); siginterrupt(SIGTERM, 1);
#endif #endif
@@ -316,7 +325,7 @@ static int parse_servercmd(struct httprequest *req)
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file %ld", req->testno); logmsg("Couldn't open test file %ld", req->testno);
@@ -617,9 +626,9 @@ static int ProcessRequest(struct httprequest *req)
while(*ptr && ISSPACE(*ptr)) while(*ptr && ISSPACE(*ptr))
ptr++; ptr++;
endptr = ptr; endptr = ptr;
SET_ERRNO(0); errno = 0;
clen = strtoul(ptr, &endptr, 10); clen = strtoul(ptr, &endptr, 10);
if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == ERRNO)) { if((ptr == endptr) || !ISSPACE(*endptr) || (ERANGE == errno)) {
/* this assumes that a zero Content-Length is valid */ /* this assumes that a zero Content-Length is valid */
logmsg("Found invalid Content-Length: (%s) in the request", ptr); logmsg("Found invalid Content-Length: (%s) in the request", ptr);
req->open = FALSE; /* closes connection */ req->open = FALSE; /* closes connection */
@@ -756,7 +765,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
do { do {
dump = fopen(dumpfile, "ab"); dump = fopen(dumpfile, "ab");
} while ((dump == NULL) && ((error = ERRNO) == EINTR)); } while ((dump == NULL) && ((error = errno) == EINTR));
if (dump == NULL) { if (dump == NULL) {
logmsg("Error opening file %s error: %d %s", logmsg("Error opening file %s error: %d %s",
dumpfile, error, strerror(error)); dumpfile, error, strerror(error));
@@ -772,7 +781,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
goto storerequest_cleanup; goto storerequest_cleanup;
if(written > 0) if(written > 0)
writeleft -= written; writeleft -= written;
} while ((writeleft > 0) && ((error = ERRNO) == EINTR)); } while ((writeleft > 0) && ((error = errno) == EINTR));
if(writeleft == 0) if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile); logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile);
@@ -787,7 +796,7 @@ storerequest_cleanup:
do { do {
res = fclose(dump); res = fclose(dump);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = errno) == EINTR));
if(res) if(res)
logmsg("Error closing file %s error: %d %s", logmsg("Error closing file %s error: %d %s",
dumpfile, error, strerror(error)); dumpfile, error, strerror(error));
@@ -1020,7 +1029,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file"); logmsg("Couldn't open test file");
@@ -1045,7 +1054,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
/* re-open the same file again */ /* re-open the same file again */
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", filename); logmsg("Error opening file: %s", filename);
logmsg("Couldn't open test file"); logmsg("Couldn't open test file");
@@ -1090,7 +1099,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
dump = fopen(responsedump, "ab"); dump = fopen(responsedump, "ab");
if(!dump) { if(!dump) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", responsedump); logmsg("Error opening file: %s", responsedump);
if(ptr) if(ptr)
@@ -1134,7 +1143,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
do { do {
res = fclose(dump); res = fclose(dump);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = errno) == EINTR));
if(res) if(res)
logmsg("Error closing file %s error: %d %s", logmsg("Error closing file %s error: %d %s",
responsedump, error, strerror(error)); responsedump, error, strerror(error));
@@ -1178,7 +1187,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
res = wait_ms(250); res = wait_ms(250);
if(res) { if(res) {
/* should not happen */ /* should not happen */
error = SOCKERRNO; error = errno;
logmsg("wait_ms() failed with error: (%d) %s", logmsg("wait_ms() failed with error: (%d) %s",
error, strerror(error)); error, strerror(error));
break; break;

View File

@@ -365,13 +365,13 @@ static void justtimeout(int signum)
static RETSIGTYPE exit_signal_handler(int signum) static RETSIGTYPE exit_signal_handler(int signum)
{ {
int old_errno = ERRNO; int old_errno = errno;
if(got_exit_signal == 0) { if(got_exit_signal == 0) {
got_exit_signal = 1; got_exit_signal = 1;
exit_signal = signum; exit_signal = signum;
} }
(void)signal(signum, exit_signal_handler); (void)signal(signum, exit_signal_handler);
SET_ERRNO(old_errno); errno = old_errno;
} }
static void install_signal_handlers(void) static void install_signal_handlers(void)
@@ -379,24 +379,24 @@ static void install_signal_handlers(void)
#ifdef SIGHUP #ifdef SIGHUP
/* ignore SIGHUP signal */ /* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR) if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO)); logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif #endif
#ifdef SIGPIPE #ifdef SIGPIPE
/* ignore SIGPIPE signal */ /* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR) if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO)); logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif #endif
#ifdef SIGINT #ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */ /* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR) if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO)); logmsg("cannot install SIGINT handler: %s", strerror(errno));
else else
siginterrupt(SIGINT, 1); siginterrupt(SIGINT, 1);
#endif #endif
#ifdef SIGTERM #ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */ /* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR) if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO)); logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else else
siginterrupt(SIGTERM, 1); siginterrupt(SIGTERM, 1);
#endif #endif
@@ -953,7 +953,7 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size)
/* Open request dump file. */ /* Open request dump file. */
server = fopen(REQUEST_DUMP, "ab"); server = fopen(REQUEST_DUMP, "ab");
if(!server) { if(!server) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", REQUEST_DUMP); logmsg("Error opening file: %s", REQUEST_DUMP);
return -1; return -1;
@@ -1071,7 +1071,7 @@ static int validate_access(struct testcase *test,
if(file) { if(file) {
FILE *stream=fopen(file, "rb"); FILE *stream=fopen(file, "rb");
if(!stream) { if(!stream) {
error = ERRNO; error = errno;
logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("fopen() failed with error: %d %s", error, strerror(error));
logmsg("Error opening file: %s", file); logmsg("Error opening file: %s", file);
logmsg("Couldn't open test file: %s", file); logmsg("Couldn't open test file: %s", file);
@@ -1123,7 +1123,7 @@ static void sendtftp(struct testcase *test, struct formats *pf)
do { do {
size = readit(test, &sdp, pf->f_convert); size = readit(test, &sdp, pf->f_convert);
if (size < 0) { if (size < 0) {
nak(ERRNO + 100); nak(errno + 100);
return; return;
} }
sdp->th_opcode = htons((unsigned short)opcode_DATA); sdp->th_opcode = htons((unsigned short)opcode_DATA);
@@ -1234,7 +1234,7 @@ send_ack:
size = writeit(test, &rdp, (int)(n - 4), pf->f_convert); size = writeit(test, &rdp, (int)(n - 4), pf->f_convert);
if (size != (n-4)) { /* ahem */ if (size != (n-4)) { /* ahem */
if (size < 0) if (size < 0)
nak(ERRNO + 100); nak(errno + 100);
else else
nak(ENOSPACE); nak(ENOSPACE);
goto abort; goto abort;

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@@ -48,6 +48,13 @@
#include "util.h" #include "util.h"
#include "timeval.h" #include "timeval.h"
#ifdef USE_WINSOCK
#undef EINTR
#define EINTR 4 /* errno.h value */
#undef EINVAL
#define EINVAL 22 /* errno.h value */
#endif
#if defined(ENABLE_IPV6) && defined(__MINGW32__) #if defined(ENABLE_IPV6) && defined(__MINGW32__)
const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }}; const struct in6_addr in6addr_any = {{ IN6ADDR_ANY_INIT }};
#endif #endif
@@ -118,7 +125,7 @@ void logmsg(const char *msg, ...)
fclose(logfp); fclose(logfp);
} }
else { else {
error = ERRNO; error = errno;
fprintf(stderr, "fopen() failed with error: %d %s\n", fprintf(stderr, "fopen() failed with error: %d %s\n",
error, strerror(error)); error, strerror(error));
fprintf(stderr, "Error opening file: %s\n", serverlogfile); fprintf(stderr, "Error opening file: %s\n", serverlogfile);
@@ -208,7 +215,7 @@ int wait_ms(int timeout_ms)
if(!timeout_ms) if(!timeout_ms)
return 0; return 0;
if(timeout_ms < 0) { if(timeout_ms < 0) {
SET_SOCKERRNO(EINVAL); errno = EINVAL;
return -1; return -1;
} }
#if defined(MSDOS) #if defined(MSDOS)
@@ -228,7 +235,7 @@ int wait_ms(int timeout_ms)
#endif /* HAVE_POLL_FINE */ #endif /* HAVE_POLL_FINE */
if(r != -1) if(r != -1)
break; break;
error = SOCKERRNO; error = errno;
if(error && (error != EINTR)) if(error && (error != EINTR))
break; break;
pending_ms = timeout_ms - (int)curlx_tvdiff(curlx_tvnow(), initial_tv); pending_ms = timeout_ms - (int)curlx_tvdiff(curlx_tvnow(), initial_tv);
@@ -249,7 +256,7 @@ int write_pidfile(const char *filename)
pid = (long)getpid(); pid = (long)getpid();
pidfile = fopen(filename, "wb"); pidfile = fopen(filename, "wb");
if(!pidfile) { if(!pidfile) {
logmsg("Couldn't write pid file: %s %s", filename, strerror(ERRNO)); logmsg("Couldn't write pid file: %s %s", filename, strerror(errno));
return 0; /* fail */ return 0; /* fail */
} }
fprintf(pidfile, "%ld\n", pid); fprintf(pidfile, "%ld\n", pid);
@@ -266,7 +273,7 @@ void set_advisor_read_lock(const char *filename)
do { do {
lockfile = fopen(filename, "wb"); lockfile = fopen(filename, "wb");
} while((lockfile == NULL) && ((error = ERRNO) == EINTR)); } while((lockfile == NULL) && ((error = errno) == EINTR));
if(lockfile == NULL) { if(lockfile == NULL) {
logmsg("Error creating lock file %s error: %d %s", logmsg("Error creating lock file %s error: %d %s",
filename, error, strerror(error)); filename, error, strerror(error));
@@ -275,7 +282,7 @@ void set_advisor_read_lock(const char *filename)
do { do {
res = fclose(lockfile); res = fclose(lockfile);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = errno) == EINTR));
if(res) if(res)
logmsg("Error closing lock file %s error: %d %s", logmsg("Error closing lock file %s error: %d %s",
filename, error, strerror(error)); filename, error, strerror(error));
@@ -294,7 +301,7 @@ void clear_advisor_read_lock(const char *filename)
do { do {
res = unlink(filename); res = unlink(filename);
} while(res && ((error = ERRNO) == EINTR)); } while(res && ((error = errno) == EINTR));
if(res) if(res)
logmsg("Error removing lock file %s error: %d %s", logmsg("Error removing lock file %s error: %d %s",
filename, error, strerror(error)); filename, error, strerror(error));