Comment 6 for bug 322214

Revision history for this message
Clint Byrum (clint-fewbar) wrote : Re: php incorrectly opens stdin

Just to confirm, this is still present as of php5-cli 5.3.3-1ubuntu3

I've taken a good long look at this, and I am 99.9% sure that this is a problem with libedit..

#include <stdio.h>
#include <histedit.h>

int main(int argc, char *argv[])
{
    using_history();
    printf("Some interesting info\n");
    return 0;
}

This program, compiled with 'gcc test.c -ledit -o test'

Will produce the exact same effect when piped to less.

using_history() is called in the init function of the readline extension at line 168 of ext/readline/readline.c

The reason this didn't break in the standard PHP build is most likely that libedit wasn't used, as readline is an optional module.

I reported it here:

https://sourceforge.net/tracker/?func=detail&aid=3044367&group_id=18314&atid=118314

But that tracker appears to be dead. Also sent report to the Debian Maintainer, and will mark it as also affecting libedit. I tested it with the GNU readline library's using_history(), and that did not exhibit the same problem.

One possible workaround is to build readline as an extension, and not load it by default. I suspect though that any packages that have php scripts that need/want readline would be fairly broken then. Another method is to have the readline extension make sure it lets go of the terminal if libedit is used.