[Pm-utils] [PATCH 3/8] pm-utils 1.2.3 proposed patches

Victor Lowther victor.lowther at gmail.com
Sat Nov 29 08:51:24 PST 2008


Added dbus_send helper function.

This function works just like dbus-send, but returns $NA if the command
fails for any reason.  Also modified hooks to use dbus_send where applicable.
---
 pm/HOWTO.hooks              |    3 +++
 pm/functions.in             |    6 ++++++
 pm/sleep.d/55NetworkManager |    6 ++----
 pm/sleep.d/55battery        |    2 +-
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/pm/HOWTO.hooks b/pm/HOWTO.hooks
index bf68813..550afd9 100644
--- a/pm/HOWTO.hooks
+++ b/pm/HOWTO.hooks
@@ -115,3 +115,6 @@ the hook. This will make the following convenience functions available:
 	hibernate the system after this function is called.
 13: inhibited
 	Test to see if inhibit has been called.
+14: dbus_send
+	Just like regular dbus-send, but return $NA if the command fails for
+	any reason.
diff --git a/pm/functions.in b/pm/functions.in
index 110282e..460d018 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -240,3 +240,9 @@ has_parameter()
 	done
 	return 1
 }
+
+# Like regular dbus-send, but returns $NA if the command fails for any reason.
+dbus_send ()
+{
+	command dbus-send "$@" 2>/dev/null || return $NA
+}
diff --git a/pm/sleep.d/55NetworkManager b/pm/sleep.d/55NetworkManager
index 244e2c7..bc0cf5a 100755
--- a/pm/sleep.d/55NetworkManager
+++ b/pm/sleep.d/55NetworkManager
@@ -8,12 +8,10 @@
 
 . "${PM_FUNCTIONS}"
 
-command_exists dbus-send || exit $NA
-
 suspend_nm()
 {
 	# Tell NetworkManager to shut down networking
-	dbus-send --system                         \
+	dbus_send --system                         \
 		--dest=org.freedesktop.NetworkManager  \
 		/org/freedesktop/NetworkManager        \
 		org.freedesktop.NetworkManager.sleep
@@ -22,7 +20,7 @@ suspend_nm()
 resume_nm()
 {
 	# Wake up NetworkManager and make it do a new connection
-	dbus-send --system                        \
+	dbus_send --system                        \
 		--dest=org.freedesktop.NetworkManager \
 		/org/freedesktop/NetworkManager       \
 		org.freedesktop.NetworkManager.wake
diff --git a/pm/sleep.d/55battery b/pm/sleep.d/55battery
index 1944e98..f41e4af 100755
--- a/pm/sleep.d/55battery
+++ b/pm/sleep.d/55battery
@@ -7,7 +7,7 @@
 resume_batteries()
 {
 	for x in $(hal-find-by-capability --capability battery 2>/dev/null); do
-		dbus-send --system --reply-timeout=2000 \
+		dbus_send --system --reply-timeout=2000 \
 			--dest=org.freedesktop.Hal "$x" \
 			org.freedesktop.Hal.Device.Rescan "string:$x"
 	done
-- 
1.6.0.4



More information about the Pm-utils mailing list