@@ -1394,11 +1394,8 @@ int main(int argc, char **argv) /* {{{ */
13941394 }
13951395
13961396 /* set exec if present on command line */
1397- if (!exec && (argc > php_optind ) && (strcmp (argv [php_optind - 1 ], "--" ) != SUCCESS )) {
1398- if (strlen (argv [php_optind ])) {
1399- if (exec ) {
1400- free (exec );
1401- }
1397+ if (argc > php_optind && (strcmp (argv [php_optind - 1 ], "--" ) != SUCCESS )) {
1398+ if (!exec && strlen (argv [php_optind ])) {
14021399 exec = strdup (argv [php_optind ]);
14031400 }
14041401 php_optind ++ ;
@@ -1529,6 +1526,14 @@ int main(int argc, char **argv) /* {{{ */
15291526
15301527 PHPDBG_G (sapi_name_ptr ) = sapi_name ;
15311528
1529+ if (exec ) { /* set execution context */
1530+ PHPDBG_G (exec ) = phpdbg_resolve_path (exec );
1531+ PHPDBG_G (exec_len ) = PHPDBG_G (exec ) ? strlen (PHPDBG_G (exec )) : 0 ;
1532+
1533+ free (exec );
1534+ exec = NULL ;
1535+ }
1536+
15321537 php_output_activate ();
15331538 php_output_deactivate ();
15341539
@@ -1542,7 +1547,7 @@ int main(int argc, char **argv) /* {{{ */
15421547 for (i = SG (request_info ).argc ; -- i ;) {
15431548 SG (request_info ).argv [i ] = estrdup (argv [php_optind - 1 + i ]);
15441549 }
1545- SG (request_info ).argv [i ] = exec ? estrdup (exec ) : estrdup ("" );
1550+ SG (request_info ).argv [0 ] = PHPDBG_G ( exec ) ? estrdup (PHPDBG_G ( exec ) ) : estrdup ("" );
15461551
15471552 php_hash_environment ();
15481553 }
@@ -1603,14 +1608,6 @@ int main(int argc, char **argv) /* {{{ */
16031608 php_stream_stdio_ops .write = phpdbg_stdiop_write ;
16041609#endif
16051610
1606- if (exec ) { /* set execution context */
1607- PHPDBG_G (exec ) = phpdbg_resolve_path (exec );
1608- PHPDBG_G (exec_len ) = PHPDBG_G (exec ) ? strlen (PHPDBG_G (exec )) : 0 ;
1609-
1610- free (exec );
1611- exec = NULL ;
1612- }
1613-
16141611 if (oplog_file ) { /* open oplog */
16151612 PHPDBG_G (oplog ) = fopen (oplog_file , "w+" );
16161613 if (!PHPDBG_G (oplog )) {
@@ -1775,7 +1772,7 @@ int main(int argc, char **argv) /* {{{ */
17751772 {
17761773 int i ;
17771774 /* free argv */
1778- for (i = SG (request_info ).argc ; -- i ;) {
1775+ for (i = SG (request_info ).argc ; i -- ;) {
17791776 efree (SG (request_info ).argv [i ]);
17801777 }
17811778 efree (SG (request_info ).argv );
@@ -1838,6 +1835,9 @@ int main(int argc, char **argv) /* {{{ */
18381835 }
18391836
18401837 if ((cleaning > 0 || remote ) && !quit_immediately ) {
1838+ /* reset internal php_getopt state */
1839+ php_getopt (-1 , argv , OPTIONS , NULL , & php_optind , 0 , 0 );
1840+
18411841 goto phpdbg_main ;
18421842 }
18431843
0 commit comments