[PATCH] Prevent wordexp from modyfying terminal parameters

Eric Blake eblake@redhat.com
Fri Jul 23 18:15:00 GMT 2010

On 07/22/2010 11:45 AM, Moulding, Dan - 0663 - MITLL wrote:
> I have found that calling wordexp can, as an unfortunate side effect, change
> the controlling terminal's parameters. I tracked the problem down to the way
> wordexp invokes Bash to perform word expansion: stdout and stderr are
> redirected to a pipe, but stdin is left alone. It seems that if Bash sees that
> stdin is connected to a terminal, then Bash will immediately reset the
> terminal's parameters (presumably to some state that Bash considers sane).
> The below patch is my first stab at fixing the problem. This makes wordexp also
> redirect stdin to the pipe before invoking Bash. It thereby prevents Bash from
> seeing it is connected to a terminal and avoids the reset of the controlling
> terminal's parameters.

Rather than redirecting stdin, would it be sufficient to add "-c" to the
list of arguments passed to bash?  Also, it is a bit faster to just
close(STDIN_FILENO) (and start bash with closed stdin) than to dup2 an
output-only pipe over to stdin (either way, bash doesn't appear to be
reading from stdin during --wordexp).

You probably also want to file a bug report with bug-bash AT gnu DOT org
that --wordexp should never need to do a check for interactive mode,
since it is a special-purpose invocation mode not even documented in the
man page.

Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20100723/054f97f3/attachment.sig>

More information about the Newlib mailing list