diff options
| author | jvoisin | 2020-08-12 08:48:59 +0000 |
|---|---|---|
| committer | GitHub | 2020-08-12 10:48:59 +0200 |
| commit | a0d21a189cf04bb963dce93dcbd0bd9694584a0b (patch) | |
| tree | 59fa646b7536fbef7de42eb111c82df592262a12 /src/snuffleupagus.c | |
| parent | f3360c4de72b6735bc5f5873dd671c2e56292ce6 (diff) | |
Allow empty configuration (#342)
This commit allows php to run (with a warning) if there
is no specified snuffleupagus configuration,
instead of refusing to start.
Diffstat (limited to 'src/snuffleupagus.c')
| -rw-r--r-- | src/snuffleupagus.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/snuffleupagus.c b/src/snuffleupagus.c index d62069c..7c69150 100644 --- a/src/snuffleupagus.c +++ b/src/snuffleupagus.c | |||
| @@ -68,6 +68,7 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { | |||
| 68 | STANDARD_ZEND_EXTENSION_PROPERTIES}; | 68 | STANDARD_ZEND_EXTENSION_PROPERTIES}; |
| 69 | 69 | ||
| 70 | PHP_GINIT_FUNCTION(snuffleupagus) { | 70 | PHP_GINIT_FUNCTION(snuffleupagus) { |
| 71 | snuffleupagus_globals->is_config_valid = SP_CONFIG_NONE; | ||
| 71 | snuffleupagus_globals->in_eval = 0; | 72 | snuffleupagus_globals->in_eval = 0; |
| 72 | 73 | ||
| 73 | #define SP_INIT_HT(F) snuffleupagus_globals->F = \ | 74 | #define SP_INIT_HT(F) snuffleupagus_globals->F = \ |
| @@ -186,8 +187,12 @@ PHP_RINIT_FUNCTION(snuffleupagus) { | |||
| 186 | ZEND_TSRMLS_CACHE_UPDATE(); | 187 | ZEND_TSRMLS_CACHE_UPDATE(); |
| 187 | #endif | 188 | #endif |
| 188 | 189 | ||
| 189 | if (!SNUFFLEUPAGUS_G(allow_broken_configuration) && !SNUFFLEUPAGUS_G(is_config_valid)) { | 190 | if (!SNUFFLEUPAGUS_G(allow_broken_configuration)) { |
| 190 | sp_log_err("config", "Invalid configuration file"); | 191 | if (SNUFFLEUPAGUS_G(is_config_valid) == SP_CONFIG_INVALID ) { |
| 192 | sp_log_err("config", "Invalid configuration file"); | ||
| 193 | } else if (SNUFFLEUPAGUS_G(is_config_valid) == SP_CONFIG_NONE) { | ||
| 194 | sp_log_warn("config", "No configuration specificed via sp.configuration_file"); | ||
| 195 | } | ||
| 191 | } | 196 | } |
| 192 | 197 | ||
| 193 | // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. | 198 | // We need to disable wrappers loaded by extensions loaded after SNUFFLEUPAGUS. |
| @@ -209,12 +214,23 @@ PHP_RINIT_FUNCTION(snuffleupagus) { | |||
| 209 | PHP_RSHUTDOWN_FUNCTION(snuffleupagus) { return SUCCESS; } | 214 | PHP_RSHUTDOWN_FUNCTION(snuffleupagus) { return SUCCESS; } |
| 210 | 215 | ||
| 211 | PHP_MINFO_FUNCTION(snuffleupagus) { | 216 | PHP_MINFO_FUNCTION(snuffleupagus) { |
| 217 | const char *valid_config; | ||
| 218 | switch(SNUFFLEUPAGUS_G(is_config_valid)) { | ||
| 219 | case SP_CONFIG_VALID: | ||
| 220 | valid_config = "yes"; | ||
| 221 | break; | ||
| 222 | case SP_CONFIG_INVALID: | ||
| 223 | valid_config = "invalid"; | ||
| 224 | break; | ||
| 225 | case SP_CONFIG_NONE: | ||
| 226 | default: | ||
| 227 | valid_config = "no"; | ||
| 228 | } | ||
| 212 | php_info_print_table_start(); | 229 | php_info_print_table_start(); |
| 213 | php_info_print_table_row(2, "snuffleupagus support", "enabled"); | 230 | php_info_print_table_row(2, "snuffleupagus support", |
| 231 | SNUFFLEUPAGUS_G(is_config_valid)?"enabled":"disabled"); | ||
| 214 | php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); | 232 | php_info_print_table_row(2, "Version", PHP_SNUFFLEUPAGUS_VERSION); |
| 215 | php_info_print_table_row( | 233 | php_info_print_table_row( 2, "Valid config", valid_config); |
| 216 | 2, "Valid config", | ||
| 217 | (SNUFFLEUPAGUS_G(is_config_valid) == true) ? "yes" : "no"); | ||
| 218 | php_info_print_table_end(); | 234 | php_info_print_table_end(); |
| 219 | DISPLAY_INI_ENTRIES(); | 235 | DISPLAY_INI_ENTRIES(); |
| 220 | } | 236 | } |
| @@ -234,14 +250,14 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 234 | int ret = glob(config_file, GLOB_NOCHECK, NULL, &globbuf); | 250 | int ret = glob(config_file, GLOB_NOCHECK, NULL, &globbuf); |
| 235 | 251 | ||
| 236 | if (ret != 0) { | 252 | if (ret != 0) { |
| 237 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 253 | SNUFFLEUPAGUS_G(is_config_valid) = SP_CONFIG_INVALID; |
| 238 | globfree(&globbuf); | 254 | globfree(&globbuf); |
| 239 | return FAILURE; | 255 | return FAILURE; |
| 240 | } | 256 | } |
| 241 | 257 | ||
| 242 | for (size_t i = 0; globbuf.gl_pathv[i]; i++) { | 258 | for (size_t i = 0; globbuf.gl_pathv[i]; i++) { |
| 243 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { | 259 | if (sp_parse_config(globbuf.gl_pathv[i]) != SUCCESS) { |
| 244 | SNUFFLEUPAGUS_G(is_config_valid) = false; | 260 | SNUFFLEUPAGUS_G(is_config_valid) = SP_CONFIG_INVALID; |
| 245 | globfree(&globbuf); | 261 | globfree(&globbuf); |
| 246 | return FAILURE; | 262 | return FAILURE; |
| 247 | } | 263 | } |
| @@ -249,7 +265,7 @@ static PHP_INI_MH(OnUpdateConfiguration) { | |||
| 249 | globfree(&globbuf); | 265 | globfree(&globbuf); |
| 250 | } | 266 | } |
| 251 | 267 | ||
| 252 | SNUFFLEUPAGUS_G(is_config_valid) = true; | 268 | SNUFFLEUPAGUS_G(is_config_valid) = SP_CONFIG_VALID; |
| 253 | 269 | ||
| 254 | if ((SNUFFLEUPAGUS_G(config).config_sloppy->enable)) { | 270 | if ((SNUFFLEUPAGUS_G(config).config_sloppy->enable)) { |
| 255 | hook_sloppy(); | 271 | hook_sloppy(); |
