OSDN Git Service

Update Go library to r60.
[pf3gnuchains/gcc-fork.git] / libgo / go / os / exec_plan9.go
index 11874ab..6f0722a 100644 (file)
@@ -15,6 +15,7 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err E
        sysattr := &syscall.ProcAttr{
                Dir: attr.Dir,
                Env: attr.Env,
+               Sys: attr.Sys,
        }
 
        // Create array of integer (system) fds.
@@ -37,6 +38,38 @@ func StartProcess(name string, argv []string, attr *ProcAttr) (p *Process, err E
        return newProcess(pid, h), nil
 }
 
+// Plan9Note implements the Signal interface on Plan 9.
+type Plan9Note string
+
+func (note Plan9Note) String() string {
+       return string(note)
+}
+
+func (p *Process) Signal(sig Signal) Error {
+       if p.done {
+               return NewError("os: process already finished")
+       }
+
+       f, e := OpenFile("/proc/"+itoa(p.Pid)+"/note", O_WRONLY, 0)
+       if iserror(e) {
+               return NewSyscallError("signal", e)
+       }
+       defer f.Close()
+       _, e = f.Write([]byte(sig.String()))
+       return e
+}
+
+// Kill causes the Process to exit immediately.
+func (p *Process) Kill() Error {
+       f, e := OpenFile("/proc/"+itoa(p.Pid)+"/ctl", O_WRONLY, 0)
+       if iserror(e) {
+               return NewSyscallError("kill", e)
+       }
+       defer f.Close()
+       _, e = f.Write([]byte("kill"))
+       return e
+}
+
 // Exec replaces the current process with an execution of the
 // named binary, with arguments argv and environment envv.
 // If successful, Exec never returns.  If it fails, it returns an Error.
@@ -51,7 +84,9 @@ func Exec(name string, argv []string, envv []string) Error {
 }
 
 // Waitmsg stores the information about an exited process as reported by Wait.
-type Waitmsg syscall.Waitmsg
+type Waitmsg struct {
+       syscall.Waitmsg
+}
 
 // Wait waits for the Process to exit or stop, and then returns a
 // Waitmsg describing its status and an Error, if any. The options
@@ -71,11 +106,12 @@ func (p *Process) Wait(options int) (w *Waitmsg, err Error) {
                }
 
                if waitmsg.Pid == p.Pid {
+                       p.done = true
                        break
                }
        }
 
-       return (*Waitmsg)(&waitmsg), nil
+       return &Waitmsg{waitmsg}, nil
 }
 
 // Wait waits for process pid to exit or stop, and then returns a
@@ -109,6 +145,9 @@ func FindProcess(pid int) (p *Process, err Error) {
        return newProcess(pid, 0), nil
 }
 
-func (w Waitmsg) String() string {
+func (w *Waitmsg) String() string {
+       if w == nil {
+               return "<nil>"
+       }
        return "exit status: " + w.Msg
 }