Debian Codegraph @

debian/addons/lib/policy-funcs

raw
1 . /usr/share/acpi-support/power-funcs
2
3 CheckUPowerPolicy() {
4 pidof upowerd > /dev/null
5 }
6
7 # The (not very aptly named) function CheckPolicy checks if the current X
8 # console user is running a power management daemon that handles suspend/resume
9 # requests. This is used in various places to determine if we need to handle
10 # something ourselves or if we need to pass the info on to a power management
11 # daemon (e.g. through a fake key press).
12
13 CheckPolicy() {
14 local PMS
15
16 getXconsole
17 PMS="/usr/bin/xfce4-power-manager /usr/bin/mate-power-manager /usr/lib/dalston/dalston-power-applet"
18 pidof -x $PMS > /dev/null ||
19 PowerDevilRunning ||
20 GnomeSettingsDaemonPowerRunning
21 }
22
23 # Find a DBUS session bus, by looking at the given process' environment and
24 # then send a message to that bus. If multiple processes match the given name,
25 # the message is sent to all of the buses (and output is simply concatenated.
26 DBusSend() {
27 # The process to get the DBUS session address from
28 local PROC_NAME="$1"
29
30 # Parameters for dbus-send
31 local DEST="$2"
32 local DBUS_PATH="$3"
33 local METHOD="$4"
34
35 local DBUS_SESS
36 getXuser
37 if test "$XUSER" != "" && test -x /usr/bin/dbus-send; then
38 serverpid=$(pgrep -n -u "$XUSER" "$PROC_NAME")
39 if test "$serverpid" != ""; then
40 DBUS_SESS=$(su - "$XUSER" -c "grep -a -z DBUS_SESSION_BUS_ADDRESS /proc/$serverpid/environ || :")
41 if test "$DBUS_SESS" != "" && su - "$XUSER" -s /bin/sh -c "export \"$DBUS_SESS\"; dbus-send --print-reply --dest='$DEST' '$DBUS_PATH' '$METHOD' >/dev/null 2>&1"; then
42 return 0
43 fi
44 fi
45 fi
46 }
47
48 # Check if org.freedesktop.login1.Manager interface is available
49 HasDBusLogin1() {
50 test -x /usr/bin/dbus-send &&
51 # CanHalt used as a representative of login1 methods
52 dbus-send --print-reply --system --type=method_call \
53 --dest=org.freedesktop.login1 \
54 /org/freedesktop/login1 \
55 org.freedesktop.login1.Manager.CanHalt \
56 > /dev/null 2>&1
57 }
58
59 # Ask kde if the powerdevil module is loaded
60 PowerDevilRunning() {
61 DBusSend kded4 org.kde.kded /kded org.kde.kded.loadedModules | grep -q powerdevil
62 }
63
64 # gnome-power-manager was integrated into gnome-settings-daemon from version
65 # 3.1.4, in a new Power plugin (though the handling of buttons is done in the
66 # MediaKeys plugin.
67 #
68 # gnome-settings-daemon does not export a list of loaded plugins, but
69 # fortunately the Power plugin does have its own Dbus interface we can check
70 # for (We can't check the MediaKeys plugin, since that has been around for
71 # longer).
72 GnomeSettingsDaemonPowerRunning() {
73 # only check for gnome-settings- instead of gnome-settings-daemon
74 # because /proc/<pid>/stat only lists the first 15 characters
75 DBusSend gnome-settings- org.gnome.SettingsDaemon /org/gnome/SettingsDaemon/Power org.freedesktop.DBus.Introspectable.Introspect | grep -q 'interface name="org.gnome.SettingsDaemon.Power"'
76 }