From 89c644e7178abc4abf51e4d1c82222ec18f9878a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20St=C3=BChrk?= Date: Mon, 15 Mar 2021 01:13:19 +0100 Subject: [PATCH] Use machinectl shell instead of su That way it's a real session and systemd is aware of it, so for example user units get started automatically. Fixes #18 --- syschdemd.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/syschdemd.sh b/syschdemd.sh index bf94ddad..1e305d5f 100644 --- a/syschdemd.sh +++ b/syschdemd.sh @@ -20,7 +20,24 @@ if [ ! -e "/run/systemd.pid" ]; then LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive \ @daemonize@/bin/daemonize /run/current-system/sw/bin/unshare -fp --mount-proc systemd /run/current-system/sw/bin/pgrep -xf systemd > /run/systemd.pid + + # Wait for systemd to start + status=1 + while [[ $status -gt 0 ]]; do + $sw/sleep 1 + status=0 + $sw/nsenter -t $(< /run/systemd.pid) -p -m -- \ + $sw/systemctl is-system-running -q --wait 2>/dev/null \ + || status=$? + done fi userShell=$($sw/getent passwd @defaultUser@ | $sw/cut -d: -f7) -exec $sw/nsenter -t $(< /run/systemd.pid) -p -m --wd="$PWD" -- @wrapperDir@/su -s $userShell @defaultUser@ "$@" +if [[ $# -gt 0 ]]; then + # wsl seems to prefix with "-c" + shift + cmd="$@" +else + cmd="$userShell" +fi +exec $sw/nsenter -t $(< /run/systemd.pid) -p -m -- $sw/machinectl -q --uid=@defaultUser@ shell .host /bin/sh -c "cd \"$PWD\"; exec $cmd"