X Tutup
Skip to content

Commit ab74e7b

Browse files
committed
Merge pull request adamlaska#112 from jhowardmsft/processsyscalls
Refactor process.go for platform specific
2 parents 2644a7d + 1acf685 commit ab74e7b

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

runtime/process.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"os"
99
"path/filepath"
1010
"strconv"
11-
"syscall"
1211
"time"
1312

1413
"github.com/opencontainers/specs"
@@ -122,22 +121,6 @@ func loadProcess(root, id string, c *container, s *ProcessState) (*process, erro
122121
return p, nil
123122
}
124123

125-
func getExitPipe(path string) (*os.File, error) {
126-
if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
127-
return nil, err
128-
}
129-
// add NONBLOCK in case the other side has already closed or else
130-
// this function would never return
131-
return os.OpenFile(path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
132-
}
133-
134-
func getControlPipe(path string) (*os.File, error) {
135-
if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
136-
return nil, err
137-
}
138-
return os.OpenFile(path, syscall.O_RDWR|syscall.O_NONBLOCK, 0)
139-
}
140-
141124
type process struct {
142125
root string
143126
id string
@@ -190,11 +173,6 @@ func (p *process) ExitStatus() (int, error) {
190173
return strconv.Atoi(string(data))
191174
}
192175

193-
// Signal sends the provided signal to the process
194-
func (p *process) Signal(s os.Signal) error {
195-
return syscall.Kill(p.pid, s.(syscall.Signal))
196-
}
197-
198176
func (p *process) Spec() specs.Process {
199177
return p.spec
200178
}

runtime/process_linux.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package runtime
2+
3+
import (
4+
"os"
5+
"syscall"
6+
)
7+
8+
func getExitPipe(path string) (*os.File, error) {
9+
if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
10+
return nil, err
11+
}
12+
// add NONBLOCK in case the other side has already closed or else
13+
// this function would never return
14+
return os.OpenFile(path, syscall.O_RDONLY|syscall.O_NONBLOCK, 0)
15+
}
16+
17+
func getControlPipe(path string) (*os.File, error) {
18+
if err := syscall.Mkfifo(path, 0755); err != nil && !os.IsExist(err) {
19+
return nil, err
20+
}
21+
return os.OpenFile(path, syscall.O_RDWR|syscall.O_NONBLOCK, 0)
22+
}
23+
24+
// Signal sends the provided signal to the process
25+
func (p *process) Signal(s os.Signal) error {
26+
return syscall.Kill(p.pid, s.(syscall.Signal))
27+
}

runtime/process_windows.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package runtime
2+
3+
import "os"
4+
5+
// TODO Windows: Linux uses syscalls which don't map to Windows. Needs alternate mechanism
6+
func getExitPipe(path string) (*os.File, error) {
7+
return nil, nil
8+
}
9+
10+
// TODO Windows: Linux uses syscalls which don't map to Windows. Needs alternate mechanism
11+
func getControlPipe(path string) (*os.File, error) {
12+
return nil, nil
13+
}
14+
15+
// TODO Windows. Windows does not support signals. Need alternate mechanism
16+
// Signal sends the provided signal to the process
17+
func (p *process) Signal(s os.Signal) error {
18+
return nil
19+
}

0 commit comments

Comments
 (0)
X Tutup