| 123 | } |
| 124 | |
| 125 | static void cache_the_file(cmd_parms *cmd, const char *filename, int mmap) |
| 126 | { |
| 127 | a_server_config *sconf; |
| 128 | a_file *new_file; |
| 129 | a_file tmp; |
| 130 | apr_file_t *fd = NULL; |
| 131 | apr_status_t rc; |
| 132 | const char *fspec; |
| 133 | |
| 134 | fspec = ap_server_root_relative(cmd->pool, filename); |
| 135 | if (!fspec) { |
| 136 | ap_log_error(APLOG_MARK, APLOG_WARNING, APR_EBADPATH, cmd->server, APLOGNO(00794) |
| 137 | "invalid file path " |
| 138 | "%s, skipping", filename); |
| 139 | return; |
| 140 | } |
| 141 | if ((rc = apr_stat(&tmp.finfo, fspec, APR_FINFO_MIN, |
| 142 | cmd->temp_pool)) != APR_SUCCESS) { |
| 143 | ap_log_error(APLOG_MARK, APLOG_WARNING, rc, cmd->server, APLOGNO(00795) |
| 144 | "unable to stat(%s), skipping", fspec); |
| 145 | return; |
| 146 | } |
| 147 | if (tmp.finfo.filetype != APR_REG) { |
| 148 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00796) |
| 149 | "%s isn't a regular file, skipping", fspec); |
| 150 | return; |
| 151 | } |
| 152 | if (tmp.finfo.size > AP_MAX_SENDFILE) { |
| 153 | ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, APLOGNO(00797) |
| 154 | "%s is too large to cache, skipping", fspec); |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | rc = apr_file_open(&fd, fspec, APR_READ | APR_BINARY | APR_XTHREAD, |
| 159 | APR_OS_DEFAULT, cmd->pool); |
| 160 | if (rc != APR_SUCCESS) { |
| 161 | ap_log_error(APLOG_MARK, APLOG_WARNING, rc, cmd->server, APLOGNO(00798) |
| 162 | "unable to open(%s, O_RDONLY), skipping", fspec); |
| 163 | return; |
| 164 | } |
| 165 | apr_file_inherit_set(fd); |
| 166 | |
| 167 | /* WooHoo, we have a file to put in the cache */ |
| 168 | new_file = apr_pcalloc(cmd->pool, sizeof(a_file)); |
| 169 | new_file->finfo = tmp.finfo; |
| 170 | |
| 171 | #if APR_HAS_MMAP |
| 172 | if (mmap) { |
| 173 | /* MMAPFile directive. MMAP'ing the file |
| 174 | * XXX: APR_HAS_LARGE_FILES issue; need to reject this request if |
| 175 | * size is greater than MAX(apr_size_t) (perhaps greater than 1M?). |
| 176 | */ |
| 177 | if ((rc = apr_mmap_create(&new_file->mm, fd, 0, |
| 178 | (apr_size_t)new_file->finfo.size, |
| 179 | APR_MMAP_READ, cmd->pool)) != APR_SUCCESS) { |
| 180 | apr_file_close(fd); |
| 181 | ap_log_error(APLOG_MARK, APLOG_WARNING, rc, cmd->server, APLOGNO(00799) |
| 182 | "unable to mmap %s, skipping", filename); |
no test coverage detected