Re: Weirdest shell behavior ever...
- From: Janis Papanagnou <janis_papanagnou@xxxxxxxxxxx>
- Date: Wed, 01 Sep 2010 22:45:58 +0300
Am 01.09.2010 22:27, schrieb Seebs:
Okay, weirdest I've seen.
There's a hunk of shell code I use to generate some large hunks of source
code. The basic logic looks like this:
exec 5>wrapfuncs.c
for i in big_list
do
cat >&5 <<EOF
int $i(void) {
EOF
cat >&5 <<EOF
return 3;
}
EOF
cat >&5 <<EOF
int dummy_$i(void) { return 4; }
EOF
done
(The contents are actually much more complicated.)
Out of about fifty thousand runs, we've had two fail, both on the same
host, both on the same day. The failure is that the entire file
comes out fine, except that ONE instance (out of dozens) in the file
comes out as:
int foo(void) {
int dummy_foo(void) { return 4; }
return 3;
}
instead of
int foo(void) {
return 3;
}
int dummy_foo(void) { return 4; }
This happens only once in the whole file -- and not in the same place on
the two different runs that failed. There are no duplicated lines or
other things to suggest two simultaneous copies of the script, there's no
nothing.
I found one warning many years old that fd 5 might act strangely in bash, but
I don't know whether it's still true, and we're not seeing anything like the
reported failure modes. The failures both occurred on Ubuntu 10.04, which
is using bash 4.1.5 (yes, we're using bash rather than dash, loooong story).
If you want a look at the code,
Not really :-)
it's actually the "makewrappers" script in
pseudo:
http://github.com/wrpseudo/pseudo
So, we've had a few people look at this, and we can't find ANYTHING to explain
this. The cat programs exit, and are not backgrounded, so before the shell
gets control back to continue execution, so far as we can tell, so the writes
should finish.
Only thing I can think of is that somehow the here documents are getting
swapped around or mangled. But I've never seen that, and it's certainly
not happening *consistently*.
Anyone got cool suggestions?
Probably not cool, but - without knowing the context details
of your program system - what I've checked would have been;
A) try the same with another descriptor than 5,
B) try the same with Kornshell or zsh (to locate the issue),
C) try to close descriptor 5 after the last usage,
D) try to run smaller chunks/slices (<10000) but more often,
and observe any differences with above variations.
Janis
-s
.
- Follow-Ups:
- Re: Weirdest shell behavior ever...
- From: Seebs
- Re: Weirdest shell behavior ever...
- References:
- Weirdest shell behavior ever...
- From: Seebs
- Weirdest shell behavior ever...
- Prev by Date: Re: repeating a character a variable number of times
- Next by Date: Re: Weirdest shell behavior ever...
- Previous by thread: Weirdest shell behavior ever...
- Next by thread: Re: Weirdest shell behavior ever...
- Index(es):
Relevant Pages
|