mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
- use a lock instead of a thread in once avoids deadlock in recursive once calls - implement os.Setenv - remove "export" from some scripts - remove _ from names in time package - fix time test for non-MTV machines R=r DELTA=265 (87 added, 58 deleted, 120 changed) OCL=25057 CL=25057
73 lines
1.6 KiB
Go
73 lines
1.6 KiB
Go
// Copyright 2009 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 os
|
|
|
|
import (
|
|
"os";
|
|
"syscall";
|
|
)
|
|
|
|
func ForkExec(argv0 string, argv []string, envv []string, fd []*FD)
|
|
(pid int, err *Error)
|
|
{
|
|
// Create array of integer (system) fds.
|
|
intfd := make([]int64, len(fd));
|
|
for i, f := range(fd) {
|
|
if f == nil {
|
|
intfd[i] = -1;
|
|
} else {
|
|
intfd[i] = f.Fd();
|
|
}
|
|
}
|
|
|
|
p, e := syscall.ForkExec(argv0, argv, envv, intfd);
|
|
return int(p), ErrnoToError(e);
|
|
}
|
|
|
|
func Exec(argv0 string, argv []string, envv []string) *Error {
|
|
if envv == nil {
|
|
envv = Environ();
|
|
}
|
|
e := syscall.Exec(argv0, argv, envv);
|
|
return ErrnoToError(e);
|
|
}
|
|
|
|
// 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 os.Rusage struct,
|
|
// since syscall one might have different field types across
|
|
// different OS.
|
|
|
|
type Waitmsg struct {
|
|
Pid int;
|
|
syscall.WaitStatus;
|
|
Rusage *syscall.Rusage;
|
|
}
|
|
|
|
const (
|
|
WNOHANG = syscall.WNOHANG;
|
|
WSTOPPED = syscall.WSTOPPED;
|
|
WRUSAGE = 1<<60;
|
|
)
|
|
|
|
func Wait(pid int, options uint64) (w *Waitmsg, err *Error) {
|
|
var status syscall.WaitStatus;
|
|
var rusage *syscall.Rusage;
|
|
if options & WRUSAGE != 0 {
|
|
rusage = new(syscall.Rusage);
|
|
options ^= WRUSAGE;
|
|
}
|
|
pid1, e := syscall.Wait4(int64(pid), &status, int64(options), rusage);
|
|
if e != 0 {
|
|
return nil, ErrnoToError(e);
|
|
}
|
|
w = new(Waitmsg);
|
|
w.Pid = pid;
|
|
w.WaitStatus = status;
|
|
w.Rusage = rusage;
|
|
return w, nil;
|
|
}
|
|
|