Download this file
| 1 | // Package pause holds every process of a step's sandbox stopped while the |
| 2 | // runner reads the sandbox's workspace (spec §3, "What it renders"; plan |
| 3 | // task 9). |
| 4 | // |
| 5 | // The pause is signals only: SIGSTOP to every descendant of the sandbox's |
| 6 | // first process, rescanning /proc until each one reads stopped, and |
| 7 | // SIGCONT to all of them on every way out. No cgroup is frozen: freezing a |
| 8 | // slice systemd spawns into once stalled PID 1. |
| 9 | package pause |
| 10 | |
| 11 | import ( |
| 12 | "errors" |
| 13 | "time" |
| 14 | ) |
| 15 | |
| 16 | // Bound is the longest a sandbox stays paused: stopping it and the work |
| 17 | // done inside the pause together (spec §3: "at most 10 seconds"). |
| 18 | const Bound = 10 * time.Second |
| 19 | |
| 20 | // Process is a sandbox's first process as containment recorded it when it |
| 21 | // started: its host pid, its start time in clock ticks (field 22 of |
| 22 | // /proc/<pid>/stat) and its pid namespace link ("pid:[...]"; "" skips |
| 23 | // that check). |
| 24 | type Process struct { |
| 25 | PID int |
| 26 | StartTicks uint64 |
| 27 | Namespace string |
| 28 | } |
| 29 | |
| 30 | var ( |
| 31 | // ErrBusy: the sandbox could not be held stopped within the bound, or |
| 32 | // the work inside the pause ran past it. Everything is resumed. |
| 33 | ErrBusy = errors.New("sandbox could not be paused in time") |
| 34 | // ErrGone: the recorded first process is no longer the one running |
| 35 | // at that pid (it exited, or the pid was reused). Nothing is signalled. |
| 36 | ErrGone = errors.New("sandbox process is gone") |
| 37 | // ErrUnsupported: this system has no pause (only Linux does). |
| 38 | ErrUnsupported = errors.New("pausing a sandbox is not supported on this system") |
| 39 | ) |
| 40 | |