From 839d972e95d28f7a7ec00ffb9519126094ddfdeb Mon Sep 17 00:00:00 2001 From: Joe Groocock Date: Mon, 21 Mar 2022 21:46:28 +0000 Subject: [PATCH] systemd-run-i3: Add ExitType=cgroup to user units systemd v250 added ExitType= which allows systemd to wait for all processes in the cgroup to exit before terminating the unit, instead of only the main pid. This has many uses, but for desktop applications in particular it allows self-restarting (forking) applications to correctly fork/restart and other background processes that may have been spawned to continue when their forked parent inevitably exits first (like ssh processes inside terminals). Signed-off-by: Joe Groocock --- scripts/systemd-run-i3 | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/systemd-run-i3 b/scripts/systemd-run-i3 index 1b74d7a..6b8a4d3 100755 --- a/scripts/systemd-run-i3 +++ b/scripts/systemd-run-i3 @@ -1,5 +1,6 @@ #!/bin/bash -e +slice=app rand=$(tr -dc 'a-f0-9' < /dev/urandom | head -c 8) args=() @@ -16,14 +17,11 @@ do case "$opt" in done shift $((OPTIND-1)) -if [ -z "$slice" ]; then - slice=app -fi - exec systemd-run \ --user \ --collect \ --slice="$slice" \ --unit="$slice-$1-$rand" \ --property=BindsTo=graphical-session.target \ - ${args[@]} -- "$@" + --property=ExitType=cgroup \ + "${args[@]}" -- "$@"