]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: remove the Signal type on Plan 9
authorAnthony Martin <ality@pbrane.org>
Fri, 4 May 2012 10:44:41 +0000 (03:44 -0700)
committerAnthony Martin <ality@pbrane.org>
Fri, 4 May 2012 10:44:41 +0000 (03:44 -0700)
Instead use a new type, "Note", whose underlying
type is just a string.  This change allows us to
remove the exported os.Plan9Note type.

R=bradfitz, seed, rsc
CC=golang-dev
https://golang.org/cl/6015046

src/pkg/os/exec.go
src/pkg/os/exec_plan9.go
src/pkg/os/exec_posix.go
src/pkg/syscall/syscall_plan9.go
src/pkg/syscall/zerrors_plan9_386.go

index 531b87ca55671a179e20a43f04af36899316fbda..eb6a4f825a1db3cf5b52e0d41e0e956f50a8ccbc 100644 (file)
@@ -54,14 +54,6 @@ type Signal interface {
        Signal() // to distinguish from other Stringers
 }
 
-// The only signal values guaranteed to be present on all systems
-// are Interrupt (send the process an interrupt) and
-// Kill (force the process to exit).
-var (
-       Interrupt Signal = syscall.SIGINT
-       Kill      Signal = syscall.SIGKILL
-)
-
 // Getpid returns the process id of the caller.
 func Getpid() int { return syscall.Getpid() }
 
index 41cc8c26f4ce7efd505887e606570f91b235c300..ca2dfbf6bc3fb68dd2255dcfade07219fa86c018 100644 (file)
@@ -11,6 +11,14 @@ import (
        "time"
 )
 
+// The only signal values guaranteed to be present on all systems
+// are Interrupt (send the process an interrupt) and Kill (force
+// the process to exit).
+var (
+       Interrupt Signal = syscall.Note("interrupt")
+       Kill      Signal = syscall.Note("kill")
+)
+
 func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
        sysattr := &syscall.ProcAttr{
                Dir: attr.Dir,
@@ -30,35 +38,35 @@ 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) writeProcFile(file string, data string) error {
+       f, e := OpenFile("/proc/"+itoa(p.Pid)+"/"+file, O_WRONLY, 0)
+       if e != nil {
+               return e
+       }
+       defer f.Close()
+       _, e = f.Write([]byte(data))
+       return e
 }
 
 func (p *Process) signal(sig Signal) error {
        if p.done {
                return errors.New("os: process already finished")
        }
-
-       f, e := OpenFile("/proc/"+itoa(p.Pid)+"/note", O_WRONLY, 0)
-       if e != nil {
+       if sig == Kill {
+               // Special-case the kill signal since it doesn't use /proc/$pid/note.
+               return p.Kill()
+       }
+       if e := p.writeProcFile("note", sig.String()); e != nil {
                return NewSyscallError("signal", e)
        }
-       defer f.Close()
-       _, e = f.Write([]byte(sig.String()))
-       return e
+       return nil
 }
 
 func (p *Process) kill() error {
-       f, e := OpenFile("/proc/"+itoa(p.Pid)+"/ctl", O_WRONLY, 0)
-       if e != nil {
+       if e := p.writeProcFile("ctl", "kill"); e != nil {
                return NewSyscallError("kill", e)
        }
-       defer f.Close()
-       _, e = f.Write([]byte("kill"))
-       return e
+       return nil
 }
 
 func (p *Process) wait() (ps *ProcessState, err error) {
index 70351cfb313144951e30007343d2e4fa1dcaa518..2feec480d72a864def176e8d31a7215723b4befa 100644 (file)
@@ -10,6 +10,14 @@ import (
        "syscall"
 )
 
+// The only signal values guaranteed to be present on all systems
+// are Interrupt (send the process an interrupt) and Kill (force
+// the process to exit).
+var (
+       Interrupt Signal = syscall.SIGINT
+       Kill      Signal = syscall.SIGKILL
+)
+
 func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
        // Double-check existence of the directory we want
        // to chdir into.  We can make the error clearer this way.
index c1f45f3a2c0477c1d0dd6f22e578add3387ed6bc..eab4cdae41d9358ef9d8eb6c475c92d608f1a886 100644 (file)
@@ -23,6 +23,16 @@ func (e ErrorString) Error() string { return string(e) }
 // NewError converts s to an ErrorString, which satisfies the Error interface.
 func NewError(s string) error { return ErrorString(s) }
 
+// A Note is a string describing a process note.
+// It implements the os.Signal interface.
+type Note string
+
+func (n Note) Signal() {}
+
+func (n Note) String() string {
+       return string(n)
+}
+
 var (
        Stdin  = 0
        Stdout = 1
@@ -322,14 +332,6 @@ func Getgroups() (gids []int, err error) {
        return make([]int, 0), nil
 }
 
-type Signal int
-
-func (s Signal) Signal() {}
-
-func (s Signal) String() string {
-       return ""
-}
-
 //sys  Dup(oldfd int, newfd int) (fd int, err error)
 //sys  Open(path string, mode int) (fd int, err error)
 //sys  Create(path string, mode int, perm uint32) (fd int, err error)
index e7c993c0f1a9531ccbc32d78fab50d814652eabf..3d62508d397b9590280ef948dd5dc6accdfd1a50 100644 (file)
@@ -24,9 +24,6 @@ const (
        S_IFREG  = 0x8000
        S_IFLNK  = 0xa000
        S_IFSOCK = 0xc000
-
-       SIGINT  = Signal(0x2)
-       SIGKILL = Signal(0x9)
 )
 
 // Errors