Merge pull request #112 from jhowardmsft/processsyscalls
Refactor process.go for platform specific
This commit is contained in:
commit
ab74e7b2aa
3 changed files with 46 additions and 22 deletions
|
@ -8,7 +8,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/opencontainers/specs"
|
"github.com/opencontainers/specs"
|
||||||
|
@ -122,22 +121,6 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro
|
||||||
return p, nil
|
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 {
|
type process struct {
|
||||||
root string
|
root string
|
||||||
id string
|
id string
|
||||||
|
@ -190,11 +173,6 @@ func (p *process) ExitStatus() (int, error) {
|
||||||
return strconv.Atoi(string(data))
|
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 {
|
func (p *process) Spec() specs.Process {
|
||||||
return p.spec
|
return p.spec
|
||||||
}
|
}
|
||||||
|
|
27
runtime/process_linux.go
Normal file
27
runtime/process_linux.go
Normal file
|
@ -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))
|
||||||
|
}
|
19
runtime/process_windows.go
Normal file
19
runtime/process_windows.go
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue