Changeset 2135
- Timestamp:
- 03/21/2008 03:22:50 PM (4 months ago)
- Files:
-
- trunk/NEWS (modified) (1 diff)
- trunk/src/mod_compress.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/NEWS
r2134 r2135 26 26 * fix auth-ldap configuration in tests 27 27 * fcgi-stat-accel: Fix unused var / indentation 28 * fix mod_compress bug (#1027) 28 29 29 30 - 1.5.0-r19.. - trunk/src/mod_compress.c
r2131 r2135 105 105 } 106 106 107 void mkdir_recursive(const char *dir) { 108 109 char dir_copy[256]; 110 char *p = dir_copy; 107 // 0 on success, -1 for error 108 static int mkdir_recursive(char *dir) { 109 char *p = dir; 111 110 112 111 if (!dir || !dir[0]) 113 return; 114 115 strncpy(dir_copy, dir, sizeof(dir_copy) / sizeof(dir_copy[0])); 112 return 0; 116 113 117 114 while ((p = strchr(p + 1, '/')) != NULL) { 118 115 119 116 *p = '\0'; 120 if ((mkdir(dir_copy, 0700) != 0) && (errno != EEXIST)) 121 return; 117 if ((mkdir(dir, 0700) != 0) && (errno != EEXIST)) { 118 *p = '/'; 119 return -1; 120 } 122 121 123 122 *p++ = '/'; 124 } 125 126 mkdir(dir, 0700); 123 if (!*p) return 0; // Ignore trailing slash 124 } 125 126 return (mkdir(dir, 0700) != 0) && (errno != EEXIST) ? -1 : 0; 127 } 128 129 // 0 on success, -1 for error 130 static int mkdir_for_file(char *filename) { 131 char *p = filename; 132 133 if (!filename || !filename[0]) 134 return -1; 135 136 while ((p = strchr(p + 1, '/')) != NULL) { 137 138 *p = '\0'; 139 if ((mkdir(filename, 0700) != 0) && (errno != EEXIST)) { 140 ERROR("creating cache-directory \"%s\" failed: %s", filename, strerror(errno)); 141 *p = '/'; 142 return -1; 143 } 144 145 *p++ = '/'; 146 if (!*p) { 147 ERROR("unexpected trailing slash for filename \"%s\"", filename); 148 return -1; 149 } 150 } 151 152 return 0; 127 153 } 128 154 … … 162 188 if (0 != stat(s->compress_cache_dir->ptr, &st)) { 163 189 164 log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir, attempting to create", 165 s->compress_cache_dir, strerror(errno)); 190 ERROR("can't stat compress.cache-dir (%s), attempting to create '%s'", strerror(errno),SAFE_BUF_STR(s->compress_cache_dir)); 166 191 mkdir_recursive(s->compress_cache_dir->ptr); 167 192 168 193 if (0 != stat(s->compress_cache_dir->ptr, &st)) { 169 170 log_error_write(srv, __FILE__, __LINE__, "sbs", "can't stat compress.cache-dir, create failed", 171 s->compress_cache_dir, strerror(errno)); 172 194 ERROR("can't stat compress.cache-dir (%s), failed to create '%s'", strerror(errno),SAFE_BUF_STR(s->compress_cache_dir)); 173 195 return HANDLER_ERROR; 174 196 } … … 378 400 379 401 if (0 == strncmp(con->physical.path->ptr, con->physical.doc_root->ptr, con->physical.doc_root->used-1)) { 380 size_t offset = p->ofn->used - 1;381 char *dir, *nextdir;382 383 402 buffer_append_string(p->ofn, con->physical.path->ptr + con->physical.doc_root->used - 1); 384 385 403 buffer_copy_string_buffer(p->b, p->ofn); 386 387 /* mkdir -p ... */388 for (dir = p->b->ptr + offset; NULL != (nextdir = strchr(dir, '/')); dir = nextdir + 1) {389 *nextdir = '\0';390 391 if (-1 == mkdir(p->b->ptr, 0700)) {392 if (errno != EEXIST) {393 log_error_write(srv, __FILE__, __LINE__, "sbss", "creating cache-directory", p->b, "failed", strerror(errno));394 395 return -1;396 }397 }398 399 *nextdir = '/';400 }401 404 } else { 402 405 buffer_append_string_buffer(p->ofn, con->uri.path); … … 414 417 break; 415 418 default: 416 log_error_write(srv, __FILE__, __LINE__, "sd", "unknown compression type", type);419 ERROR("unknown compression type %d", type); 417 420 return -1; 418 421 } … … 423 426 if (HANDLER_ERROR != stat_cache_get_entry(srv, con, p->ofn, &compressed_sce)) { 424 427 /* file exists */ 425 if (con->conf.log_request_handling) TRACE("file exists in the cache (%s), sending it", BUF_STR(p->ofn));428 if (con->conf.log_request_handling) TRACE("file exists in the cache (%s), sending it", SAFE_BUF_STR(p->ofn)); 426 429 427 430 chunkqueue_reset(con->send); … … 433 436 434 437 if (-1 == (ofd = open(p->ofn->ptr, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))) { 435 if (errno == EEXIST) { 436 /* cache-entry exists */ 437 438 } 439 440 log_error_write(srv, __FILE__, __LINE__, "sbss", 441 "creating cachefile", p->ofn, 442 "failed", strerror(errno)); 443 444 return -1; 438 if (-1 == mkdir_for_file(p->ofn->ptr)) { 439 return -1; // error message in mkdir_for_file 440 } else if (-1 == (ofd = open(p->ofn->ptr, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600))) { 441 ERROR("creating cachefile '%s' failed: %s", SAFE_BUF_STR(p->ofn), strerror(errno)); 442 return -1; 443 } 445 444 } 446 445 447 446 if (-1 == (ifd = open(filename, O_RDONLY | O_BINARY))) { 448 log_error_write(srv, __FILE__, __LINE__, "sbss", 449 "opening plain-file", fn, 450 "failed", strerror(errno)); 451 447 ERROR("opening plain-file '%s' failed: %s", SAFE_BUF_STR(fn), strerror(errno)); 452 448 close(ofd); 453 454 449 return -1; 455 450 } … … 457 452 458 453 if (MAP_FAILED == (start = mmap(NULL, sce->st.st_size, PROT_READ, MAP_SHARED, ifd, 0))) { 459 log_error_write(srv, __FILE__, __LINE__, "sbss", 460 "mmaping", fn, 461 "failed", strerror(errno)); 462 454 ERROR("mmaping '%s' failed: %s", SAFE_BUF_STR(fn), strerror(errno)); 463 455 close(ofd); 464 456 close(ifd); … … 526 518 527 519 if (-1 == (ifd = open(fn->ptr, O_RDONLY | O_BINARY))) { 528 log_error_write(srv, __FILE__, __LINE__, "sbss", "opening plain-file", fn, "failed", strerror(errno));520 ERROR("opening plain-file '%s' failed: %s", SAFE_BUF_STR(fn), strerror(errno)); 529 521 530 522 return -1; … … 536 528 537 529 if (MAP_FAILED == start) { 538 log_error_write(srv, __FILE__, __LINE__, "sbss", "mmaping", fn, "failed", strerror(errno));530 ERROR("mmaping '%s' failed: %s", SAFE_BUF_STR(fn), strerror(errno)); 539 531 540 532 return -1; … … 644 636 645 637 if (HANDLER_GO_ON != stat_cache_get_entry(srv, con, con->physical.path, &sce)) { 646 if (con->conf.log_request_handling) TRACE("file '%s' not found", BUF_STR(con->physical.path));638 if (con->conf.log_request_handling) TRACE("file '%s' not found", SAFE_BUF_STR(con->physical.path)); 647 639 return HANDLER_GO_ON; 648 640 } … … 651 643 if (max_fsize && (sce->st.st_size >> 10) > max_fsize) { 652 644 if (con->conf.log_request_handling) TRACE("file '%s' is too large: %jd", 653 BUF_STR(con->physical.path),645 SAFE_BUF_STR(con->physical.path), 654 646 (intmax_t) sce->st.st_size); 655 647 … … 660 652 if (sce->st.st_size < 128) { 661 653 if (con->conf.log_request_handling) TRACE("file '%s' is too small: %jd", 662 BUF_STR(con->physical.path),654 SAFE_BUF_STR(con->physical.path), 663 655 (intmax_t) sce->st.st_size); 664 656 … … 671 663 672 664 if (!compress_ds) { 673 ERROR("evil: %s .. %s", BUF_STR(con->physical.path),BUF_STR(con->uri.path));665 ERROR("evil: %s .. %s", SAFE_BUF_STR(con->physical.path), SAFE_BUF_STR(con->uri.path)); 674 666 675 667 return HANDLER_GO_ON; … … 748 740 * current version */ 749 741 if (HANDLER_FINISHED == http_response_handle_cachable(srv, con, mtime)) { 750 if (con->conf.log_request_handling) TRACE("%s is still the same, caching", BUF_STR(con->physical.path));742 if (con->conf.log_request_handling) TRACE("%s is still the same, caching", SAFE_BUF_STR(con->physical.path)); 751 743 return HANDLER_FINISHED; 752 744 } … … 780 772 CONST_BUF_LEN(sce->content_type)); 781 773 782 if (con->conf.log_request_handling) TRACE("looks like %s could be compressed", BUF_STR(con->physical.path));774 if (con->conf.log_request_handling) TRACE("looks like %s could be compressed", SAFE_BUF_STR(con->physical.path)); 783 775 return HANDLER_FINISHED; 784 776 }

