From aa5263956b446472d1f0e2b3834157b33a28c64e Mon Sep 17 00:00:00 2001 From: Pierre Carrier Date: Sat, 11 Aug 2012 13:17:50 +0100 Subject: [PATCH] Zend: support relative paths for extensions This would simplify greatly puppetization of Zend modules such as xdebug in heterogeneous environments. For example: zend_extension="/usr/lib/php5/20090626/xdebug.so" can become: zend_extension=xdebug.so --- Zend/zend_extensions.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Zend/zend_extensions.c b/Zend/zend_extensions.c index 5c66b4a30c63e..86830ec621ecc 100644 --- a/Zend/zend_extensions.c +++ b/Zend/zend_extensions.c @@ -20,6 +20,7 @@ /* $Id$ */ #include "zend_extensions.h" +#include "php.h" ZEND_API zend_llist zend_extensions; static int last_resource_number; @@ -30,8 +31,28 @@ int zend_load_extension(const char *path) DL_HANDLE handle; zend_extension *new_extension; zend_extension_version_info *extension_version_info; + char *normalized_path; + char *extension_dir = INI_STR("extension_dir"); + int extension_dir_len = strlen(extension_dir); + + if (strchr(path, '/') == NULL || strchr(path, DEFAULT_SLASH) == NULL) { + if (extension_dir && extension_dir[0]) { + if (IS_SLASH(extension_dir[extension_dir_len-1])) { + spprintf(&normalized_path, 0, "%s%s", extension_dir, path); + } else { + spprintf(&normalized_path, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, path); + } + } else { + return FAILURE; + } + } else { + normalized_path = estrdup(path); + } + + handle = DL_LOAD(normalized_path); + + efree(normalized_path); - handle = DL_LOAD(path); if (!handle) { #ifndef ZEND_WIN32 fprintf(stderr, "Failed loading %s: %s\n", path, DL_ERROR());