Subject: | Prompt not displayed in interactive mode due to file descriptor closure |
Hello.
Problem description following.
Example:
$ xsh -i
----------------------------------------
xsh - XML Editing Shell version 2.1.27
----------------------------------------
Copyright (c) 2002 Petr Pajas.
This is free software, you may use it and distribute it under
either the GNU GPL Version 2, or under the Perl Artistic License.
Using terminal type: Term::ReadLine::Gnu
Hint: Type `help' or `help | less' to get more help.
$scratch/> ls
<?xml version='1.0' encoding='utf-8'?>
<scratch/>
Found 1 node(s).
<?xml version='1.0' encoding='utf-8'?>
<scratch/>
Found 1 node(s).
The output above is the one of two "ls" commands in sequence.
As you can see the prompt is displayed only the first time.
Afterwards there's no echo of the commands one inputs.
Debugging and tracing syscalls I've narrowed it down to
https://metacpan.org/source/CHOROBA/XML-XSH2-2.1.27/lib/XML/XSH2/Functions.pm#L256
Basically the open() call in the xsh_init function.
Below an excerpt from the strace output
[BEGIN STRACE]
write(6, "\33[4m$scratch/> \33[24m", 20$scratch/> ) = 20
read(5, "l", 1) = 1
write(6, "l", 1l) = 1
read(5, "s", 1) = 1
write(6, "s", 1s) = 1
read(5, "\r", 1) = 1
write(6, "\n", 1
) = 1
close(6) = 0
open("/usr/local/share/perl/5.22.1/XML/XSH2/Parser.pm", O_RDONLY) = 6
read(6, "{\n# GENERATE RECURSIVE DESCENT P"..., 8192) = 8192
[...]
read(6, "", 8192) = 0
close(6) = 0
write(4, "<?xml version='1.0' encoding='ut"..., 39<?xml version='1.0' encoding='utf-8'?>
) = 39
write(4, "<scratch/>", 10<scratch/>) = 10
write(4, "\n", 1
) = 1
write(2, "\n", 1
) = 1
write(2, "Found ", 6Found ) = 6
write(2, "1", 11) = 1
write(2, " node(s).\n", 10 node(s).
) = 10
write(6, "\33[4m$scratch/> \33[24m", 20) = -1 EBADF (Bad file descriptor)
[END STRACE]
Apparently the output file descriptor is closed but the program is still trying to write the prompt and the echo of the inputted commands to it.