From: Adam Dickmeiss Date: Wed, 25 Sep 2002 12:37:07 +0000 (+0000) Subject: Thread-safe handling of errno variable. X-Git-Tag: YAZ.1.9.1~15 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=d054cdd41417401fbba915e20203882159f32283;p=yaz-moved-to-github.git Thread-safe handling of errno variable. For server option -a@ produces APDU prints in YAZ log. --- diff --git a/comstack/tcpip.c b/comstack/tcpip.c index a7d33d2..4abb057 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: tcpip.c,v 1.49 2002-09-20 22:23:13 adam Exp $ + * $Id: tcpip.c,v 1.50 2002-09-25 12:37:07 adam Exp $ */ #include @@ -310,7 +310,7 @@ int tcpip_connect(COMSTACK h, void *address) return 1; } #else - if (errno == EINPROGRESS) + if (yaz_errno() == EINPROGRESS) { h->event = CS_CONNECT; h->state = CS_ST_CONNECTING; @@ -468,10 +468,10 @@ int tcpip_listen(COMSTACK h, char *raddr, int *addrlen, #ifdef WIN32 WSAGetLastError() == WSAEWOULDBLOCK #else - errno == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif #endif @@ -672,22 +672,22 @@ int tcpip_get(COMSTACK h, char **buf, int *bufsize) else return -1; #else - if (errno == EWOULDBLOCK + if (yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif - || errno == EINPROGRESS + || yaz_errno() == EINPROGRESS #ifdef __sun__ - || errno == ENOENT /* Sun's sometimes set errno to this */ + || yaz_errno() == ENOENT /* Sun's sometimes set errno to this */ #endif ) { h->io_pending = CS_WANT_READ; break; } - else if (errno == 0) + else if (yaz_errno() == 0) continue; else return -1; @@ -847,10 +847,10 @@ int tcpip_put(COMSTACK h, char *buf, int size) #ifdef WIN32 WSAGetLastError() == WSAEWOULDBLOCK #else - errno == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif #endif diff --git a/comstack/unix.c b/comstack/unix.c index 0cccf5f..960ccec 100644 --- a/comstack/unix.c +++ b/comstack/unix.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: unix.c,v 1.6 2002-09-20 22:23:13 adam Exp $ + * $Id: unix.c,v 1.7 2002-09-25 12:37:07 adam Exp $ * UNIX socket COMSTACK. By Morten Bøgeskov. */ #ifndef WIN32 @@ -213,7 +213,7 @@ int unix_connect(COMSTACK h, void *address) r = connect(h->iofile, (struct sockaddr *) add, SUN_LEN(add)); if (r < 0) { - if (errno == EINPROGRESS) + if (yaz_errno() == EINPROGRESS) { h->event = CS_CONNECT; h->state = CS_ST_CONNECTING; @@ -264,7 +264,7 @@ int unix_bind(COMSTACK h, void *address, int mode) int socket_out = -1; if(! S_ISSOCK(stat_buf.st_mode)) { h->cerrno = CSYSERR; - errno = EEXIST; /* Not a socket (File exists) */ + yaz_set_errno(EEXIST); /* Not a socket (File exists) */ return -1; } if((socket_out = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { @@ -274,7 +274,7 @@ int unix_bind(COMSTACK h, void *address, int mode) socket_unix.sun_family = AF_UNIX; strncpy(socket_unix.sun_path, path, sizeof(socket_unix.sun_path)); if(connect(socket_out, (struct sockaddr *) &socket_unix, SUN_LEN(&socket_unix)) < 0) { - if(errno == ECONNREFUSED) { + if(yaz_errno() == ECONNREFUSED) { TRC (fprintf (stderr, "Socket exists but nobody is listening\n")); } else { h->cerrno = CSYSERR; @@ -283,7 +283,7 @@ int unix_bind(COMSTACK h, void *address, int mode) } else { close(socket_out); h->cerrno = CSYSERR; - errno = EADDRINUSE; + yaz_set_errno(EADDRINUSE); return -1; } unlink(path); @@ -321,10 +321,10 @@ int unix_listen(COMSTACK h, char *raddr, int *addrlen, if (h->newfd < 0) { if ( - errno == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif ) @@ -451,19 +451,19 @@ int unix_get(COMSTACK h, char **buf, int *bufsize) TRC(fprintf(stderr, " recv res=%d, hasread=%d\n", res, hasread)); if (res < 0) { - if (errno == EWOULDBLOCK + if (yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif - || errno == EINPROGRESS + || yaz_errno() == EINPROGRESS ) { h->io_pending = CS_WANT_READ; break; } - else if (errno == 0) + else if (yaz_errno() == 0) continue; else return -1; @@ -535,10 +535,10 @@ int unix_put(COMSTACK h, char *buf, int size) )) < 0) { if ( - errno == EWOULDBLOCK + yaz_errno() == EWOULDBLOCK #ifdef EAGAIN #if EAGAIN != EWOULDBLOCK - || errno == EAGAIN + || yaz_errno() == EAGAIN #endif #endif ) diff --git a/include/yaz/nmem.h b/include/yaz/nmem.h index 416199c..0f5bf4c 100644 --- a/include/yaz/nmem.h +++ b/include/yaz/nmem.h @@ -24,7 +24,11 @@ * OF THIS SOFTWARE. * * $Log: nmem.h,v $ - * Revision 1.7 2002-09-10 18:41:18 adam + * Revision 1.8 2002-09-25 12:37:07 adam + * Thread-safe handling of errno variable. + * For server option -a@ produces APDU prints in YAZ log. + * + * Revision 1.7 2002/09/10 18:41:18 adam * Added yaz_errno * * Revision 1.6 2001/06/26 14:11:27 adam @@ -130,6 +134,7 @@ YAZ_EXPORT void *nmem_malloc(NMEM n, int size); YAZ_EXPORT void nmem_init (void); YAZ_EXPORT void nmem_exit (void); YAZ_EXPORT int yaz_errno (void); +YAZ_EXPORT void yaz_set_errno (int v); YAZ_END_CDECL diff --git a/server/eventl.c b/server/eventl.c index aade89b..0ba7f4a 100644 --- a/server/eventl.c +++ b/server/eventl.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: eventl.c,v 1.31 2001-10-05 14:43:22 adam Exp $ + * $Id: eventl.c,v 1.32 2002-09-25 12:37:07 adam Exp $ */ #include @@ -83,7 +83,7 @@ int event_loop(IOCHAN *iochans) res = YAZ_EV_SELECT(max + 1, &in, &out, &except, timeout); if (res < 0) { - if (errno == EINTR) + if (yaz_errno() == EINTR) continue; else { diff --git a/server/seshigh.c b/server/seshigh.c index a9e17fa..90b1a70 100644 --- a/server/seshigh.c +++ b/server/seshigh.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: seshigh.c,v 1.131 2002-07-25 12:52:54 adam Exp $ + * $Id: seshigh.c,v 1.132 2002-09-25 12:37:07 adam Exp $ */ /* @@ -107,7 +107,11 @@ association *create_association(IOCHAN channel, COMSTACK link) strcpy(filename, control_block->apdufile); if (!(anew->print = odr_createmem(ODR_PRINT))) return 0; - if (*control_block->apdufile != '-') + if (*control_block->apdufile == '@') + { + odr_setprint(anew->print, yaz_log_file()); + } + else if (*control_block->apdufile != '-') { strcpy(filename, control_block->apdufile); if (!control_block->dynamic) diff --git a/server/statserv.c b/server/statserv.c index b38b806..3e236bc 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -6,7 +6,7 @@ * NT threaded server code by * Chas Woodfield, Fretwell Downing Informatics. * - * $Id: statserv.c,v 1.84 2002-09-06 19:52:57 adam Exp $ + * $Id: statserv.c,v 1.85 2002-09-25 12:37:07 adam Exp $ */ #include @@ -412,7 +412,8 @@ static void listener(IOCHAN h, int event) char dummy[1]; int res; - if ((res = read(hand[0], dummy, 1)) < 0 && errno != EINTR) + if ((res = read(hand[0], dummy, 1)) < 0 && + yaz_errno() != EINTR) { yaz_log(LOG_FATAL|LOG_ERRNO, "handshake read"); return; diff --git a/util/log.c b/util/log.c index 42e1167..e208fbf 100644 --- a/util/log.c +++ b/util/log.c @@ -2,7 +2,7 @@ * Copyright (c) 1995-2002, Index Data * See the file LICENSE for details. * - * $Id: log.c,v 1.28 2002-08-29 09:58:42 adam Exp $ + * $Id: log.c,v 1.29 2002-09-25 12:37:07 adam Exp $ */ #if HAVE_CONFIG_H @@ -177,7 +177,7 @@ void yaz_log(int level, const char *fmt, ...) strcat(buf, "]"); } #else - sprintf(buf + strlen(buf), " [%s]", strerror(errno)); + sprintf(buf + strlen(buf), " [%s]", strerror(yaz_errno())); #endif } if (start_hook_func) diff --git a/util/nmem.c b/util/nmem.c index 15fe281..75cbd20 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -3,7 +3,7 @@ * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * - * $Id: nmem.c,v 1.36 2002-09-10 18:41:18 adam Exp $ + * $Id: nmem.c,v 1.37 2002-09-25 12:37:07 adam Exp $ */ /* @@ -435,3 +435,8 @@ int yaz_errno(void) { return errno; } + +void yaz_set_errno(int v) +{ + errno = v; +} diff --git a/util/siconv.c b/util/siconv.c index 8bbc4ed..c89de49 100644 --- a/util/siconv.c +++ b/util/siconv.c @@ -2,7 +2,7 @@ * Copyright (c) 1997-2002, Index Data * See the file LICENSE for details. * - * $Id: siconv.c,v 1.5 2002-09-24 08:05:41 adam Exp $ + * $Id: siconv.c,v 1.6 2002-09-25 12:37:08 adam Exp $ */ /* mini iconv and wrapper for system iconv library (if present) */ @@ -373,7 +373,7 @@ size_t yaz_iconv (yaz_iconv_t cd, char **inbuf, size_t *inbytesleft, iconv(cd->iconv_cd, inbuf, inbytesleft, outbuf, outbytesleft); if (r == (size_t)(-1)) { - switch (errno) + switch (yaz_errno()) { case E2BIG: cd->my_errno = YAZ_ICONV_E2BIG;