rbb 99/09/08 07:16:09
Modified: src/include ap_config.h ap_listen.h http_log.h http_protocol.h httpd.h util_md5.h src/main http_config.c http_core.c http_log.c http_protocol.c listen.c rfc1413.c util.c util_md5.c util_script.c src/modules/mpm/mpmt_pthread acceptlock.c mpmt_pthread.c src/modules/mpm/prefork Makefile.tmpl prefork.c src/modules/standard mod_asis.c mod_autoindex.c mod_log_config.c mod_negotiation.c Log: Remove all of the calls to functions like "ap_popenf". These functions were moved down to APR, but they are being removed. They are not portable, and were only moved down for backwards compatability. With this change, they can be safely removed, which is the next commit on it's way. Submitted by: Ryan Bloom and Paul Reder Revision Changes Path 1.8 +0 -6 apache-2.0/src/include/ap_config.h Index: ap_config.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/ap_config.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ap_config.h 1999/09/06 03:23:39 1.7 +++ ap_config.h 1999/09/08 14:15:39 1.8 @@ -1206,12 +1206,6 @@ select(_a, _b, _c, _d, _e) #endif -#ifdef USE_TPF_ACCEPT -#define ap_accept(_fd, _sa, _ln) tpf_accept(_fd, _sa, _ln) -#else -#define ap_accept(_fd, _sa, _ln) accept(_fd, _sa, _ln) -#endif - #ifdef NEED_SIGNAL_INTERRUPT #define ap_check_signals() tpf_process_signals() #else 1.5 +3 -3 apache-2.0/src/include/ap_listen.h Index: ap_listen.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/ap_listen.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ap_listen.h 1999/08/31 05:32:17 1.4 +++ ap_listen.h 1999/09/08 14:15:40 1.5 @@ -58,12 +58,12 @@ #ifndef AP_LISTEN_H #define AP_LISTEN_H +#include "apr_network_io.h" + typedef struct ap_listen_rec ap_listen_rec; struct ap_listen_rec { ap_listen_rec *next; - struct sockaddr_in local_addr; /* local IP address and port */ -/* TODO: replace the fd with APR stuff */ - int fd; + ap_socket_t *sd; /* more stuff here, like which protocol is bound to the port */ }; 1.4 +3 -3 apache-2.0/src/include/http_log.h Index: http_log.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/http_log.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- http_log.h 1999/08/31 05:32:18 1.3 +++ http_log.h 1999/09/08 14:15:40 1.4 @@ -139,9 +139,9 @@ #ifndef NO_RELIABLE_PIPED_LOGS char *program; int pid; - int fds[2]; + ap_file_t fds[2]; #else - FILE *write_f; + ap_file_t *write_f; #endif } piped_log; @@ -152,7 +152,7 @@ #define ap_piped_log_write_fd(pl) ((pl)->fds[1]) #else #define ap_piped_log_read_fd(pl) (-1) -#define ap_piped_log_write_fd(pl) (fileno((pl)->write_f)) +#define ap_piped_log_write_fd(pl) ((pl)->write_f) #endif #ifdef __cplusplus 1.4 +3 -2 apache-2.0/src/include/http_protocol.h Index: http_protocol.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/http_protocol.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- http_protocol.h 1999/08/26 14:18:32 1.3 +++ http_protocol.h 1999/09/08 14:15:40 1.4 @@ -59,6 +59,7 @@ #define APACHE_HTTP_PROTOCOL_H #include "ap_hooks.h" +#include "apr_portable.h" #ifdef __cplusplus extern "C" { @@ -133,8 +134,8 @@ * (Ditto the send_header stuff). */ -API_EXPORT(long) ap_send_fd(APRFile fd, request_rec *r); -API_EXPORT(long) ap_send_fd_length(APRFile fd, request_rec *r, long length); +API_EXPORT(long) ap_send_fd(int fd, request_rec *r); +API_EXPORT(long) ap_send_fd_length(int fd, request_rec *r, long length); API_EXPORT(long) ap_send_fb(BUFF *f, request_rec *r); API_EXPORT(long) ap_send_fb_length(BUFF *f, request_rec *r, long length); 1.8 +1 -1 apache-2.0/src/include/httpd.h Index: httpd.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- httpd.h 1999/08/31 05:32:19 1.7 +++ httpd.h 1999/09/08 14:15:40 1.8 @@ -859,7 +859,7 @@ /* Log files --- note that transfer log is now in the modules... */ char *error_fname; - FILE *error_log; + ap_file_t *error_log; int loglevel; /* Module-specific configuration for server, and defaults... */ 1.4 +2 -2 apache-2.0/src/include/util_md5.h Index: util_md5.h =================================================================== RCS file: /home/cvs/apache-2.0/src/include/util_md5.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- util_md5.h 1999/08/31 05:32:19 1.3 +++ util_md5.h 1999/09/08 14:15:40 1.4 @@ -68,9 +68,9 @@ API_EXPORT(char *) ap_md5_binary(ap_context_t *a, const unsigned char *buf, int len); API_EXPORT(char *) ap_md5contextTo64(ap_context_t *p, AP_MD5_CTX * context); #ifdef CHARSET_EBCDIC -API_EXPORT(char *) ap_md5digest(ap_context_t *p, FILE *infile, int convert); +API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile, int convert); #else -API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile); +API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile); #endif /* CHARSET_EBCDIC */ #ifdef __cplusplus 1.10 +3 -1 apache-2.0/src/main/http_config.c Index: http_config.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/http_config.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- http_config.c 1999/08/31 05:32:56 1.9 +++ http_config.c 1999/09/08 14:15:42 1.10 @@ -72,6 +72,7 @@ #define CORE_PRIVATE +#include "apr_portable.h" #include "httpd.h" #include "http_config.h" #include "http_core.h" @@ -1243,13 +1244,14 @@ static server_rec *init_server_config(ap_context_t *p) { + int errfile = STDERR_FILENO; server_rec *s = (server_rec *) ap_pcalloc(p, sizeof(server_rec)); s->port = 0; s->server_admin = DEFAULT_ADMIN; s->server_hostname = NULL; s->error_fname = DEFAULT_ERRORLOG; - s->error_log = stderr; + ap_put_os_file(p, &s->error_log, &errfile); s->loglevel = DEFAULT_LOGLEVEL; s->srm_confname = RESOURCE_CONFIG_FILE; s->access_confname = ACCESS_CONFIG_FILE; 1.11 +18 -21 apache-2.0/src/main/http_core.c Index: http_core.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/http_core.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- http_core.c 1999/08/31 05:32:57 1.10 +++ http_core.c 1999/09/08 14:15:42 1.11 @@ -2472,9 +2472,10 @@ static int default_handler(request_rec *r) { core_dir_config *d = - (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module); + (core_dir_config *)ap_get_module_config(r->per_dir_config, &core_module); int rangestatus, errstatus; - APRFile fd; /* Abstract out File descriptors. */ + ap_file_t *fd = NULL; + int fd_os; #ifdef USE_MMAP_FILES caddr_t mm; #endif @@ -2514,18 +2515,13 @@ return METHOD_NOT_ALLOWED; } -#if defined(OS2) || defined(WIN32) - /* Need binary mode for OS/2 */ - fd = ap_popenf(r->pool, r->filename, O_RDONLY | O_BINARY, 0); -#else - fd = ap_popenf(r->pool, r->filename, O_RDONLY, 0); -#endif - - if (fd == -1) { + if (ap_open (r->pool, r->filename, APR_READ | APR_BINARY, 0, &fd) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "file permissions deny server access: %s", r->filename); return FORBIDDEN; } + else + ap_get_os_file (fd, &fd_os); ap_update_mtime(r, r->finfo.st_mtime); ap_set_last_modified(r); @@ -2533,7 +2529,7 @@ ap_table_setn(r->headers_out, "Accept-Ranges", "bytes"); if (((errstatus = ap_meets_conditions(r)) != OK) || (errstatus = ap_set_content_length(r, r->finfo.st_size))) { - ap_pclosef(r->pool, fd); + ap_close(fd); return errstatus; } @@ -2544,7 +2540,7 @@ /* we need to protect ourselves in case we die while we've got the * file mmapped */ mm = mmap(NULL, r->finfo.st_size, PROT_READ, MAP_PRIVATE, - fd, 0); + fd_os, 0); if (mm == (caddr_t)-1) { ap_log_rerror(APLOG_MARK, APLOG_CRIT, r, "default_handler: mmap failed: %s", r->filename); @@ -2568,12 +2564,12 @@ convert_flag = ap_checkconv(r); if (d->content_md5 & 1) { ap_table_setn(r->headers_out, "Content-MD5", - ap_md5digest(r->pool, fd, convert_flag)); + ap_md5digest(r->pool, fd_os, convert_flag)); } #else if (d->content_md5 & 1) { ap_table_setn(r->headers_out, "Content-MD5", - ap_md5digest(r->pool, fd)); + ap_md5digest(r->pool, fd_os)); } #endif /* CHARSET_EBCDIC */ @@ -2583,19 +2579,20 @@ if (!r->header_only) { if (!rangestatus) { - ap_send_fd(fd, r); + ap_send_fd(fd_os, r); } else { - long offset, length; + long length; + ap_off_t offset; + while (ap_each_byterange(r, &offset, &length)) { - /* ZZZ change to AP func */ - if (lseek(fd, offset, SEEK_SET) == -1) { + if (ap_seek(fd, APR_SET, &offset) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, r->server, "error byteserving file: %s", r->filename); - ap_pclosef(r->pool, fd); + ap_close(fd); return HTTP_INTERNAL_SERVER_ERROR; } - ap_send_fd_length(fd, r, length); + ap_send_fd_length(fd_os, r, length); } } } @@ -2636,7 +2633,7 @@ } #endif - ap_pclosef(r->pool, fd); + ap_close(fd); return OK; } 1.6 +36 -24 apache-2.0/src/main/http_log.c Index: http_log.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/http_log.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- http_log.c 1999/08/31 05:32:58 1.5 +++ http_log.c 1999/09/08 14:15:43 1.6 @@ -65,6 +65,7 @@ #define CORE_PRIVATE #include "apr_lib.h" +#include "apr_portable.h" #include "httpd.h" #include "http_config.h" #include "http_core.h" @@ -190,6 +191,7 @@ if (*s->error_fname == '|') { FILE *dummy; + int dummyno; #ifdef TPF TPF_FORK_CHILD cld; cld.filename = s->error_fname+1; @@ -206,7 +208,8 @@ exit(1); } - s->error_log = dummy; + dummyno = fileno(dummy); + ap_put_os_file(p, &s->error_log, &dummyno); } #ifdef HAVE_SYSLOG @@ -233,7 +236,8 @@ else { fname = ap_server_root_relative(p, s->error_fname); /* Change to AP funcs. */ - if (!(s->error_log = ap_pfopen(p, fname, "a"))) { + if (ap_open(p, fname, APR_BUFFERED | APR_APPEND | APR_READ | APR_WRITE, + APR_OS_DEFAULT, &s->error_log) != APR_SUCCESS) { perror("fopen"); fprintf(stderr, "%s: could not open error log file %s.\n", ap_server_argv0, fname); @@ -246,6 +250,7 @@ { server_rec *virt, *q; int replace_stderr; + int errfile; open_error_log(s_main, p); @@ -253,7 +258,8 @@ if (s_main->error_log) { /* replace stderr with this new log */ fflush(stderr); - if (dup2(fileno(s_main->error_log), STDERR_FILENO) == -1) { + ap_get_os_file(s_main->error_log, &errfile); + if (dup2(errfile, STDERR_FILENO) == -1) { ap_log_error(APLOG_MARK, APLOG_CRIT, s_main, "unable to replace stderr with error_log"); } else { @@ -287,9 +293,12 @@ } API_EXPORT(void) ap_error_log2stderr(server_rec *s) { + int errfile; + + ap_get_os_file(s->error_log, &errfile); if ( s->error_log != NULL - && fileno(s->error_log) != STDERR_FILENO) - dup2(fileno(s->error_log), STDERR_FILENO); + && errfile != STDERR_FILENO) + dup2(errfile, STDERR_FILENO); } static void log_error_core(const char *file, int line, int level, @@ -300,7 +309,8 @@ size_t len; /* change to AP errno funcs. */ int save_errno = errno; - FILE *logf; + ap_file_t *logf = NULL; + int errfileno = STDERR_FILENO; if (s == NULL) { /* @@ -311,7 +321,7 @@ if (((level & APLOG_LEVELMASK) != APLOG_NOTICE) && ((level & APLOG_LEVELMASK) > DEFAULT_LOGLEVEL)) return; - logf = stderr; + ap_put_os_file(NULL, &logf, &errfileno); } else if (s->error_log) { /* @@ -448,9 +458,9 @@ if (logf) { /* ZZZ let's just use AP funcs to Write to the error log. If failure, can we output a message to the console??? */ - fputs(errstr, logf); - fputc('\n', logf); - fflush(logf); + ap_puts(logf, errstr); + ap_putc(logf, '\n'); + ap_flush(logf); } #ifdef HAVE_SYSLOG else { @@ -514,11 +524,11 @@ * that may screw up scripts written to do something * based on the last modification time of the pid file. */ - ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, - ap_psprintf(p, - "pid file %s overwritten -- Unclean shutdown of previous Apache run?", - fname) - ); + ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, + ap_psprintf(p, + "pid file %s overwritten -- Unclean shutdown of previous Apache run?", + fname) + ); } if(!(pid_file = fopen(fname, "w"))) { @@ -664,8 +674,8 @@ kill(pl->pid, SIGTERM); } ap_unregister_other_child(pl); - close(pl->fds[0]); - close(pl->fds[1]); + ap_close(pl->fds[0]); + ap_close(pl->fds[1]); } @@ -673,8 +683,8 @@ { piped_log *pl = data; - close(pl->fds[0]); - close(pl->fds[1]); + ap_close(pl->fds[0]); + ap_close(pl->fds[1]); } @@ -686,7 +696,7 @@ pl->p = p; pl->program = ap_pstrdup(p, program); pl->pid = -1; - if (pipe(pl->fds) == -1) { + if (ap_create_pipe(p, &pl->fds[0], &pl->fds[1]) != APR_SUCCESS) { int save_errno = errno; errno = save_errno; return NULL; @@ -695,8 +705,8 @@ if (piped_log_spawn(pl) == -1) { int save_errno = errno; ap_kill_cleanup(p, pl, piped_log_cleanup); - close(pl->fds[0]); - close(pl->fds[1]); + ap_close(pl->fds[0]); + ap_close(pl->fds[1]); errno = save_errno; return NULL; } @@ -743,6 +753,7 @@ { piped_log *pl; FILE *dummy; + int dummyno; #ifdef TPF TPF_FORK_CHILD cld; cld.filename = (char *)program; @@ -761,7 +772,8 @@ } pl = ap_palloc(p, sizeof (*pl)); pl->p = p; - pl->write_f = dummy; + dummyno = fileno(dummy); + ap_put_os_file(p, &pl->write_f, &dummyno); return pl; } @@ -769,6 +781,6 @@ API_EXPORT(void) ap_close_piped_log(piped_log *pl) { - ap_pfclose(pl->p, pl->write_f); + ap_close(pl->write_f); } #endif 1.14 +2 -2 apache-2.0/src/main/http_protocol.c Index: http_protocol.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/http_protocol.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- http_protocol.c 1999/08/31 05:32:58 1.13 +++ http_protocol.c 1999/09/08 14:15:43 1.14 @@ -1997,12 +1997,12 @@ /* * Send the body of a response to the client. */ -API_EXPORT(long) ap_send_fd(APRFile fd, request_rec *r) +API_EXPORT(long) ap_send_fd(int fd, request_rec *r) { return ap_send_fd_length(fd, r, -1); } -API_EXPORT(long) ap_send_fd_length(APRFile fd, request_rec *r, long length) +API_EXPORT(long) ap_send_fd_length(int fd, request_rec *r, long length) { char buf[IOBUFSIZE]; long total_bytes_sent = 0; 1.7 +51 -73 apache-2.0/src/main/listen.c Index: listen.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/listen.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- listen.c 1999/08/31 05:33:00 1.6 +++ listen.c 1999/09/08 14:15:43 1.7 @@ -55,6 +55,7 @@ * */ +#include "apr_network_io.h" #include "httpd.h" #include "http_config.h" #include "ap_listen.h" @@ -66,50 +67,28 @@ static int send_buffer_size; /* TODO: make_sock is just begging and screaming for APR abstraction */ -static int make_sock(const struct sockaddr_in *server) +static ap_status_t make_sock(ap_context_t *p, ap_listen_rec *server) { - int s; + ap_socket_t *s = server->sd; int one = 1; char addr[512]; + ap_status_t stat; - if (server->sin_addr.s_addr != htonl(INADDR_ANY)) - ap_snprintf(addr, sizeof(addr), "address %s port %d", - inet_ntoa(server->sin_addr), ntohs(server->sin_port)); - else - ap_snprintf(addr, sizeof(addr), "port %d", ntohs(server->sin_port)); - -#ifdef WIN32 - s = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED); - if (s == INVALID_SOCKET) { + stat = ap_setsocketopt(s, APR_SO_REUSEADDR, one); + if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) { ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, - "make_sock: failed to get a socket for %s", addr); - return -1; - } -#else - if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { - ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, - "make_sock: failed to get a socket for %s", addr); - return -1; - } -#endif - -#ifdef SO_REUSEADDR - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(int)) < 0) { - ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, "make_sock: for %s, setsockopt: (SO_REUSEADDR)", addr); - close(s); - return -1; + ap_close_socket(s); + return stat; } -#endif - one = 1; -#ifdef SO_KEEPALIVE - if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(int)) < 0) { + + stat = ap_setsocketopt(s, APR_SO_KEEPALIVE, one); + if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) { ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, "make_sock: for %s, setsockopt: (SO_KEEPALIVE)", addr); - close(s); - return -1; + ap_close_socket(s); + return stat; } -#endif /* * To send data over high bandwidth-delay connections at full @@ -130,33 +109,32 @@ * * If no size is specified, use the kernel default. */ -#ifdef SO_SNDBUF if (send_buffer_size) { - if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, - (char *) &send_buffer_size, sizeof(int)) < 0) { - ap_log_error(APLOG_MARK, APLOG_WARNING, NULL, + stat = ap_setsocketopt(s, SO_SNDBUF, send_buffer_size); + if (stat != APR_SUCCESS && stat != APR_ENOTIMPL) { + ap_log_error(APLOG_MARK, APLOG_WARNING, NULL, "make_sock: failed to set SendBufferSize for %s, " "using default", addr); /* not a fatal error */ } } -#endif - if (bind(s, (struct sockaddr *) server, sizeof(struct sockaddr_in)) == -1) { + if ((stat = ap_bind(s)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, "make_sock: could not bind to %s", addr); - close(s); - return -1; + ap_close_socket(s); + return stat; } - if (listen(s, ap_listenbacklog) == -1) { + if ((stat = ap_listen(s, ap_listenbacklog)) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, NULL, "make_sock: unable to listen for connections on %s", addr); - close(s); - return -1; + ap_close_socket(s); + return stat; } - return s; + server->sd = s; + return APR_SUCCESS; } @@ -165,20 +143,24 @@ ap_listen_rec *lr; for (lr = ap_listeners; lr; lr = lr->next) { - close(lr->fd); + ap_close_socket(lr->sd); } return APR_SUCCESS; } -static void alloc_listener(struct sockaddr_in *local_addr) +static void alloc_listener(char *addr, unsigned int port) { ap_listen_rec **walk; ap_listen_rec *new; + char *oldaddr; + unsigned int oldport; /* see if we've got an old listener for this address:port */ for (walk = &old_listeners; *walk; walk = &(*walk)->next) { - if (!memcmp(&(*walk)->local_addr, local_addr, sizeof(local_addr))) { + ap_getport((*walk)->sd, &oldport); + ap_getipaddr((*walk)->sd, &oldaddr); + if (!strcmp(oldaddr, addr) && port == oldport) { /* re-use existing record */ new = *walk; *walk = new->next; @@ -190,8 +172,13 @@ /* this has to survive restarts */ new = malloc(sizeof(ap_listen_rec)); - new->local_addr = *local_addr; - new->fd = -1; + if (ap_create_tcp_socket(NULL, &new->sd) != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_CRIT, NULL, + "make_sock: failed to get a socket for %s", addr); + return; + } + ap_setport(new->sd, port); + ap_setipaddr(new->sd, addr); new->next = ap_listeners; ap_listeners = new; } @@ -202,31 +189,25 @@ ap_listen_rec *lr; ap_listen_rec *next; int num_open; - struct sockaddr_in local_addr; - + ap_status_t stat; /* allocate a default listener if necessary */ if (ap_listeners == NULL) { - local_addr.sin_family = AF_INET; - local_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* XXX */ - local_addr.sin_port = htons(port ? port : DEFAULT_HTTP_PORT); - alloc_listener(&local_addr); + alloc_listener(APR_ANYADDR, port ? port : DEFAULT_HTTP_PORT); } num_open = 0; for (lr = ap_listeners; lr; lr = lr->next) { - if (lr->fd < 0) { - lr->fd = make_sock(&lr->local_addr); - } - if (lr->fd >= 0) { + stat = make_sock(pconf, lr); + if (stat == APR_SUCCESS) { ++num_open; } } /* close the old listeners */ for (lr = old_listeners; lr; lr = next) { - close(lr->fd); + ap_close_socket(lr->sd); next = lr->next; - free(lr); +/* free(lr);*/ } old_listeners = NULL; @@ -248,7 +229,6 @@ { char *ports; unsigned short port; - struct sockaddr_in local_addr; const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err != NULL) { @@ -269,20 +249,18 @@ ports = ips; } - local_addr.sin_family = AF_INET; - if (ports == ips) { /* no address */ - local_addr.sin_addr.s_addr = htonl(INADDR_ANY); - } - else { - local_addr.sin_addr.s_addr = ap_get_virthost_addr(ips, NULL); - } port = atoi(ports); if (!port) { return "Port must be numeric"; } - local_addr.sin_port = htons(port); - alloc_listener(&local_addr); + if (ports == ips) { /* no address */ + alloc_listener(APR_ANYADDR, port); + } + else { + ips[(ports - ips) - 1] = '\0'; + alloc_listener(ips, port); + } return NULL; } 1.3 +30 -27 apache-2.0/src/main/rfc1413.c Index: rfc1413.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/rfc1413.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- rfc1413.c 1999/08/26 12:54:15 1.2 +++ rfc1413.c 1999/09/08 14:15:43 1.3 @@ -81,6 +81,7 @@ #include "http_log.h" /* for aplog_error */ #include "rfc1413.h" #include "http_main.h" /* set_callback_and_alarm */ +#include "apr_network_io.h" /* Local stuff. */ /* Semi-well-known port */ @@ -102,12 +103,12 @@ /* bind_connect - bind both ends of a socket */ /* Ambarish fix this. Very broken */ -static int get_rfc1413(int sock, const struct sockaddr_in *our_sin, - const struct sockaddr_in *rmt_sin, +static int get_rfc1413(ap_socket_t *sock, const char *local_ip, + const char *rmt_ip, char user[RFC1413_USERLEN+1], server_rec *srv) { - struct sockaddr_in rmt_query_sin, our_query_sin; unsigned int rmt_port, our_port; + unsigned int sav_rmt_port, sav_our_port; int i; char *cp; char buffer[RFC1413_MAXDATA + 1]; @@ -122,29 +123,30 @@ * addresses from the query socket. */ - our_query_sin = *our_sin; - our_query_sin.sin_port = htons(ANY_PORT); - rmt_query_sin = *rmt_sin; - rmt_query_sin.sin_port = htons(RFC1413_PORT); + ap_setport(sock, ANY_PORT); + ap_setipaddr(sock, local_ip); - if (bind(sock, (struct sockaddr *) &our_query_sin, - sizeof(struct sockaddr_in)) < 0) { + if (ap_bind(sock) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, srv, "bind: rfc1413: Error binding to local port"); return -1; } + ap_getport(sock, &sav_our_port); /* * errors from connect usually imply the remote machine doesn't support * the service */ - if (connect(sock, (struct sockaddr *) &rmt_query_sin, - sizeof(struct sockaddr_in)) < 0) - return -1; + ap_setport(sock, RFC1413_PORT); + ap_setipaddr(sock, rmt_ip); + + if (ap_connect(sock, NULL) != APR_SUCCESS) + return -1; + ap_getport(sock, &sav_rmt_port); /* send the data */ - buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", ntohs(rmt_sin->sin_port), - ntohs(our_sin->sin_port)); + buflen = ap_snprintf(buffer, sizeof(buffer), "%u,%u\r\n", sav_rmt_port, + sav_our_port); /* send query to server. Handle short write. */ #ifdef CHARSET_EBCDIC @@ -152,9 +154,10 @@ #endif i = 0; while(i < strlen(buffer)) { - int j; - j = write(sock, buffer+i, (strlen(buffer+i))); - if (j < 0 && errno != EINTR) { + int j = strlen(buffer + i); + ap_status_t stat; + stat = ap_send(sock, buffer+i, &j); + if (stat != APR_SUCCESS && stat != APR_EINTR) { ap_log_error(APLOG_MARK, APLOG_CRIT, srv, "write: rfc1413: error sending request"); return -1; @@ -177,9 +180,10 @@ * this allows it to work on both ASCII and EBCDIC machines. */ while((cp = strchr(buffer, '\012')) == NULL && i < sizeof(buffer) - 1) { - int j; - j = read(sock, buffer+i, (sizeof(buffer) - 1) - i); - if (j < 0 && errno != EINTR) { + int j = sizeof(buffer) - 1 - i; + ap_status_t stat; + stat = ap_recv(sock, buffer+i, &j); + if (stat != APR_SUCCESS && stat != APR_EINTR) { ap_log_error(APLOG_MARK, APLOG_CRIT, srv, "read: rfc1413: error reading response"); return -1; @@ -194,8 +198,8 @@ ascii2ebcdic(&buffer, &buffer, (size_t)i); #endif if (sscanf(buffer, "%u , %u : USERID :%*[^:]:%512s", &rmt_port, &our_port, - user) != 3 || ntohs(rmt_sin->sin_port) != rmt_port - || ntohs(our_sin->sin_port) != our_port) + user) != 3 || sav_rmt_port != rmt_port + || sav_our_port != our_port) return -1; /* @@ -214,12 +218,11 @@ { static char user[RFC1413_USERLEN + 1]; /* XXX */ static char *result; - static int sock; + static ap_socket_t *sock; result = FROM_UNKNOWN; - sock = ap_psocket(conn->pool, AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock < 0) { + if (ap_create_tcp_socket(conn->pool, &sock) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, srv, "socket: rfc1413: error creating socket"); conn->remote_logname = result; @@ -230,10 +233,10 @@ */ if (ap_setjmp(timebuf) == 0) { - if (get_rfc1413(sock, &conn->local_addr, &conn->remote_addr, user, srv) >= 0) + if (get_rfc1413(sock, conn->local_ip, conn->remote_ip, user, srv) >= 0) result = user; } - ap_pclosesocket(conn->pool, sock); + ap_close_socket(sock); conn->remote_logname = result; return conn->remote_logname; 1.7 +23 -28 apache-2.0/src/main/util.c Index: util.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/util.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- util.c 1999/08/31 05:33:01 1.6 +++ util.c 1999/09/08 14:15:44 1.7 @@ -803,38 +803,37 @@ return (cfp->close == NULL) ? 0 : cfp->close(cfp->param); } -/* Common structure that holds the file and ap_context_t for ap_pcfg_openfile */ -typedef struct { - ap_context_t *pool; - FILE *file; -} poolfile_t; - -static int cfg_close(void *param) +static ap_status_t cfg_close(void *param) { - poolfile_t *cfp = (poolfile_t *) param; - return (ap_pfclose(cfp->pool, cfp->file)); + ap_file_t *cfp = (ap_file_t *) param; + return (ap_close(cfp)); } static int cfg_getch(void *param) { - poolfile_t *cfp = (poolfile_t *) param; - return (fgetc(cfp->file)); + char ch; + ap_file_t *cfp = (ap_file_t *) param; + if (ap_getc(cfp, &ch) == APR_SUCCESS) + return ch; + return (int)EOF; } static void *cfg_getstr(void *buf, size_t bufsiz, void *param) { - poolfile_t *cfp = (poolfile_t *) param; - return (fgets(buf, bufsiz, cfp->file)); + ap_file_t *cfp = (ap_file_t *) param; + if (ap_gets(cfp, buf, bufsiz) == APR_SUCCESS) + return buf; + return NULL; } /* Open a configfile_t as FILE, return open configfile_t struct pointer */ API_EXPORT(configfile_t *) ap_pcfg_openfile(ap_context_t *p, const char *name) { configfile_t *new_cfg; - poolfile_t *new_pfile; - FILE *file; - struct stat stbuf; + ap_file_t *file; int saved_errno; + ap_status_t stat; + ap_filetype_e type; if (name == NULL) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL, @@ -850,41 +849,37 @@ return NULL; } - /* ZZZ bopenf and use AP defines for flags. */ - file = ap_pfopen(p, name, "r"); + stat = ap_open(p, name, APR_READ | APR_BUFFERED, APR_OS_DEFAULT, &file); #ifdef DEBUG saved_errno = errno; ap_log_error(APLOG_MARK, APLOG_DEBUG | APLOG_NOERRNO, NULL, "Opening config file %s (%s)", - name, (file == NULL) ? strerror(errno) : "successful"); + name, (stat != APR_SUCCESS) ? strerror(errno) : "successful"); errno = saved_errno; #endif - if (file == NULL) + if (stat != APR_SUCCESS) return NULL; - if (fstat(fileno(file), &stbuf) == 0 && - !S_ISREG(stbuf.st_mode) && + if (ap_get_filetype(file, &type) == APR_SUCCESS && + type == APR_REG && #if defined(WIN32) || defined(OS2) !(strcasecmp(name, "nul") == 0 || (strlen(name) >= 4 && strcasecmp(name + strlen(name) - 4, "/nul") == 0))) { #else - strcmp(name, "/dev/null") != 0) { + strcmp(name, "/dev/null") == 0) { #endif /* WIN32 || OS2 */ saved_errno = errno; ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, NULL, "Access to file %s denied by server: not a regular file", name); - ap_pfclose(p, file); + ap_close(file); errno = saved_errno; return NULL; } new_cfg = ap_palloc(p, sizeof(*new_cfg)); - new_pfile = ap_palloc(p, sizeof(*new_pfile)); - new_pfile->file = file; - new_pfile->pool = p; - new_cfg->param = new_pfile; + new_cfg->param = file; new_cfg->name = ap_pstrdup(p, name); new_cfg->getch = (int (*)(void *)) cfg_getch; new_cfg->getstr = (void *(*)(void *, size_t, void *)) cfg_getstr; 1.4 +3 -2 apache-2.0/src/main/util_md5.c Index: util_md5.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/util_md5.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- util_md5.c 1999/08/31 05:33:02 1.3 +++ util_md5.c 1999/09/08 14:15:44 1.4 @@ -84,6 +84,7 @@ /* md5.c --Module Interface to MD5. */ /* Jeff Hostetler, Spyglass, Inc., 1994. */ +#include "apr_portable.h" #include "httpd.h" #include "util_md5.h" @@ -189,7 +190,7 @@ #ifdef CHARSET_EBCDIC -API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile, int convert) +API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile, int convert) { AP_MD5_CTX context; unsigned char buf[1000]; @@ -212,7 +213,7 @@ #else -API_EXPORT(char *) ap_md5digest(ap_context_t *p, APRFile infile) +API_EXPORT(char *) ap_md5digest(ap_context_t *p, int infile) { AP_MD5_CTX context; unsigned char buf[1000]; 1.8 +2 -1 apache-2.0/src/main/util_script.c Index: util_script.c =================================================================== RCS file: /home/cvs/apache-2.0/src/main/util_script.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- util_script.c 1999/08/31 05:33:03 1.7 +++ util_script.c 1999/09/08 14:15:44 1.8 @@ -688,6 +688,7 @@ char **env, int shellcmd) { int pid = 0; + int errfileno = STDERR_FILENO; #if !defined(WIN32) && !defined(OS2) /* the fd on r->server->error_log is closed, but we need somewhere to @@ -695,7 +696,7 @@ * since that is better than allowing errors to go unnoticed. Don't do * this on Win32, though, since we haven't fork()'d. */ - r->server->error_log = stderr; + ap_put_os_file(r->pool, &r->server->error_log, &errfileno); #endif /* TODO: all that RLimit stuff should become part of the spawning API, 1.8 +4 -2 apache-2.0/src/modules/mpm/mpmt_pthread/acceptlock.c Index: acceptlock.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/acceptlock.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- acceptlock.c 1999/08/31 05:33:22 1.7 +++ acceptlock.c 1999/09/08 14:15:47 1.8 @@ -486,6 +486,7 @@ { int i; char * lock_fname; + ap_file_t *tempfile; lock_count = number_of_locks; lock_fd = (int *)ap_palloc(p, lock_count * sizeof(int *)); @@ -503,8 +504,9 @@ init_lock_fname(p); for (i = 0; i < lock_count; i++) { lock_fname = expand_lock_fname(p, i); - lock_fd[i] = ap_popenf(p, lock_fname, - O_CREAT | O_WRONLY | O_EXCL, 0644); + ap_open(p, lock_fname, APR_CREATE | APR_WRITE | APR_EXCL, + APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, &tempfile); + ap_get_os_file(tempfile, &lock_fd[i]); if (lock_fd[i] == -1) { perror("open"); fprintf(stderr, "Cannot open lock file: %s\n", lock_fname); 1.31 +15 -10 apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c Index: mpmt_pthread.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/mpmt_pthread/mpmt_pthread.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- mpmt_pthread.c 1999/08/31 05:33:23 1.30 +++ mpmt_pthread.c 1999/09/08 14:15:47 1.31 @@ -57,6 +57,7 @@ #define CORE_PRIVATE +#include "apr_portable.h" #include "httpd.h" #include "http_main.h" #include "http_log.h" @@ -677,7 +678,6 @@ { ap_listen_rec *lr; int num_listeners = 0; - if (ap_listen_open(pconf, s->port)) { return 0; } @@ -800,12 +800,12 @@ int thread_slot = ti->tid; ap_context_t *tpool = ti->tpool; struct sockaddr sa_client; - int csd = -1; + ap_socket_t *csd = NULL; ap_context_t *ptrans; /* Pool for per-transaction stuff */ - int sd = -1; + ap_socket_t *sd = NULL; int srv; int curr_pollfd, last_pollfd = 0; - size_t len = sizeof(struct sockaddr); + int thesock; free(ti); @@ -853,7 +853,7 @@ } if (num_listenfds == 1) { - sd = ap_listeners->fd; + sd = ap_listeners->sd; goto got_fd; } else { @@ -867,7 +867,7 @@ /* XXX: Should we check for POLLERR? */ if (listenfds[curr_pollfd].revents & POLLIN) { last_pollfd = curr_pollfd; - sd = listenfds[curr_pollfd].fd; + ap_put_os_sock(tpool, &sd, &listenfds[curr_pollfd].fd); goto got_fd; } } while (curr_pollfd != last_pollfd); @@ -875,7 +875,7 @@ } got_fd: if (!workers_may_exit) { - csd = ap_accept(sd, &sa_client, &len); + ap_accept(sd, &csd); SAFE_ACCEPT(accept_mutex_off(0)); SAFE_ACCEPT(intra_mutex_off(0)); } @@ -884,7 +884,8 @@ SAFE_ACCEPT(intra_mutex_off(0)); break; } - process_socket(ptrans, &sa_client, csd, process_slot, thread_slot); + ap_get_os_sock(csd, &thesock); + process_socket(ptrans, &sa_client, thesock, process_slot, thread_slot); ap_clear_pool(ptrans); requests_this_child--; } @@ -948,7 +949,7 @@ listenfds[0].events = POLLIN; listenfds[0].revents = 0; for (lr = ap_listeners, i = 1; i <= num_listenfds; lr = lr->next, ++i) { - listenfds[i].fd = lr->fd; + ap_get_os_sock(lr->sd, &listenfds[i].fd); listenfds[i].events = POLLIN; /* should we add POLLPRI ?*/ listenfds[i].revents = 0; } @@ -1288,8 +1289,13 @@ "pipe: (pipe_of_death)"); exit(1); } +/* XXXXXX Removed because these functions don't exist anymore. When + These pipes are changed to apr_types, these functions won't be needed + anyway. ap_note_cleanups_for_fd(pconf, pipe_of_death[0]); ap_note_cleanups_for_fd(pconf, pipe_of_death[1]); +*/ + if (fcntl(pipe_of_death[0], F_SETFD, O_NONBLOCK) == -1) { ap_log_error(APLOG_MARK, APLOG_ERR, (const server_rec*) server_conf, @@ -1310,7 +1316,6 @@ } set_signals(); - /* Don't thrash... */ if (max_spare_threads < min_spare_threads + ap_threads_per_child) max_spare_threads = min_spare_threads + ap_threads_per_child; 1.9 +8 -2 apache-2.0/src/modules/mpm/prefork/Makefile.tmpl Index: Makefile.tmpl =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/prefork/Makefile.tmpl,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- Makefile.tmpl 1999/07/16 18:24:25 1.8 +++ Makefile.tmpl 1999/09/08 14:15:48 1.9 @@ -59,11 +59,17 @@ $(INCDIR)/ap_config.h $(INCDIR)/ap_mmn.h \ $(INCDIR)/ap_config_auto.h $(OSDIR)/os.h \ $(OSDIR)/os-inline.c $(INCDIR)/ap_ctype.h \ - $(INCDIR)/alloc.h $(INCDIR)/buff.h \ + $(INCDIR)/hsregex.h ../../../lib/apr/include/apr_general.h \ + ../../../lib/apr/include/apr_config.h \ + ../../../lib/apr/include/apr_errno.h \ + ../../../lib/apr/include/apr_lib.h \ + ../../../lib/apr/include/apr_file_io.h \ + ../../../lib/apr/include/hsregex.h $(INCDIR)/buff.h \ $(INCDIR)/ap_iol.h $(INCDIR)/ap.h \ $(INCDIR)/apr.h $(INCDIR)/util_uri.h mpm_default.h \ $(INCDIR)/http_main.h $(INCDIR)/http_log.h \ $(INCDIR)/http_config.h $(INCDIR)/ap_hooks.h \ $(INCDIR)/http_core.h $(INCDIR)/http_connection.h \ scoreboard.h $(INCDIR)/ap_mpm.h $(OSDIR)/unixd.h \ - $(OSDIR)/iol_socket.h $(INCDIR)/ap_listen.h + $(OSDIR)/iol_socket.h $(INCDIR)/ap_listen.h \ + ../../../lib/apr/include/apr_network_io.h 1.33 +31 -21 apache-2.0/src/modules/mpm/prefork/prefork.c Index: prefork.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/mpm/prefork/prefork.c,v retrieving revision 1.32 retrieving revision 1.33 diff -u -r1.32 -r1.33 --- prefork.c 1999/08/31 05:33:25 1.32 +++ prefork.c 1999/09/08 14:15:49 1.33 @@ -87,6 +87,7 @@ #define CORE_PRIVATE +#include "apr_portable.h" #include "httpd.h" #include "mpm_default.h" #include "http_main.h" @@ -135,7 +136,7 @@ /* *Non*-shared http_main globals... */ static server_rec *server_conf; -static int sd; +static ap_socket_t *sd; static fd_set listenfds; static int listenmaxfd; @@ -528,7 +529,7 @@ */ static void accept_mutex_init(ap_context_t *p) { - + ap_file_t *tempfile; lock_it.l_whence = SEEK_SET; /* from current point */ lock_it.l_start = 0; /* -"- */ lock_it.l_len = 0; /* until end of file */ @@ -541,7 +542,9 @@ unlock_it.l_pid = 0; /* pid not actually interesting */ expand_lock_fname(p); - lock_fd = ap_popenf(p, ap_lock_fname, O_CREAT | O_WRONLY | O_EXCL, 0644); + ap_open(p, ap_lock_fname, APR_CREATE | APR_WRITE | APR_EXCL, + APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD, &tempfile); + ap_get_os_file(tempfile, &lock_fd); if (lock_fd == -1) { perror("open"); fprintf(stderr, "Cannot open lock file: %s\n", ap_lock_fname); @@ -1903,7 +1906,7 @@ */ static int srv; -static int csd; +static ap_socket_t *csd; static int requests_this_child; static fd_set main_fds; @@ -1934,9 +1937,11 @@ ap_context_t *ptrans; conn_rec *current_conn; ap_iol *iol; + ap_status_t stat; + int sockdes; my_pid = getpid(); - csd = -1; + csd = NULL; my_child_num = child_num_arg; requests_this_child = 0; last_lr = NULL; @@ -2034,7 +2039,8 @@ } first_lr=lr; do { - if (FD_ISSET(lr->fd, &main_fds)) + ap_get_os_sock(lr->sd, &sockdes); + if (FD_ISSET(sockdes, &main_fds)) goto got_listener; lr = lr->next; if (!lr) @@ -2047,11 +2053,11 @@ continue; got_listener: last_lr = lr; - sd = lr->fd; + sd = lr->sd; } else { /* only one socket, just pretend we did the other stuff */ - sd = ap_listeners->fd; + sd = ap_listeners->sd; } /* if we accept() something we don't want to die, so we have to @@ -2064,12 +2070,12 @@ clean_child_exit(0); } clen = sizeof(sa_client); - csd = ap_accept(sd, &sa_client, &clen); - if (csd >= 0 || errno != EINTR) + stat = ap_accept(sd, &csd); + if (stat == APR_SUCCESS || stat != APR_EINTR) break; } - if (csd >= 0) + if (stat == APR_SUCCESS) break; /* We have a socket ready for reading */ else { @@ -2192,28 +2198,30 @@ * socket options, file descriptors, and read/write buffers. */ + ap_get_os_sock(csd, &sockdes); + clen = sizeof(sa_server); - if (getsockname(csd, &sa_server, &clen) < 0) { + if (getsockname(sockdes, &sa_server, &clen) < 0) { ap_log_error(APLOG_MARK, APLOG_ERR, server_conf, "getsockname"); - close(csd); + ap_close_socket(csd); continue; } - sock_disable_nagle(csd); + sock_disable_nagle(sockdes); - iol = unix_attach_socket(csd); + iol = unix_attach_socket(sockdes); if (iol == NULL) { if (errno == EBADF) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, "filedescriptor (%u) larger than FD_SETSIZE (%u) " "found, you probably need to rebuild Apache with a " - "larger FD_SETSIZE", csd, FD_SETSIZE); + "larger FD_SETSIZE", sockdes, FD_SETSIZE); } else { ap_log_error(APLOG_MARK, APLOG_WARNING, NULL, "error attaching to socket"); } - close(csd); + ap_close_socket(csd); continue; } @@ -2517,6 +2525,7 @@ static int setup_listeners(ap_context_t *p, server_rec *s) { ap_listen_rec *lr; + int sockdes; if (ap_listen_open(p, s->port)) { ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, s, @@ -2527,9 +2536,10 @@ listenmaxfd = -1; FD_ZERO(&listenfds); for (lr = ap_listeners; lr; lr = lr->next) { - FD_SET(lr->fd, &listenfds); - if (lr->fd > listenmaxfd) { - listenmaxfd = lr->fd; + ap_get_os_sock(lr->sd, &sockdes); + FD_SET(sockdes, &listenfds); + if (sockdes > listenmaxfd) { + listenmaxfd = sockdes; } } return 0; @@ -2547,7 +2557,7 @@ pconf = _pconf; server_conf = s; - + ap_log_pid(pconf, ap_pid_fname); if (setup_listeners(pconf, s)) { 1.4 +14 -9 apache-2.0/src/modules/standard/mod_asis.c Index: mod_asis.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_asis.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- mod_asis.c 1999/08/31 05:33:42 1.3 +++ mod_asis.c 1999/09/08 14:15:54 1.4 @@ -65,8 +65,10 @@ static int asis_handler(request_rec *r) { - FILE *f; + ap_file_t *f; const char *location; + FILE *thefile; /* XXX leave these alone until we convert */ + int thefd; /* everything to use apr_file_t's. */ r->allowed |= (1 << M_GET); if (r->method_number != M_GET) @@ -77,21 +79,23 @@ return NOT_FOUND; } - f = ap_pfopen(r->pool, r->filename, "r"); - - if (f == NULL) { + if (ap_open(r->pool, r->filename, APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, &f) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "file permissions deny server access: %s", r->filename); return FORBIDDEN; } - ap_scan_script_header_err(r, f, NULL); + ap_get_os_file(f, &thefd); + thefile = fdopen(thefd, "r"); + + ap_scan_script_header_err(r, thefile, NULL); location = ap_table_get(r->headers_out, "Location"); if (location && location[0] == '/' && ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) { - ap_pfclose(r->pool, f); + ap_close(f); /* Internal redirect -- fake-up a pseudo-request */ r->status = HTTP_OK; @@ -108,11 +112,12 @@ ap_send_http_header(r); if (!r->header_only) { - fseek(f, 0, SEEK_CUR); - ap_send_fd(fileno(f), r); + ap_off_t zero = 0; + ap_seek(f, APR_CUR, &zero); + ap_send_fd(thefd, r); } - ap_pfclose(r->pool, f); + ap_close(f); return OK; } 1.5 +30 -23 apache-2.0/src/modules/standard/mod_autoindex.c Index: mod_autoindex.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_autoindex.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- mod_autoindex.c 1999/08/31 05:33:45 1.4 +++ mod_autoindex.c 1999/09/08 14:15:54 1.5 @@ -884,17 +884,19 @@ /* * emit a plain text file */ -static void do_emit_plain(request_rec *r, FILE *f) +static void do_emit_plain(request_rec *r, ap_file_t *f) { char buf[IOBUFSIZE + 1]; int i, n, c, ch; + ap_status_t stat; ap_rputs("<PRE>\n", r); - while (!feof(f)) { + while (!ap_eof(f)) { do { - n = fread(buf, sizeof(char), IOBUFSIZE, f); + n = sizeof(char) * IOBUFSIZE; + stat = ap_read(f, buf, &n); } - while (n == -1 && ferror(f) && errno == EINTR); + while (stat != APR_SUCCESS && stat == EINTR); if (n == -1 || n == 0) { break; } @@ -936,7 +938,7 @@ static void emit_head(request_rec *r, char *header_fname, int suppress_amble, char *title) { - FILE *f; + ap_file_t *f; request_rec *rr = NULL; int emit_amble = 1; int emit_H1 = 1; @@ -984,11 +986,12 @@ * the file's contents, any HTML header it had won't end up * where it belongs. */ - if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) { + if (ap_open(r->pool, rr->filename, APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, &f) == APR_SUCCESS) { emit_preamble(r, title); emit_amble = 0; do_emit_plain(r, f); - ap_pfclose(r->pool, f); + ap_close(f); emit_H1 = 0; } } @@ -1018,7 +1021,7 @@ */ static void emit_tail(request_rec *r, char *readme_fname, int suppress_amble) { - FILE *f; + ap_file_t *f; request_rec *rr = NULL; int suppress_post = 0; int suppress_sig = 0; @@ -1051,9 +1054,10 @@ /* * If we can open the file, suppress the signature. */ - if ((f = ap_pfopen(r->pool, rr->filename, "r")) != 0) { + if (ap_open(r->pool, rr->filename, APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, &f) == APR_SUCCESS) { do_emit_plain(r, f); - ap_pfclose(r->pool, f); + ap_close(f); suppress_sig = 1; } } @@ -1075,7 +1079,7 @@ static char *find_title(request_rec *r) { char titlebuf[MAX_STRING_LEN], *find = "<TITLE>"; - FILE *thefile = NULL; + ap_file_t *thefile = NULL; int x, y, n, p; if (r->status != HTTP_OK) { @@ -1086,12 +1090,14 @@ "text/html") || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE)) && !r->content_encoding) { - if (!(thefile = ap_pfopen(r->pool, r->filename, "r"))) { + if (ap_open(r->pool, r->filename, APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, &thefile) != APR_SUCCESS) { return NULL; } - n = fread(titlebuf, sizeof(char), MAX_STRING_LEN - 1, thefile); + n = sizeof(char) * (MAX_STRING_LEN - 1); + ap_read(thefile, titlebuf, &n); if (n <= 0) { - ap_pfclose(r->pool, thefile); + ap_close(thefile); return NULL; } titlebuf[n] = '\0'; @@ -1112,7 +1118,7 @@ } } } - ap_pfclose(r->pool, thefile); + ap_close(thefile); return ap_pstrdup(r->pool, &titlebuf[x]); } } @@ -1120,7 +1126,7 @@ p = 0; } } - ap_pfclose(r->pool, thefile); + ap_close(thefile); } return NULL; } @@ -1498,8 +1504,7 @@ char *title_endp; char *name = r->filename; - DIR *d; - struct DIR_TYPE *dstruct; + ap_dir_t *d; int num_ent = 0, x; struct ent *head, *p; struct ent **ar = NULL; @@ -1508,7 +1513,7 @@ char keyid; char direction; - if (!(d = ap_popendir(r->pool, name))) { + if (ap_opendir(r->pool, name, &d) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "Can't open directory for index: %s", r->filename); return HTTP_FORBIDDEN; @@ -1519,7 +1524,7 @@ ap_send_http_header(r); if (r->header_only) { - ap_pclosedir(r->pool, d); + ap_closedir(d); return 0; } @@ -1571,8 +1576,10 @@ * linked list and then arrayificate them so qsort can use them. */ head = NULL; - while ((dstruct = readdir(d))) { - p = make_autoindex_entry(dstruct->d_name, autoindex_opts, + while (ap_readdir(d)) { + char *d_name; + ap_get_dir_filename(d, &d_name); + p = make_autoindex_entry(d_name, autoindex_opts, autoindex_conf, r, keyid, direction); if (p != NULL) { p->next = head; @@ -1595,7 +1602,7 @@ } output_directories(ar, num_ent, autoindex_conf, r, autoindex_opts, keyid, direction); - ap_pclosedir(r->pool, d); + ap_closedir(d); if (autoindex_opts & FANCY_INDEXING) { ap_rputs("<HR>\n", r); 1.5 +11 -11 apache-2.0/src/modules/standard/mod_log_config.c Index: mod_log_config.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_log_config.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- mod_log_config.c 1999/08/31 05:33:54 1.4 +++ mod_log_config.c 1999/09/08 14:15:55 1.5 @@ -178,12 +178,12 @@ module MODULE_VAR_EXPORT config_log_module; -static int xfer_flags = (O_WRONLY | O_APPEND | O_CREAT); +static int xfer_flags = (APR_WRITE | APR_APPEND | APR_CREATE); #if defined(OS2) || defined(WIN32) /* OS/2 dosen't support users and groups */ static mode_t xfer_mode = (S_IREAD | S_IWRITE); #else -static mode_t xfer_mode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); +static mode_t xfer_mode = (APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD); #endif /* POSIX.1 defines PIPE_BUF as the maximum number of bytes that is @@ -229,7 +229,7 @@ * be NULL, which means this module does no logging for this * request. format might be NULL, in which case the default_format * from the multi_log_state should be used, or if that is NULL as - * well, use the CLF. log_fd is -1 before the log file is opened and + * well, use the CLF. log_fd is NULL before the log file is opened and * set to a valid fd after it is opened. */ @@ -237,7 +237,7 @@ char *fname; char *format_string; ap_array_header_t *format; - int log_fd; + ap_file_t *log_fd; char *condition_var; #ifdef BUFFERED_LOGS int outcnt; @@ -723,8 +723,8 @@ #ifdef BUFFERED_LOGS static void flush_log(config_log_state *cls) { - if (cls->outcnt && cls->log_fd != -1) { - write(cls->log_fd, cls->outbuf, cls->outcnt); + if (cls->outcnt && cls->log_fd != NULL) { + ap_write(cls->log_fd, cls->outbuf, cls->outcnt); cls->outcnt = 0; } } @@ -797,7 +797,7 @@ memcpy(s, strs[i], strl[i]); s += strl[i]; } - write(cls->log_fd, str, len); + ap_write(cls->log_fd, str, len); } else { for (i = 0, s = &cls->outbuf[cls->outcnt]; i < format->nelts; ++i) { @@ -814,7 +814,7 @@ s += strl[i]; } - write(cls->log_fd, str, len); + ap_write(cls->log_fd, str, &len); #endif return OK; @@ -949,7 +949,7 @@ else { cls->format = parse_log_string(cmd->pool, fmt, &err_string); } - cls->log_fd = -1; + cls->log_fd = NULL; return err_string; } @@ -982,7 +982,7 @@ config_log_state *cls, ap_array_header_t *default_format) { - if (cls->log_fd > 0) { + if (cls->log_fd != NULL) { return cls; /* virtual config shared w/main server */ } @@ -1001,7 +1001,7 @@ } else { const char *fname = ap_server_root_relative(p, cls->fname); - if ((cls->log_fd = ap_popenf(p, fname, xfer_flags, xfer_mode)) < 0) { + if (ap_open(p, fname, xfer_flags, xfer_mode, &cls->log_fd) != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR, s, "could not open transfer log file %s.", fname); exit(1); 1.4 +24 -25 apache-2.0/src/modules/standard/mod_negotiation.c Index: mod_negotiation.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_negotiation.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- mod_negotiation.c 1999/08/31 05:33:57 1.3 +++ mod_negotiation.c 1999/09/08 14:15:55 1.4 @@ -635,16 +635,16 @@ header_eof, header_seen, header_sep }; -static enum header_state get_header_line(char *buffer, int len, FILE *map) +static enum header_state get_header_line(char *buffer, int len, ap_file_t *map) { char *buf_end = buffer + len; char *cp; - int c; + char c; /* Get a noncommented line */ do { - if (fgets(buffer, MAX_STRING_LEN, map) == NULL) { + if (ap_gets(map, buffer, MAX_STRING_LEN) != APR_SUCCESS) { return header_eof; } } while (buffer[0] == '#'); @@ -665,10 +665,10 @@ cp += strlen(cp); - while ((c = getc(map)) != EOF) { + while (ap_getc(map, &c) != APR_EOF) { if (c == '#') { /* Comment line */ - while ((c = getc(map)) != EOF && c != '\n') { + while (ap_getc(map, &c) != EOF && c != '\n') { continue; } } @@ -679,10 +679,10 @@ */ while (c != EOF && c != '\n' && ap_isspace(c)) { - c = getc(map); + ap_getc(map, &c); } - ungetc(c, map); + ap_ungetc(map, c); if (c == '\n') { return header_seen; /* Blank line */ @@ -690,7 +690,7 @@ /* Continuation */ - while (cp < buf_end - 2 && (c = getc(map)) != EOF && c != '\n') { + while (cp < buf_end - 2 && (ap_getc(map, &c)) != EOF && c != '\n') { *cp++ = c; } @@ -701,7 +701,7 @@ /* Line beginning with something other than whitespace */ - ungetc(c, map); + ap_ungetc(map, c); return header_seen; } } @@ -772,7 +772,7 @@ static int read_type_map(negotiation_state *neg, request_rec *rr) { request_rec *r = neg->r; - FILE *map; + ap_file_t *map; char buffer[MAX_STRING_LEN]; enum header_state hstate; struct var_rec mime_info; @@ -781,8 +781,8 @@ /* We are not using multiviews */ neg->count_multiviews_variants = 0; - map = ap_pfopen(neg->pool, rr->filename, "r"); - if (map == NULL) { + if (ap_open(neg->pool, rr->filename, APR_READ | APR_BUFFERED, + APR_OS_DEFAULT, &map) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "cannot access type map file: %s", rr->filename); return HTTP_FORBIDDEN; @@ -851,7 +851,7 @@ } } while (hstate != header_eof); - ap_pfclose(neg->pool, map); + ap_close(map); set_vlist_validator(r, rr); @@ -889,8 +889,7 @@ char *filp; int prefix_len; - DIR *dirp; - struct DIR_TYPE *dir_entry; + ap_dir_t *dirp; struct var_rec mime_info; struct accept_rec accept_info; void *new_var; @@ -908,23 +907,23 @@ ++filp; prefix_len = strlen(filp); - dirp = ap_popendir(neg->pool, neg->dir_name); - - if (dirp == NULL) { + if (ap_opendir(neg->pool, neg->dir_name, &dirp) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "cannot read directory for multi: %s", neg->dir_name); return HTTP_FORBIDDEN; } - while ((dir_entry = readdir(dirp))) { + while (ap_readdir(dirp) == APR_SUCCESS) { request_rec *sub_req; + char *d_name; + ap_get_dir_filename(dirp, &d_name); /* Do we have a match? */ - if (strncmp(dir_entry->d_name, filp, prefix_len)) { + if (strncmp(d_name, filp, prefix_len)) { continue; } - if (dir_entry->d_name[prefix_len] != '.') { + if (d_name[prefix_len] != '.') { continue; } @@ -933,7 +932,7 @@ * which we'll be slapping default_type on later). */ - sub_req = ap_sub_req_lookup_file(dir_entry->d_name, r); + sub_req = ap_sub_req_lookup_file(d_name, r); /* If it has a handler, we'll pretend it's a CGI script, * since that's a good indication of the sort of thing it @@ -957,7 +956,7 @@ ((sub_req->handler) && !strcmp(sub_req->handler, "type-map"))) { - ap_pclosedir(neg->pool, dirp); + ap_closedir(dirp); neg->avail_vars->nelts = 0; if (sub_req->status != HTTP_OK) { return sub_req->status; @@ -968,7 +967,7 @@ /* Have reasonable variant --- gather notes. */ mime_info.sub_req = sub_req; - mime_info.file_name = ap_pstrdup(neg->pool, dir_entry->d_name); + mime_info.file_name = ap_pstrdup(neg->pool, d_name); if (sub_req->content_encoding) { mime_info.content_encoding = sub_req->content_encoding; } @@ -987,7 +986,7 @@ clean_var_rec(&mime_info); } - ap_pclosedir(neg->pool, dirp); + ap_closedir(dirp); set_vlist_validator(r, r);