mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
sapi/*: move duplicate "--define" code to library
This commit is contained in:
parent
462dc9da6a
commit
d87ba95acd
8 changed files with 220 additions and 168 deletions
|
@ -21,6 +21,7 @@
|
|||
#include "php.h"
|
||||
#include "php_globals.h"
|
||||
#include "php_variables.h"
|
||||
#include "php_ini_builder.h"
|
||||
#include "zend_hash.h"
|
||||
#include "zend_modules.h"
|
||||
#include "zend_interfaces.h"
|
||||
|
@ -131,7 +132,7 @@ const char HARDCODED_INI[] =
|
|||
"implicit_flush=1\n"
|
||||
"output_buffering=0\n"
|
||||
"max_execution_time=0\n"
|
||||
"max_input_time=-1\n\0";
|
||||
"max_input_time=-1\n";
|
||||
|
||||
|
||||
const opt_struct OPTIONS[] = {
|
||||
|
@ -1176,8 +1177,7 @@ int main(int argc, char *argv[])
|
|||
char *php_optarg = NULL;
|
||||
int php_optind = 1, use_extended_info = 0;
|
||||
char *ini_path_override = NULL;
|
||||
char *ini_entries = NULL;
|
||||
size_t ini_entries_len = 0;
|
||||
struct php_ini_builder ini_builder;
|
||||
int ini_ignore = 0;
|
||||
sapi_module_struct *sapi_module = &cli_sapi_module;
|
||||
|
||||
|
@ -1239,6 +1239,8 @@ int main(int argc, char *argv[])
|
|||
setmode(_fileno(stderr), O_BINARY); /* make the stdio mode be binary */
|
||||
#endif
|
||||
|
||||
php_ini_builder_init(&ini_builder);
|
||||
|
||||
while ((c = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 1, 2))!=-1) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
|
@ -1250,37 +1252,10 @@ int main(int argc, char *argv[])
|
|||
case 'n':
|
||||
ini_ignore = 1;
|
||||
break;
|
||||
case 'd': {
|
||||
case 'd':
|
||||
/* define ini entries on command line */
|
||||
size_t len = strlen(php_optarg);
|
||||
char *val;
|
||||
|
||||
if ((val = strchr(php_optarg, '='))) {
|
||||
val++;
|
||||
if (!isalnum(*val) && *val != '"' && *val != '\'' && *val != '\0') {
|
||||
ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\"\"\n\0"));
|
||||
memcpy(ini_entries + ini_entries_len, php_optarg, (val - php_optarg));
|
||||
ini_entries_len += (val - php_optarg);
|
||||
memcpy(ini_entries + ini_entries_len, "\"", 1);
|
||||
ini_entries_len++;
|
||||
memcpy(ini_entries + ini_entries_len, val, len - (val - php_optarg));
|
||||
ini_entries_len += len - (val - php_optarg);
|
||||
memcpy(ini_entries + ini_entries_len, "\"\n\0", sizeof("\"\n\0"));
|
||||
ini_entries_len += sizeof("\n\0\"") - 2;
|
||||
} else {
|
||||
ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("\n\0"));
|
||||
memcpy(ini_entries + ini_entries_len, php_optarg, len);
|
||||
memcpy(ini_entries + ini_entries_len + len, "\n\0", sizeof("\n\0"));
|
||||
ini_entries_len += len + sizeof("\n\0") - 2;
|
||||
}
|
||||
} else {
|
||||
ini_entries = realloc(ini_entries, ini_entries_len + len + sizeof("=1\n\0"));
|
||||
memcpy(ini_entries + ini_entries_len, php_optarg, len);
|
||||
memcpy(ini_entries + ini_entries_len + len, "=1\n\0", sizeof("=1\n\0"));
|
||||
ini_entries_len += len + sizeof("=1\n\0") - 2;
|
||||
}
|
||||
php_ini_builder_define(&ini_builder, php_optarg);
|
||||
break;
|
||||
}
|
||||
#ifndef PHP_CLI_WIN32_NO_CONSOLE
|
||||
case 'S':
|
||||
sapi_module = &cli_server_sapi_module;
|
||||
|
@ -1317,18 +1292,10 @@ exit_loop:
|
|||
sapi_module->executable_location = argv[0];
|
||||
|
||||
if (sapi_module == &cli_sapi_module) {
|
||||
if (ini_entries) {
|
||||
ini_entries = realloc(ini_entries, ini_entries_len + sizeof(HARDCODED_INI));
|
||||
memmove(ini_entries + sizeof(HARDCODED_INI) - 2, ini_entries, ini_entries_len + 1);
|
||||
memcpy(ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI) - 2);
|
||||
} else {
|
||||
ini_entries = malloc(sizeof(HARDCODED_INI));
|
||||
memcpy(ini_entries, HARDCODED_INI, sizeof(HARDCODED_INI));
|
||||
}
|
||||
ini_entries_len += sizeof(HARDCODED_INI) - 2;
|
||||
php_ini_builder_prepend_literal(&ini_builder, HARDCODED_INI);
|
||||
}
|
||||
|
||||
sapi_module->ini_entries = ini_entries;
|
||||
sapi_module->ini_entries = php_ini_builder_finish(&ini_builder);
|
||||
|
||||
/* startup after we get the above ini override se we get things right */
|
||||
if (sapi_module->startup(sapi_module) == FAILURE) {
|
||||
|
@ -1375,9 +1342,7 @@ out:
|
|||
if (ini_path_override) {
|
||||
free(ini_path_override);
|
||||
}
|
||||
if (ini_entries) {
|
||||
free(ini_entries);
|
||||
}
|
||||
php_ini_builder_deinit(&ini_builder);
|
||||
if (module_started) {
|
||||
php_module_shutdown();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue