File laptop_mode-1.49.diff of Package laptop-mode-tools

Index: b/usr/sbin/laptop_mode
===================================================================
--- a/usr/sbin/laptop_mode
+++ b/usr/sbin/laptop_mode
@@ -414,11 +414,12 @@ if [ "$1" = "status" ] ; then
 		log "STATUS" "Laptop Mode Tools is allowed to run: /var/run/laptop-mode-tools/enabled exists."
 	else
 		log "STATUS" "Laptop Mode Tools is NOT allowed to run: /var/run/laptop-mode-tools/enabled does not exist."
 	fi
     log "STATUS" " "
-	STATFILES="/proc/sys/vm/laptop_mode /proc/apm /proc/pmu/info /proc/sys/vm/bdflush /proc/sys/vm/dirty_ratio /proc/sys/fs/xfs/age_buffer /proc/sys/fs/xfs/sync_interval /proc/sys/fs/xfs/lm_age_buffer /proc/sys/fs/xfs/lm_sync_interval /proc/sys/vm/pagebuf/lm_flush_age /proc/sys/fs/xfs/xfsbufd_centisecs /proc/sys/fs/xfs/xfssyncd_centisecs /proc/sys/vm/dirty_background_ratio /proc/sys/vm/dirty_expire_centisecs /proc/sys/fs/xfs/age_buffer/centisecs /proc/sys/vm/dirty_writeback_centisecs /sys/devices/system/cpu/*/cpufreq/cpuinfo_*_freq /sys/devices/system/cpu/*/cpufreq/scaling_governor /proc/acpi/button/lid/*/state /proc/acpi/ac_adapter/*/state /proc/acpi/battery/*/state /sys/class/power_supply/*/online /sys/class/power_supply/*/state"
+#	STATFILES="/proc/sys/vm/laptop_mode /proc/apm /proc/pmu/info /proc/sys/vm/bdflush /proc/sys/vm/dirty_ratio /proc/sys/fs/xfs/age_buffer /proc/sys/fs/xfs/sync_interval /proc/sys/fs/xfs/lm_age_buffer /proc/sys/fs/xfs/lm_sync_interval /proc/sys/vm/pagebuf/lm_flush_age /proc/sys/fs/xfs/xfsbufd_centisecs /proc/sys/fs/xfs/xfssyncd_centisecs /proc/sys/vm/dirty_background_ratio /proc/sys/vm/dirty_expire_centisecs /proc/sys/fs/xfs/age_buffer/centisecs /proc/sys/vm/dirty_writeback_centisecs /sys/devices/system/cpu/*/cpufreq/cpuinfo_*_freq /sys/devices/system/cpu/*/cpufreq/scaling_governor /proc/acpi/button/lid/*/state /proc/acpi/ac_adapter/*/state /proc/acpi/battery/*/state /sys/class/power_supply/AC/online /sys/class/power_supply/*/state"
+	STATFILES="/proc/sys/vm/laptop_mode /proc/apm /proc/pmu/info /proc/sys/vm/bdflush /proc/sys/vm/dirty_ratio /proc/sys/fs/xfs/age_buffer /proc/sys/fs/xfs/sync_interval /proc/sys/fs/xfs/lm_age_buffer /proc/sys/fs/xfs/lm_sync_interval /proc/sys/vm/pagebuf/lm_flush_age /proc/sys/fs/xfs/xfsbufd_centisecs /proc/sys/fs/xfs/xfssyncd_centisecs /proc/sys/vm/dirty_background_ratio /proc/sys/vm/dirty_expire_centisecs /proc/sys/fs/xfs/age_buffer/centisecs /proc/sys/vm/dirty_writeback_centisecs"
 	for THISFILE in $STATFILES ; do
 		if [ -e "$THISFILE" ] ; then
 			log "STATUS" "$THISFILE:"
 			if [ -r "$THISFILE" ] ; then
 				cat "$THISFILE" | sed "s/^/   /"
@@ -476,18 +477,19 @@ if [ ! -w /proc/sys/vm/laptop_mode ] ; t
 	exit 1
 fi
 
 INIT=0          # Display info in init script format?
 FORCE=0         # Force reapplying the current state?
+FAKE_AC=""
 while [ "$1" != "" ] ; do
 	case "$1" in 
 		init) INIT=1 ;;
 		force) FORCE=1 ;;
 		# Old options. We always do "auto" for any option now, but
 		# we still have to accept the options.
-		start) ;;
-		stop) ;;
+		start) FORCE=1; FAKE_AC=0 ;;
+		stop) FORCE=1; FAKE_AC=1 ;;
 		auto) ;;
 		*) log "ERR" "Unrecognized option $1."
 		   exit 1 ;;
 	esac
 	shift
@@ -502,69 +504,19 @@ STATE=enabled
 if [ "$ENABLE_LAPTOP_MODE_ON_BATTERY" -eq 0 -a "$ENABLE_LAPTOP_MODE_ON_AC" -eq 0 -a "$ENABLE_LAPTOP_MODE_WHEN_LID_CLOSED" -eq 0 ] ; then
 	STATE=disabled
 fi
 
 # Determine the power state.
-
-# First try /sys/class/power_supply/*
-FOUND_SYS_CLASS_POWER_SUPPLY_AC=0
-ON_AC=0
-for POWER_SUPPLY in /sys/class/power_supply/* ; do
-	if [ -f $POWER_SUPPLY/type ] ; then
-		if [ "$(cat $POWER_SUPPLY/type)" = "Mains" ] ;then
-			log "VERBOSE" "Determining power state from $POWER_SUPPLY/online."
-			FOUND_SYS_CLASS_POWER_SUPPLY_AC=1
-			if [ "$(cat $POWER_SUPPLY/online)" = 1 ] ; then
-				ON_AC=1
-			fi
-		fi
-	fi
-done
-
-if [ $FOUND_SYS_CLASS_POWER_SUPPLY_AC = 1 ] ; then
-	# Already found it!
-	log "VERBOSE" "Not trying other options, already found a power supply."
-elif [ -d /proc/acpi/ac_adapter ] ; then
-	log "VERBOSE" "Determining power state from /proc/acpi/ac_adapter."
-	ADAPTERS_FOUND=0
-	ON_AC=0
-	for ADAPTER in /proc/acpi/ac_adapter/* ; do
-		if [ -f $ADAPTER/state ] ; then
-			ADAPTERS_FOUND=1
-			STATUS=`awk '/^state: / { print $2 }' $ADAPTER/state`
-			if [ "$STATUS" = "on-line" ] ; then
-				ON_AC=1
-			fi
-		fi
-	done
-	if [ "$ADAPTERS_FOUND" -eq 0 ] ; then
-		ON_AC=1
-	fi
-elif [ -f /proc/pmu/info ] ; then
-	log "VERBOSE" "Determining power state from /proc/pmu/info."
-	if ( grep -q "^AC Power.*0$" /proc/pmu/info ) ; then
-		log "VERBOSE" "/proc/pmu/info indicates absence of AC power."
-		ON_AC=0
-	else
-		# It is possible that there is no AC Power = 1 in the file,
-		# but we always assume AC power when we're not sure.
-		ON_AC=1
-		log "VERBOSE" "/proc/pmu/info indicates presence of AC power."
-	fi
-elif [ -f /proc/apm ] ; then
-	log "VERBOSE" "Determining power state from /proc/apm."
-	read D1 D2 D3 APM_AC_STATE D0 </proc/apm
-	if [ "$APM_AC_STATE" = "0x00" ] ; then
-		ON_AC=0
-	else
-		ON_AC=1
-	fi
-else
-	log "VERBOSE" "No /sys/class/power_supply, ACPI, APM or PMU power management information found -- assuming AC power is present."
+if on_ac_power; then
 	ON_AC=1
+else
+	ON_AC=0
 fi
 
+if [ -n "$FAKE_AC" ]; then
+	ON_AC=$FAKE_AC
+fi
 
 # Determine whether to activate or deactivate laptop mode.
 ACTIVATE=0
 
 if [ "$ON_AC" -eq 1 ] ; then