Commit fe5005f7 authored by Anthony Martin's avatar Anthony Martin

syscall: remove the Signal type on Plan 9

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
parent 2bed8a7e
...@@ -54,14 +54,6 @@ type Signal interface { ...@@ -54,14 +54,6 @@ type Signal interface {
Signal() // to distinguish from other Stringers 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. // Getpid returns the process id of the caller.
func Getpid() int { return syscall.Getpid() } func Getpid() int { return syscall.Getpid() }
......
...@@ -11,6 +11,14 @@ import ( ...@@ -11,6 +11,14 @@ import (
"time" "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) { func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
sysattr := &syscall.ProcAttr{ sysattr := &syscall.ProcAttr{
Dir: attr.Dir, Dir: attr.Dir,
...@@ -30,35 +38,35 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e ...@@ -30,35 +38,35 @@ func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err e
return newProcess(pid, h), nil return newProcess(pid, h), nil
} }
// Plan9Note implements the Signal interface on Plan 9. func (p *Process) writeProcFile(file string, data string) error {
type Plan9Note string f, e := OpenFile("/proc/"+itoa(p.Pid)+"/"+file, O_WRONLY, 0)
if e != nil {
func (note Plan9Note) String() string { return e
return string(note) }
defer f.Close()
_, e = f.Write([]byte(data))
return e
} }
func (p *Process) signal(sig Signal) error { func (p *Process) signal(sig Signal) error {
if p.done { if p.done {
return errors.New("os: process already finished") return errors.New("os: process already finished")
} }
if sig == Kill {
f, e := OpenFile("/proc/"+itoa(p.Pid)+"/note", O_WRONLY, 0) // Special-case the kill signal since it doesn't use /proc/$pid/note.
if e != nil { return p.Kill()
}
if e := p.writeProcFile("note", sig.String()); e != nil {
return NewSyscallError("signal", e) return NewSyscallError("signal", e)
} }
defer f.Close() return nil
_, e = f.Write([]byte(sig.String()))
return e
} }
func (p *Process) kill() error { func (p *Process) kill() error {
f, e := OpenFile("/proc/"+itoa(p.Pid)+"/ctl", O_WRONLY, 0) if e := p.writeProcFile("ctl", "kill"); e != nil {
if e != nil {
return NewSyscallError("kill", e) return NewSyscallError("kill", e)
} }
defer f.Close() return nil
_, e = f.Write([]byte("kill"))
return e
} }
func (p *Process) wait() (ps *ProcessState, err error) { func (p *Process) wait() (ps *ProcessState, err error) {
......
...@@ -10,6 +10,14 @@ import ( ...@@ -10,6 +10,14 @@ import (
"syscall" "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) { func startProcess(name string, argv []string, attr *ProcAttr) (p *Process, err error) {
// Double-check existence of the directory we want // Double-check existence of the directory we want
// to chdir into. We can make the error clearer this way. // to chdir into. We can make the error clearer this way.
......
...@@ -23,6 +23,16 @@ func (e ErrorString) Error() string { return string(e) } ...@@ -23,6 +23,16 @@ func (e ErrorString) Error() string { return string(e) }
// NewError converts s to an ErrorString, which satisfies the Error interface. // NewError converts s to an ErrorString, which satisfies the Error interface.
func NewError(s string) error { return ErrorString(s) } 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 ( var (
Stdin = 0 Stdin = 0
Stdout = 1 Stdout = 1
...@@ -322,14 +332,6 @@ func Getgroups() (gids []int, err error) { ...@@ -322,14 +332,6 @@ func Getgroups() (gids []int, err error) {
return make([]int, 0), nil 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 Dup(oldfd int, newfd int) (fd int, err error)
//sys Open(path string, mode 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) //sys Create(path string, mode int, perm uint32) (fd int, err error)
......
...@@ -24,9 +24,6 @@ const ( ...@@ -24,9 +24,6 @@ const (
S_IFREG = 0x8000 S_IFREG = 0x8000
S_IFLNK = 0xa000 S_IFLNK = 0xa000
S_IFSOCK = 0xc000 S_IFSOCK = 0xc000
SIGINT = Signal(0x2)
SIGKILL = Signal(0x9)
) )
// Errors // Errors
......
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