Skip to content

Commit

Permalink
fix #46 ignore EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanogenmod committed Jan 13, 2014
1 parent 7d51e47 commit 333264f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
10 changes: 4 additions & 6 deletions phpdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1257,10 +1257,8 @@ int main(int argc, char **argv) /* {{{ */
/* this must be forced */
CG(unclean_shutdown) = 0;
} else {
/* local client quit console */
CG(unclean_shutdown) = 0;

goto phpdbg_out;
/* local consoles cannot disconnect, ignore EOF */
PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
}
}
#endif
Expand All @@ -1275,7 +1273,7 @@ int main(int argc, char **argv) /* {{{ */

phpdbg_out:
#ifndef _WIN32
if (PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED) {
if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
goto phpdbg_interact;
}
Expand Down Expand Up @@ -1324,7 +1322,7 @@ int main(int argc, char **argv) /* {{{ */
if (cleaning || remote) {
goto phpdbg_main;
}

#ifdef ZTS
/* bugggy */
/* tsrm_shutdown(); */
Expand Down
35 changes: 23 additions & 12 deletions phpdbg_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,32 +467,43 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
}

if (buffered == NULL) {
#ifndef HAVE_LIBREADLINE
char buf[PHPDBG_MAX_CMD];
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!");
disconnect:
if (0) {
PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED);
zend_bailout();
return NULL;
}

#ifndef HAVE_LIBREADLINE
char buf[PHPDBG_MAX_CMD];
if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
if (!phpdbg_write(phpdbg_get_prompt(TSRMLS_CC))) {
goto disconnect;
}
}

/* note: EOF is ignored */
readline:
if (!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
/* the user has gone away */
if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
goto disconnect;
} else goto readline;
}

cmd = buf;
#else
/* note: EOF makes readline write prompt again in local console mode */
readline:
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 goto disconnect;
} else cmd = readline(phpdbg_get_prompt(TSRMLS_C));

if (!cmd) {
/* the user has gone away */
phpdbg_error("Failed to read console!");
PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED);
zend_bailout();
return NULL;
goto readline;
}

if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
Expand Down

0 comments on commit 333264f

Please sign in to comment.