diff options
author | Dmitry Stogov <dmitry@php.net> | 2007-12-03 09:38:25 +0000 |
---|---|---|
committer | Dmitry Stogov <dmitry@php.net> | 2007-12-03 09:38:25 +0000 |
commit | e54f02059e07f41d61818a4e7e7690ff5e401766 (patch) | |
tree | f69acae98c17bb45039eb3b54ce3e9e675c9051d | |
parent | 91ea43e4112b993d1ac266e4f0c04ad7919d1a46 (diff) | |
download | php-git-e54f02059e07f41d61818a4e7e7690ff5e401766.tar.gz |
The -f option is fixed to work in the same way as in CLI sapi
-rw-r--r-- | sapi/cgi/cgi_main.c | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/sapi/cgi/cgi_main.c b/sapi/cgi/cgi_main.c index ecdcbe269d..d80faaff85 100644 --- a/sapi/cgi/cgi_main.c +++ b/sapi/cgi/cgi_main.c @@ -1697,12 +1697,12 @@ consult the installation file that came with this distribution, or visit \n\ } script_file = estrdup(php_optarg); no_headers = 1; - /* arguments after the file are considered script args */ - SG(request_info).argc = argc - (php_optind - 1); - SG(request_info).argv = &argv[php_optind - 1]; break; case 'i': /* php info & quit */ + if (script_file) { + efree(script_file); + } if (php_request_startup(TSRMLS_C) == FAILURE) { SG(server_context) = NULL; php_module_shutdown(TSRMLS_C); @@ -1723,6 +1723,9 @@ consult the installation file that came with this distribution, or visit \n\ break; case 'm': /* list compiled in modules */ + if (script_file) { + efree(script_file); + } SG(headers_sent) = 1; php_printf("[PHP Modules]\n"); print_modules(TSRMLS_C); @@ -1744,6 +1747,9 @@ consult the installation file that came with this distribution, or visit \n\ break; case 'v': /* show php version & quit */ + if (script_file) { + efree(script_file); + } no_headers = 1; if (php_request_startup(TSRMLS_C) == FAILURE) { SG(server_context) = NULL; @@ -1780,6 +1786,18 @@ consult the installation file that came with this distribution, or visit \n\ /* override path_translated if -f on command line */ STR_FREE(SG(request_info).path_translated); SG(request_info).path_translated = script_file; + /* before registering argv to module exchange the *new* argv[0] */ + /* we can achieve this without allocating more memory */ + SG(request_info).argc = argc - (php_optind - 1); + SG(request_info).argv = &argv[php_optind - 1]; + SG(request_info).argv[0] = script_file; + } else if (argc > php_optind) { + /* file is on command line, but not in -f opt */ + STR_FREE(SG(request_info).path_translated); + SG(request_info).path_translated = estrdup(argv[php_optind++]); + /* arguments after the file are considered script args */ + SG(request_info).argc = argc - php_optind; + SG(request_info).argv = &argv[php_optind]; } if (no_headers) { @@ -1787,14 +1805,6 @@ consult the installation file that came with this distribution, or visit \n\ SG(request_info).no_headers = 1; } - if (!SG(request_info).path_translated && argc > php_optind) { - /* arguments after the file are considered script args */ - SG(request_info).argc = argc - php_optind; - SG(request_info).argv = &argv[php_optind]; - /* file is on command line, but not in -f opt */ - SG(request_info).path_translated = estrdup(argv[php_optind++]); - } - /* all remaining arguments are part of the query string this section of code concatenates all remaining arguments into a single string, seperating args with a & |