-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakemore
executable file
·47 lines (37 loc) · 978 Bytes
/
makemore
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
#!/bin/bash
set -eu -o pipefail
rdfd=${2:-3}
wrfd=${3:-$(($rdfd+1))}
if [[ -z $1 ]]; then
echo >&2 "Usage: $0 <pid>"
exit 1
fi
exe="$(realpath -eq /proc/$1/exe)"
if [[ -z "$exe" ]]; then
echo >&2 "error: no such pid"
exit 1
fi
exe_expect="$(realpath "$(which make)")"
if [[ "$exe" != "$exe_expect" ]]; then
echo >&2 "error: pid $1 is $exe, not $exe_expect"
exit 1
fi
rdpipe="$(readlink /proc/$1/fd/$rdfd)"
if [[ "$rdpipe" != pipe:* ]]; then
echo >&2 "error: fd $rdfd is not a pipe; is this a parallel make?"
exit 1
fi
wrpipe="$(readlink /proc/$1/fd/$wrfd)"
if [[ "$wrpipe" != pipe:* ]]; then
echo >&2 "error: fd $wrfd is not a pipe; is this a parallel make?"
exit 1
fi
if [[ "$rdpipe" != "$wrpipe" ]]; then
echo >&2 "error: fd $rdfd and fd $wrfd are not the same pipe; is this a parallel make?"
exit 1
fi
if ! echo -n '+' > /proc/$1/fd/$wrfd; then
exit 1
fi
# TODO: show actual process name
echo >&2 "Successfully injected a jobserver token into make $1"