Skip to content

Commit 333264f

Browse files
author
cyanogenmod
committed
fix #46 ignore EOF
1 parent 7d51e47 commit 333264f

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

phpdbg.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -1257,10 +1257,8 @@ int main(int argc, char **argv) /* {{{ */
12571257
/* this must be forced */
12581258
CG(unclean_shutdown) = 0;
12591259
} else {
1260-
/* local client quit console */
1261-
CG(unclean_shutdown) = 0;
1262-
1263-
goto phpdbg_out;
1260+
/* local consoles cannot disconnect, ignore EOF */
1261+
PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
12641262
}
12651263
}
12661264
#endif
@@ -1275,7 +1273,7 @@ int main(int argc, char **argv) /* {{{ */
12751273

12761274
phpdbg_out:
12771275
#ifndef _WIN32
1278-
if (PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED) {
1276+
if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
12791277
PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
12801278
goto phpdbg_interact;
12811279
}
@@ -1324,7 +1322,7 @@ int main(int argc, char **argv) /* {{{ */
13241322
if (cleaning || remote) {
13251323
goto phpdbg_main;
13261324
}
1327-
1325+
13281326
#ifdef ZTS
13291327
/* bugggy */
13301328
/* tsrm_shutdown(); */

phpdbg_cmd.c

+23-12
Original file line numberDiff line numberDiff line change
@@ -467,32 +467,43 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
467467
}
468468

469469
if (buffered == NULL) {
470-
#ifndef HAVE_LIBREADLINE
471-
char buf[PHPDBG_MAX_CMD];
472-
if ((!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && !phpdbg_write(phpdbg_get_prompt(TSRMLS_C))) ||
473-
!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
474-
/* the user has gone away */
475-
phpdbg_error("Failed to read console!");
470+
disconnect:
471+
if (0) {
476472
PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED);
477473
zend_bailout();
478474
return NULL;
479475
}
480476

477+
#ifndef HAVE_LIBREADLINE
478+
char buf[PHPDBG_MAX_CMD];
479+
if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
480+
if (!phpdbg_write(phpdbg_get_prompt(TSRMLS_CC))) {
481+
goto disconnect;
482+
}
483+
}
484+
485+
/* note: EOF is ignored */
486+
readline:
487+
if (!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
488+
/* the user has gone away */
489+
if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
490+
goto disconnect;
491+
} else goto readline;
492+
}
493+
481494
cmd = buf;
482495
#else
496+
/* note: EOF makes readline write prompt again in local console mode */
497+
readline:
483498
if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
484499
char buf[PHPDBG_MAX_CMD];
485500
if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
486501
cmd = buf;
487-
} else cmd = NULL;
502+
} else goto disconnect;
488503
} else cmd = readline(phpdbg_get_prompt(TSRMLS_C));
489504

490505
if (!cmd) {
491-
/* the user has gone away */
492-
phpdbg_error("Failed to read console!");
493-
PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED);
494-
zend_bailout();
495-
return NULL;
506+
goto readline;
496507
}
497508

498509
if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {

0 commit comments

Comments
 (0)