Changeset 784
- Timestamp:
- 07/02/07 21:54:07 (1 year ago)
- Files:
-
- cherokee/trunk/ChangeLog (modified) (1 diff)
- cherokee/trunk/cherokee/buffer.c (modified) (1 diff)
- cherokee/trunk/cherokee/cherokee_logrotate.c (modified) (1 diff)
- cherokee/trunk/cherokee/fdpoll-epoll.c (modified) (5 diffs)
- cherokee/trunk/cherokee/fdpoll-kqueue.c (modified) (1 diff)
- cherokee/trunk/cherokee/fdpoll-port.c (modified) (7 diffs)
- cherokee/trunk/cherokee/handler_cgi.c (modified) (2 diffs)
- cherokee/trunk/cherokee/logger_writer.c (modified) (2 diffs)
- cherokee/trunk/cherokee/ncpus.c (modified) (4 diffs)
- cherokee/trunk/cherokee/server.c (modified) (3 diffs)
- cherokee/trunk/cherokee/socket.c (modified) (5 diffs)
- cherokee/trunk/cherokee/util.c (modified) (1 diff)
- cherokee/trunk/cherokee/util.h (modified) (2 diffs)
- cherokee/trunk/cherokee/validator_ldap.c (modified) (1 diff)
- cherokee/trunk/cherokee/win32_misc.c (modified) (5 diffs)
- cherokee/trunk/cherokee/win32_misc.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cherokee/trunk/ChangeLog
r783 r784 1 2 2007-07-02 A.D.F <adefacc@tin.it> 3 4 * cherokee/util.h 5 - added new cherokee_strerror_r() prototype; 6 7 * cherokee/util.c 8 - added new cherokee_strerror_r() function 9 in order to ensure thread safety; 10 11 * cherokee/win32_misc.h 12 - changed win_strerror() prototype; 13 14 * cherokee/win32_misc.c 15 - changed win_strerror() function to accept 16 a buffer in formal parameters; 17 18 * cherokee/buffer.c, 19 cherokee/cherokee_logrotate.c, 20 cherokee/fdpoll_epoll.c, 21 cherokee/fdpoll_kqueue.c, 22 cherokee/fdpoll_port.c, 23 cherokee/handler_cgi.c, 24 cherokee/logger_writer.c, 25 cherokee/ncpus.c, 26 cherokee/server.c, 27 cherokee/socket.c, 28 cherokee/validator_ldap.c 29 - replaced strerror() with cherokee_strerror_r() calls. 1 30 2 31 2007-06-29 A.D.F <adefacc@tin.it> cherokee/trunk/cherokee/buffer.c
r690 r784 884 884 case EIO: return ret_error; 885 885 } 886 887 PRINT_ERROR ("ERROR: read(%d, %u,..) -> errno=%d '%s'\n", fd, size, errno, strerror(errno)); 886 { 887 char buferr[ERROR_MAX_BUFSIZE]; 888 PRINT_ERROR ("ERROR: read(%d, %u,..) -> errno=%d '%s'\n", fd, size, errno, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 889 } 888 890 return ret_error; 889 891 } cherokee/trunk/cherokee/cherokee_logrotate.c
r597 r784 177 177 re = rename (argv[2], logname.buf); 178 178 if (re != 0) { 179 PRINT_ERROR("Could not move '%s' to '%s': %s\n", argv[2], logname.buf, strerror(errno)); 179 char buferr[ERROR_MAX_BUFSIZE]; 180 PRINT_ERROR("Could not move '%s' to '%s': %s\n", argv[2], logname.buf, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 180 181 } 181 182 printf ("Log file '%s' moved to '%s' successfully\n", argv[2], logname.buf); cherokee/trunk/cherokee/fdpoll-epoll.c
r731 r784 109 109 110 110 if (epoll_ctl (fdp->ep_fd, EPOLL_CTL_ADD, fd, &ev) < 0) { 111 char buferr[ERROR_MAX_BUFSIZE]; 111 112 PRINT_ERROR ("ERROR: epoll_ctl(%d, EPOLL_CTL_ADD, %d): %s\n", 112 fdp->ep_fd, fd, strerror(errno));113 fdp->ep_fd, fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 113 114 return ret_error; 114 115 } … … 136 137 137 138 if (epoll_ctl(fdp->ep_fd, EPOLL_CTL_DEL, fd, &ev) < 0) { 139 char buferr[ERROR_MAX_BUFSIZE]; 138 140 PRINT_ERROR ("ERROR: epoll_ctl(%d, EPOLL_CTL_DEL, %d): %s\n", 139 fdp->ep_fd, fd, strerror(errno));141 fdp->ep_fd, fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 140 142 return ret_error; 141 143 } … … 226 228 } 227 229 228 if (epoll_ctl(fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) 229 {230 if (epoll_ctl(fdp->ep_fd, EPOLL_CTL_MOD, fd, &ev) < 0) { 231 char buferr[ERROR_MAX_BUFSIZE]; 230 232 PRINT_ERROR ("ERROR: epoll_ctl (%d, EPOLL_CTL_MOD, %d): %s\n", 231 fdp->ep_fd, fd, strerror(errno));233 fdp->ep_fd, fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 232 234 return ret_error; 233 235 } … … 303 305 */ 304 306 #if 0 307 char buferr[ERROR_MAX_BUFSIZE]; 305 308 PRINT_ERROR ("ERROR: epoll_create(%d): %s\n", 306 nfd->nfiles+1, strerror(errno));309 nfd->nfiles+1, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 307 310 #endif 308 311 _free (n); … … 312 315 re = fcntl (n->ep_fd, F_SETFD, FD_CLOEXEC); 313 316 if (re < 0) { 317 char buferr[ERROR_MAX_BUFSIZE]; 314 318 PRINT_ERROR ("ERROR: could not set CloseExec to the epoll descriptor: fcntl: %s\n", 315 strerror(errno));319 cherokee_strerror_r(errno, buferr, sizeof(buferr))); 316 320 _free (n); 317 321 return ret_error; cherokee/trunk/cherokee/fdpoll-kqueue.c
r731 r784 170 170 fdp->nchanges=0; 171 171 if ( n_events < 0 ) { 172 PRINT_ERROR ("ERROR: kevent: %s\n", strerror(errno)); 172 char buferr[ERROR_MAX_BUFSIZE]; 173 PRINT_ERROR ("ERROR: kevent: %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 173 174 return 0; 174 175 } else if ( n_events > 0 ) { cherokee/trunk/cherokee/fdpoll-port.c
r731 r784 81 81 82 82 if ( rc == -1 ) { 83 PRINT_ERROR ("ERROR: port_associate: fd %d: %s\n", fd,84 strerror(errno));83 char buferr[ERROR_MAX_BUFSIZE]; 84 PRINT_ERROR ("ERROR: port_associate: fd %d: %s\n", fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 85 85 return ret_error; 86 86 } … … 120 120 rc = fd_associate(fdp, fd, (rw == FDPOLL_MODE_WRITE ? WRITE : READ)); 121 121 if ( rc == -1 ) { 122 PRINT_ERROR ("ERROR: port_associate: fd %d: %s\n", fd,123 strerror(errno));122 char buferr[ERROR_MAX_BUFSIZE]; 123 PRINT_ERROR ("ERROR: port_associate: fd %d: %s\n", fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 124 124 return ret_error; 125 125 } … … 139 139 fd); /* object */ 140 140 if ( rc == -1 ) { 141 PRINT_ERROR ("ERROR: port_dissociate: %d,%s\n", fd,142 strerror(errno));141 char buferr[ERROR_MAX_BUFSIZE]; 142 PRINT_ERROR ("ERROR: port_dissociate: %d,%s\n", fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 143 143 return ret_error; 144 144 } … … 172 172 &timeout); 173 173 if ( rc < 0 ) { 174 PRINT_ERROR ("ERROR: port_getn: %s\n", strerror(errno)); 174 char buferr[ERROR_MAX_BUFSIZE]; 175 PRINT_ERROR ("ERROR: port_getn: %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 175 176 return 0; 176 177 } … … 188 189 &fdp->port_readyfds, &timeout); 189 190 if ( ( (rc < 0) && (errno != ETIME) ) || (fdp->port_readyfds == -1)) { 190 PRINT_ERROR ("ERROR: port_getn: %s\n", strerror(errno)); 191 char buferr[ERROR_MAX_BUFSIZE]; 192 PRINT_ERROR ("ERROR: port_getn: %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 191 193 return 0; 192 194 } … … 201 203 fdp->port_events[i].portev_user); 202 204 if ( rc < 0 ) { 203 PRINT_ERROR ("ERROR: port_associate: %s\n",204 strerror(errno));205 char buferr[ERROR_MAX_BUFSIZE]; 206 PRINT_ERROR ("ERROR: port_associate: %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 205 207 } 206 208 } … … 253 255 (rw == FDPOLL_MODE_WRITE ? WRITE : READ)); 254 256 if ( rc == -1 ) { 255 PRINT_ERROR ("ERROR: port_associate: fd %d: %s\n", fd,256 strerror(errno));257 char buferr[ERROR_MAX_BUFSIZE]; 258 PRINT_ERROR ("ERROR: port_associate: fd %d: %s\n", fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 257 259 return ret_error; 258 260 } cherokee/trunk/cherokee/handler_cgi.c
r597 r784 455 455 456 456 if (fcntl (fd, F_SETFL, flags) == -1) { 457 PRINT_ERROR ("ERROR: Setting pipe properties fd=%d: %s\n", fd, strerror(errno)); 457 char buferr[ERROR_MAX_BUFSIZE]; 458 PRINT_ERROR ("ERROR: Setting pipe properties fd=%d: %s\n", fd, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 458 459 return ret_error; 459 460 } … … 568 569 } 569 570 571 { 572 char buferr[ERROR_MAX_BUFSIZE]; 570 573 cherokee_logger_write_string (CONN_VSRV(conn)->logger, 571 "couldn't execute '%s': %s", 572 absolute_path, strerror(err)); 574 "couldn't execute '%s': %s", 575 absolute_path, 576 cherokee_strerror_r(err, buferr, sizeof(buferr))); 577 } 573 578 exit(1); 574 579 } cherokee/trunk/cherokee/logger_writer.c
r650 r784 201 201 202 202 if (pipe (to_log_fds)) { 203 PRINT_MSG ("Pipe error: %s\n", strerror(errno)); 203 char buferr[ERROR_MAX_BUFSIZE]; 204 PRINT_MSG ("Pipe error: %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 204 205 return ret_error; 205 206 } … … 222 223 223 224 case -1: 224 PRINT_MSG ("Fork failed: %s\n", strerror(errno)); 225 { 226 char buferr[ERROR_MAX_BUFSIZE]; 227 PRINT_MSG ("Fork failed: %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 228 } 225 229 break; 226 230 cherokee/trunk/cherokee/ncpus.c
r170 r784 25 25 #include "config.h" 26 26 #include "ncpus.h" 27 #include "util.h" 27 28 28 29 #include <stdio.h> … … 57 58 return 0; 58 59 } else { 59 fprintf (stderr, "pstat_getdynamic failed: %s", strerror(errno)); 60 char buferr[ERROR_MAX_BUFSIZE]; 61 fprintf (stderr, "pstat_getdynamic failed: %s", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 60 62 *ncpus = -1; 61 63 return EXIT_DISTCC_FAILED; … … 109 111 return 0; 110 112 else { 113 char buferr[ERROR_MAX_BUFSIZE]; 111 114 fprintf(stderr,"sysctl(CTL_HW:HW_NCPU) failed: %s", 112 strerror(errno));115 cherokee_strerror_r(errno, buferr, sizeof(buferr))); 113 116 return EXIT_DISTCC_FAILED; 114 117 } … … 138 141 139 142 if (*ncpus == -1) { 143 char buferr[ERROR_MAX_BUFSIZE]; 140 144 fprintf(stderr,"sysconf(_SC_NPROCESSORS_ONLN) failed: %s", 141 strerror(errno));145 cherokee_strerror_r(errno, buferr, sizeof(buferr))); 142 146 return EXIT_DISTCC_FAILED; 143 147 } else if (*ncpus == 0) { cherokee/trunk/cherokee/server.c
r775 r784 1086 1086 srv->chrooted = (chroot (srv->chroot.buf) == 0); 1087 1087 if (srv->chrooted == 0) { 1088 PRINT_ERROR ("Cannot chroot() to '%s': %s\n", srv->chroot.buf, strerror(errno)); 1088 char buferr[ERROR_MAX_BUFSIZE]; 1089 PRINT_ERROR ("Cannot chroot() to '%s': %s\n", srv->chroot.buf, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 1089 1090 return ret_error; 1090 1091 } … … 1102 1103 re = chdir ("/"); 1103 1104 if (re < 0) { 1104 PRINT_ERROR ("Couldn't chdir(\"/\"): %s\n", strerror(errno)); 1105 char buferr[ERROR_MAX_BUFSIZE]; 1106 PRINT_ERROR ("Couldn't chdir(\"/\"): %s\n", cherokee_strerror_r(errno, buferr, sizeof(buferr))); 1105 1107 return ret_error; 1106 1108 } … … 1944 1946 file = fopen (srv->pidfile.buf, "w"); 1945 1947 if (file == NULL) { 1946 PRINT_MSG ("ERROR: Can't write PID file '%s': %s\n", srv->pidfile.buf, strerror(errno)); 1948 char buferr[ERROR_MAX_BUFSIZE]; 1949 PRINT_MSG ("ERROR: Can't write PID file '%s': %s\n", srv->pidfile.buf, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 1947 1950 return ret_error; 1948 1951 } cherokee/trunk/cherokee/socket.c
r764 r784 896 896 return ret_error; 897 897 } 898 898 { 899 char buferr[ERROR_MAX_BUFSIZE]; 899 900 PRINT_ERROR ("ERROR: write(%d, ..) -> errno=%d '%s'\n", 900 SOCKET_FD(socket), err, strerror(err)); 901 SOCKET_FD(socket), err, cherokee_strerror_r(err, buferr, sizeof(buferr))); 902 } 901 903 return ret_error; 902 904 } … … 1040 1042 return ret_error; 1041 1043 } 1042 1044 { 1045 char buferr[ERROR_MAX_BUFSIZE]; 1043 1046 PRINT_ERROR ("ERROR: read(%d, ..) -> errno=%d '%s'\n", 1044 SOCKET_FD(socket), err, strerror(err)); 1047 SOCKET_FD(socket), err, cherokee_strerror_r(err, buferr, sizeof(buferr))); 1048 } 1045 1049 return ret_error; 1046 1050 } … … 1223 1227 return ret_error; 1224 1228 } 1225 1229 { 1230 char buferr[ERROR_MAX_BUFSIZE]; 1226 1231 PRINT_ERROR ("ERROR: writev(%d, ..) -> errno=%d '%s'\n", 1227 SOCKET_FD(socket), err, strerror(err)); 1232 SOCKET_FD(socket), err, cherokee_strerror_r(err, buferr, sizeof(buferr))); 1233 } 1228 1234 return ret_error; 1229 1235 } … … 1568 1574 default: 1569 1575 #if 1 1570 PRINT_ERROR ("ERROR: Can not connect: %s\n", strerror(err)); 1576 { 1577 char buferr[ERROR_MAX_BUFSIZE]; 1578 PRINT_ERROR ("ERROR: Can not connect: %s\n", cherokee_strerror_r(err, buferr, sizeof(buferr))); 1579 } 1571 1580 #endif 1572 1581 return ret_error; … … 1735 1744 if (re < 0) { 1736 1745 int err = errno; 1746 char buferr[ERROR_MAX_BUFSIZE]; 1737 1747 PRINT_ERROR ("Couldn't set SO_RCVTIMEO, fd=%d, timeout=%d: %s\n", 1738 socket->socket, timeout, strerror(err));1748 socket->socket, timeout, cherokee_strerror_r(err, buferr, sizeof(buferr))); 1739 1749 return ret_error; 1740 1750 } cherokee/trunk/cherokee/util.c
r773 r784 86 86 87 87 const char *cherokee_version = PACKAGE_VERSION; 88 89 /* Given an error number (errno) it returns an error string. 90 * Parameters "buf" and "bufsize" are passed by caller 91 * in order to make the function "thread safe". 92 * If the error number is unknown 93 * then an "Unknown error nnn" string is returned. 94 */ 95 char * 96 cherokee_strerror_r (int err, char *buf, size_t bufsize) 97 { 98 #ifdef _WIN32 99 return win_strerror (err, buf, bufsize); 100 #else 101 char *p; 102 if (buf == NULL) 103 return NULL; 104 105 if (bufsize < ERROR_MIN_BUFSIZE) 106 return NULL; 107 108 if ((p = strerror(err)) == NULL) { 109 buf[0] = '\0'; 110 snprintf(buf, bufsize, "Unknown error %d (errno)", err); 111 buf[bufsize-1] = '\0'; 112 return buf; 113 } 114 115 return p; 116 #endif 117 } 88 118 89 119 cherokee/trunk/cherokee/util.h
r644 r784 56 56 CHEROKEE_BEGIN_DECLS 57 57 58 /* Error buffer size for cherokee_strerror_r(). 59 */ 60 #define ERROR_MIN_BUFSIZE 64 /* min. buffer size */ 61 #define ERROR_MAX_BUFSIZE 512 /* max. buffer size */ 62 58 63 #ifdef _WIN32 59 64 # define cherokee_stat(path,buf) cherokee_win32_stat(path,buf) … … 73 78 /* String management functions 74 79 */ 80 char *cherokee_strerror_r (int err, char *buf, size_t bufsize); 75 81 int cherokee_isbigendian (void); 76 82 char *cherokee_min_str (char *s1, char *s2); cherokee/trunk/cherokee/validator_ldap.c
r782 r784 159 159 ldap->conn = ldap_init (props->server.buf, props->port); 160 160 if (ldap->conn == NULL) { 161 char buferr[ERROR_MAX_BUFSIZE]; 161 162 PRINT_ERROR ("ERROR: LDAP validator: Couldn't connect to LDAP: %s:%d: %s\n", 162 props->server.buf, props->port, strerror(errno));163 props->server.buf, props->port, cherokee_strerror_r(errno, buferr, sizeof(buferr))); 163 164 return ret_error; 164 165 } cherokee/trunk/cherokee/win32_misc.c
r780 r784 75 75 re = WSAStartup (MAKEWORD(1,1), &wsa_data); 76 76 if (re != 0) { 77 PRINT_ERROR ("WSAStartup failed; %s\n", win_strerror(GetLastError())); 77 char errbuf[ERROR_MAX_BUFSIZE]; 78 PRINT_ERROR ("WSAStartup failed; %s\n", win_strerror(GetLastError(), errbuf, sizeof(errbuf))); 78 79 exit (-1); 79 80 } … … 376 377 * A smarter strerror() 377 378 * 378 * TODO: make this function thread-safe (by using some smart trick). 379 */ 380 char *win_strerror (int err) 381 { 382 static char buf[512]; /* WARNING!! not thread-safe */ 379 * NOTE: buf is a buffer passed by caller of at least ERROR_MIN_BUFSIZE size. 380 */ 381 char *win_strerror (int err, char *buf, size_t bufsize) 382 { 383 383 DWORD lang = MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT); 384 384 DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | … … 387 387 char *p; 388 388 389 if (buf == NULL) 390 return NULL; 391 392 if (bufsize < ERROR_MIN_BUFSIZE) 393 return NULL; 394 395 buf[0] = '\0'; 396 buf [bufsize-1] = '\0'; 397 389 398 if (err >= 0 && err < sys_nerr) { 390 399 /* Call the strerror() func, do not use the macro! */ 391 strncpy (buf, (strerror)(err), sizeof(buf)-1); 392 buf [sizeof(buf)-1] = '\0'; 400 strncpy (buf, (strerror)(err), bufsize - 1); 393 401 } else { 394 if (!get_winsock_error (err, buf, sizeof(buf)) &&402 if (!get_winsock_error (err, buf, bufsize - 1) && 395 403 !FormatMessage (flags, NULL, err, lang, 396 buf, sizeof(buf)-1, NULL))397 s printf (buf, "Unknown error %d (%#x)", err, err);404 buf, bufsize - 1, NULL)) 405 snprintf (buf, bufsize, "Unknown error %d (%#x)", err, err); 398 406 } 399 407 … … 404 412 if ((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1) 405 413 *p = '\0'; 414 406 415 return (buf); 407 416 } … … 627 636 return (NULL); 628 637 638 { /* FIXME, error buf should be passed by caller. */ 639 char buf[ERROR_MAX_BUFSIZE] 629 640 snprintf (win_dlerror_buf, sizeof(win_dlerror_buf)-1, "%s(): %s", 630 last_func, win_strerror(last_error ));631 641 last_func, win_strerror(last_error, buf, sizeof(buf))); 642 } 632 643 return (win_dlerror_buf); 633 644 } cherokee/trunk/cherokee/win32_misc.h
r597 r784 33 33 #undef localtime_r /* in <pthread.h> */ 34 34 #define SHUT_WR SD_SEND 35 #define strerror(e) win_strerror(e)36 35 #define pipe(h) _pipe(h,0,0) 37 36 38 37 void init_win32 (void); 39 char *win_strerror (int err );38 char *win_strerror (int err, char *buf, size_t bufsize); 40 39 struct tm *localtime_r (const time_t *time, struct tm *tm); 41 40 unsigned int sleep (unsigned int seconds);