ablfs-more
trunk
Last change
on this file since 249d4ad was 249d4ad, checked in by Pierre Labastie <pierre.labastie@…>, 12 months ago |
Fix (again) the run-in-cgroup.sh script
When using "sh << EOF", what is between this line and EOF runs
with no attached terminal. But we need a terminal for running the
build. So we have to use "sh -c ". But then nesting of double
quotes, $, etc is too complicated. So run as root, and become back
user only when exec'ing. For some reason $@ does not work, so use
a variable set to $@.
|
-
Property mode
set to
100755
|
File size:
1.1 KB
|
Rev | Line | |
---|
[8e9343b] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
| 3 | if [ -z "$CPUSPEC" ] || [ "$#" -lt 1 ]; then
|
---|
| 4 | echo "usage: CPUSPEC=... $0 command"
|
---|
| 5 | exit 1
|
---|
| 6 | fi
|
---|
| 7 |
|
---|
[249d4ad] | 8 | ARGS="$@"
|
---|
| 9 |
|
---|
[8e9343b] | 10 | set +e
|
---|
| 11 |
|
---|
[cff36a7] | 12 | if type systemd-run >/dev/null 2>&1 ; then # systemd
|
---|
| 13 | sudo systemd-run -G --pty -d --uid=$(whoami) \
|
---|
| 14 | -p AllowedCPUs="$CPUSPEC" \
|
---|
| 15 | --slice "user-$(whoami).slice" \
|
---|
| 16 | "$@"
|
---|
| 17 | elif type loginctl >/dev/null 2>&1 ; then #elogind
|
---|
| 18 | sudo mkdir /sys/fs/cgroup/jhalfs
|
---|
| 19 | sudo sh -c "echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control"
|
---|
| 20 | (
|
---|
| 21 | sudo sh -c "echo $BASHPID > /sys/fs/cgroup/jhalfs/cgroup.procs"
|
---|
[249d4ad] | 22 | sudo sh -c "
|
---|
[cff36a7] | 23 | SESS_CGROUP=/sys/fs/cgroup/\$XDG_SESSION_ID
|
---|
[249d4ad] | 24 | echo $CPUSPEC > \$SESS_CGROUP/cpuset.cpus
|
---|
| 25 | ( echo \$BASHPID > \$SESS_CGROUP/cgroup.procs &&
|
---|
| 26 | exec sudo -u $(whoami) $ARGS )"
|
---|
[cff36a7] | 27 | )
|
---|
| 28 | sudo rmdir /sys/fs/cgroup/jhalfs
|
---|
| 29 | else # no session manager
|
---|
| 30 | sudo mkdir /sys/fs/cgroup/jhalfs
|
---|
| 31 | sudo sh -c "echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control"
|
---|
| 32 | sudo sh -c "echo \"$CPUSPEC\" > /sys/fs/cgroup/jhalfs/cpuset.cpus"
|
---|
| 33 | (sudo sh -c "echo $BASHPID > /sys/fs/cgroup/jhalfs/cgroup.procs" &&
|
---|
| 34 | exec "$@")
|
---|
| 35 | sudo rmdir /sys/fs/cgroup/jhalfs
|
---|
[8e9343b] | 36 | fi
|
---|
Note:
See
TracBrowser
for help on using the repository browser.