Changeset 423
- Timestamp:
- 07/11/10 23:03:25 (2 months ago)
- Location:
- eaccelerator/trunk
- Files:
-
- 2 edited
-
eaccelerator.c (modified) (7 diffs)
-
eaccelerator.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
eaccelerator/trunk/eaccelerator.c
r420 r423 258 258 ea_mm_instance->check_mtime_enabled = 1; 259 259 ea_mm_instance->removed = NULL; 260 ea_mm_instance->cache_dir_uid = 0; 260 261 ea_mm_instance->last_prune = time(NULL); /* this time() call is harmless since this is init phase */ 261 262 EACCELERATOR_PROTECT(); … … 392 393 PHP_MD5Final(digest, &context); 393 394 make_digest(md5str, digest); 394 snprintf(s, MAXPATHLEN-1, "%s/ ", EAG(cache_dir));395 snprintf(s, MAXPATHLEN-1, "%s/%d/", EAG(cache_dir), ea_mm_instance->cache_dir_uid); 395 396 n = strlen(s); 396 397 for (i = 0; i < EACCELERATOR_HASH_LEVEL && n < MAXPATHLEN - 1; i++) { … … 1656 1657 } 1657 1658 1659 /* 1660 * Create a hash directory 1661 */ 1658 1662 static void make_hash_dirs(char *fullpath, int lvl) { 1659 int j; 1660 int n = strlen(fullpath); 1661 mode_t old_umask = umask(0); 1662 1663 if (lvl < 1) 1664 return; 1665 if (fullpath[n-1] != '/') 1666 fullpath[n++] = '/'; 1667 1668 for (j = 0; j < 16; j++) { 1669 fullpath[n] = num2hex[j]; 1670 fullpath[n+1] = 0; 1671 mkdir(fullpath, 0777); 1672 make_hash_dirs(fullpath, lvl-1); 1673 } 1674 fullpath[n+2] = 0; 1675 umask(old_umask); 1676 } 1677 1663 int j; 1664 int n = strlen(fullpath); 1665 1666 //ea_debug_error("Creating hash in %s at level %d\n", fullpath, lvl); 1667 1668 if (lvl < 1) { 1669 return; 1670 } 1671 1672 if (fullpath[n-1] != '/') { 1673 fullpath[n++] = '/'; 1674 } 1675 1676 for (j = 0; j < 16; j++) { 1677 fullpath[n] = num2hex[j]; 1678 fullpath[n+1] = 0; 1679 mkdir(fullpath, 0700); 1680 make_hash_dirs(fullpath, lvl-1); 1681 } 1682 fullpath[n+2] = 0; 1683 } 1684 1685 /* 1686 * Initialise the cache directory for use 1687 */ 1688 static void init_cache_dir(const char *cache_path) { 1689 char fullpath[MAXPATHLEN]; 1690 uid_t uid = getuid(); 1691 mode_t old_umask = umask(077); 1692 struct stat buffer; 1693 1694 snprintf(fullpath, MAXPATHLEN-1, "%s/%d/", cache_path, uid); 1695 if (lstat(fullpath, &buffer) != 0) { 1696 // error, create the directory 1697 if (mkdir(fullpath, 0700) != 0) { 1698 ea_debug_error("Unable to create cachedir %s\n", fullpath); 1699 return; 1700 } 1701 } else if (!S_ISDIR(buffer.st_mode)) { 1702 // not a directory 1703 ea_debug_error("Cachedir %s exists but is not a directory\n", 1704 fullpath); 1705 return; 1706 } 1707 1708 // create the hashed dirs 1709 make_hash_dirs(fullpath, EACCELERATOR_HASH_LEVEL); 1710 1711 umask(old_umask); 1712 1713 ea_mm_instance->cache_dir_uid = uid; 1714 } 1715 1716 /* 1717 * Check if the cache dir exists and is world-writable so the forked process 1718 * can create the cache directories 1719 */ 1720 static void check_cache_dir(const char *cache_path) { 1721 struct stat buffer; 1722 mode_t old_umask = umask(0); 1723 1724 int status = stat(cache_path, &buffer); 1725 1726 if (status == 0) { 1727 // check permissions 1728 if (buffer.st_mode != 777) { 1729 status = chmod(cache_path, 0777); 1730 if (status < 0) { 1731 ea_debug_error( 1732 "Unable to change cache cache directory %s permissions\n", 1733 cache_path); 1734 } 1735 } 1736 } else { 1737 // create the cache directory if possible 1738 status = mkdir(cache_path, 0777); 1739 if (status < 0) { 1740 ea_debug_error("Unable to create cache directory %s\n", cache_path); 1741 } 1742 } 1743 1744 umask(old_umask); 1745 } 1678 1746 1679 1747 PHP_MINIT_FUNCTION(eaccelerator) { 1680 char fullpath[MAXPATHLEN];1681 1682 1748 if (type == MODULE_PERSISTENT) { 1683 1749 #ifndef ZEND_WIN32 … … 1711 1777 ea_debug_init(TSRMLS_C); 1712 1778 1713 if(!ea_scripts_shm_only) { 1714 snprintf(fullpath, MAXPATHLEN-1, "%s/", EAG(cache_dir)); 1715 make_hash_dirs(fullpath, EACCELERATOR_HASH_LEVEL); 1716 } 1779 check_cache_dir(EAG(cache_dir)); 1717 1780 1718 1781 if (type == MODULE_PERSISTENT && … … 1810 1873 DBG(ea_debug_printf, (EA_DEBUG, "[%d] Leave RINIT\n",getpid())); 1811 1874 1875 if (ea_mm_instance->cache_dir_uid != getuid()) { 1876 // lock this operation with a global eA lock and do the check again 1877 // to avoid multiple calls during startup 1878 EACCELERATOR_LOCK_RW(); 1879 if (ea_mm_instance->cache_dir_uid != getuid()) { 1880 init_cache_dir(EAG(cache_dir)); 1881 } 1882 EACCELERATOR_UNLOCK(); 1883 } 1884 1812 1885 return SUCCESS; 1813 1886 } … … 1871 1944 PHP_FE(eaccelerator_caching, NULL) 1872 1945 PHP_FE(eaccelerator_clear, NULL) 1873 PHP_FE(eaccelerator_clean, NULL)1946 PHP_FE(eaccelerator_clean, NULL) 1874 1947 PHP_FE(eaccelerator_info, NULL) 1875 1948 PHP_FE(eaccelerator_purge, NULL) … … 1878 1951 PHP_FE(eaccelerator_check_mtime, NULL) 1879 1952 #ifdef WITH_EACCELERATOR_OPTIMIZER 1880 PHP_FE(eaccelerator_optimizer, NULL)1953 PHP_FE(eaccelerator_optimizer, NULL) 1881 1954 #endif 1882 1955 #endif -
eaccelerator/trunk/eaccelerator.h
r394 r423 333 333 time_t last_prune; 334 334 ea_cache_entry *removed; 335 uid_t cache_dir_uid; 335 336 336 337 ea_cache_entry *hash[EA_HASH_SIZE];
Note: See TracChangeset
for help on using the changeset viewer.