Skip to content

Commit db12998

Browse files
committed
fix remote mode when readline is enabled
1 parent 87b556e commit db12998

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

phpdbg.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,11 @@ int phpdbg_open_socket(short port) /* {{{ */
589589
return fd;
590590
} /* }}} */
591591

592-
int phpdbg_open_sockets(short listen[2], FILE* streams[2]) /* {{{ */
592+
int phpdbg_open_sockets(int listen[2], FILE* streams[2]) /* {{{ */
593593
{
594594
int sockets[2] = {
595-
phpdbg_open_socket(listen[0]),
596-
phpdbg_open_socket(listen[1])
595+
phpdbg_open_socket((short)listen[0]),
596+
phpdbg_open_socket((short)listen[1])
597597
};
598598
int accepted[2] = {-1, -1};
599599

@@ -614,11 +614,11 @@ int phpdbg_open_sockets(short listen[2], FILE* streams[2]) /* {{{ */
614614

615615
memset(&address, 0, size);
616616
accepted[0] = accept(
617-
sockets[0], &address, &size);
617+
sockets[0], (struct sockaddr *) &address, &size);
618618

619619
memset(&address, 0, size);
620620
accepted[1] = accept(
621-
sockets[1], &address, &size);
621+
sockets[1], (struct sockaddr *) &address, &size);
622622
}
623623

624624
streams[0] = fdopen(accepted[0], "r");
@@ -648,7 +648,7 @@ int main(int argc, char **argv) /* {{{ */
648648
int run = 0;
649649
int step = 0;
650650
char *bp_tmp_file;
651-
short listen[2];
651+
int listen[2];
652652
FILE* streams[2] = {NULL, NULL};
653653

654654
#ifdef ZTS
@@ -803,7 +803,6 @@ int main(int argc, char **argv) /* {{{ */
803803
if (!cleaning &&
804804
(listen[0] && listen[1])) {
805805
phpdbg_open_sockets(listen, streams);
806-
/* now is a sensible time to announce listen settings on the console */
807806
}
808807

809808
phpdbg->ini_defaults = phpdbg_ini_defaults;
@@ -842,6 +841,9 @@ int main(int argc, char **argv) /* {{{ */
842841
#endif
843842

844843
PG(modules_activated) = 0;
844+
845+
/* set flags from command line */
846+
PHPDBG_G(flags) = flags;
845847

846848
/* setup io here */
847849
if (streams[0] && streams[1]) {
@@ -850,7 +852,6 @@ int main(int argc, char **argv) /* {{{ */
850852
PHPDBG_G(io)[PHPDBG_STDIN] = streams[0];
851853
PHPDBG_G(io)[PHPDBG_STDOUT] = streams[1];
852854
PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
853-
854855
signal(SIGPIPE, SIG_IGN);
855856
} else {
856857
/* local console */
@@ -876,9 +877,6 @@ int main(int argc, char **argv) /* {{{ */
876877
free(oplog_file);
877878
}
878879

879-
/* set flags from command line */
880-
PHPDBG_G(flags) = flags;
881-
882880
/* set default colors */
883881
phpdbg_set_color_ex(PHPDBG_COLOR_PROMPT, PHPDBG_STRL("white-bold") TSRMLS_CC);
884882
phpdbg_set_color_ex(PHPDBG_COLOR_ERROR, PHPDBG_STRL("red-bold") TSRMLS_CC);

phpdbg_cmd.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,22 +220,30 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
220220
if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
221221
if (buffered == NULL) {
222222

223-
fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
223+
if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
224+
fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
225+
}
224226

225227
#ifndef HAVE_LIBREADLINE
226228
char buf[PHPDBG_MAX_CMD];
227-
if (!phpdbg_write(phpdbg_get_prompt(TSRMLS_C)) ||
229+
if ((!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && !phpdbg_write(phpdbg_get_prompt(TSRMLS_C))) ||
228230
!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
229231
/* the user has gone away */
230232
phpdbg_error("Failed to read console !");
231233
PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
232234
zend_bailout();
233235
return NULL;
234236
}
235-
237+
236238
cmd = buf;
237239
#else
238-
cmd = readline(phpdbg_get_prompt(TSRMLS_C));
240+
if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
241+
char buf[PHPDBG_MAX_CMD];
242+
if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
243+
cmd = buf;
244+
} else cmd = NULL;
245+
} else cmd = readline(phpdbg_get_prompt(TSRMLS_C));
246+
239247
if (!cmd) {
240248
/* the user has gone away */
241249
phpdbg_error("Failed to read console !");
@@ -244,7 +252,9 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
244252
return NULL;
245253
}
246254

247-
add_history(cmd);
255+
if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
256+
add_history(cmd);
257+
}
248258
#endif
249259
} else cmd = buffered;
250260

@@ -275,7 +285,8 @@ PHPDBG_API phpdbg_input_t *phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
275285
#endif
276286

277287
#ifdef HAVE_LIBREADLINE
278-
if (!buffered && cmd) {
288+
if (!buffered && cmd &&
289+
!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
279290
free(cmd);
280291
}
281292
#endif

phpdbg_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */
299299
} /* }}} */
300300

301301
PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */
302-
{
302+
{
303303
/* find cached prompt */
304304
if (PHPDBG_G(prompt)[1]) {
305305
return PHPDBG_G(prompt)[1];

0 commit comments

Comments
 (0)