Currently, libgo uses wait4 unconditionally, which is missing on IRIX 6.5. Fortunately, the rusage * arg is used nowhere, so I've decide to replace wait4 by waitpid, which seems to be considerably more portable.
The following patch does this. Together with the IRIX 6 infrastructure patch (to be reposted separately once I've figured out why sockets don't work yet) and a strerror_r patch (to be posted shortly), this allowed the go and libgo testsuites to run on IRIX 6.5. Besides, I've included it in a i386-pc-solaris2.11 bootstrap to make sure that it works on other systems, too. Rainer 2011-01-30 Rainer Orth <r...@cebitec.uni-bielefeld.de> PR go/47515 * syscalls/exec.go (libc_wait4): Replace by libc_waitpid. (forkExec): Call Waitpid instead of Wait4. (Wait4): Renamed to Waitpid. Call libc_waitpid instead of libc_wait4. * syscalls/exec_stubs.go (Wait4): Renamed to Waitpid. * go/os/exec.go: Remove reference to Rusage. (Waitmsg): Remove Rusage member. Remove WRUSAGE option. * go/os/exec_unix.go (Wait): Remove rusage. Call Waitpid instead of Wait4. * mksysinfo.sh: Remove Rusage. * Makefile.am: Refer to waitpid instead of wait4. * go/debug/proc/proc_linux.go: Likewise. * Makefile.in: Regenerate. diff -r 4fb11b32a76a libgo/Makefile.am --- a/libgo/Makefile.am Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/Makefile.am Sat Mar 19 21:55:54 2011 +0100 @@ -1,6 +1,6 @@ # Makefile.am -- Go library Makefile. -# Copyright 2009 The Go Authors. All rights reserved. +# Copyright 2009, 2011 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. @@ -1206,7 +1210,7 @@ endif # !LIBGO_IS_LINUX -# Define ForkExec, PtraceForkExec, Exec, and Wait4. +# Define ForkExec, PtraceForkExec, Exec, and Waitpid. if LIBGO_IS_RTEMS syscall_exec_os_file = syscalls/exec_stubs.go else diff -r 4fb11b32a76a libgo/go/debug/proc/proc_linux.go --- a/libgo/go/debug/proc/proc_linux.go Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/go/debug/proc/proc_linux.go Sat Mar 19 21:55:54 2011 +0100 @@ -1,4 +1,4 @@ -// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2009, 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -22,7 +22,7 @@ // Linux's ptrace(2) interface. The implementation is multi-threaded. // Each attached process has an associated monitor thread, and each // running attached thread has an associated "wait" thread. The wait -// thread calls wait4 on the thread's TID and reports any wait events +// thread calls waitpid on the thread's TID and reports any wait events // or errors via "debug events". The monitor thread consumes these // wait events and updates the internally maintained state of each // thread. All ptrace calls must run in the monitor thread, so the diff -r 4fb11b32a76a libgo/go/os/exec.go --- a/libgo/go/os/exec.go Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/go/os/exec.go Sat Mar 19 21:55:54 2011 +0100 @@ -1,4 +1,4 @@ -// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2009, 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -65,16 +65,11 @@ // TODO(rsc): Should os implement its own syscall.WaitStatus // wrapper with the methods, or is exposing the underlying one enough? -// -// TODO(rsc): Certainly need to have Rusage struct, -// since syscall one might have different field types across -// different OS. // Waitmsg stores the information about an exited process as reported by Wait. type Waitmsg struct { Pid int // The process's id. syscall.WaitStatus // System-dependent status info. - Rusage *syscall.Rusage // System-dependent resource usage info. } // Wait waits for process pid to exit or stop, and then returns a diff -r 4fb11b32a76a libgo/go/os/exec_unix.go --- a/libgo/go/os/exec_unix.go Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/go/os/exec_unix.go Sat Mar 19 21:55:54 2011 +0100 @@ -1,4 +1,4 @@ -// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2009, 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -14,13 +14,8 @@ WNOHANG = syscall.WNOHANG // Don't wait if no process has exited. WSTOPPED = syscall.WSTOPPED // If set, status of stopped subprocesses is also reported. WUNTRACED = syscall.WUNTRACED // Usually an alias for WSTOPPED. - WRUSAGE = 1 << 20 // Record resource usage. ) -// WRUSAGE must not be too high a bit, to avoid clashing with Linux's -// WCLONE, WALL, and WNOTHREAD flags, which sit in the top few bits of -// the options - // Wait waits for the Process to exit or stop, and then returns a // Waitmsg describing its status and an Error, if any. The options // (WNOHANG etc.) affect the behavior of the Wait call. @@ -29,19 +24,13 @@ return nil, EINVAL } var status syscall.WaitStatus - var rusage *syscall.Rusage - if options&WRUSAGE != 0 { - rusage = new(syscall.Rusage) - options ^= WRUSAGE - } - pid1, e := syscall.Wait4(p.Pid, &status, options, rusage) + pid1, e := syscall.Waitpid(p.Pid, &status, options) if e != 0 { return nil, NewSyscallError("wait", e) } w = new(Waitmsg) w.Pid = pid1 w.WaitStatus = status - w.Rusage = rusage return w, nil } diff -r 4fb11b32a76a libgo/mksysinfo.sh --- a/libgo/mksysinfo.sh Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/mksysinfo.sh Sat Mar 19 21:55:54 2011 +0100 @@ -1,6 +1,6 @@ #!/bin/sh -# Copyright 2009 The Go Authors. All rights reserved. +# Copyright 2009, 2011 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. @@ -355,30 +372,6 @@ >> ${OUT} echo "type DIR _DIR" >> ${OUT} -# The rusage struct. -rusage=`grep '^type _rusage struct' gen-sysinfo.go` -if test "$rusage" != ""; then - rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'` - rusage=`echo $rusage | sed -e 's/^ *//'` - nrusage= - while test -n "$rusage"; do - field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'` - rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'` - # Drop the leading ru_, capitalize the next character. - field=`echo $field | sed -e 's/^ru_//'` - f=`echo $field | sed -e 's/^\(.\).*$/\1/'` - r=`echo $field | sed -e 's/^.\(.*\)$/\1/'` - f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ` - # Fix _timeval _timespec, and _timestruc_t. - r=`echo $r | sed -e s'/ _timeval$/ Timeval/'` - r=`echo $r | sed -e s'/ _timespec$/ Timespec/'` - r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'` - field="$f$r" - nrusage="$nrusage $field;" - done - echo "type Rusage struct {$nrusage }" >> ${OUT} -fi - # The utsname struct. grep '^type _utsname ' gen-sysinfo.go | \ sed -e 's/_utsname/Utsname/' \ diff -r 4fb11b32a76a libgo/syscalls/exec.go --- a/libgo/syscalls/exec.go Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/syscalls/exec.go Sat Mar 19 21:55:54 2011 +0100 @@ -1,6 +1,6 @@ // exec.go -- fork/exec syscall support. -// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2009, 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -16,7 +16,7 @@ func libc_dup2(int, int) int __asm__ ("dup2") func libc_execve(*byte, **byte, **byte) int __asm__ ("execve") func libc_sysexit(int) __asm__ ("_exit") -func libc_wait4(Pid_t, *int, int, *Rusage) Pid_t __asm__ ("wait4") +func libc_waitpid(Pid_t, *int, int) Pid_t __asm__ ("waitpid") // Fork, dup fd onto 0..len(fd), and exec(argv0, argvv, envv) in child. // If a dup or exec fails, write the errno int to pipe. @@ -204,9 +204,9 @@ // Child failed; wait for it to exit, to make sure // the zombies don't accumulate. - _, err1 := Wait4(pid, &wstatus, 0, nil) + _, err1 := Waitpid(pid, &wstatus, 0) for err1 == EINTR { - _, err1 = Wait4(pid, &wstatus, 0, nil) + _, err1 = Waitpid(pid, &wstatus, 0) } return 0, err } @@ -239,9 +239,9 @@ return pid, 0, err } -func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, errno int) { +func Waitpid(pid int, wstatus *WaitStatus, options int) (wpid int, errno int) { var status int - r := libc_wait4(Pid_t(pid), &status, options, rusage) + r := libc_waitpid(Pid_t(pid), &status, options) wpid = int(r) if r < 0 { errno = GetErrno() diff -r 4fb11b32a76a libgo/syscalls/exec_stubs.go --- a/libgo/syscalls/exec_stubs.go Sat Mar 19 10:51:23 2011 +0100 +++ b/libgo/syscalls/exec_stubs.go Sat Mar 19 21:55:54 2011 +0100 @@ -1,6 +1,6 @@ // exec_stubs.go -- fork/exec stubs. -// Copyright 2010 The Go Authors. All rights reserved. +// Copyright 2010, 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -20,6 +20,6 @@ return ENOSYS; } -func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, errno int) { +func Waitpid(pid int, wstatus *WaitStatus, options int) (wpid int, errno int) { return -1, ENOSYS; } -- ----------------------------------------------------------------------------- Rainer Orth, Center for Biotechnology, Bielefeld University