[haiku] Re: File system races?

  • From: David Given <dg@xxxxxxxxxxx>
  • To: haiku@xxxxxxxxxxxxx
  • Date: Sun, 06 Aug 2017 11:35:16 +0000

I spoke too soon. That bug didn't go away; it only manifests if I build the
ACK via ninja. If I build it with make (the build system supports both),
then it works fine (until it hits another bug).

<rummage>

Aha! Sorted!

The temporary files are generated by a driver program creating a bunch of
filenames with mktemp(), then running each stage with system(), and then
deleting the files.

And on Haiku... Haiku's mktemp() uses rand() to generate the temporary
filenames, but rand() isn't seeded, which means that you always get the
same temporary files on every run of the program. ninja seems to be running
jobs in parallel even on a single-core machine, which means they stamp all
over each other's temporary files. This also explains a lot of other random
crashes.

So I reckon there are two bugs here:

(a) I shouldn't be using mktemp(); I should be using mkstemp() instead
which atomically creates the file, guaranteeing uniqueness --- although in
fairness, most of this code was written in the 1980s, when mkstemp() didn't
exist;
(b) Haiku really shouldn't be doing that.

Demonstration test program:

#include <stdlib.h>
#include <stdio.h>
int main() {
char s[] = "/tmp/XXXXXX";
mktemp(s);
printf("%s\n", s);
}

$ gcc test.c
$ ./test
/tmp/temp.mq2NP5
$ ./test
/tmp/temp.mq2NP5
$ ./test
/tmp/temp.mq2NP5
$ ./test
/tmp/temp.mq2NP5

On Sun, 6 Aug 2017 at 12:46 David Given <dg@xxxxxxxxxxx> wrote:

The two main systems I've seen it build on are Debian/Ubuntu Linux and
OpenBSD, although I've had people on other Linuxes and BSDs who build it.
It doesn't build on OSX and Cygwin due to case-insensitive file systems,
although it'll target OSX (fix in progress). If supported, the build system
will do massively parallel builds, which we spent a lot of time tuning, so
if there were any build system races I'd expect them to show up there.

The ACK's the compiler written by Andy Tanenbaum and Ceriel Jacobs for the
Minix project. With the right (heavily customised) build configuration,
it'll build an ANSI C89 compiler that'll run in 64kB of RAM. However, it
was written in the 1980s, and is packed full of K&Risms, which makes
building on new architectures a bit of an adventure.

After some more fiddling I think that the file system stuff was a red
herring. ANSI-fying some of the K&R code made the build issue go away.

So the only thing I can think of here is that the calling convention
generated by gcc when given a K&R function call isn't matching the actual
convention, resulting in garbled parameters. But Haiku's ABI is pretty
vanilla, isn't it? The biggest gotcha with K&R functions is when
sizeof(long)==8, but that's not the case here. It also doesn't explain why
it was so sporadic. I would expect calling convention issues to case
reliable failures. So still confused.

(Of course, it's still not building --- there are other issues elsewhere,
which I'm looking into.)

On Sun, 6 Aug 2017 at 02:42 Thomas Mueller <mueller6723@xxxxxxx> wrote:

from David Given:

Is anyone aware of any problems with the file system (potentially only
showing up on slow machines) where closing a file and then immediately
reopening it will fail?

The context is: I am the sort of maintainer for a compiler suite, the
Amsterdam Compiler Kit: http://tack.sourceforge.net/

This is failing to build, in a rather odd fashion --- I'm getting
spurious
file-not-found errors as one stage of the compiler is failing to open an
intermediate file provided by a previous stage.

The way the ACK works is that there are lots of different passes, all
running one after the other, all communicating via quite a lot of
temporary
files; e.g. the optimiser stage uses five or so files *per stage*, and
there are six or seven stages. So it's possible that the ACK is
exercising
this part of the system rather harder than, say, gcc is.

And, of course, this only manifests during a full build. Just running
the
compiler from the command line doesn't make this happen.

Has anyone observed anything similar?

Under what operating systems did you attempt to build the Amsterdam
Compiler Kit?

Was Haiku one of them?

I never heard of the ACK prior to your post.

Tom


--
┌─── http://cowlark.com ───
│ "There is nothing in the world so dangerous --- and I mean *nothing*
│ --- as a children's story that happens to be true." --- Master Li Kao,
│ _The Bridge of Birds_

--
┌─── http://cowlark.com ───
│ "There is nothing in the world so dangerous --- and I mean *nothing*
│ --- as a children's story that happens to be true." --- Master Li Kao,
│ _The Bridge of Birds_

Other related posts: