]> granicus.if.org Git - php/commitdiff
fix remote mode when readline is enabled
authorkrakjoe <joe.watkins@live.co.uk>
Wed, 27 Nov 2013 17:32:15 +0000 (17:32 +0000)
committerkrakjoe <joe.watkins@live.co.uk>
Wed, 27 Nov 2013 17:32:15 +0000 (17:32 +0000)
phpdbg.c
phpdbg_cmd.c
phpdbg_utils.c

index 687237b90a435799d43a19e9652ec11a508ff9aa..d536f9d801e7f285e46c3cf9af7719188d9ff9db 100644 (file)
--- a/phpdbg.c
+++ b/phpdbg.c
@@ -589,11 +589,11 @@ int phpdbg_open_socket(short port) /* {{{ */
        return fd;
 } /* }}} */
 
-int phpdbg_open_sockets(short listen[2], FILE* streams[2]) /* {{{ */
+int phpdbg_open_sockets(int listen[2], FILE* streams[2]) /* {{{ */
 {
        int sockets[2] = {
-               phpdbg_open_socket(listen[0]),
-               phpdbg_open_socket(listen[1])
+               phpdbg_open_socket((short)listen[0]),
+               phpdbg_open_socket((short)listen[1])
        };
        int accepted[2] = {-1, -1};
        
@@ -614,11 +614,11 @@ int phpdbg_open_sockets(short listen[2], FILE* streams[2]) /* {{{ */
 
         memset(&address, 0, size);
         accepted[0] = accept(
-               sockets[0], &address, &size);
+               sockets[0], (struct sockaddr *) &address, &size);
         
         memset(&address, 0, size);
         accepted[1] = accept(
-               sockets[1], &address, &size);
+               sockets[1], (struct sockaddr *) &address, &size);
        }
        
        streams[0] = fdopen(accepted[0], "r");
@@ -648,7 +648,7 @@ int main(int argc, char **argv) /* {{{ */
        int run = 0;
        int step = 0;
        char *bp_tmp_file;
-       short listen[2];
+       int listen[2];
        FILE* streams[2] = {NULL, NULL};
 
 #ifdef ZTS
@@ -803,7 +803,6 @@ phpdbg_main:
        if (!cleaning && 
                (listen[0] && listen[1])) {
                phpdbg_open_sockets(listen, streams);
-               /* now is a sensible time to announce listen settings on the console */
        }
        
        phpdbg->ini_defaults = phpdbg_ini_defaults;
@@ -842,6 +841,9 @@ phpdbg_main:
 #endif
 
                PG(modules_activated) = 0;
+               
+               /* set flags from command line */
+               PHPDBG_G(flags) = flags;
 
                /* setup io here */
                if (streams[0] && streams[1]) {
@@ -850,7 +852,6 @@ phpdbg_main:
                        PHPDBG_G(io)[PHPDBG_STDIN] = streams[0];
                        PHPDBG_G(io)[PHPDBG_STDOUT] = streams[1];
                        PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
-                       
                        signal(SIGPIPE, SIG_IGN);
                } else {
                        /* local console */
@@ -876,9 +877,6 @@ phpdbg_main:
                        free(oplog_file);
                }
 
-               /* set flags from command line */
-               PHPDBG_G(flags) = flags;
-
                /* set default colors */
                phpdbg_set_color_ex(PHPDBG_COLOR_PROMPT,  PHPDBG_STRL("white-bold") TSRMLS_CC);
                phpdbg_set_color_ex(PHPDBG_COLOR_ERROR,   PHPDBG_STRL("red-bold") TSRMLS_CC);
index 27641a695e9d6412f1975333802b10bab0fec35e..c4ba06e5db40e3c32290060ee4aea1d551132800 100644 (file)
@@ -220,11 +220,13 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
        if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
                if (buffered == NULL) {
                
-                       fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
+                       if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {     
+                               fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
+                       }
                        
 #ifndef HAVE_LIBREADLINE
                        char buf[PHPDBG_MAX_CMD];
-                       if (!phpdbg_write(phpdbg_get_prompt(TSRMLS_C)) ||
+                       if ((!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && !phpdbg_write(phpdbg_get_prompt(TSRMLS_C))) ||
                                !fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
                                /* the user has gone away */
                                phpdbg_error("Failed to read console !");
@@ -232,10 +234,16 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
                                zend_bailout();
                                return NULL;
                        }
-
+                       
                        cmd = buf;
 #else
-                       cmd = readline(phpdbg_get_prompt(TSRMLS_C));
+                       if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
+                               char buf[PHPDBG_MAX_CMD];
+                               if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
+                                       cmd = buf;
+                               } else cmd = NULL;
+                       } else cmd = readline(phpdbg_get_prompt(TSRMLS_C));
+                       
                        if (!cmd) {
                                /* the user has gone away */
                                phpdbg_error("Failed to read console !");
@@ -244,7 +252,9 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
                                return NULL;
                        }
 
-                       add_history(cmd);
+                       if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
+                               add_history(cmd);
+                       }
 #endif
                } else cmd = buffered;
 
@@ -275,7 +285,8 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
 #endif
 
 #ifdef HAVE_LIBREADLINE
-               if (!buffered && cmd) {
+               if (!buffered && cmd && 
+                       !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
                        free(cmd);
                }
 #endif
index f18bbb55fa8a1b0216e1d46bf380f3f984fcbf1a..33ead6034ca6d5f15f5cbf18627595fced0daee8 100644 (file)
@@ -299,7 +299,7 @@ PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */
 } /* }}} */
 
 PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */
-{
+{      
        /* find cached prompt */
        if (PHPDBG_G(prompt)[1]) {
                return PHPDBG_G(prompt)[1];