hal/tools Makefile.am, 1.38, 1.39 hal-luks-remove, 1.1, 1.2 hal-luks-remove.in, 1.3, 1.4 hal-luks-setup, 1.4, 1.5 hal-luks-teardown, 1.2, 1.3 hal-storage-mount.c, 1.4, 1.5 hal-system-lcd-get-brightness, 1.9, 1.10 hal-system-lcd-set-brightness, 1.10, 1.11 hal-system-power-hibernate, 1.12, 1.13 hal-system-power-pmu.c, 1.1, 1.2 hal-system-power-reboot, 1.6, 1.7 hal-system-power-set-power-save, 1.5, 1.6 hal-system-power-shutdown, 1.6, 1.7 hal-system-power-suspend, 1.12, 1.13 hal-system-storage-cleanup-mountpoint, 1.1, 1.2 hal-system-storage-cleanup-mountpoints, 1.3, 1.4 hal-system-storage-eject, 1.10, 1.11 hal-system-storage-unmount, 1.11, 1.12

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


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

Modified Files:
	Makefile.am hal-luks-remove hal-luks-remove.in hal-luks-setup 
	hal-luks-teardown hal-storage-mount.c 
	hal-system-lcd-get-brightness hal-system-lcd-set-brightness 
	hal-system-power-hibernate hal-system-power-pmu.c 
	hal-system-power-reboot hal-system-power-set-power-save 
	hal-system-power-shutdown hal-system-power-suspend 
	hal-system-storage-cleanup-mountpoint 
	hal-system-storage-cleanup-mountpoints 
	hal-system-storage-eject hal-system-storage-unmount 
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


Index: Makefile.am
===================================================================
RCS file: /cvs/hal/hal/tools/Makefile.am,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- Makefile.am	9 May 2006 20:09:10 -0000	1.38
+++ Makefile.am	14 May 2006 18:49:53 -0000	1.39
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS =  linux device-manager
+SUBDIRS =  freebsd linux device-manager
 
 INCLUDES = \
 	-DPACKAGE_LIBEXEC_DIR=\""$(libexecdir)"\" \

Index: hal-luks-remove
===================================================================
RCS file: /cvs/hal/hal/tools/hal-luks-remove,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hal-luks-remove	13 Feb 2006 07:29:44 -0000	1.1
+++ hal-luks-remove	14 May 2006 18:49:53 -0000	1.2
@@ -6,43 +6,15 @@
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2.
 
-if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] || [ "$HAL_PROP_VOLUME_UUID" == "" ] ; then
+if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] || [ -z "$HAL_PROP_VOLUME_UUID" ] ; then
         echo "Missing or empty environment variable(s)." >&2
         echo "This script should be started by hald." >&2
         exit 1
 fi
 
-CRYPTSETUP=/sbin/cryptsetup
-
-# make sure that the cleartext volume is unmounted
-CLEARTEXT_VOLUME_UDI=`hal-find-by-property --key volume.crypto_luks.clear.backing_volume --string $HAL_PROP_INFO_UDI`
-RET=$?
-if [ x$RET = x0 ]; then
-    MOUNT_POINT=`hal-get-property --udi $CLEARTEXT_VOLUME_UDI --key volume.mount_point`
-    if [ ! x${#MOUNT_POINT} = x0 ]; then
-	/bin/umount -l "$MOUNT_POINT"
-        # remove directory only if HAL has created it
-	if [ -e "$MOUNT_POINT/.created-by-hal" ]; then
-	    rm -f "$MOUNT_POINT/.created-by-hal"
-	    rmdir --ignore-fail-on-non-empty "$MOUNT_POINT"
-	fi
-	
-    fi
-fi
-
-if [ ! -f $CRYPTSETUP ]; then
-	echo Error removing $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
-	exit 1
-fi
-
-if [ -z $HAL_PROP_VOLUME_UUID ]; then
-	echo Error determining UUID of $HAL_PROP_BLOCK_DEVICE >&2
-	exit 1
-fi
-
-if ! $CRYPTSETUP luksClose luks_crypto_$HAL_PROP_VOLUME_UUID 2> /dev/null; then
-	echo Error removing luks_crypto_$HAL_PROP_VOLUME_UUID >&2
-	exit 1
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
+    exit 1
 fi
-
-exit 0

Index: hal-luks-remove.in
===================================================================
RCS file: /cvs/hal/hal/tools/hal-luks-remove.in,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hal-luks-remove.in	29 Nov 2005 17:47:54 -0000	1.3
+++ hal-luks-remove.in	14 May 2006 18:49:53 -0000	1.4
@@ -22,40 +22,15 @@
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 # Check for environment variables
-if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] || [ "$HAL_PROP_VOLUME_UUID" == "" ] ; then
+if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] || [ -z "$HAL_PROP_VOLUME_UUID" ] ; then
         echo "Missing or empty environment variable(s)." >&2
         echo "This script should be started by hald." >&2
         exit 1
 fi
 
-CRYPTSETUP=/sbin/cryptsetup
-
-HAL_FIND_BY_PROPERTY=@BINDIR@/hal-find-by-property
-HAL_GET_PROPERTY=@BINDIR@/hal-get-property
-
-# make sure that the cleartext volume is unmounted
-CLEARTEXT_VOLUME_UDI=`$HAL_FIND_BY_PROPERTY --key volume.crypto_luks.clear.backing_volume --string $HAL_PROP_INFO_UDI`
-RET=$?
-if [ x$RET = x0 ]; then
-  MOUNT_POINT=`$HAL_GET_PROPERTY --udi $CLEARTEXT_VOLUME_UDI --key volume.mount_point`
-  if [ ! x${#MOUNT_POINT} = x0 ]; then
-    /bin/umount -l $MOUNT_POINT
-  fi
-fi
-
-if [ ! -f $CRYPTSETUP ]; then
-	echo Error removing $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
-	exit 1
-fi
-
-if [ -z $HAL_PROP_VOLUME_UUID ]; then
-	echo Error determining UUID of $HAL_PROP_BLOCK_DEVICE >&2
-	exit 1
-fi
-
-if ! $CRYPTSETUP remove luks_crypto_$HAL_PROP_VOLUME_UUID 2> /dev/null; then
-	echo Error removing luks_crypto_$HAL_PROP_VOLUME_UUID >&2
-	exit 1
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
+    exit 1
 fi
-
-exit 0

Index: hal-luks-setup
===================================================================
RCS file: /cvs/hal/hal/tools/hal-luks-setup,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- hal-luks-setup	24 Feb 2006 04:29:06 -0000	1.4
+++ hal-luks-setup	14 May 2006 18:49:53 -0000	1.5
@@ -6,36 +6,15 @@
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2.
 
-if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] || [ "$HAL_PROP_VOLUME_UUID" == "" ] ; then
+if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] || [ -z "$HAL_PROP_VOLUME_UUID" ] ; then
         echo "Missing or empty environment variable(s)." >&2
         echo "This script should be started by hald." >&2
         exit 1
 fi
 
-read password
-PASSWORD=${PASSWORD//[^[:alnum:]_=[:space:]:.+-]/@}
-
-CRYPTSETUP=/sbin/cryptsetup
-
-if [ ! -f $CRYPTSETUP ]; then
-    echo org.freedesktop.Hal.Device.Volume.Crypto.SetupError >&2
-    echo Error setting up $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
-    exit 1
-fi
-
-if [ -e /dev/mapper/luks_crypto_$HAL_PROP_VOLUME_UUID ]; then
-    echo org.freedesktop.Hal.Device.Volume.Crypto.SetupError >&2
-    echo $HAL_PROP_BLOCK_DEVICE is already setup? >&2
-    exit 1
-fi
-
-if ! echo $password | $CRYPTSETUP luksOpen $HAL_PROP_BLOCK_DEVICE luks_crypto_$HAL_PROP_VOLUME_UUID  2> /dev/null; then
-    /bin/sleep 3
-    echo org.freedesktop.Hal.Device.Volume.Crypto.SetupPasswordError >&2
-    echo Error setting up $HAL_PROP_BLOCK_DEVICE - bad password? >&2
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
     exit 1
 fi
-
-hal-set-property --udi=$UDI --key="info.callouts.remove" --strlist-pre="hal-luks-remove" > /dev/null 2>&1
-
-exit 0

Index: hal-luks-teardown
===================================================================
RCS file: /cvs/hal/hal/tools/hal-luks-teardown,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- hal-luks-teardown	14 Feb 2006 02:52:44 -0000	1.2
+++ hal-luks-teardown	14 May 2006 18:49:53 -0000	1.3
@@ -7,24 +7,15 @@
 # it under the terms of the GNU General Public License version 2.
 
 # Check for environment variables
-if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] || [ "$HAL_PROP_VOLUME_UUID" == "" ] ; then
+if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] || [ -z "$HAL_PROP_VOLUME_UUID" ] ; then
         echo "Missing or empty environment variable(s)." >&2
         echo "This script should be started by hald." >&2
         exit 1
 fi
 
-CRYPTSETUP=/sbin/cryptsetup
-
-if [ ! -f $CRYPTSETUP ]; then
-	echo org.freedesktop.Hal.Device.Volume.Crypto.TeardownError >&2
-	echo Error tearing down $HAL_PROP_BLOCK_DEVICE - $CRYPTSETUP not found >&2
-	exit 1
-fi
-
-if ! $CRYPTSETUP luksClose luks_crypto_$HAL_PROP_VOLUME_UUID  2> /dev/null; then
-	echo org.freedesktop.Hal.Device.Volume.Crypto.TeardownError >&2
-	echo Error tearing down $HAL_PROP_BLOCK_DEVICE - fs still mounted? >&2
-	exit 1
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
+    exit 1
 fi
-
-hal-set-property --udi=$UDI --key="info.callouts.remove" --strlist-rem="hal-luks-remove" > /dev/null 2>&1

Index: hal-storage-mount.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal-storage-mount.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- hal-storage-mount.c	28 Apr 2006 18:48:07 -0000	1.4
+++ hal-storage-mount.c	14 May 2006 18:49:53 -0000	1.5
@@ -31,7 +31,16 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#ifdef __FreeBSD__
+#include <fstab.h>
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+#include <limits.h>
+#include <pwd.h>
+#else
 #include <mntent.h>
+#endif
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -42,6 +51,23 @@
 /*#define DEBUG*/
 #define DEBUG
 
+#ifdef __FreeBSD__
+struct mtab_handle
+{
+  struct statfs	*mounts;
+  int		n_mounts;
+  int		iter;
+};
+#endif
+
+#ifdef __FreeBSD__
+#define MOUNT		"/sbin/mount"
+#define MOUNT_OPTIONS	"noexec,nosuid"
+#else
+#define MOUNT		"/bin/mount"
+#define MOUNT_OPTIONS	"noexec,nosuid,nodev"
+#endif
+
 static void
 usage (void)
 {
@@ -229,64 +255,166 @@
 	return f;
 }
 
+static gboolean
+fstab_open (gpointer *handle)
+{
+#ifdef __FreeBSD__
+	return setfsent () == 1;
+#else
+	*handle = fopen ("/etc/fstab", "r");
+	return *handle != NULL;
+#endif
+}
+
+static char *
+fstab_next (gpointer handle)
+{
+#ifdef __FreeBSD__
+	struct fstab *fstab;
+
+	fstab = getfsent ();
+
+	return fstab ? fstab->fs_spec : NULL;
+#else
+	struct mntent *mnt;
+
+	mnt = getmntent (handle);
+
+	return mnt ? mnt->mnt_fsname : NULL;
+#endif
+}
+
+static void
+fstab_close (gpointer handle)
+{
+#ifdef __FreeBSD__
+	endfsent ();
+#else
+	fclose (handle);
+#endif
+}
+
 static void
 bailout_if_in_fstab (const char *device)
 {
-	FILE *fstab;
-	struct mntent *mnt;
+	gpointer handle;
+	char *entry;
 
 	/* check if /etc/fstab mentions this device... (with symlinks etc) */
-	fstab = fopen ("/etc/fstab", "r");
-	if (fstab == NULL) {
+	if (! fstab_open (&handle)) {
 		printf ("cannot open /etc/fstab\n");
 		unknown_error ();		
 	}
-	while ((mnt = getmntent (fstab)) != NULL) {
+	while ((entry = fstab_next (handle)) != NULL) {
 		char *resolved;
 
-		resolved = resolve_symlink (mnt->mnt_fsname);
+		resolved = resolve_symlink (entry);
 #ifdef DEBUG
-		printf ("/etc/fstab: device %s -> %s \n", mnt->mnt_fsname, resolved);
+		printf ("/etc/fstab: device %s -> %s \n", entry, resolved);
 #endif
 		if (strcmp (device, resolved) == 0) {
-			printf ("%s (-> %s) found in /etc/fstab. Not mounting.\n", mnt->mnt_fsname, resolved);
+			printf ("%s (-> %s) found in /etc/fstab. Not mounting.\n", entry, resolved);
 			permission_denied_etc_fstab (device);
 		}
 
 		g_free (resolved);
 	}
-	fclose (fstab);
+	fstab_close (handle);
+}
+
+static gboolean
+mtab_open (gpointer *handle)
+{
+#ifdef __FreeBSD__
+	struct mtab_handle *mtab;
+
+	mtab = g_new0 (struct mtab_handle, 1);
+	mtab->n_mounts = getmntinfo (&mtab->mounts, MNT_NOWAIT);
+	if (mtab->n_mounts == 0) {
+		g_free (mtab);
+		return FALSE;
+	}
+
+	*handle = mtab;
+	return TRUE;
+#else
+	*handle = fopen ("/proc/mounts", "r");
+	return *handle != NULL;
+#endif
+}
+
+static char *
+mtab_next (gpointer handle)
+{
+#ifdef __FreeBSD__
+	struct mtab_handle *mtab = handle;
+
+	if (mtab->iter < mtab->n_mounts)
+		return mtab->mounts[mtab->iter++].f_mntfromname;
+	else
+		return NULL;
+#else
+	struct mntent *mnt;
+
+	mnt = getmntent (handle);
+
+	return mnt ? mnt->mnt_fsname : NULL;
+#endif
+}
+
+static void
+mtab_close (gpointer handle)
+{
+#ifdef __FreeBSD__
+	g_free (handle);
+#else
+	fclose (handle);
+#endif
 }
 
 static void
 bailout_if_mounted (const char *device)
 {
-	FILE *mtab;
-	struct mntent *mnt;
+	gpointer handle;
+	char *entry;
 
 	/* check if /proc/mounts mentions this device... (with symlinks etc) */
-	mtab = fopen ("/proc/mounts", "r");
-	if (mtab == NULL) {
-		printf ("cannot open /proc/mounts\n");
+	if (! mtab_open (&handle)) {
+		printf ("cannot open mount list\n");
 		unknown_error ();		
 	}
-	while ((mnt = getmntent (mtab)) != NULL) {
+	while ((entry = mtab_next (handle)) != NULL) {
 		char *resolved;
 
-		resolved = resolve_symlink (mnt->mnt_fsname);
+		resolved = resolve_symlink (entry);
 #ifdef DEBUG
-		printf ("/proc/mounts: device %s -> %s \n", mnt->mnt_fsname, resolved);
+		printf ("/proc/mounts: device %s -> %s \n", entry, resolved);
 #endif
 		if (strcmp (device, resolved) == 0) {
-			printf ("%s (-> %s) found in /proc/mounts. Not mounting.\n", mnt->mnt_fsname, resolved);
+			printf ("%s (-> %s) found in mount list. Not mounting.\n", entry, resolved);
 			already_mounted (device);
 		}
 
 		g_free (resolved);
 	}
-	fclose (mtab);
+	mtab_close (handle);
 }
 
+/* maps volume_id fs types to the appropriate -t mount option */
+static const char *
+map_fstype (const char *fstype)
+{
+#ifdef __FreeBSD__
+	if (! strcmp (fstype, "iso9660"))
+		return "cd9660";
+	else if (! strcmp (fstype, "ext2"))
+		return "ext2fs";
+	else if (! strcmp (fstype, "vfat"))
+		return "msdosfs";
+#endif
+
+	return fstype;
+}
 
 static void
 handle_mount (LibHalContext *hal_ctx, LibPolKitContext *pol_ctx, const char *udi,
@@ -318,6 +446,11 @@
 	gboolean is_temporary_privilege;
 	gboolean explicit_mount_point_given;
 	const char *end;
+#ifdef __FreeBSD__
+	struct passwd *pw;
+	uid_t calling_uid;
+	gid_t calling_gid;
+#endif
 
 #ifdef DEBUG
 	printf ("device         = %s\n", device);
@@ -569,6 +702,22 @@
 		unknown_error ();
 	}
 
+#ifdef __FreeBSD__
+	calling_uid = (uid_t) strtol (invoked_by_uid, (char **) NULL, 10);
+	pw = getpwuid (calling_uid);
+	if (pw != NULL) {
+		calling_gid = pw->pw_gid;
+	} else {
+		calling_gid = 0;
+	}
+	if (chown (mount_dir, calling_uid, calling_gid) != 0) {
+		printf ("Cannot chown '%s' to uid: %d, gid: %d\n", mount_dir,
+		        calling_uid, calling_gid);
+		g_rmdir (mount_dir);
+		unknown_error ();
+	}
+#endif
+
 	cbh_path = g_strdup_printf ("%s/.created-by-hal", mount_dir);
 	cbh = fopen (cbh_path, "w");
 	if (cbh == NULL) {
@@ -580,21 +729,21 @@
 
 	/* construct arguments to mount */
 	na = 0;
-	args[na++] = "/bin/mount";
+	args[na++] = MOUNT;
 	if (strlen (mount_fstype) > 0) {
 		args[na++] = "-t";
-		args[na++] = mount_fstype;
+		args[na++] = (char *) map_fstype (mount_fstype);
 	} else if (volume == NULL) {
 		/* non-pollable drive; force auto */
 		args[na++] = "-t";
 		args[na++] = "auto";
 	} else if (libhal_volume_get_fstype (volume) != NULL && strlen (libhal_volume_get_fstype (volume)) > 0) {
 		args[na++] = "-t";
-		args[na++] = (char *) libhal_volume_get_fstype (volume);
+		args[na++] = (char *) map_fstype (libhal_volume_get_fstype (volume));
 	}
 
 	args[na++] = "-o";
-	mount_option_str = g_string_new("noexec,nosuid,nodev");
+	mount_option_str = g_string_new(MOUNT_OPTIONS);
 	for (i = 0; given_options[i] != NULL; i++) {
 		g_string_append (mount_option_str, ",");
 		g_string_append (mount_option_str, given_options[i]);
@@ -615,7 +764,7 @@
 			   &serr,
 			   &exit_status,
 			   &err)) {
-		printf ("Cannot execute /bin/mount\n");
+		printf ("Cannot execute %s\n", MOUNT);
 		g_unlink (cbh_path);
 		g_rmdir (mount_dir);
 		unknown_error ();
@@ -625,7 +774,7 @@
 	if (exit_status != 0) {
 		char errstr[] = "mount: unknown filesystem type";
 
-		printf ("/bin/mount error %d, stdout='%s', stderr='%s'\n", exit_status, sout, serr);
+		printf ("%s error %d, stdout='%s', stderr='%s'\n", MOUNT, exit_status, sout, serr);
 
 		g_unlink (cbh_path);
 		g_rmdir (mount_dir);

Index: hal-system-lcd-get-brightness
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-lcd-get-brightness,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- hal-system-lcd-get-brightness	27 Apr 2006 21:31:37 -0000	1.9
+++ hal-system-lcd-get-brightness	14 May 2006 18:49:53 -0000	1.10
@@ -8,71 +8,15 @@
 # (at your option) any later version.
 
 # Check for environment variables
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "" ]; then
+if [ -z "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" ]; then
 	echo "Missing or empty environment variable(s)." >&2
 	echo "This script should be started by hald." >&2
 	exit 1
 fi
 
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
-	value="`hal-system-power-pmu getlcd`"
-	if [ $? -ne 0 ]; then
-		echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-		exit 1
-	fi
-	exit ${value}
-fi
-
-# Check for file existance and that it's readable
-if [ ! -r $HAL_PROP_LINUX_ACPI_PATH ]; then
-	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-	echo "$1 not readable!" >&2
-	exit 1
-fi
-
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "toshiba" ]; then
-	# cat /proc/acpi/toshiba/lcd
-	#  brightness:              5
-	#  brightness_levels:       8
-	value="`cat $HAL_PROP_LINUX_ACPI_PATH | grep brightness: | awk '{print $2;}'`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "asus" ]; then
-	# cat /proc/acpi/asus/brn
-	#  5
-	value="`cat $HAL_PROP_LINUX_ACPI_PATH`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "panasonic" ]; then
-	# cat /proc/acpi/pcc/brightness
-	#  5
-	value="`cat $HAL_PROP_LINUX_ACPI_PATH`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "ibm" ]; then
-	# cat /proc/acpi/ibm/brightness
-	#  level:          5
-	#  commands:       up, down
-	#  commands:       level <level> (<level> is 0-7)
-	value="`cat $HAL_PROP_LINUX_ACPI_PATH | grep level: | awk '{print $2;}'`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "sony" ]; then
-	# cat /proc/acpi/sony/brightness
-	#  5
-	value="`cat $HAL_PROP_LINUX_ACPI_PATH`"
-	let "value = ${value} - 1"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "omnibook" ]; then
-	# cat /proc/omnibook/lcd
-	#  LCD brightness:  7
-	value="`cat $HAL_PROP_LINUX_ACPI_PATH | awk '{print $3;}'`"
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "sonypi" -a -x /usr/sbin/spicctrl ]; then
-		# spicctrl -B
-		# 70
-		# 0..255
-		value="`/usr/sbin/spicctrl -B`"
-		RETVAL=$?
-		if [ $RETVAL != 0 ]; then
-			echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-			exit 1;
-		fi
-		exit ${value}
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
 else
-	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-	echo "No ACPI method found" >&2
-	exit 1
-	fi
-
-exit ${value}
+    echo "No back-end for your operating system" >&2
+    exit 1
+fi

Index: hal-system-lcd-set-brightness
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-lcd-set-brightness,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- hal-system-lcd-set-brightness	27 Apr 2006 21:31:37 -0000	1.10
+++ hal-system-lcd-set-brightness	14 May 2006 18:49:53 -0000	1.11
@@ -8,8 +8,8 @@
 # (at your option) any later version.
 
 # Check for environment variables
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "" ] || 
-   [ "$HAL_PROP_LAPTOP_PANEL_NUM_LEVELS" == "" ] ; then
+if [ -z "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" ] || 
+   [ -z "$HAL_PROP_LAPTOP_PANEL_NUM_LEVELS" ] ; then
         echo "Missing or empty environment variable(s)." >&2
         echo "This script should be started by hald." >&2
         exit 1
@@ -18,23 +18,6 @@
 # read value for set brightness
 read value
 
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
-	hal-system-power-pmu setlcd $value
-	if [ $? -ne 0 ]; then
-		echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-		exit 1
-	fi
-	exit 0
-fi
-
-# Check for file existance and that it's writable and that we don't have a sonypi
-# access method
-if [ ! -w $HAL_PROP_LINUX_ACPI_PATH -a "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" != "sonypi" ]; then
-	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-	echo "$1 not writable!" >&2
-	exit 1
-fi
-
 # Check for values outside range
 if [ ${value} -lt 0 ] || [ ${value} -ge $HAL_PROP_LAPTOP_PANEL_NUM_LEVELS ]; then
 	echo "org.freedesktop.Hal.Device.LaptopPanel.Invalid" >&2
@@ -42,36 +25,11 @@
 	exit 1
 fi
 
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "toshiba" ]; then
-	# echo "brightness: {0..x}" >/proc/acpi/toshiba/lcd
-	echo "brightness: $value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "asus" ]; then
-	# echo {0..15} > /proc/acpi/asus/brn
-	# http://www.taupro.com/wiki/ChemBook/LCDdisplayPowerConfiguration
-	echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "panasonic" ]; then
-	# echo {0..15} > /proc/acpi/pcc/brightness
-	# http://readlist.com/lists/vger.kernel.org/linux-kernel/7/36405.html
-	echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "ibm" ]; then
-	# echo "level {0..7}" > /proc/acpi/ibm/brightness
-	# http://ibm-acpi.sourceforge.net/README
-	echo "level $value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "sony" ]; then
-	# echo "{1..8}" > /proc/acpi/sony/brightness
-	# http://popies.net/sonypi/2.6-sony_acpi4.patch
-	echo "$((value + 1))" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "omnibook" ]; then
-	# echo "{0..7}" > /proc/omnibook/lcd
-	# http://bugzilla.gnome.org/show_bug.cgi?id=331458
-	echo "$value" > $HAL_PROP_LINUX_ACPI_PATH
-elif [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "sonypi" -a -x /usr/sbin/spicctrl ]; then
-	# spicctrl -b "{0..255}"
-	/usr/sbin/spicctrl -b ${value}
-else
-	echo "org.freedesktop.Hal.Device.LaptopPanel.NotSupported" >&2
-	echo "No ACPI method found" >&2
-	exit 1
-	fi
+export value
 
-exit 0
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
+    exit 1
+fi

Index: hal-system-power-hibernate
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-hibernate,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- hal-system-power-hibernate	24 Apr 2006 17:46:03 -0000	1.12
+++ hal-system-power-hibernate	14 May 2006 18:49:53 -0000	1.13
@@ -1,15 +1,5 @@
 #!/bin/sh
 
-POWERSAVED_SUSPEND2DISK="dbus-send --system --dest=com.novell.powersave \
-                         --print-reply /com/novell/powersave \
-                         com.novell.powersave.action.SuspendToDisk"
-
-unsupported() {
-	echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
-	echo No hibernate script found >&2
-	exit 1
-}
-
 POLICY=hal-power-hibernate
 if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ] ; then
     polkit-is-privileged --privilege $POLICY --user $HAL_METHOD_INVOKED_BY_UID
@@ -21,57 +11,9 @@
     fi
 fi
 
-#SuSE and ALTLinux only support powersave
-if [ -f /etc/altlinux-release ] || [ -f "/etc/SuSE-release" ] ; then
-	if [ -x /usr/bin/powersave ] ; then
-	        $POWERSAVED_SUSPEND2DISK
-		RET=$?
-	else
-		unsupported
-	fi
-
-#RedHat/Fedora only support pm-utils
-elif [ -f /etc/redhat-release ] || [ -f /etc/fedora-release ] ; then
-	if [ -x /usr/sbin/pm-hibernate ] ; then
-		/usr/sbin/pm-hibernate
-		RET=$?
-	else
-		unsupported
-	fi
-
-#Other distros just need to have *any* tools installed
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
 else
-	if [ -x "/usr/bin/powersave" ] ; then
-	        $POWERSAVED_SUSPEND2DISK
-		RET=$?
-	elif [ -x "/usr/sbin/pmi" ] ; then
-		/usr/sbin/pmi action hibernate force
-		RET=$?
-	elif [ -x "/usr/sbin/pm-hibernate" ] ; then
-		/usr/sbin/pm-hibernate
-		RET=$?
-	elif [ -x "/usr/sbin/hibernate" ] ; then
-		# Suspend2 tools installed
-		/usr/sbin/hibernate --force
-		RET=$?
-	elif [ -w "/sys/power/state" ] ; then
-		# Use the raw kernel sysfs interface
-		echo "disk" > /sys/power/state
-		RET=$?
-	else
-		unsupported
-		fi
-	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 --print-reply --dest=org.freedesktop.Hal \
-			  $device org.freedesktop.Hal.Device.Rescan
-	done
-done
-
-exit $RET
+    echo "No back-end for your operating system" >&2
+    exit 1
+fi

Index: hal-system-power-pmu.c
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-pmu.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hal-system-power-pmu.c	29 Jan 2006 15:51:39 -0000	1.1
+++ hal-system-power-pmu.c	14 May 2006 18:49:53 -0000	1.2
@@ -35,7 +35,9 @@
 #include <fcntl.h>
 
 #include <sys/ioctl.h>
+#ifdef __linux__
 #include <linux/pmu.h>
+#endif
 #include <libhal/libhal.h>
 
 #define PMUDEV		"/dev/pmu"
@@ -57,6 +59,9 @@
 static int
 pmac_sleep (void)
 {
+#ifdef __FreeBSD__
+	return FALSE;			/* FIXME implement */
+#else
 	int ret;
 	int fd;
 
@@ -73,6 +78,7 @@
 		return FALSE;
 	}
 	return TRUE;
+#endif /* ! __FreeBSD__ */
 }
 
 /** Gets the LCD brightness
@@ -83,6 +89,9 @@
 static int
 pmac_get_lcd_brightness (int *val)
 {
+#ifdef __FreeBSD__
+	return FALSE;			/* FIXME implement */
+#else
 	int ret;
 	int fd;
 
@@ -99,6 +108,7 @@
 		return FALSE;
 	}
 	return TRUE;
+#endif /* ! __FreeBSD__ */
 }
 
 /** Sets the LCD brightness
@@ -109,6 +119,9 @@
 static int
 pmac_set_lcd_brightness (int val)
 {
+#ifdef __FreeBSD__
+	return FALSE;			/* FIXME implement */
+#else
 	int ret;
 	int fd;
 
@@ -125,6 +138,7 @@
 		return FALSE;
 	}
 	return TRUE;
+#endif /* ! __FreeBSD__ */
 }
 
 /** Print out program usage.

Index: hal-system-power-reboot
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-reboot,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- hal-system-power-reboot	26 Mar 2006 20:13:03 -0000	1.6
+++ hal-system-power-reboot	14 May 2006 18:49:53 -0000	1.7
@@ -1,11 +1,5 @@
 #!/bin/sh
 
-unsupported() {
-	echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
-	echo "No reboot command found" >&2
-	exit 1
-}
-
 POLICY=hal-power-reboot
 if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ] ; then
     polkit-is-privileged --privilege $POLICY --user $HAL_METHOD_INVOKED_BY_UID
@@ -17,13 +11,9 @@
     fi
 fi
 
-#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 $?
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
 else
-	unsupported
+    echo "No back-end for your operating system" >&2
+    exit 1
 fi

Index: hal-system-power-set-power-save
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-set-power-save,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- hal-system-power-set-power-save	24 Feb 2006 16:47:11 -0000	1.5
+++ hal-system-power-set-power-save	14 May 2006 18:49:53 -0000	1.6
@@ -1,44 +1,8 @@
 #!/bin/sh
-read value
-
-unsupported() {
-	echo org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported >&2
-	echo No powersave method found >&2
-	exit 1
-}
-
-#SuSE and ALTLinux only support powersave
-if [ -f /etc/altlinux-release ] || [ -f /etc/SuSE-release ] ; then
-	if [ -x "/usr/bin/powersave" ] ; then
-		if [ $value = "true" ]; then
-			/usr/bin/powersave -e Powersave
-			RET=$?
-		elif [ $value = "false" ]; then
-			/usr/bin/powersave -e Performance
-			RET=$?
-		fi
-	else
-		unsupported
-	fi
-
-#RedHat/Fedora only support pm-utils
-elif [ -f /etc/redhat-release ] || [ -f /etc/fedora-release ] ; then
-	if [ -x "/usr/sbin/pm-powersave" ] ; then
-		if [ $value = "true" ]; then
-			/usr/sbin/pm-powersave true
-			RET=$?
-		elif [ $value = "false" ]; then
-			/usr/sbin/pm-powersave false
-			RET=$?
-		fi
-	else
-		unsupported
-	fi
 
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
 else
-	# cannot set proc stuff here, so error out
-	unsupported
-	fi 
-
-exit $RET
-
+    echo "No back-end for your operating system" >&2
+    exit 1
+fi

Index: hal-system-power-shutdown
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-shutdown,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- hal-system-power-shutdown	26 Mar 2006 20:13:03 -0000	1.6
+++ hal-system-power-shutdown	14 May 2006 18:49:53 -0000	1.7
@@ -1,11 +1,5 @@
 #!/bin/sh
 
-unsupported() {
-	echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
-	echo "No shutdown command found" >&2
-	exit 1
-}
-
 POLICY=hal-power-poweroff
 if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ] ; then
     polkit-is-privileged --privilege $POLICY --user $HAL_METHOD_INVOKED_BY_UID
@@ -17,13 +11,9 @@
     fi
 fi
 
-#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 $?
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
 else
-	unsupported
+    echo "No back-end for your operating system" >&2
+    exit 1
 fi

Index: hal-system-power-suspend
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-power-suspend,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- hal-system-power-suspend	24 Apr 2006 17:46:03 -0000	1.12
+++ hal-system-power-suspend	14 May 2006 18:49:53 -0000	1.13
@@ -1,21 +1,5 @@
 #!/bin/sh
 
-POWERSAVED_SUSPEND2RAM="dbus-send --system --dest=com.novell.powersave \
-                        --print-reply /com/novell/powersave \
-                        com.novell.powersave.action.SuspendToRam"
-
-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
-}
-
 POLICY=hal-power-suspend
 if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ] ; then
     polkit-is-privileged --privilege $POLICY --user $HAL_METHOD_INVOKED_BY_UID
@@ -27,71 +11,9 @@
     fi
 fi
 
-read seconds_to_sleep
-
-#PMU systems cannot use /sys/power/state yet, so use a helper to issue an ioctl
-if [ "$HAL_PROP_LAPTOP_PANEL_ACCESS_METHOD" == "pmu" ]; then
-	hal-system-power-pmu sleep
-	if [ $? -ne 0 ]; then
-		echo "org.freedesktop.Hal.Device.SystemPowerManagement.NotSupported" >&2
-		exit 1
-	fi
-	exit 0
-fi
-
-#SuSE and ALTLinux only support powersave
-if [ -f "/etc/altlinux-release" ] || [ -f "/etc/SuSE-release" ] ; then
-	if [ -x /usr/bin/powersave ] ; then
-	        $POWERSAVED_SUSPEND2RAM
-		RET=$?
-	else
-		# TODO: add support
-		unsupported
-	fi
-
-#RedHat/Fedora only support pm-utils
-elif [ -f "/etc/redhat-release" ] || [ -f "/etc/fedora-release" ] ; then
-	# TODO: fix pm-suspend to take a --wakeup-alarm argument
-	if [ $seconds_to_sleep != "0" ] ; then
-		alarm_not_supported
-	fi
-	# TODO: fixup pm-suspend to define erroc code (see alarm above) and throw
-	#	   the appropriate exception
-	if [ -x "/usr/sbin/pm-suspend" ] ; then
-		/usr/sbin/pm-suspend
-		RET=$?
-	else
-		# TODO: add support
-		unsupported
-	fi
-
-#Other distros just need to have *any* tools installed
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
 else
-	if [ -x "/usr/bin/powersave" ] ; then
-	    $POWERSAVED_SUSPEND2RAM
-	    RET=$?
-	elif [ -x "/usr/sbin/pmi" ] ; then
-	    /usr/sbin/pmi action suspend force
-	    RET=$?
-	elif [ -w "/sys/power/state" ] ; then
-	    # Use the raw kernel sysfs interface
-	    echo "mem" > /sys/power/state
-	    RET=$?
-	else
-	    # TODO: add other scripts support
-	    unsupported
-	    fi
-	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 --print-reply --dest=org.freedesktop.Hal \
-			  $device org.freedesktop.Hal.Device.Rescan
-	done
-done
-
-exit $RET
+    echo "No back-end for your operating system" >&2
+    exit 1
+fi

Index: hal-system-storage-cleanup-mountpoint
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-cleanup-mountpoint,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- hal-system-storage-cleanup-mountpoint	12 Feb 2006 22:38:45 -0000	1.1
+++ hal-system-storage-cleanup-mountpoint	14 May 2006 18:49:53 -0000	1.2
@@ -5,7 +5,7 @@
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 2.
 
-if [ "$HALD_CLEANUP" = "" ]; then
+if [ -z "$HALD_CLEANUP" ]; then
     echo Specify directory to clean up with the environment variable HALD_CLEANUP
     exit 1
 fi
@@ -16,4 +16,5 @@
 fi
 
 rm -f "$HALD_CLEANUP/.created-by-hal"
-rmdir --ignore-fail-on-non-empty "$HALD_CLEANUP"
+rmdir "$HALD_CLEANUP" 2>/dev/null || true
+

Index: hal-system-storage-cleanup-mountpoints
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-cleanup-mountpoints,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- hal-system-storage-cleanup-mountpoints	13 Feb 2006 02:39:22 -0000	1.3
+++ hal-system-storage-cleanup-mountpoints	14 May 2006 18:49:53 -0000	1.4
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
 # Copyright (C) 2006, David Zeuthen <davidz at redhat.com>
@@ -6,27 +6,9 @@
 # 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
-
-    # /proc/mounts substitute spaces with 040
-    DIRMOD=${DIR//[[:space:]]/040}
-
-    # check if we created it
-    if [ -e "$DIR/.created-by-hal" ]; then
-	BUSY=0
-	while read dev dir type options; do
-	    if [ "$dir" = "$DIRMOD" ]; then
-		BUSY=1
-		break
-	    fi
-	done < /proc/mounts
-	if [ "$BUSY" != "1" ]; then
-	    rm -f "$DIR/.created-by-hal"
-	    rmdir --ignore-fail-on-non-empty "$DIR"
-	fi
-    fi
-done
-
-exit 0
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
+    exit 1
+fi

Index: hal-system-storage-eject
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-eject,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- hal-system-storage-eject	26 Mar 2006 20:13:03 -0000	1.10
+++ hal-system-storage-eject	14 May 2006 18:49:53 -0000	1.11
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
 # Copyright (C) 2006, David Zeuthen <david at fubar.dk>
@@ -7,14 +7,14 @@
 # it under the terms of the GNU General Public License version 2.
 #
 # Check for environment variables
-if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] ; then
+if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] ; then
     echo "Missing or empty environment variable(s)." >&2
     echo "This script should be started by hald." >&2
     exit 1
 fi
 
 if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ]; then
-    if [ "$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT" != "" ]; then
+    if [ -n "$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT" ]; then
 	if [ "$HAL_METHOD_INVOKED_BY_UID" != "$HAL_PROP_INFO_HAL_MOUNT_MOUNTED_BY_UID" ]; then
 	    echo "org.freedesktop.Hal.Device.Volume.PermissionDenied" >&2
 	    echo "Volume mounted by uid $HAL_PROP_INFO_HAL_MOUNT_MOUNTED_BY_UID cannot be ejected by uid $HAL_METHOD_INVOKED_BY_UID." >&2
@@ -35,34 +35,9 @@
 #    fi
 #fi
 
-# 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`
-
-read GIVEN_EJECTOPTIONS
-GIVEN_EJECTOPTIONS=${GIVEN_EJECTOPTIONS//[^a-zA-Z0-9_=[:space:]]/_}
-
-RESULT=$(eject "$HAL_PROP_BLOCK_DEVICE" 2>&1)
-if [ $? -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
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
     exit 1
 fi
-
-if [ "$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 --ignore-fail-on-non-empty "$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT"
-    fi
-fi
-
-exit 0

Index: hal-system-storage-unmount
===================================================================
RCS file: /cvs/hal/hal/tools/hal-system-storage-unmount,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- hal-system-storage-unmount	26 Mar 2006 20:13:03 -0000	1.11
+++ hal-system-storage-unmount	14 May 2006 18:49:53 -0000	1.12
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 # Copyright (C) 2005, Kay Sievers <kay.sievers at vrfy.org>
 # Copyright (C) 2006, David Zeuthen <david at fubar.dk>
@@ -7,16 +7,16 @@
 # it under the terms of the GNU General Public License version 2.
 
 # Check for environment variables
-if [ "$HAL_PROP_BLOCK_DEVICE" == "" ] || [ "$HAL_PROP_INFO_UDI" == "" ] ; then
+if [ -z "$HAL_PROP_BLOCK_DEVICE" ] || [ -z "$HAL_PROP_INFO_UDI" ] ; then
     echo "Missing or empty environment variable(s)." >&2
     echo "This script should be started by hald." >&2
     exit 1
 fi
 
 MOUNT_POINT="$HAL_PROP_INFO_HAL_MOUNT_CREATED_MOUNT_POINT"
-if [ "$MOUNT_POINT" == "" ]; then
+if [ -z "$MOUNT_POINT" ]; then
     MOUNT_POINT="$HAL_PROP_VOLUME_MOUNT_POINT"
-    if [ "$MOUNT_POINT" == "" ]; then
+    if [ -z "$MOUNT_POINT" ]; then
 	echo "org.freedesktop.Hal.Device.Volume.NotMounted" >&2
 	echo "Cannot figure out where device is mounted." >&2
 	exit 1
@@ -34,7 +34,7 @@
 if [ "$HAL_METHOD_INVOKED_BY_UID" != "0" ]; then
     if [ "$HAL_METHOD_INVOKED_BY_UID" != "$HAL_PROP_INFO_HAL_MOUNT_MOUNTED_BY_UID" ]; then
 	UID_MOUNTED="$HAL_PROP_INFO_HAL_MOUNT_MOUNTED_BY_UID"
-	if [ "$UID_MOUNTED" == "" ]; then
+	if [ -z "$UID_MOUNTED" ]; then
 	    UID_MOUNTED="UNKNOWN"
 	fi
 	echo "org.freedesktop.Hal.Device.Volume.PermissionDenied" >&2
@@ -55,72 +55,9 @@
 #    fi
 #fi
 
-# 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=${GIVEN_UNMOUNTOPTIONS//[^a-zA-Z0-9_=[:space:]]/_}
-
-if [ "$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 [ "$OPTION" == "$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
+if [ -n "$HALD_UNAME_S" -a -x ./$0-$HALD_UNAME_S ]; then
+    exec ./$0-$HALD_UNAME_S $@
+else
+    echo "No back-end for your operating system" >&2
     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 --ignore-fail-on-non-empty "$MOUNT_POINT"
-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