bug in System.system on ghc-6.2.1

Malcolm Wallace Malcolm.Wallace at cs.york.ac.uk
Tue Jul 20 09:25:31 EDT 2004


"Simon Marlow" <simonmar at microsoft.com> writes:

> >     import System.Cmd
> >     main = do v <- system("ghc --version 2>&1")
> >               print v
> 
> Are you sure your shell understands the '>&' syntax?  Not all do.

Yes, on RH7.2, /bin/sh is bash.

> Assuming you're using the same shell in both cases, this could indicate
> a problem somewhere.  Could you try strace on the binary?

There doesn't seem to be much significant difference.  Here are the relevant
chunks of strace output, first for the working 6.2.1 on glibc-2.3:

    vfork()                                 = 3552
    wait4(3552, The Glorious Glasgow Haskell Compilation System, version 6.2.1
    [WIFEXITED(s) && WEXITSTATUS(s) == 0], 0, NULL) = 3552
    --- SIGCHLD (Child exited) ---
    ioctl(1, SNDCTL_TMR_TIMEBASE, 0xbfffd6f0) = -1 EINVAL (Invalid argument)
    times({tms_utime=0, tms_stime=0, tms_cutime=1, tms_cstime=0}) = 9887108
    write(1, "ExitSuccess\n", 12)           = 12

and for the non-working 6.2.1 on glibc-2.2:

    vfork()                                 = 10120
    --- SIGCHLD (Child exited) ---
    wait4(10120, [WIFEXITED(s) && WEXITSTATUS(s) == 127], 0, NULL) = 10120
    ioctl(1, 0x5401, {B38400 opost isig icanon echo ...}) = 0
    write(1, "ExitFailure 127\n", 16)       = 16

I notice from an strace of the same program compiled with ghc-5.04.2
that earlier versions of ghc used a plain fork instead of a vfork.
Unfortunately, the use of vfork rather than fork prevents me from
examining the child process's system calls with strace -f.  For instance,
with ghc-5.04.2 I can see

    fork()                                  = 10363
    [pid 10362] wait4(10363,  <unfinished ...>
    [pid 10363] setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
    [pid 10363] setitimer(ITIMER_VIRTUAL, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
    [pid 10363] setitimer(ITIMER_PROF, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
    [pid 10363] execve("/bin/sh", ["sh", "-c", "ghc --version 2>&1"], [/* 31 vars */]) = 0
    ...

The exit status of 127 indicates that the command ("ghc") could not
be found.  Considering the possibility of a bash configuration problem
on RH7.2, I tried compiling essentially the same code in C:

    main () {
        int v = system("ghc --version 2>&1");
        printf("Exit %d\n",v);
    }

but it too works fine.  Is it possible that there are #ifdef's around
some of the internals of the ghc system primitive, that are somehow
misconfigured when built on RedHat 7.2?

> The '2>&1' will be passed as a raw argument to GHC in this case.
> Fortunately GHC is ignoring it.

Yes, I realised that, but it is irrelevant to the problem at hand.

Regards,
    Malcolm



More information about the Glasgow-haskell-bugs mailing list