On 23.05.2024 09:18, Nop wrote:
From my terminal emulator that I start by clicking in the menu:
echo "kitty: $(pidof kitty) - $INVOCATION_ID" && echo "plasmashell:
$(pidof plasmashell) - $(sudo strings /proc/$(pidof
plasmashell)/environ | grep INVOCATION_ID)"
kitty: 4441 - e3ec804609094a139948a1887c90ac7a
plasmashell: 857 - INVOCATION_ID=e3ec804609094a139948a1887c90ac7a
But indeed, looking at systemd-cgls, it is in its own scope:
-.slice
├─user.slice
│ └─user-1000.slice
│ ├─user@1000.service …
│ │ ├─session.slice
│ │ │ ├─plasma-plasmashell.service
│ │ │ │ └─857 /usr/bin/plasmashell --no-respawn
│ │ ├─app.slice
│ │ │ ├─app-kitty-96877b039d10481298f59807a062a5c5.scope
│ │ │ │ ├─4441 /usr/bin/kitty
│ │ │ │ ├─4450 /bin/zsh
│ │ │ │ ├─9810 systemd-cgls
│ │ │ ├─app-steam-68615b37d4554dc8bcdce0bb903517bb.scope
│ │ │ │ ├─2777 bash /home/ctxnop/.local/share/Steam/steam.sh
│ │ │ └─app-chromium-185faea96ff5421b8ecfb0753298c32b.scope
│ │ │ ├─2266 /usr/lib/chromium/chromium
│ │ │ ├─2269 /usr/lib/chromium/chrome_crashpad_handler --monitor-self
Did not know about this, thank you. But it feels even more weird now:
for P in 857 4441 4450 2777 2269; do echo -n "$P: " && tr '\0' '\n' <
/proc/$P/environ | grep INV; done
857: INVOCATION_ID=e3ec804609094a139948a1887c90ac7a
4441: INVOCATION_ID=e3ec804609094a139948a1887c90ac7a
4450: INVOCATION_ID=e3ec804609094a139948a1887c90ac7a
2777: INVOCATION_ID=e3ec804609094a139948a1887c90ac7a
2269: INVOCATION_ID=e3ec804609094a139948a1887c90ac7a
Looking here on GNOME I confirm the same behavior. Unless program
explicitly handles INVOCATION_ID (or, I assume, any other environment
variable set by systemd) they are inherited. I am "lucky" in that
gnome-terminal does not propagate it, so I can use INVOCATION_ID to
distinguish between being called from interactive shell and invoked as
service. But I was about to add some launcher icons and they would
certainly have the same issue as you described.
But everything started by gnome-shell inherits gnome-shell
INVOCATION_ID. Everything started by gnome-session-binary inherits
gnome-session-binary INVOCATION_ID. Etc ...
All that I am interested in is how I can distinguish between "it runs as
part of interactive user session" or "it runs as part of systemd
service". I do not see any way to do it.
It was so simple initially until someone got brilliant idea to misuse
systemd user instance for session management ...