From 1acf68535aff908bcf737f9248af2e17b758235a Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 25 Feb 2016 12:59:34 -0800 Subject: [PATCH] Refactor process.go for platform specific Signed-off-by: John Howard --- runtime/process.go | 22 ---------------------- runtime/process_linux.go | 27 +++++++++++++++++++++++++++ runtime/process_windows.go | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 runtime/process_linux.go create mode 100644 runtime/process_windows.go diff --git a/runtime/process.go b/runtime/process.go index 3aa5654..a877146 100644 --- a/runtime/process.go +++ b/runtime/process.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" "strconv" - "syscall" "time" "github.com/opencontainers/specs" @@ -122,22 +121,6 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro return p, nil } -func getExitPipe(path string) (*os.File, error) { - if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) { - return nil, err - } - // add NONBLOCK in case the other side has already closed or else - // this function would never return - return os.OpenFile(path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0) -} - -func getControlPipe(path string) (*os.File, error) { - if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) { - return nil, err - } - return os.OpenFile(path, syscall.O_RDWR|syscall.O_NONBLOCK, 0) -} - type process struct { root string id string @@ -190,11 +173,6 @@ func (p *process) ExitStatus() (int, error) { return strconv.Atoi(string(data)) } -// Signal sends the provided signal to the process -func (p *process) Signal(s os.Signal) error { - return syscall.Kill(p.pid, s.(syscall.Signal)) -} - func (p *process) Spec() specs.Process { return p.spec } diff --git a/runtime/process_linux.go b/runtime/process_linux.go new file mode 100644 index 0000000..82e4940 --- /dev/null +++ b/runtime/process_linux.go @@ -0,0 +1,27 @@ +package runtime + +import ( + "os" + "syscall" +) + +func getExitPipe(path string) (*os.File, error) { + if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) { + return nil, err + } + // add NONBLOCK in case the other side has already closed or else + // this function would never return + return os.OpenFile(path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0) +} + +func getControlPipe(path string) (*os.File, error) { + if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) { + return nil, err + } + return os.OpenFile(path, syscall.O_RDWR|syscall.O_NONBLOCK, 0) +} + +// Signal sends the provided signal to the process +func (p *process) Signal(s os.Signal) error { + return syscall.Kill(p.pid, s.(syscall.Signal)) +} diff --git a/runtime/process_windows.go b/runtime/process_windows.go new file mode 100644 index 0000000..bbeea5f --- /dev/null +++ b/runtime/process_windows.go @@ -0,0 +1,19 @@ +package runtime + +import "os" + +// TODO Windows: Linux uses syscalls which don't map to Windows. Needs alternate mechanism +func getExitPipe(path string) (*os.File, error) { + return nil, nil +} + +// TODO Windows: Linux uses syscalls which don't map to Windows. Needs alternate mechanism +func getControlPipe(path string) (*os.File, error) { + return nil, nil +} + +// TODO Windows. Windows does not support signals. Need alternate mechanism +// Signal sends the provided signal to the process +func (p *process) Signal(s os.Signal) error { + return nil +}