Re: bash, named pipe and lock :(
[email protected] (Paul Jarc) Sun, 05 Sep 2004 18:46:16 -0400
| Newsgroups | gmane.comp.lib.ptyget |
|---|---|
| Organization | What did you have in mind? A short, blunt, human pyramid? |
| Message-ID | <[email protected]> |
Sauron The Dark <[email protected]> wrote: > mknod out.${pid} p If you have execline installed, you could avoid creating a fifo. <URL:http://www.skarnet.org/software/execline/piperw.html> Then you don't need to worry about other processes interfering, accidentally or otherwise. > ( ${wf} 'password:' <out.${pid} ; echo "$2" ; ${wf} 'password:' <out.${pid} ; echo "$2" ; cat >/dev/null <out.${pid} ) Since there are two instances of waitfor reading from the fifo separately, it should probably not use stdio, to avoid buffering problems. (It's not likely to really matter, though, since passwd won't print the second password prompt until it receives the first password.) You should also not ignore errors: { "$wf" password: < out."$pid" && echo "$2" && "$wf" password: < out."$pid" && echo "$pid" && cat > /dev/null < out."$pid"; } > ( ptyget passwd "$1" &>out.$$ ) This pty is never used; ptyget doesn't redirect stdin/out/err for the subprogram. Maybe you're looking for ptybandage. I think this is the main reason you're having trouble. { ptybandage passwd "$1" > out.$$ 2>&1; } > My guess, is that waitfor is sometimes launched before passwd (before > passwd prompt gets written to the named pipe), tries to read from the > empty pipe and locks... The open() should block until a writer also open()s the fifo, and then the open() will complete and waitfor should be able to read normally. paul