Giter VIP home page Giter VIP logo

dbus-listen-inhibit's Introduction

dbus-listen-inhibit

Tool to check for dbus messages inhibiting sleep in power management. It does so by listening for messages in the session dbus inhibiting/uninhibiting power management, and the HasInhibitChanged message.

Description

The applications that want to keep the system awake do so by sending messages on the session dbus to org.freedesktop.PowerManagement asking it to inhibit system power management. For example:

method call sender=:1.787 -> dest=org.freedesktop.PowerManagement serial=3 path=/org/freedesktop/PowerManagement/Inhibit; interface=org.freedesktop.PowerManagement.Inhibit; member=Inhibit
   string "/usr/bin/google-chrome-beta"
   string "Playing Video"

When the application ends the task that prevents inhibit it does so by sending an UnInhibit message like:

method call sender=:1.787 -> dest=org.freedesktop.PowerManagement serial=4 path=/org/freedesktop/PowerManagement/Inhibit; interface=org.freedesktop.PowerManagement.Inhibit; member=UnInhibit
   uint32 275

org.freedesktop.PowerManagement (kded4 / powerdevil in my system) will keep track of the pending inhibits and send a message whenever the session Inhibit status changes like those:

signal sender=:1.2 -> dest=(null destination) serial=6392 path=/org/freedesktop/PowerManagement/Inhibit; interface=org.freedesktop.PowerManagement.Inhibit; member=HasInhibitChanged
   boolean true

signal sender=:1.2 -> dest=(null destination) serial=6403 path=/org/freedesktop/PowerManagement/Inhibit; interface=org.freedesktop.PowerManagement.Inhibit; member=HasInhibitChanged
   boolean false

Usage

Just run it and observe the output it should start from a state with no pending inhibits:

$ qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit  org.freedesktop.PowerManagement.Inhibit.HasInhibit
false

And a green light:

![Sleep possible](sleep possible.png)

The script will dump the active list of pending inhibits whenever there is a change on it, and also inform if sleep is possible or is inhibited.

It will signal that sleep is inhibitted by using a red light when sleep is inhibitted and sending a notify to the desktop whenever an application adds itself to inhibit or removes itself: ![inhibit started](inhibit started.png)

![inhibit finished](inhibit finished.png)

$ python dbus-listen-inhibit.py 

Active Inhibits:
2014-11-14 12:40:57 App = /usr/bin/google-chrome-beta (pid: 6462), Reason = Playing Video
Power management inhibited
Active Inhibits:
2014-11-14 12:40:57 App = /usr/bin/google-chrome-beta (pid: 6462), Reason = Playing Video

Active Inhibits:
2014-11-14 12:40:57 App = /usr/bin/google-chrome-beta (pid: 6462), Reason = Playing Video
2014-11-14 12:40:58 App = /usr/bin/google-chrome-beta (pid: 6462), Reason = Playing Audio

Active Inhibits:
2014-11-14 12:40:58 App = /usr/bin/google-chrome-beta (pid: 6462), Reason = Playing Audio

Sleep possible

You can use the right click button over the green|red light to see the about window, exit the tool, and to see the current tracked pending inhibits with "Show status":

menu

inhibit dump

You want a way to see the raw messages?

  • dbus-monitor --session interface=org.freedesktop.PowerManagement.Inhibit.

You want to remove stale Inhibits leftover from crashed of bad behaved apps? Then there's also an ugly way to solve it:

$ qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Inhibit.Inhibit "$$" "Testing D-Bus Interface"
404

That "404" is the value of the cookie to be used as an argument to UnInhibit to lift the Inhibit.

$ qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.UnInhibit 404

So, the extremely ugly hack, is to call UnInhibit with what seems to be the cookie values produced before the previous test:

$ for i in {1..403} ; do echo -n "$i " ; qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement/Inhibit org.freedesktop.PowerManagement.Inhibit.UnInhibit $i ; done
1 
2 
3 
[...]

Inhibit should be gone now.

dbus-listen-inhibit's People

Contributors

jnerin avatar

Stargazers

Krzysztof Wilczyński avatar  avatar Eugene San avatar Tim Richardson avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

dbus-listen-inhibit's Issues

not compatible with python3, hard to run with python2

sauron:~/src/dbus-listen-inhibit$ sudo apt install python-pip
sauron:~/src/dbus-listen-inhibit$ pip2 install pynotify
sauron:~/src/dbus-listen-inhibit$ ./dbus-listen-inhibit.py 
Traceback (most recent call last):
  File "./dbus-listen-inhibit.py", line 317, in <module>
    if not pynotify.init (PROGRAM):
AttributeError: 'module' object has no attribute 'init'
sauron:~/src/dbus-listen-inhibit$ find /home/merlin/.local/lib/python2.7/site-packages/pynotify/
/home/merlin/.local/lib/python2.7/site-packages/pynotify/
/home/merlin/.local/lib/python2.7/site-packages/pynotify/__init__.py
/home/merlin/.local/lib/python2.7/site-packages/pynotify/pynotify.py
/home/merlin/.local/lib/python2.7/site-packages/pynotify/__init__.pyc
/home/merlin/.local/lib/python2.7/site-packages/pynotify/pynotify.pyc
sauron:~/src/dbus-listen-inhibit$ grep -5 init /home/merlin/.local/lib/python2.7/site-packages/pynotify/pynotify.py
__email__ = "[email protected]"


class ExecutionNotifierDecorator(object):

    def __init__(self, username, password, destination=[]):
        """
        If there are decorator arguments, the function
        to be decorated is not passed to the constructor!
        """
        self.username = username
sauron:~/src/dbus-listen-inhibit$ cat /home/merlin/.local/lib/python2.7/site-packages/pynotify/__init__.pyc
�
]�$cc@sdZdZdZdS([email protected](t
__author__t
           __license__t	__email__(((sD/home/merlin/.local/lib/python2.7/site-packages/pynotify/__init__.py

manual dbus instruction's don't work anymore?

sauron:~$ dbus-monitor --session interface=org.freedesktop.PowerManagement.Inhibit.
dbus-monitor: unable to enable new-style monitoring: org.freedesktop.DBus.Error.MatchRuleInvalid: "Interface name 'org.freedesktop.PowerManagement.Inhibit.' is invalid
". Falling back to eavesdropping.
Failed to setup match "eavesdrop=true,interface=org.freedesktop.PowerManagement.Inhibit.": Interface name 'org.freedesktop.PowerManagement.Inhibit.' is invalid

sauron:~$ qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Inhibit.Inhibit "$$" "Testing D-Bus Interface" qdbus org.freedesktop.PowerManagement /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Inhibit.Inhibit "$$" "Testing D-Bus Interface" 404
qdbus: could not find a Qt installation of ''

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.