hal/tools/freebsd Makefile.am, NONE, 1.1 hal-system-lcd-get-brightness-freebsd, NONE, 1.1 hal-system-lcd-set-brightness-freebsd, NONE, 1.1 hal-system-power-reboot-freebsd, NONE, 1.1 hal-system-power-set-power-save-freebsd, NONE, 1.1 hal-system-power-shutdown-freebsd, NONE, 1.1 hal-system-power-suspend-freebsd, NONE, 1.1 hal-system-storage-cleanup-mountpoints-freebsd, NONE, 1.1 hal-system-storage-eject-freebsd, NONE, 1.1 hal-system-storage-unmount-freebsd, NONE, 1.1

Joe Marcus Clarke marcus at kemper.freedesktop.org
Sun May 14 11:49:55 PDT 2006


Update of /cvs/hal/hal/tools/freebsd
In directory kemper:/tmp/cvs-serv17906/tools/freebsd

Added Files:
	Makefile.am hal-system-lcd-get-brightness-freebsd 
	hal-system-lcd-set-brightness-freebsd 
	hal-system-power-reboot-freebsd 
	hal-system-power-set-power-save-freebsd 
	hal-system-power-shutdown-freebsd 
	hal-system-power-suspend-freebsd 
	hal-system-storage-cleanup-mountpoints-freebsd 
	hal-system-storage-eject-freebsd 
	hal-system-storage-unmount-freebsd 
Log Message:
Split out the tools scripts into an OS-independent wrapper, and an OS-dependent
backend.  The backend selection with be based on the utsname.sysname value.
Also, add FreeBSD support to hal-storage-mount.c (code from
Jean-Yves Lefort <jylefort at FreeBSD.org>).

Reviewed by:	Artem Kachitchkine, David Zeuthen
Approved by:	David Zeuthen


--- NEW FILE: Makefile.am ---
## Process this file with automake to produce Makefile.in

scriptdir = $(libdir)/hal/scripts

script_SCRIPTS =					\
	hal-system-power-suspend-freebsd		\
	hal-system-power-shutdown-freebsd		\
	hal-system-power-reboot-freebsd			\
	hal-system-lcd-get-brightness-freebsd		\
	hal-system-lcd-set-brightness-freebsd		\
	hal-system-power-set-power-save-freebsd		\
	hal-system-storage-unmount-freebsd		\
	hal-system-storage-eject-freebsd		\
	hal-system-storage-cleanup-mountpoints-freebsd


--- NEW FILE: hal-system-lcd-get-brightness-freebsd ---
#!/bin/sh
#
# Copyright (C) 2006 Joe Marcus Clarke <marcus at FreeBSD.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "toshiba" ]; then
	value="`sysctl -n hw.acpi.toshiba.lcd_brightness`"
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "fujitsu" ]; then
	value="`sysctl -n hw.acpi.fujitsu.lcd_brightness`"
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "asus" ]; then
	value="`sysctl -n hw.acpi.asus.lcd_brightness`"
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "panasonic" ]; then
	value="`sysctl -n hw.acpi.panasonic.lcd_brightness`"
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "ibm" ]; then
	value="`sysctl -n dev.acpi_ibm.0.lcd_brightness`"
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "sony" ]; then
	value="`sysctl -n dev.acpi_sony.0.brightness`"
	value=`expr $value - 1`
else
	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
	echo "No ACPI method found" >&2
	exit 1
fi

exit ${value}

--- NEW FILE: hal-system-lcd-set-brightness-freebsd ---
#!/bin/sh
#
# Copyright (C) 2006 Joe Marcus Clarke <marcus at FreeBSD.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.


if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "toshiba" ]; then
	sysctl hw.acpi.toshiba.lcd_brightness=$value
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "fujitsu" ]; then
	sysctl hw.acpi.fujitsu.lcd_brightness=$value
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "asus" ]; then
	sysctl hw.acpi.asus.lcd_brightness=$value
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "panasonic" ]; then
	sysctl hw.acpi.panasonic.lcd_brightness=$value
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "ibm" ]; then
	sysctl dev.acpi_ibm.0.lcd_brightness=$value
elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" = "sony" ]; then
	sysctl dev.acpi_sony.0.brightness=$(expr $value + 1)
else
	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
	echo "No ACPI method found" >&2
	exit 1
fi

exit 0

--- NEW FILE: hal-system-power-reboot-freebsd ---
#!/bin/sh

unsupported() {
	echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
	echo "No reboot command found" >&2
	exit 1
}

#Try for common tools
if [ -x "/sbin/shutdown" ] ; then
	/sbin/shutdown -r now
	exit $?
elif [ -x "/usr/sbin/shutdown" ] ; then
	/usr/sbin/shutdown -r now
	exit $?
else
	unsupported
fi

--- NEW FILE: hal-system-power-set-power-save-freebsd ---
#!/bin/sh
read value

unsupported() {
	echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
	echo No powersave method found >&2
	exit 1
}

if [ -x "/etc/rc.d/power_profile" ] ; then
	if [ $value = "true" ]; then
		/etc/rc.d/power_profile 0x00
		RET=$?
	elif [ $value = "false" ]; then
		/etc/rc.d/power_profile 0x01
		RET=$?
	fi
else
	unsupported
fi

exit $RET


--- NEW FILE: hal-system-power-shutdown-freebsd ---
#!/bin/sh

unsupported() {
	echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
	echo "No shutdown command found" >&2
	exit 1
}

#Try for common tools
if [ -x "/sbin/shutdown" ] ; then
	/sbin/shutdown -h now
	exit $?
elif [ -x "/usr/sbin/shutdown" ] ; then
	/usr/sbin/shutdown -h now
	exit $?
else
	unsupported
fi

--- NEW FILE: hal-system-power-suspend-freebsd ---
#!/bin/sh

alarm_not_supported() {
	echo org.freedesktop.Hal.Device.SystemPowerManagement.AlarmNotSupported >&2
	echo Waking the system up is not supported >&2
	exit 1
}

unsupported() {
	echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
	echo No suspend method found >&2
	exit 1
}

read seconds_to_sleep

if [ -x /usr/sbin/zzz ] ; then
	/usr/sbin/zzz
	RET=$?
else
	unsupported
fi

#Refresh devices as a resume can do funny things
for type in button battery ac_adapter
do
	devices=`hal-find-by-capability --capability $type`
	for device in $devices
	do
		dbus-send --system --dest=org.freedesktop.Hal \
			  $device org.freedesktop.Hal.Device.Rescan
	done
done

exit $RET

--- NEW FILE: hal-system-storage-cleanup-mountpoints-freebsd ---
#!/bin/sh

# Copyright (C) 2006, Jean-Yves Lefort <jylefort at FreeBSD.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.

MOUNT_ROOT="/media"

for DIR in $MOUNT_ROOT/*; do

    # check if we created it
    if [ -e "$DIR/.created-by-hal" ]; then
	BUSY=0
	/sbin/mount | while read dev on dir rest; do
	    if [ "x$dir" = "x$DIR" ]; then
	        exit 1
	    fi
	done
	BUSY=$?

	if [ "$BUSY" != "1" ]; then
	    rm -f "$DIR/.created-by-hal"
	    rmdir "$DIR" 2>/dev/null || true
	fi
    fi
done

exit 0

--- NEW FILE: hal-system-storage-eject-freebsd ---
#!/bin/sh

# Copyright (C) 2006, Jean-Yves Lefort <jylefort at FreeBSD.org>
# Copyright (C) 2006, Joe Marcus Clarke <marcus at FreeBSD.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.
#

# read parameters
# "<option1>\t<option2>\n"
# Only allow ^a-zA-Z0-9_= in the string because otherwise someone may
# pass e.g. umask=0600,suid,dev or umask=`/bin/evil`

rc=0
read GIVEN_EJECTOPTIONS
GIVEN_EJECTOPTIONS="`echo \"$GIVEN_EJECTOPTIONS\" | tr -Cd \"a-zA-Z0-9_=[:space:]\"`"
if [ -n "$HAL_PROP_VOLUME_MOUNT_POINT" ]; then
    RESULT=$(umount $HAL_PROP_VOLUME_MOUNT_POINT 2>&1)
    rc=$?

    if [ $? -eq 0 ]; then
        RESULT=$(cdcontrol -f "$HAL_PROP_BLOCK_DEVICE" eject 2>&1)
        rc=$?
    fi
else
    RESULT=$(cdcontrol -f "$HAL_PROP_BLOCK_DEVICE" eject 2>&1)
    rc=$?
fi

if [ $rc -ne 0 ]; then
    case "$RESULT" in
	*busy*)
	    echo "org.freedesktop.Hal.Device.Volume.Busy" >&2
	    echo "Device is busy." >&2
	    ;;
	*)
	    echo "org.freedesktop.Hal.Device.Volume.UnknownFailure" >&2
	    echo "Unknown failure." >&2
    esac
    exit 1
fi

if [ -n "$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT" ]; then
    # remove directory only if HAL has created it
    if [ -e $HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT/.created-by-hal ]; then
	rm -f $HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT/.created-by-hal
	rmdir "$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT" 2>/dev/null || true
    fi
fi

exit 0

--- NEW FILE: hal-system-storage-unmount-freebsd ---
#!/bin/sh

# Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
# Copyright (C) 2006, David Zeuthen <david at fubar.dk>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2.

# read parameters
# "lazy\tforce\n"
# Only allow ^a-zA-Z0-9_= in the string because otherwise someone may
# pass e.g. umask=0600,suid,dev or umask=`/bin/evil`

read GIVEN_UNMOUNTOPTIONS
GIVEN_UNMOUNTOPTIONS="`echo \"$GIVEN_UNMOUNTOPTIONS\" | tr -Cd \"a-zA-Z0-9_=[:space:]\"`"

if [ -n "$GIVEN_UNMOUNTOPTIONS" ]; then
    for OPTION in $GIVEN_UNMOUNTOPTIONS; do
	OPTION_WAS_OK="0"
	for VALID_OPTION in $HAL_PROP_VOLUME_UNMOUNT_VALID_OPTIONS; do
	    if [ "x$OPTION" = "x$VALID_OPTION" ]; then
		OPTION_WAS_OK="1"
		break
	    fi
	done

	if [ "$OPTION_WAS_OK" = "1" ]; then
		case "$OPTION" in
		    "lazy")
			UNMOUNTOPTIONS="$UNMOUNTOPTIONS -l"
			OPTION_WAS_OK="1"
			;;
		    "force")
			UNMOUNTOPTIONS="$UNMOUNTOPTIONS -f"
			OPTION_WAS_OK="1"
			;;
		    *)
			echo "org.freedesktop.Hal.Device.Volume.UnsupportedUnmountOption" >&2
			echo "The option '$OPTION' is not supported" >&2
			exit 1
		esac
	else
		echo "org.freedesktop.Hal.Device.Volume.InvalidUnmountOption" >&2
		echo "The option '$OPTION' is invalid" >&2
		exit 1
	fi
    done
fi

RESULT=$(umount $UNMOUNTOPTIONS "$MOUNT_POINT"  2>&1)
if [ $? -ne 0 ]; then
    case "$RESULT" in
	*busy*)
	    echo "org.freedesktop.Hal.Device.Volume.Busy" >&2
	    echo "Device is busy." >&2
	    ;;
	*"not mounted"*)
	    echo "org.freedesktop.Hal.Device.Volume.NotMounted" >&2
	    echo "Device is not mounted." >&2
	    ;;
	*)
	    echo "org.freedesktop.Hal.Device.Volume.UnknownFailure" >&2
	    echo "Unknown failure." >&2
    esac
    exit 1
fi

# remove directory only if HAL has created it
if [ -e "$MOUNT_POINT/.created-by-hal" ]; then
  rm -f "$MOUNT_POINT/.created-by-hal"
  rmdir "$MOUNT_POINT" 2>/dev/null || true
fi

hal-set-property --udi $UDI --key info.hal_mount.created_mount_point --remove > /dev/null 2>&1
hal-set-property --udi $UDI --key info.hal_mount.mounted_by_uid --remove > /dev/null 2>&1

exit 0




More information about the hal-commit mailing list