dreid 99/11/20 04:55:27
Modified: src/modules/experimental Makefile.tmpl mod_mmap_static.c Log: This brings mod_mmap_static into Apache 2.0 using APR. Tested on BeOS. Revision Changes Path 1.5 +5 -4 apache-2.0/src/modules/experimental/Makefile.tmpl Index: Makefile.tmpl =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/experimental/Makefile.tmpl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- Makefile.tmpl 1999/11/19 18:46:00 1.4 +++ Makefile.tmpl 1999/11/20 12:55:26 1.5 @@ -7,12 +7,12 @@ mod_mmap_static.o: mod_mmap_static.c $(INCDIR)/httpd.h \ $(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)/hsregex.h ../../lib/apr/include/apr_general.h \ + $(INCDIR)/ap_ctype.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 \ $(INCDIR)/buff.h $(INCDIR)/ap_iol.h $(INCDIR)/ap.h \ - $(INCDIR)/util_uri.h \ + $(INCDIR)/apr.h $(INCDIR)/util_uri.h \ $(INCDIR)/http_config.h $(INCDIR)/ap_hooks.h \ $(INCDIR)/http_log.h $(INCDIR)/http_protocol.h \ ../../lib/apr/include/apr_portable.h \ @@ -20,4 +20,5 @@ ../../lib/apr/include/apr_win.h \ ../../lib/apr/include/apr_network_io.h \ ../../lib/apr/include/apr_lock.h ../../lib/apr/include/apr_time.h \ - $(INCDIR)/http_request.h $(INCDIR)/http_core.h + ../../lib/apr/include/apr_mmap.h $(INCDIR)/http_request.h \ + $(INCDIR)/http_core.h 1.5 +49 -56 apache-2.0/src/modules/experimental/mod_mmap_static.c Index: mod_mmap_static.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/experimental/mod_mmap_static.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- mod_mmap_static.c 1999/08/31 21:37:08 1.4 +++ mod_mmap_static.c 1999/11/20 12:55:26 1.5 @@ -111,7 +111,6 @@ #include <fcntl.h> #include <errno.h> #include <string.h> -#include <sys/mman.h> #define CORE_PRIVATE @@ -121,14 +120,16 @@ #include "http_protocol.h" #include "http_request.h" #include "http_core.h" +#include "apr_mmap.h" module MODULE_VAR_EXPORT mmap_static_module; typedef struct { + ap_mmap_t *mm; char *filename; - void *mm; struct stat finfo; } a_file; +ap_context_t *context; typedef struct { ap_array_header_t *files; @@ -145,7 +146,7 @@ return sconf; } -static void cleanup_mmap(void *sconfv) +ap_status_t cleanup_mmap(void *sconfv) { a_server_config *sconf = sconfv; size_t n; @@ -154,10 +155,11 @@ n = sconf->files->nelts; file = (a_file *)sconf->files->elts; while(n) { - munmap(file->mm, file->finfo.st_size); - ++file; - --n; + ap_mmap_delete(file->mm); + ++file; + --n; } + return APR_SUCCESS; } static const char *mmapfile(cmd_parms *cmd, void *dummy, char *filename) @@ -165,36 +167,33 @@ a_server_config *sconf; a_file *new_file; a_file tmp; - int fd; + ap_file_t *fd; caddr_t mm; if (stat(filename, &tmp.finfo) == -1) { - ap_log_error(APLOG_MARK, APLOG_WARNING, cmd->server, + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, cmd->server, "mmap_static: unable to stat(%s), skipping", filename); return NULL; } if ((tmp.finfo.st_mode & S_IFMT) != S_IFREG) { - ap_log_error(APLOG_MARK, APLOG_WARNING, cmd->server, + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, cmd->server, "mmap_static: %s isn't a regular file, skipping", filename); return NULL; } - fd = open(filename, O_RDONLY, 0); - if (fd == -1) { - ap_log_error(APLOG_MARK, APLOG_WARNING, cmd->server, + if (ap_open(&fd, filename, APR_READ, APR_OS_DEFAULT, context) != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, cmd->server, "mmap_static: unable to open(%s, O_RDONLY), skipping", filename); return NULL; } - mm = mmap(NULL, tmp.finfo.st_size, PROT_READ, MAP_SHARED, fd, 0); - if (mm == (caddr_t)-1) { + if (ap_mmap_create(&tmp.mm, fd, 0, tmp.finfo.st_size, context) != APR_SUCCESS) { int save_errno = errno; - close(fd); + ap_close(fd); errno = save_errno; - ap_log_error(APLOG_MARK, APLOG_WARNING, cmd->server, + ap_log_error(APLOG_MARK, APLOG_WARNING, errno, cmd->server, "mmap_static: unable to mmap %s, skipping", filename); return NULL; } - close(fd); - tmp.mm = mm; + ap_close(fd); tmp.filename = ap_pstrdup(cmd->pool, filename); sconf = ap_get_module_config(cmd->server->module_config, &mmap_static_module); new_file = ap_push_array(sconf->files); @@ -206,17 +205,6 @@ return NULL; } -static command_rec mmap_static_cmds[] = -{ - { - "mmapfile", mmapfile, NULL, RSRC_CONF, ITERATE, - "A space separated list of files to mmap at config time" - }, - { - NULL - } -}; - static int file_compare(const void *av, const void *bv) { const a_file *a = av; @@ -238,7 +226,8 @@ return c; } -static void mmap_init(server_rec *s, ap_context_t *p) +static void mmap_post_config(ap_context_t *p, ap_context_t *plog, + ap_context_t *ptemp, server_rec *s) { a_server_config *sconf; ap_array_header_t *inodes; @@ -246,6 +235,7 @@ int nelts; int i; + context = p; /* sort the elements of the main_server, by filename */ sconf = ap_get_module_config(s->module_config, &mmap_static_module); elts = (a_file *)sconf->files->elts; @@ -283,17 +273,17 @@ if (ap_is_empty_table(sconf->files)) return DECLINED; - /* we require other modules to first set up a filename */ - res = core_module.translate_handler(r); +/* res = core_module.translate_handler(r); if (res == DECLINED || !r->filename) { return res; - } + }*/ + if (!r->filename) + return DECLINED; tmp.filename = r->filename; match = (a_file *)bsearch(&tmp, sconf->files->elts, sconf->files->nelts, sizeof(a_file), file_compare); - if (match == NULL) { - return DECLINED; - } + if (match == NULL) + return DECLINED; /* shortcircuit the get_path_info() stat() calls and stuff */ r->finfo = match->finfo; @@ -352,7 +342,8 @@ ap_send_mmap (match->mm, r, 0, match->finfo.st_size); } else { - long offset, length; + long length; + ap_off_t offset; while (ap_each_byterange(r, &offset, &length)) { ap_send_mmap(match->mm, r, offset, length); } @@ -361,6 +352,19 @@ return OK; } +static command_rec mmap_cmds[] = +{ + {"mmapfile", mmapfile, NULL, RSRC_CONF, ITERATE, + "A space seperated list of files to mmap at config time"}, + {NULL} +}; + +static void register_hooks(void) +{ + static const char* const aszPre[]={"http_core.c",NULL}; + ap_hook_post_config(mmap_post_config, NULL, NULL, HOOK_MIDDLE); + ap_hook_translate_name(mmap_static_xlat, aszPre, NULL, HOOK_LAST); +}; static const handler_rec mmap_static_handlers[] = { @@ -370,23 +374,12 @@ module MODULE_VAR_EXPORT mmap_static_module = { - STANDARD_MODULE_STUFF, - mmap_init, /* initializer */ - NULL, /* dir config creater */ - NULL, /* dir merger --- default is to override */ - create_server_config, /* server config */ - NULL, /* merge server config */ - mmap_static_cmds, /* command handlers */ - mmap_static_handlers, /* handlers */ - mmap_static_xlat, /* filename translation */ - NULL, /* check_user_id */ - NULL, /* check auth */ - NULL, /* check access */ - NULL, /* type_checker */ - NULL, /* fixups */ - NULL, /* logger */ - NULL, /* header parser */ - NULL, /* child_init */ - NULL, /* child_exit */ - NULL /* post read-request */ + STANDARD20_MODULE_STUFF, + NULL, /* create per-directory config structure */ + NULL, /* merge per-directory config structures */ + create_server_config, /* create per-server config structure */ + NULL, /* merge per-server config structures */ + mmap_cmds, /* command handlers */ + mmap_static_handlers, /* handlers */ + register_hooks /* register hooks */ };