Bug#333138: [Pkg-shadow-devel] chfn behaves bogusly when either fd 0,
1 or 2 is not a tty
Robert Millan
rmh at aybabtu.com
Tue Oct 11 06:10:15 UTC 2005
tags 333138 patch
thanks
On Tue, Oct 11, 2005 at 02:22:51AM +0300, Alexander Gattin wrote:
>
> chfn/chsh without cmdline parameters work interactively
> so you _should_ use ptys/expect-like program to script
> them (or use cmdline parameters). It's common issue
> with a lot of Unix utils.
The problem with this one is that when it's being called indirectly by adduser,
then your script has no control over it.
> you see The Classical Effect of Pipe Being
> Block-Buffered. I.e. without using smth. like
> fsync()/fflush() you won't see output until pipe is
> closed gracefully or buffer (4096 usually) gets full.
Ah, right, you just say it. I've found this before, and fflush works wonders.
> must be contained just in the following code:
> > printf ("\t%s [%s]: ", prompt, buf);
> > if (fgets (newf, maxsize, stdin) != newf)
This patch solves the problem. It affects the first lines of output (since
they're in the same buffer), and all subsequent prompt queries.
I've tested it with:
# cat | chfn rmh 2>&1 | cat
And works perfectly. Thanks for your help (even if you thought it was not a
bug, you actualy solved it..)
--- shadow-4.0.12.old/libmisc/fields.c 2005-06-14 22:27:35.000000000 +0200
+++ shadow-4.0.12/libmisc/fields.c 2005-10-11 07:58:57.000000000 +0200
@@ -71,6 +71,7 @@
maxsize = sizeof (newf);
printf ("\t%s [%s]: ", prompt, buf);
+ fflush (stdout);
if (fgets (newf, maxsize, stdin) != newf)
return;
--
Robert Millan
More information about the Pkg-shadow-devel
mailing list