Aloas,

attached is a patch with the main purpose to add an option "--hal-quirks" to 
make pm-action get the quirk information via hal. Also it adds an 
option "--show-quirks" that shows the values of the quirk variables. The 
patch also moves the check whether root invokes pm-action to a point after 
processing the options, to make it possible for non root users to get the 
help or to get a list of the used quirks without accidently suspending the 
machine. Last but not least there are two changes to the help text, one 
substitutes pm-action with the actual name it was invoked and the other
-       echo "Possible actions are:"
+       echo "Possible options are:"

makes it a consistent with the first line:
+       echo "$(basename "$0") [options]"

The next improvement would be to remove the redundancy of the list of possible 
quirks, they are now hardcoded in the help text, twice in the option 
processing and once each in the hal-quirks and the show-quirks option 
processing.

The best way to change this would be imho to have an array with all possible 
quirks (dpms_on dpms_suspend radeon_off reset_brightness s3_bios s3_mode 
vbe_post vbemode_restore vbestate_restore vga_mode3) and a function that 
returns the resulting variable name and use these in pm-action. To make it 
easier to code, it would be nice when the syntax could be changed, so that 
options follow this pattern:

--quirk-dpms_on
--quirk-dpms_suspend
[...]
because currently only in the options the use "-" instead of "_".

I can provide a patch for this, too, but I want to start slowly with 
submitting patches.

Regards,
Till

Btw. In case it is neccessary: My contributions may be licensed with GPLv2 or 
any later version, if you want to change the license of pm-utils somewhere in 
the future.
Index: src/pm-action
===================================================================
RCS file: /cvs/pm-utils/pm-utils/src/pm-action,v
retrieving revision 1.12
diff -u -r1.12 pm-action
--- src/pm-action	18 Jun 2007 20:42:36 -0000	1.12
+++ src/pm-action	30 Aug 2007 18:42:41 -0000
@@ -26,12 +26,13 @@
 
 # The rule here? Simplicity.
 
+
 help_options() {
-	echo "pm-action [options]"
+	echo "$(basename "$0") [options]"
 	echo
 	echo "Options can change how the supend or hibernate is done."
 	echo
-	echo "Possible actions are:"
+	echo "Possible options are:"
 	echo
 	echo "  --quirk-dpms-on"
 	echo "  --quirk-dpms-suspend"
@@ -43,16 +44,35 @@
 	echo "  --quirk-vbemode-restore"
 	echo "  --quirk-vbestate-restore"
 	echo "  --quirk-vga-mode3"
+	echo "  --hal-quirks"
+	echo "  --show-quirks"
 	echo
 }
 
-if [ -n "$EUID" -a "$EUID" != "0" ]; then
-	echo This utility may only be run by the root user. 1>&2
-	exit 1
-fi
 
 export LC_COLLATE=C
 
+get_hal_quirks() {
+local value
+
+for quirk in dpms_on dpms_suspend radeon_off reset_brightness s3_bios s3_mode vbe_post vbemode_restore vbestate_restore vga_mode3 
+do
+	value=$(/usr/bin/hal-get-property --udi /org/freedesktop/Hal/devices/computer --key power_management.quirk.${quirk} 2>/dev/null)
+	if [ ${value:-"false"} == "true" ]
+	then
+		eval DISPLAY_QUIRK_$(echo $quirk|tr a-z- A-Z_)="true"
+	fi	
+done
+}
+
+show_quirks_config() {
+for variable in DISPLAY_QUIRK_DPMS_ON DISPLAY_QUIRK_DPMS_SUSPEND DISPLAY_QUIRK_RADEON_OFF DISPLAY_QUIRK_RESET_BRIGHTNESS DISPLAY_QUIRK_S3_BIOS DISPLAY_QUIRK_S3_MODE DISPLAY_QUIRK_VBE_POST DISPLAY_QUIRK_VBEMODE_RESTORE DISPLAY_QUIRK_VBESTATE_RESTORE DISPLAY_QUIRK_VGA_MODE_3
+do
+	echo -n $variable=
+	eval echo \$\{${variable}:-"false"\}
+done
+}
+
 # Get the command line options
 while [ $# -gt 0 ]
 do
@@ -77,6 +97,10 @@
 			export DISPLAY_QUIRK_VBESTATE_RESTORE="true" ;;
 		--quirk-vga-mode3)
 			export DISPLAY_QUIRK_VGA_MODE_3="true" ;;
+		--hal-quirks)
+			get_hal_quirks ;;
+		--show-quirks)
+			export OPTION_SHOW_QUIRKS="true";;
 		--help)
 			help_options
 			exit 0 ;;
@@ -86,6 +110,17 @@
 	shift
 done
 
+if [ ${OPTION_SHOW_QUIRKS:-"false"} == "true" ]
+then
+	show_quirks_config
+	exit 0
+fi
+
+if [ -n "$EUID" -a "$EUID" != "0" ]; then
+	echo This utility may only be run by the root user. 1>&2
+	exit 1
+fi
+
 . /usr/lib/pm-utils/functions
 
 [ -f /sys/power/state ] || exit 1
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to