Bug 432975

Summary: krunner starts applications with cwd "/" with init system other than systemd (openrc, runit, ...)
Product: [Plasma] krunner Reporter: Andreas Sturmlechner <asturm>
Component: generalAssignee: Alexander Lohnau <alexander.lohnau>
Status: CONFIRMED ---    
Severity: normal CC: holgersson, kde, kde, Martin, nate, o.freyermuth, pjfloyd, plasma-bugs
Priority: NOR    
Version: 5.20.5   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
See Also: https://bugs.gentoo.org/show_bug.cgi?id=767478
https://bugs.kde.org/show_bug.cgi?id=490469
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Andreas Sturmlechner 2021-02-15 15:46:51 UTC
krunner is starting applications with cwd "/" instead of "~", confirmed on several systems to be fixed after reverting 0e575a20. This is what I did for the Gentoo package.

See also downstream link.

Filing a seperate bug as requested in bug 416145#c49.

This is still reproducible in Plasma 5.21.0 and Frameworks 5.79.0.
Comment 1 Andreas Sturmlechner 2021-05-09 11:32:52 UTC
Just a quick status update that I need to continue to revert this in 5.21.5.
Comment 2 David Edmundson 2021-05-09 23:57:39 UTC
Please include output of:
qdbus org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.Environment


cat /proc/`pidof krunner`/environ  | tr '\0' '\n'
Comment 3 holgersson 2021-06-15 14:33:17 UTC
Hi,

it is not fixed in Gentoo in plasma-5.22.0 which does not apply the downstream patch. Another user tested the old downstream patch without success. I'll try again when plasma-5.22.1 is in our repos and report back.

Gentoo supports systemd and openrc as init systems. As I run openrc  the qdbus call fails with "Service 'org.freedesktop.systemd1' does not exist."

The environment variables you asked for:

MOZ_GMP_PATH=/usr/lib64/nsbrowser/plugins/gmp-gmpopenh264/system-installed
XDG_RUNTIME_DIR=/run/user/1000
QT_AUTO_SCREEN_SCALE_FACTOR=0
SESSION_MANAGER=local/pygoscelis:@/tmp/.ICE-unix/9865,unix/pygoscelis:/tmp/.ICE-unix/9865
MOTD_SHOWN=pam
XDG_SESSION_TYPE=tty
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-L0JTZDmtCp,guid=b95478657a5aeec41fd790f260c87641
XAUTHORITY=/home/holgersson/.Xauthority
USER=holgersson
ETCKEEPER_CONF_DIR=/etc/etckeeper
DBUS_STARTER_BUS_TYPE=session
SHLVL=2
GOPATH=/home/holgersson/Projekte/go/golib:/home/holgersson/Projekte/go/code
SHELL=/bin/zsh
KDE_APPLICATIONS_AS_SCOPE=1
SSH_ASKPASS=/usr/bin/ksshaskpass
INFOPATH=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.1.0/info:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.36.1/info:/usr/share/info
LC_MEASUREMENT=de_DE.UTF-8
LC_TIME=de_DE.UTF-8
LC_MONETARY=de_DE.UTF-8
WINDOWPATH=2
FLTK_DOCDIR=/usr/share/doc/fltk-1.3.5-r4/html
XDG_DATA_DIRS=/usr/local/share:/usr/share
XCURSOR_THEME=breeze_cursors
QT_SCREEN_SCALE_FACTORS=eDP-1=1;DP-1=1;HDMI-1=1;DP-2=1;HDMI-2=1;DP-2-1=1;DP-2-2=1;DP-2-3=1;
LANGUAGE=de
CONFIG_PROTECT_MASK=/etc/sandbox.d /etc/fonts/fonts.conf /etc/gentoo-release /etc/terminfo /etc/dconf /etc/ca-certificates.conf /etc/texmf/web2c /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/revdep-rebuild
LESS=-R -M --shift 5
KDE_FULL_SESSION=true
PWD=/home/holgersson
QT_API=pyqt5
MANPATH=/usr/share/gcc-data/x86_64-pc-linux-gnu/11.1.0/man:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.36.1/man:/usr/local/share/man:/usr/share/man:/usr/lib/rust/man:/usr/lib/llvm/12/share/man
HOME=/home/holgersson
GSETTINGS_BACKEND=dconf
GCC_SPECS=
DBUS_STARTER_ADDRESS=unix:abstract=/tmp/dbus-L0JTZDmtCp,guid=b95478657a5aeec41fd790f260c87641
DISPLAY=:0
LESSOPEN=|lesspipe %s
PAGER=/usr/bin/less
SSH_AUTH_SOCK=/tmp/ssh-XXXXXXsg7Ye7/agent.9754
LC_NUMERIC=de_DE.UTF-8
PATH=/bin:/usr/bin
GTK_USE_PORTAL=1
XDG_VTNR=2
HUSHLOGIN=FALSE
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.cfg=00;32:*.conf=00;32:*.diff=00;32:*.doc=00;32:*.ini=00;32:*.log=00;32:*.patch=00;32:*.pdf=00;32:*.ps=00;32:*.tex=00;32:*.txt=00;32:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
XDG_SESSION_ID=936
XDG_SEAT=seat0
MANPAGER=manpager
GTK_RC_FILES=/etc/gtk/gtkrc:/home/holgersson/.gtkrc:/home/holgersson/.config/gtkrc
XDG_SESSION_CLASS=user
PORTAGE_GPG_DIR=~/.gnupg
TERM=linux
EDITOR=/usr/bin/nvim
LANG=de_DE.UTF-8
LOGNAME=holgersson
XDG_CURRENT_DESKTOP=KDE
XCURSOR_SIZE=24
CONFIG_PROTECT=/usr/share/gnupg/qualified.txt /usr/share/config /usr/lib64/libreoffice/program/sofficerc
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/holgersson/.gtkrc-2.0:/home/holgersson/.config/gtkrc-2.0
KDE_SESSION_UID=1000
OLDPWD=/home/holgersson
MAIL=/var/mail/holgersson
SSH_AGENT_PID=9755
PASSWORD_STORE_CLIP_TIME=20
KDE_SESSION_VERSION=5
LC_COLLATE=de_DE.UTF-8
XDG_CONFIG_DIRS=/home/holgersson/.config/kdedefaults:/etc/xdg
SCIPY_PIL_IMAGE_VIEWER=display
Comment 4 Felix Tiede 2021-06-18 09:42:45 UTC
Hi,

it is also not fixed in plasma-5.22.1, which included the downstream patch.

I also use OpenRC over systemd, so I can't report the qdbus call.

My environment variables are:
XDG_RUNTIME_DIR=/run/user/1000
QT_AUTO_SCREEN_SCALE_FACTOR=0
SESSION_MANAGER=local/pip:@/tmp/.ICE-unix/8790,unix/pip:/tmp/.ICE-unix/8790
MOTD_SHOWN=pam
DISTCC_ENABLE_DISCREPANCY_EMAIL=
SGML_CATALOG_FILES=/etc/sgml/xml-docbook-4.4.cat:/etc/sgml/sgml-docbook-3.0.cat:/etc/sgml/dsssl-docbook-stylesheets.cat:/etc/sgml/xml-docbook-4.3.cat:/etc/sgml/sgml-docbook.cat:/etc/sgml/sgml-docbook-4.2.cat:/etc/sgml/sgml-docbook-3.1.cat:/etc/sgml/xml-docbook-4.1.2.cat:/etc/sgml/xml-docbook-4.2.cat:/etc/sgml/sgml-docbook-4.1.cat:/etc/sgml/sgml-docbook-4.0.cat:/etc/sgml/sgml-ent.cat:/etc/sgml/sgml-lite.cat:/etc/sgml/xml-docbook-4.5.cat:/etc/sgml/openjade-1.3.2.cat
XDG_SESSION_TYPE=x11
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-pP06cavdGy,guid=d469ed8c4536d781d7beb77e60cc67a7
XAUTHORITY=/home/felix/.Xauthority
USER=felix
DBUS_STARTER_BUS_TYPE=session
JDK_HOME=/home/felix/.gentoo/java-config-2/current-user-vm
SHLVL=0
XDG_SESSION_DESKTOP=KDE
KDE_APPLICATIONS_AS_SCOPE=1
SHELL=/bin/bash
SSH_ASKPASS=/usr/bin/ksshaskpass
INFOPATH=/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/info:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.35.2/info:/usr/share/info
QT_GRAPHICSSYSTEM=raster
DISTCC_SAVE_TEMPS=0
XDG_DATA_DIRS=/usr/local/share:/usr/share
ANT_HOME=/usr/share/ant
XCURSOR_THEME=Oxygen_White
KDE_FULL_SESSION=true
CONFIG_PROTECT_MASK=/etc/sandbox.d /etc/fonts/fonts.conf /etc/gentoo-release /etc/gconf /etc/terminfo /etc/dconf /etc/ca-certificates.conf /etc/texmf/web2c /etc/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/revdep-rebuild /var/spool/fax/etc/xferfaxlog
LESS=-R -M --shift 5
LV2_PATH=/usr/lib64/lv2
JAVA_HOME=/home/felix/.gentoo/java-config-2/current-user-vm
PWD=/home/felix
XSESSION=KDE-4
i18n=de_DE
PAM_KWALLET5_LOGIN=/run/user/1000/kwallet5.socket
GSETTINGS_BACKEND=dconf
MANPATH=/home/felix/.gentoo/java-config-2/current-user-vm/man:/usr/share/gcc-data/x86_64-pc-linux-gnu/10.3.0/man:/usr/share/binutils-data/x86_64-pc-linux-gnu/2.35.2/man:/etc/java-config-2/current-system-vm/man/:/usr/local/share/man:/usr/share/man:/usr/lib/rust/man:/usr/lib/llvm/11/share/man
HOME=/home/felix
GCC_SPECS=
DBUS_STARTER_ADDRESS=unix:abstract=/tmp/dbus-pP06cavdGy,guid=d469ed8c4536d781d7beb77e60cc67a7
OPENSSL_CONF=/home/felix/office/sslCA/openssl.cnf
JAVAC=/home/felix/.gentoo/java-config-2/current-user-vm/bin/javac
DISPLAY=:0
LESSOPEN=|lesspipe %s
PAGER=/usr/bin/less
SSH_AUTH_SOCK=/tmp/ssh-XXXXXX19pexJ/agent.8717
PATH=/home/felix/scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/lib/llvm/11/bin:/usr/games/bin:/var/spool/fax/bin:/home/felix/bin
XDG_VTNR=7
GTK_MODULES=canberra-gtk-module:appmenu-gtk-module
XDG_SESSION_ID=2
DISTCC_VERBOSE=0
XDG_SEAT=seat0
MANPAGER=manpager
GTK_RC_FILES=/etc/gtk/gtkrc:/home/felix/.gtkrc:/home/felix/.config/gtkrc
XDG_SESSION_CLASS=user
EDITOR=/usr/bin/vim
LANG=de_DE.utf8
LOGNAME=felix
DISTCC_SSH=
TEXINPUTS=/usr/lib64/ocaml/ocamldoc:
XCURSOR_SIZE=24
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
CONFIG_PROTECT=/usr/share/maven-bin-3.8/conf /usr/share/gnupg/qualified.txt /usr/share/config /var/spool/fax/etc /usr/lib64/fax /usr/lib64/libreoffice/program/sofficerc /usr/share/themes/oxygen-gtk/gtk-2.0
XDG_CURRENT_DESKTOP=KDE
DESKTOP_SESSION=/usr/share/xsessions/plasma
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/felix/.gtkrc-2.0:/home/felix/.config/gtkrc-2.0
KDE_SESSION_UID=1000
MAIL=/var/mail/felix
UBUNTU_MENUPROXY=1
OPENGL_PROFILE=xorg-x11
SSH_AGENT_PID=8718
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
DISTCC_FALLBACK=1
KDE_SESSION_VERSION=5
DISTCC_TCP_CORK=
UNCACHED_ERR_FD=
OPENCL_PROFILE=nvidia
XDG_CONFIG_DIRS=/home/felix/.config/kdedefaults:/etc/xdg
DCC_EMAILLOG_WHOM_TO_BLAME=
Comment 5 Felix Tiede 2021-06-25 19:27:23 UTC
It is still not fixed in Plasma-5.22.2, still same behavior.
Comment 6 Felix Tiede 2021-07-07 17:42:20 UTC
Behaviour is unchanged in plasma-5.22.3, no change so far.
Comment 7 Andreas Sturmlechner 2021-08-03 11:01:12 UTC
Felix, when there is going to be a commit tackling this bug, then it will likely be mentioned here.
Comment 8 Andreas Sturmlechner 2021-09-14 08:53:52 UTC
I am not in a position to continue reverting problematic changes related to this bug, so this will be a known defect with stable >=5.22.5 for non-systemd users going forward.
Comment 9 David Edmundson 2021-09-14 10:09:46 UTC
To the people who pasted environment variables above, where did you get them? 

Just typing env in a konsole?
Comment 10 Felix Tiede 2021-09-15 04:56:52 UTC
(In reply to David Edmundson from comment #9)
> To the people who pasted environment variables above, where did you get
> them? 
> 
> Just typing env in a konsole?

No, executing the command you listed in comment #2:

cat /proc/`pidof krunner`/environ  | tr '\0' '\n'
Comment 11 Martin Steigerwald 2023-02-14 15:34:06 UTC
Hi! What is the status of this bug?

I found:

…proc# ls -ld $(pidof krunner)/cwd
lrwxrwxrwx 1 USER USER 0 10. Feb 14:26 15116/cwd -> /
…proc# ls -ld $(pidof plasmashell)/cwd
lrwxrwxrwx 1 USER USER 0 10. Feb 14:27 9191/cwd -> /home/USER

on my system. However PWD and OLDPWD is set properly:

% cat /proc/`pidof krunner`/environ  | tr '\0' '\n' | grep PWD
PWD=/home/USER
OLDPWD=/home/USER

This is with Devuan Ceres with Runit and Elogind. Using X11 still. I can try
wayland as well. /bin/sh is pointing to dash. User shell is either Z-Shell or
Bash, happens with both. I wonder whether that issue may also affect FreeBSD
users.

According to pstree krunner's parent process is runit which of course 
has current working directory pointing to /. I am puzzled on why that is. Surely
it must have been some other process that started krunner?

Plasmashell instead is going like this

├─runsv(2066)─┬─sddm(2116)─┬

─sddm-helper(8989)───startplasma-x11(8994)─┬─plasma_session(9056)─┬

Any other information needed?
Comment 12 Martin Steigerwald 2023-02-15 09:19:25 UTC
It is not nice, but it appears to work as a work-around:

% ~/.config/autostart> cat krunner.desktop 
[Desktop Entry]
Comment[de_DE]=
Comment=
Exec=/usr/bin/krunner --daemon --replace
GenericName[de_DE]=
GenericName=
Icon=
MimeType=
Name[de_DE]=krunner
Name=krunner
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-KDE-SubstituteUID=false
X-KDE-Username=

I added this via the autostart manager.
Comment 13 Martin Steigerwald 2023-02-15 09:42:01 UTC
I think I tracked this down a bit further. Without

% cat /usr/share/dbus-1/services/org.kde.krunner.service
[D-BUS Service]
Name=org.kde.krunner
Exec=/usr/bin/krunner
SystemdService=plasma-krunner.service

(file is from package plasma-workspace)

KRunner is not started at all (of course also without the autostart desktop file
workaround I mentioned in my last comment).

Also I can at least confirm that the current working directory of kwalletd 
and kiod5 is also /. I bet those are started by the corresponding 
service files in /usr/share/dbus-1/services.

So it appears to me that this has something do to with how dbus-x11 is handling
DBUS services. What also points at this that the issue does not happen with a Wayland
session. I am confirming with a member of the Debian other init team. If he agrees
for starters I'd file a bug report with Debian. But I can also look to file an upstream bug
report. I will keep you updated.
Comment 14 Martin Steigerwald 2023-03-05 08:48:00 UTC
I reported this downstream as

dbus-x11: Several processes in Plasma session including krunner have / as current working directory
https://bugs.debian.org/1032368

Trying to report with Devuan as well, but their mail server is running into a timeout.
Will post link once I am able to report the bug.
Comment 15 Martin Steigerwald 2023-03-05 09:06:31 UTC
Now for Devuan:

dbus-x11: Several processes in Plasma session including krunner have / as current working directory
https://bugs.devuan.org/745
Comment 16 Martin Steigerwald 2023-03-06 18:11:23 UTC
Current conclusion is that the current working directory of processes started via traditional DBUS activation is not guaranteed to be $HOME and it would be risky to change it¹.

So the suggestion would be to explicitly set the current working directory to $HOME for anything in KDE that requires this for correct operation². Especially as there are no reports of something like this happening with other current desktop environments³.

This would be KRunner and I think also the "export GTK_USE_PORTAL=1" KDE file dialog. And maybe others from:

% dpkg -L plasma-workspace | grep dbus-1/services/org
/usr/share/dbus-1/services/org.kde.KSplash.service
/usr/share/dbus-1/services/org.kde.LogoutPrompt.service
/usr/share/dbus-1/services/org.kde.Shutdown.service
/usr/share/dbus-1/services/org.kde.fontinst.service
/usr/share/dbus-1/services/org.kde.krunner.service
/usr/share/dbus-1/services/org.kde.plasma.Notifications.service
/usr/share/dbus-1/services/org.kde.runners.baloo.service

(Of course some of those may not care about current working directory being "/" and thus should likely not be changed.)

Would you be willing to make such a change? Please review linked sources for detailed explanation and justification for that conclusion.

[1] See dbus-x11: Several processes in Plasma session including krunner have / as current working directory:
https://bugs.devuan.org/cgi/bugreport.cgi?bug=745#29 (and previous comment by Simon)

also see proposed upstream patch: https://gitlab.freedesktop.org/dbus/dbus/-/issues/214

[2] See dbus-x11: Several processes in Plasma session including krunner have / as current working directory:
 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1032368#15

[3] Well this is not entirely correct, but I am at least not aware of any more recent reports. See proposed upstream patch Drop chdir("/") in dbus-launch:

https://gitlab.freedesktop.org/dbus/dbus/-/issues/214
Comment 17 Paul Floyd 2024-02-06 21:17:04 UTC
Wow, 3 years to change cwd in krunner.

FreeBSD user here.

I start konsole with krunner. Having to type "cd" every time is annoying. I almost never want to start my shell in /