main 33a243c

lock.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package sandbox
4
5import (
6	"fmt"
7	"os"
8	"path/filepath"
9
10	"golang.org/x/sys/unix"
11)
12
13// HostLock is the host-wide single-instance lock. Reaping removes every process,
14// device, firewall rule and Docker object labelled as the runner's own, so it is
15// only safe when no other runner of the same host is alive: the lock lives at a
16// fixed path of the host (DefaultLockFile), not in a state directory, which two
17// runners could choose differently, and it is taken by both isolation modes.
18type HostLock struct{ f *os.File }
19
20// AcquireHostLock takes the lock at path (the default when empty) without
21// waiting. The kernel releases it when the process dies, so a crash never leaves
22// it stuck.
23func AcquireHostLock(path string) (*HostLock, error) {
24	if path == "" {
25		path = DefaultLockFile
26	}
27	if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
28		return nil, fmt.Errorf("host lock %s: %w (set %s for another path)", path, err, EnvLockFile)
29	}
30	f, err := os.OpenFile(path, os.O_CREATE|os.O_RDWR, 0o600)
31	if err != nil {
32		return nil, fmt.Errorf("host lock %s: %w (set %s for another path)", path, err, EnvLockFile)
33	}
34	if err := unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB); err != nil {
35		_ = f.Close()
36		return nil, fmt.Errorf("another ermite-runner is running on this host (lock %s): only one runner per host is supported, because reaping removes everything the runner owns: %w", path, err)
37	}
38	return &HostLock{f: f}, nil
39}
40
41// Release drops the lock; releasing twice is fine.
42func (l *HostLock) Release() error {
43	if l == nil || l.f == nil {
44		return nil
45	}
46	err := l.f.Close()
47	l.f = nil
48	return err
49}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 4

Tags 11

↑↓ moveenter openesc close