-
Notifications
You must be signed in to change notification settings - Fork 0
/
jail.go
54 lines (41 loc) · 775 Bytes
/
jail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package jail
import (
"os/exec"
"strconv"
"syscall"
"time"
)
type Cell struct {
Dir string
}
type Cmd struct {
*exec.Cmd
Limits Resources
Usages Resources
}
type Resources struct {
Cpu time.Duration
Memory uint64
}
type ExitError syscall.WaitStatus
func (e ExitError) Error() string {
w := syscall.WaitStatus(e)
s := ""
switch {
case w.Exited():
s = "exit status " + strconv.Itoa(w.ExitStatus())
case w.Signaled():
s = "signal: " + w.Signal().String()
case w.Stopped():
s = "stop signal: " + w.StopSignal().String()
if w.StopSignal() == syscall.SIGTRAP && w.TrapCause() != 0 {
s += " (trap " + strconv.Itoa(w.TrapCause()) + ")"
}
case w.Continued():
s = "continued"
}
if w.CoreDump() {
s += " (core dumped)"
}
return s
}