[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: AT_CHECK_INTERACTIVE
From: |
Ralf Wildenhues |
Subject: |
Re: AT_CHECK_INTERACTIVE |
Date: |
Sun, 21 Jan 2007 17:01:01 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
Hello Paul,
A progress update, just FYI.
* Paul Eggert wrote on Sun, Dec 17, 2006 at 07:27:35AM CET:
> Ralf Wildenhues <address@hidden> writes:
>
> > mkfifo at-fifo-err
> > mkfifo at-fifo-out
> > command='{ sleep 2; echo out ; echo err >&2; sleep 2; exit 42; }'
> > ( exec >at-fifo-out 2>at-fifo-err ; eval "$command" ) & at_cmd1=$!
> > tee < at-fifo-out stdout & at_cmd2=$!
> > tee < at-fifo-err stderr & at_cmd3=$!
> > wait $at_cmd2 $at_cmd3 $at_cmd1
[...]
> Sure, just use pipes. You shouldn't need any of the stuff with fifos
> and sleeps and wait. It will be a bit of a pain to save $command's
> exit status, given that $command's output will be piped, but you can
> use something like the following trick (taken from zgrep):
>
> # Fail if either grep or sed fails.
> exec 3>&1
> r=`
> exec 4>&1
> (grep "$pattern" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&-
> ` &&
> exit $r
Hmm. This is what I've been able to come up with for now. Note
$at_cmd is an example command, in order to facilitate testing.
The sleep is just there to inspect progress easily.
at_cmd='{ echo out; echo err >&2; sleep 2; exit 42; }'
# The following is what AT_CHECK_MONITOR would do (not Ultrix-safe):
exec 4>&1 5>&2
at_res=`
exec 3>&1
( ( (eval "$at_cmd") 3>&- 4>&- 5>&-; echo $? 1>&3) 2>&5 \
| tee at-stdout 3>&-) 5>&1 1>&4 | tee at-stderr 3>&- 1>&2 5>&-
`
exec 4>&- 5>&-
exit $at_res
This is probably still both buggy and too complicated, but it seems to
work. I'm not sure whether closing all those fds is needed -- really
only fd leakage to $command would be a problem, I guess? And while
we're at that topic, isn't that then an issue for many other things
that, say, configure usually executes?
FWIW, with a at-status file it simplifies to
command='{ echo out; echo err >&2; sleep 2; exit 42; }'
rm -f at-status at-stdout at-stderr
exec 3>&1 4>&2
( ( (eval "$command") 2>&4 3>&- 4>&-; echo $? >at-status) |
tee at-stdout) 4>&1 >&3 | tee at-stderr >&2 4>&-
exec 3>&- 4>&-
I'm a bit afraid this warning in autoconf.info(File Descriptors):
| Don't rely on open file descriptors being open in child processes.
| In `ksh', file descriptors above 2 which are opened using `exec N>file'
| are closed by a subsequent `exec' (such as that involved in the
| fork-and-exec which runs a program or script). [...]
may torpedo this nice idea; not to speak of Ultrix, of course.
> By the way, the name AT_CHECK_INTERACTIVE confused me, since I assumed
> it was testing an interactive program, or was a test you could run
> interactively. Perhaps a better name would be AT_CHECK_MONITOR (or
> AT_CHECK_IMPATIENTLY :-)?
I like the last one ;-) but AT_CHECK_MONITOR is probably better.
Thanks. I may turn this into an actual patch eventually...
Cheers,
Ralf
- Re: AT_CHECK_INTERACTIVE,
Ralf Wildenhues <=