You are not logged in.

#1 2013-10-25 22:48:23

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Run systemd DBus Call as Normal User

I am a new Arch user, and need to know how to write a systemd hook or service that makes a DBus call as my normal user. I want to run

qdbus org.kde.kwin.Compositing /KWin toggleCompositing

everytime I suspend and resume my computer. I have tried both with a systemd service in

/etc/systemd/system/

and a hook in

/usr/lib/systemd/system-sleep

but I always get one of the following errors:

Service 'org.kde.kwin' does not exist.
Could not connect to D-Bus server: org.freedesktop.DBus.Error.Spawn.ExecFailed: /usr/bin/dbus-launch terminated abnormally with the following error: No protocol specified
Autolaunch error: X11 initialization failed.

When I execute the DBus call as my user in a normal terminal, it always works. How do I make this work in the systemd service or hook?

Thanks.


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#2 2013-10-26 01:26:28

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

Welcome to the forums.

How do you suspend? The reason I ask is that if KDE is handling that, it might be better to have KDE handle this.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#3 2013-11-05 14:33:53

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Re: Run systemd DBus Call as Normal User

I suspend using systemd, I guess. I use the suspend button in KDE, which I think calls:

systemctl suspend

I have tried making a bash script to make the DBus call after 25 minutes and put my system to sleep, but I don't know how to get the script to run when I voluntarily click "Suspend".

Thanks for the reply.


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#4 2013-11-05 22:09:27

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

I'm not sure the best way but you need the command to run as your normal user, I think. Whereas the service etc. may be running as root?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#5 2013-11-05 23:24:59

Thaodan
Member
From: Dortmund, Nordrein-Westfalen
Registered: 2012-04-28
Posts: 448

Re: Run systemd DBus Call as Normal User

what about using systemd --user? its should react about suspend.target  started from systemd --system


Linux odin 3.13.1-pf #1 SMP PREEMPT Wed Mar 5 21:47:28 CET 2014 x86_64 GNU/Linux

Offline

#6 2013-11-05 23:58:54

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Run systemd DBus Call as Normal User

I don't know much about dbus, and even less about qdbus, but might you need to specify :0 (or whatever screen you are using)?

Offline

#7 2013-11-06 06:25:05

Thaodan
Member
From: Dortmund, Nordrein-Westfalen
Registered: 2012-04-28
Posts: 448

Re: Run systemd DBus Call as Normal User

WonderWoofy wrote:

I don't know much about dbus, and even less about qdbus, but might you need to specify :0 (or whatever screen you are using)?

He needs to call qdbus(or how ever he does the dbus call) as the user that has the X11 session.


Linux odin 3.13.1-pf #1 SMP PREEMPT Wed Mar 5 21:47:28 CET 2014 x86_64 GNU/Linux

Offline

#8 2013-11-06 06:43:14

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Run systemd DBus Call as Normal User

Thaodan wrote:
WonderWoofy wrote:

I don't know much about dbus, and even less about qdbus, but might you need to specify :0 (or whatever screen you are using)?

He needs to call qdbus(or how ever he does the dbus call) as the user that has the X11 session.

Thanks, that is why it was phrased as a question. smile

Offline

#9 2013-11-06 20:36:38

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Re: Run systemd DBus Call as Normal User

I tried calling dbus using su, but dbus does PID checking so it doesn't work.


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#10 2013-11-06 22:55:37

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

Please explain exactly what you tried - which command, where you used it etc.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#11 2013-11-17 18:35:32

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Re: Run systemd DBus Call as Normal User

I have tried many commands, but non of them work.

su - myusername -c "export DISPLAY=:0; qdbus org.kde.kwin /KWin toggleCompositing"
su - myusername -c "export DBUS_SESSION_BUS_ADDRESS; export DBUS_SESSION_BUS_PID; export DISPLAY=:0; qdbus org.kde.kwin.Compositing /KWin toggleCompositing"

I tried the commands in my systemd sleep hook, but nothing seems to work.

Last edited by JohnSmithLinux (2013-11-17 18:35:44)


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#12 2013-11-17 23:36:30

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

I've never managed to get this to work for what I designed it for but it does allow interaction with the running session so these excerpts from a notification script I use to interact with a running KDE session might be useful:

export DISPLAY=:0
export XAUTHORITY=~/.Xauthority
PATH=/usr/local/bin:/usr/local/sbin:/usr/bin
export PATH

allan=0

error () {
        echo "$@" 1>&2
        ((allan++))
        exit $allan
}

# ref.: http://unix.stackexchange.com/questions/28463/run-a-dbus-program-in-crontab-how-to-know-about-the-session-id

ksession_pid=$(ps -o pid= -C 'kwin -session' | sed 's/ //g')

if [ "$ksession_pid" = "" ]
then
        dbus_session_file=~/.dbus/session-bus/$(cat /var/lib/dbus/machine-id)-0
        if [ -e "$dbus_session_file" ]
        then
                . "$dbus_session_file"
                [ $? == 0 ] || ((allan++))
                export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
        else
                error "Gwall! Allwn i ddim canfod $dbus_session_file."
        fi
else
        dbus_session_address=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$ksession_pid/environ | sed 's/^DBUS_SESSION_BUS_ADDRESS=//')
        [ "$dbus_session_address" != "" ] || error "Could not get DBUS_SESSION_BUS_ADDRESS for session." 
        export DBUS_SESSION_BUS_ADDRESS="$dbus_session_address"
fi

EDIT: Include error function and setup.

Last edited by cfr (2013-11-17 23:41:34)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#13 2013-11-18 00:27:33

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Re: Run systemd DBus Call as Normal User

Thank you. How would I use that script in a systemd hook to toggle KWin compositing? Sorry, I'm a bit inexperienced with DBus and Arch in general.


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#14 2013-11-18 02:17:26

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

I am not at all sure but I think you could use it to get and export the right values for DBUS_SESSION_BUS_ADDRESS and DBUS_SESSION_BUS_PID. I guess I'd just try then running your command and see if it works like that. Then just call the script with su -c or whatever.

Though I don't actually think this is going to work - I think it will fail for whatever reason it fails for the purposes I designed it for. But I don't know what that is sad.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#15 2013-11-18 22:26:16

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Re: Run systemd DBus Call as Normal User

I know I'm going to get opinionated here:

With all of KDE's problems, I think I might be better off with MATE or Xfce or GNOME or something... Maybe even Razor-Qt.


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#16 2013-11-18 23:14:30

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

I don't think this is a KDE-specific issue so I'm not sure that would help.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#17 2013-11-18 23:34:02

JohnSmithLinux
Member
From: The Internet
Registered: 2013-10-24
Posts: 41

Re: Run systemd DBus Call as Normal User

Well, the issue I am trying to resolve with this is how KDE shows a black screen when I resume it from suspend mode. If I turn composting off in KWin, this issue stops. I found some info here:

https://bbs.archlinux.org/viewtopic.php?id=166964
https://bbs.archlinux.org/viewtopic.php?id=170547
https://bugs.kde.org/show_bug.cgi?id=323686

Nothing seems to work...


Arch Linux | x86_64 | GPT | BIOS boot | SysLinux | systemd | EXT4
System76 Bonobo Extreme (bonx7) | Intel® Core™ i7-4900MQ CPU @ 2.80GHz (Turbo Boost 2.0 up to 3,8 GHz) | 16 GB Dual-Channel SDRAM @ 1600 MHz | 250 GB Samsung 840 EVO SSD | 750 GB WDC WD7500BPKX-75HPJT0 HDD | NVidia GeForce GTX 765M
XOrg | LightDM | GNOME Desktop

Offline

#18 2013-11-19 00:49:06

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,198

Re: Run systemd DBus Call as Normal User

Oh, possibly. I meant the problem of interacting with a user session from a process run outside that session, possibly as another user - possibly root.


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB