Commit 11f4a6c9 authored by David du Colombier's avatar David du Colombier Committed by Russ Cox

os,syscall: fix plan 9 build

NewFile take uintptr
make syscall.ProcAttr.Files be []uintptr

R=rsc
CC=golang-dev
https://golang.org/cl/5656073
parent 7c2bfa4f
...@@ -20,17 +20,9 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e ...@@ -20,17 +20,9 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
Sys: attr.Sys, Sys: attr.Sys,
} }
// Create array of integer (system) fds. for _, f := range attr.Files {
intfd := make([]int, len(attr.Files)) sysattr.Files = append(sysattr.Files, f.Fd())
for i, f := range attr.Files {
if f == nil {
intfd[i] = -1
} else {
intfd[i] = f.Fd()
} }
}
sysattr.Files = intfd
pid, h, e := syscall.StartProcess(name, argv, sysattr) pid, h, e := syscall.StartProcess(name, argv, sysattr)
if e != nil { if e != nil {
......
...@@ -26,19 +26,20 @@ type file struct { ...@@ -26,19 +26,20 @@ type file struct {
} }
// Fd returns the integer Unix file descriptor referencing the open file. // Fd returns the integer Unix file descriptor referencing the open file.
func (file *File) Fd() int { func (f *File) Fd() uintptr {
if file == nil { if f == nil {
return -1 return ^(uintptr(0))
} }
return file.fd return uintptr(f.fd)
} }
// NewFile returns a new File with the given file descriptor and name. // NewFile returns a new File with the given file descriptor and name.
func NewFile(fd int, name string) *File { func NewFile(fd uintptr, name string) *File {
if fd < 0 { fdi := int(fd)
if fdi < 0 {
return nil return nil
} }
f := &File{&file{fd: fd, name: name}} f := &File{&file{fd: fdi, name: name}}
runtime.SetFinalizer(f.file, (*file).close) runtime.SetFinalizer(f.file, (*file).close)
return f return f
} }
...@@ -128,7 +129,7 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) { ...@@ -128,7 +129,7 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
} }
} }
return NewFile(fd, name), nil return NewFile(uintptr(fd), name), nil
} }
// Close closes the File, rendering it unusable for I/O. // Close closes the File, rendering it unusable for I/O.
...@@ -330,7 +331,7 @@ func Pipe() (r *File, w *File, err error) { ...@@ -330,7 +331,7 @@ func Pipe() (r *File, w *File, err error) {
} }
syscall.ForkLock.RUnlock() syscall.ForkLock.RUnlock()
return NewFile(p[0], "|0"), NewFile(p[1], "|1"), nil return NewFile(uintptr(p[0]), "|0"), NewFile(uintptr(p[1]), "|1"), nil
} }
// not supported on Plan 9 // not supported on Plan 9
......
...@@ -182,7 +182,10 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at ...@@ -182,7 +182,10 @@ func forkAndExecInChild(argv0 *byte, argv []*byte, envv []envItem, dir *byte, at
) )
// guard against side effects of shuffling fds below. // guard against side effects of shuffling fds below.
fd := append([]int(nil), attr.Files...) fd := make([]int, len(attr.Files))
for i, ufd := range attr.Files {
fd[i] = int(ufd)
}
if envv != nil { if envv != nil {
clearenv = RFCENVG clearenv = RFCENVG
...@@ -340,7 +343,7 @@ type envItem struct { ...@@ -340,7 +343,7 @@ type envItem struct {
type ProcAttr struct { type ProcAttr struct {
Dir string // Current working directory. Dir string // Current working directory.
Env []string // Environment. Env []string // Environment.
Files []int // File descriptors. Files []uintptr // File descriptors.
Sys *SysProcAttr Sys *SysProcAttr
} }
...@@ -423,7 +426,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) ...@@ -423,7 +426,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
for _, fd := range openFds { for _, fd := range openFds {
isReserved := false isReserved := false
for _, reservedFd := range attr.Files { for _, reservedFd := range attr.Files {
if fd == reservedFd { if fd == int(reservedFd) {
isReserved = true isReserved = true
break break
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment