[jhalfs] branch xry111/parallelism updated: Fix session management in run-in-cgroup.sh

"Git Owner" ([email protected] via alfs-discuss Mailing List) <[email protected]>
Newsgroups gmane.linux.lfs.automated
Message-ID <170014232064.25967.8808143075927230442@rivendell.linuxfromscratch.org>
This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch xry111/parallelism
in repository jhalfs.

The following commit(s) were added to refs/heads/xry111/parallelism by this push:
     new cff36a7  Fix session management in run-in-cgroup.sh
cff36a7 is described below

commit cff36a77ba586d41f2e62c1f5eadd7625621aad1
Author: Pierre Labastie <[email protected]>
AuthorDate: Thu Nov 16 14:37:58 2023 +0100

    Fix session management in run-in-cgroup.sh
    
    Still WIP but some progress...
    When moving a shell to a cgroup not associated with a session,
    then subsequent calls to pam_systemd or pam_elogind create
    a new session, and a new cgroup for that session, so that the
    cgroup of the calling process is not used (this is a problem
    with both systemd and elogind). For systemd, the problem can be
    solved by passing --slice <user slice> to systemd-run. For elogind,
    we need to first move the shell to a non session cgroup, then run
    sudo so that a new session is created, then pass the cpuset to that
    session's cgroup. Hopefully, if neither systemd nor elgind is used,
    then the former solution should work (to be tested!!!).
---
 common/run-in-cgroup.sh | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/common/run-in-cgroup.sh b/common/run-in-cgroup.sh
index 9891d72..8794cd4 100755
--- a/common/run-in-cgroup.sh
+++ b/common/run-in-cgroup.sh
@@ -7,13 +7,29 @@ fi
 
 set +e
 
-if type systemd-run >/dev/null 2>&1 ; then
-	sudo systemd-run -G --pty -d --uid=$(whoami) -p AllowedCPUs="$CPUSPEC" "$@"
-else
-	sudo mkdir /sys/fs/cgroup/jhalfs
-	sudo sh -c "echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control"
-	sudo sh -c "echo \"$CPUSPEC\" > /sys/fs/cgroup/jhalfs/cpuset.cpus"
-	(sudo sh -c "echo $BASHPID > /sys/fs/cgroup/jhalfs/cgroup.procs" &&
-		exec "$@")
-	sudo rmdir /sys/fs/cgroup/jhalfs
+if type systemd-run >/dev/null 2>&1 ; then # systemd
+   sudo systemd-run -G --pty -d --uid=$(whoami)    \
+                    -p AllowedCPUs="$CPUSPEC"      \
+                    --slice "user-$(whoami).slice" \
+                    "$@"
+elif type loginctl >/dev/null 2>&1 ; then #elogind
+   sudo mkdir /sys/fs/cgroup/jhalfs
+   sudo sh -c "echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control"
+   (
+      sudo sh -c "echo $BASHPID > /sys/fs/cgroup/jhalfs/cgroup.procs"
+      sudo -u $(whoami) sh <<EOF
+         SESS_CGROUP=/sys/fs/cgroup/\$XDG_SESSION_ID
+         sudo sh -c "echo \\"$CPUSPEC\\" > \$SESS_CGROUP/cpuset.cpus"
+         (sudo sh -c "echo \$BASHPID > \$SESS_CGROUP/cgroup.procs" &&
+            exec $@)
+EOF
+   )
+   sudo rmdir /sys/fs/cgroup/jhalfs
+else # no session manager
+   sudo mkdir /sys/fs/cgroup/jhalfs
+   sudo sh -c "echo +cpuset > /sys/fs/cgroup/cgroup.subtree_control"
+   sudo sh -c "echo \"$CPUSPEC\" > /sys/fs/cgroup/jhalfs/cpuset.cpus"
+   (sudo sh -c "echo $BASHPID > /sys/fs/cgroup/jhalfs/cgroup.procs" &&
+      exec "$@")
+   sudo rmdir /sys/fs/cgroup/jhalfs
 fi

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

-- 
http://lists.linuxfromscratch.org/sympa/info/alfs-discuss
Unsubscribe: See the above information page
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.