Re: script input redirection / eof handling

Karel Zak
2013-12-02T12:54:24Z

On Mon, Dec 02, 2013 at 01:36:59PM +0100, Karel Zak wrote:
> On Thu, Oct 31, 2013 at 10:21:10AM -0400, Phillip Susi wrote:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > I came across an old bug filed in debian about script being redirected
> > from a file misbehaving.
>
> Do you mean something like:
>
> echo "ps uf" | script
>
> .. if yes, then it's pretty unexpected usage. The code expects that
> stdin is terminal. (For example it copy the current terminal
> attributes the new pseudo-terminal.)
>
> Unfortunately it does not check tcgetatt() return code so the problem
> is not visible. I'll fix it.

Note, that if you want to support this scenario (stdin is not a
terminal) then send a patch ;-)

I guess you have to initialize the terminal (see inlude/ttyutils.h,
reset_virtual_console()) and use this dummy struct termios instead of
the current 'tt'.

> Yep, I think it would be enough to add
>
> kill(0, SIGTERM);
>
> before done() in doinput() to avoid orphans.

This is probably not the best solution (because shell will print
"Terminated" etc.), but it's definitely better than orphans.