3

I've learned that it's possible to create inhibitors for a GUI session via dbus. However, when I do try to add an inhibitor, it is immediately removed. Here's an example.

I call to add inhibitor via this command (which is supposed to prevent logout from happening):

qdbus org.gnome.SessionManager  /org/gnome/SessionManager org.gnome.SessionManager.Inhibit "x-terminal-emulator" $(xdotool getactivewindow) "TEST REASON" 1

The output of dbus-monitor suggests that it is added, but then immediately removed.

$ dbus-monitor --profile | grep -i inhibitor
sig 1474613346.596581   156 :1.23   <none>  /org/gnome/SessionManager   org.gnome.SessionManager    InhibitorAdded
sig 1474613346.603137   159 :1.23   <none>  /org/gnome/SessionManager   org.gnome.SessionManager    InhibitorRemoved

How can I troubleshoot this ?

System in use: Ubuntu 16.04, Unity

terdon
  • 234,489
  • 66
  • 447
  • 667
Sergiy Kolodyazhnyy
  • 16,187
  • 11
  • 53
  • 104
  • @don_crissti yup, seems like it was exactly that - inhibitor removed once calling process exits. I've created python script which creates the inhibitor and then enters infinite while loop. The inhibitor removed only when i use keyboard interrupt on the script. Of course this cannot be closed as duplicate , since that question is on different site, but if you want - feel free to write your own answer for this one. I'll accept. I'll probably will write my own answer also, just to document the python script, but that's only a thought – Sergiy Kolodyazhnyy Sep 23 '16 at 08:15
  • 1
    @don_crissti I will do that. This question is sort of research . I'm working on another answer for AskUbuntu site, which requires this solution. Once I have coherent answers for both, I'll post so that everything can be nicely referenced . Thank you again for your help ! – Sergiy Kolodyazhnyy Sep 23 '16 at 08:49
  • related: [Detect if screensaver is active](https://unix.stackexchange.com/q/197032/1131) – maxschlepzig Nov 16 '20 at 14:58

1 Answers1

0

The inhibitor is immediately removed because it's auto-removed on dbus client disconnect.

Thus, you have to keep your client running for as long as the inhibition should be active.

Example:

python3 -c 'import pydbus; pydbus.SessionBus().get(
"org.gnome.SessionManager").Inhibit("what", 0, "why", 1);
import time; time.sleep(2**32-1)'

Related for testing is the IsInhibited and GetInhibitors methods of that org.gnome.SessionManager D-Bus interface, e.g.:

qdbus org.gnome.SessionManager /org/gnome/SessionManager \
    org.gnome.SessionManager.IsInhibited 8

For how to list the inhibitors cf. list_inhibitors() in a utility of mine.

maxschlepzig
  • 56,316
  • 50
  • 205
  • 279