This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [libgo] Replace wait4 by waitpid (PR go/47515)
- From: Ian Lance Taylor <iant at google dot com>
- To: Rainer Orth <ro at CeBiTec dot Uni-Bielefeld dot DE>
- Cc: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Wed, 30 Mar 2011 16:05:07 -0700
- Subject: Re: [libgo] Replace wait4 by waitpid (PR go/47515)
- References: <yddfwqf83hh.fsf@manam.CeBiTec.Uni-Bielefeld.DE>
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:
> 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.
Thanks for the patch, but I wasn't entirely happy with the approach
because it removes the os.Waitmsg.Rusage field. That field is
inherently system dependent but I would rather not get rid of it. I
wrote this patch instead, which I hope will also solve the problem.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.
Ian
diff -r a602eae61cf4 libgo/Makefile.am
--- a/libgo/Makefile.am Wed Mar 30 15:33:32 2011 -0700
+++ b/libgo/Makefile.am Wed Mar 30 16:01:55 2011 -0700
@@ -1246,13 +1246,20 @@
endif # !LIBGO_IS_LINUX
-# Define ForkExec, PtraceForkExec, Exec, and Wait4.
+# Define ForkExec, PtraceForkExec, and Exec.
if LIBGO_IS_RTEMS
syscall_exec_os_file = syscalls/exec_stubs.go
else
syscall_exec_os_file = syscalls/exec.go
endif
+# Define Wait4.
+if HAVE_WAIT4
+syscall_wait_file = syscalls/wait4.go
+else
+syscall_wait_file = syscalls/waitpid.go
+endif
+
# Define Sleep.
if LIBGO_IS_RTEMS
syscall_sleep_file = syscalls/sleep_rtems.go
@@ -1329,6 +1336,7 @@
$(syscall_errstr_decl_file) \
syscalls/exec_helpers.go \
$(syscall_exec_os_file) \
+ $(syscall_wait_file) \
$(syscall_filesize_file) \
$(syscall_stat_file) \
$(syscall_sleep_file) \
diff -r a602eae61cf4 libgo/configure.ac
--- a/libgo/configure.ac Wed Mar 30 15:33:32 2011 -0700
+++ b/libgo/configure.ac Wed Mar 30 16:01:55 2011 -0700
@@ -381,8 +381,9 @@
AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h)
AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes)
-AC_CHECK_FUNCS(srandom random strerror_r strsignal)
+AC_CHECK_FUNCS(srandom random strerror_r strsignal wait4)
AM_CONDITIONAL(HAVE_STRERROR_R, test "$ac_cv_func_strerror_r" = yes)
+AM_CONDITIONAL(HAVE_WAIT4, test "$ac_cv_func_wait4" = yes)
AC_CACHE_CHECK([for __sync_bool_compare_and_swap_4],
[libgo_cv_func___sync_bool_compare_and_swap_4],
diff -r a602eae61cf4 libgo/mksysinfo.sh
--- a/libgo/mksysinfo.sh Wed Mar 30 15:33:32 2011 -0700
+++ b/libgo/mksysinfo.sh Wed Mar 30 16:01:55 2011 -0700
@@ -377,6 +377,8 @@
nrusage="$nrusage $field;"
done
echo "type Rusage struct {$nrusage }" >> ${OUT}
+else
+ echo "type Rusage struct {}" >> ${OUT}
fi
# The utsname struct.
diff -r a602eae61cf4 libgo/syscalls/exec.go
--- a/libgo/syscalls/exec.go Wed Mar 30 15:33:32 2011 -0700
+++ b/libgo/syscalls/exec.go Wed Mar 30 16:01:55 2011 -0700
@@ -17,7 +17,6 @@
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")
// 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.
@@ -263,16 +262,3 @@
libc_execve(StringBytePtr(argv0), &argv_arg[0], &envv_arg[0])
return GetErrno()
}
-
-func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, errno int) {
- var status int
- r := libc_wait4(Pid_t(pid), &status, options, rusage)
- wpid = int(r)
- if r < 0 {
- errno = GetErrno()
- }
- if wstatus != nil {
- *wstatus = WaitStatus(status)
- }
- return
-}
diff -r a602eae61cf4 libgo/syscalls/wait4.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/wait4.go Wed Mar 30 16:01:55 2011 -0700
@@ -0,0 +1,22 @@
+// wait4.go -- Wait4 for systems with wait4.
+
+// Copyright 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.
+
+package syscall
+
+func libc_wait4(Pid_t, *int, int, *Rusage) Pid_t __asm__ ("wait4")
+
+func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, errno int) {
+ var status int
+ r := libc_wait4(Pid_t(pid), &status, options, rusage)
+ wpid = int(r)
+ if r < 0 {
+ errno = GetErrno()
+ }
+ if wstatus != nil {
+ *wstatus = WaitStatus(status)
+ }
+ return
+}
diff -r a602eae61cf4 libgo/syscalls/waitpid.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/waitpid.go Wed Mar 30 16:01:55 2011 -0700
@@ -0,0 +1,22 @@
+// waitpid.go -- Wait4 for systems without wait4, but with waitpid.
+
+// Copyright 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.
+
+package syscall
+
+func libc_waitpid(Pid_t, *int, int) Pid_t __asm__ ("waitpid")
+
+func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, errno int) {
+ var status int
+ r := libc_waitpid(Pid_t(pid), &status, options)
+ wpid = int(r)
+ if r < 0 {
+ errno = GetErrno()
+ }
+ if wstatus != nil {
+ *wstatus = WaitStatus(status)
+ }
+ return
+}