hal: Branch 'master' - 2 commits

David Zeuthen david at kemper.freedesktop.org
Mon Feb 19 23:33:45 PST 2007


 configure.in              |   11 ++++
 libhal/libhal.h           |    5 -
 tools/Makefile.am         |    8 +++
 tools/hal-storage-mount.c |    4 +
 tools/umount-hal.c        |  122 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 145 insertions(+), 5 deletions(-)

New commits:
diff-tree 184afb9acb61816203c852ab3559a849248362d3 (from 56d25189e3173333c457b349496f0b1b1665b6dd)
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Feb 20 02:33:41 2007 -0500

    build time for /sbin/umount.hal and make our mount helper use this
    
    This is detailed in
    
     https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=188193
    
    This option is off by default. It can enabled with --enable-umount-helper.

diff --git a/configure.in b/configure.in
index 053d738..8c4cccf 100644
--- a/configure.in
+++ b/configure.in
@@ -405,6 +405,16 @@ if test "x$enable_acl_management" != "xn
    msg_aclmgmt=yes
 fi
 
+# check for umount.hal
+AM_CONDITIONAL(HAVE_UMOUNT_HAL, false)
+AC_ARG_ENABLE(umount-helper,  [  --enable-umount-helper  Provide umount.hal helper],enable_umount_hal=$enableval,enable_umount_hal=no)
+msg_umount_hal=no
+if test "x$enable_umount_hal" != "xno"; then
+   AM_CONDITIONAL(HAVE_UMOUNT_HAL, true)
+   AC_DEFINE(HAVE_UMOUNT_HAL, [], [Set if we should provide and use the /sbin/umount.hal helper ])
+   msg_umount_hal=yes
+fi
+
 # what extra hotplug backends to use (ACPI, APM, PMU etc)
 AC_ARG_ENABLE(have_acpi, [  --disable-acpi          Build without ACPI support])
 msg_acpi=no
@@ -813,6 +823,7 @@ echo "
         use PolicyKit:              ${msg_polkit}
         use ConsoleKit:             ${msg_conkit}
         use ACL management:         ${msg_aclmgmt}
+        use umount.hal helper:      ${msg_umount_hal}
         use ACPI:                   ${msg_acpi}
         use PMU:                    ${msg_pmu}
         use APM:                    ${msg_apm}
diff --git a/tools/Makefile.am b/tools/Makefile.am
index e594bde..64b76f3 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -110,6 +110,14 @@ script_SCRIPTS =				\
 
 EXTRA_DIST=$(man_MANS) $(MAN_IN_FILES) gen-libgphoto-hal-fdi $(script_SCRIPTS)
 
+if HAVE_UMOUNT_HAL
+slashsbindir = /sbin
+slashsbin_PROGRAMS = umount.hal
+
+umount_hal_SOURCES = umount-hal.c
+umount_hal_LDADD = @DBUS_LIBS@ $(top_builddir)/libhal/libhal.la $(top_builddir)/libhal-storage/libhal-storage.la
+endif
+
 check:
 	for f in $(script_SCRIPTS); do \
             echo -n "Validate bash syntax in $$f : "; \
diff --git a/tools/hal-storage-mount.c b/tools/hal-storage-mount.c
index 8a0131e..63120c1 100644
--- a/tools/hal-storage-mount.c
+++ b/tools/hal-storage-mount.c
@@ -825,7 +825,11 @@ handle_mount (LibHalContext *hal_ctx, 
 	args[na++] = mount_do_fstype;
 
 	args[na++] = "-o";
+#ifdef HAVE_UMOUNT_HAL
+	mount_option_str = g_string_new (MOUNT_OPTIONS ",uhelper=hal");
+#else
 	mount_option_str = g_string_new (MOUNT_OPTIONS);
+#endif
 	for (i = 0; given_options[i] != NULL; i++) {
 		g_string_append (mount_option_str, ",");
 		g_string_append (mount_option_str, given_options[i]);
diff --git a/tools/umount-hal.c b/tools/umount-hal.c
new file mode 100644
index 0000000..60f7231
--- /dev/null
+++ b/tools/umount-hal.c
@@ -0,0 +1,122 @@
+/***************************************************************************
+ *
+ * umount-hal.c : Plug-in for umount(8) - see RH #188193
+ *
+ * https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=188193
+ *
+ * Copyright (C) 2007 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libhal.h>
+#include <libhal-storage.h>
+
+int
+main (int argc, char *argv[])
+{
+	int ret;
+	char *device_file;
+	DBusError error;
+	DBusConnection *con;
+	LibHalContext *hal_ctx;
+	LibHalVolume *vol;
+	DBusMessage *message;
+	DBusMessage *reply;
+	int hal_retcode;
+	char **options = NULL;
+	int num_options = 0;
+
+	ret = 1;
+
+	if (argc != 2) {
+		fprintf (stderr, "%s: program is supposed to be called with only one argument.", argv[0]);
+		goto out;
+	}
+
+	device_file = argv[1];
+
+	dbus_error_init (&error);
+	con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+	if (con == NULL) {
+		fprintf (stderr, "%s: dbus_bus_get(): %s: %s\n", argv[0], error.name, error.message);
+		goto out;
+	}
+
+	hal_ctx = libhal_ctx_new ();
+	libhal_ctx_set_dbus_connection (hal_ctx, con);
+	if (!libhal_ctx_init (hal_ctx, &error)) {
+		if (dbus_error_is_set(&error)) {
+			fprintf (stderr, "%s: libhal_ctx_init: %s: %s\n", argv[0], error.name, error.message);
+			dbus_error_free (&error);
+		}
+		goto out;
+	}
+
+	vol = libhal_volume_from_device_file (hal_ctx, device_file);
+	if (vol == NULL) {
+		fprintf (stderr, "%s: %s is not recognized by hal\n", argv[0], device_file);
+		goto out;
+	}
+
+	message = dbus_message_new_method_call ("org.freedesktop.Hal", 
+						libhal_volume_get_udi (vol),
+						"org.freedesktop.Hal.Device.Volume",
+						"Unmount");
+	if (message == NULL) {
+		goto out;
+	}
+
+	if (!dbus_message_append_args (message, 
+				       DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &options, num_options,
+				       DBUS_TYPE_INVALID)) {
+		goto out;
+	}
+
+
+	if (!(reply = dbus_connection_send_with_reply_and_block (con, 
+								 message, 
+								 -1,
+								 &error)) || dbus_error_is_set (&error)) {
+		fprintf (stderr, "%s: Unmounting %s failed: %s: %s\n", 
+			 argv[0], device_file, error.name, error.message);
+		goto out;
+	}
+
+	if (!dbus_message_get_args (reply, 
+				    &error,
+				    DBUS_TYPE_INT32, &hal_retcode,
+				    DBUS_TYPE_INVALID)) {
+		/* should never happen */
+		goto out;
+	}
+
+	if (hal_retcode != 0) {
+		/* should never happen; we should get an exception instead */
+		goto out;
+	}
+
+	ret = 0;
+
+out:
+	return ret;	
+}
diff-tree 56d25189e3173333c457b349496f0b1b1665b6dd (from a7b41e73c214fa95a8ca2ab1805de5558251f599)
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Feb 20 02:28:46 2007 -0500

    remove annoying LIBHAL_FREE_DBUS_ERROR spew to stderr

diff --git a/libhal/libhal.h b/libhal/libhal.h
index 9962da1..34135b7 100644
--- a/libhal/libhal.h
+++ b/libhal/libhal.h
@@ -46,11 +46,6 @@ extern "C" {
 	do {									\
 		if (dbus_error_is_set(_dbus_error_))				\
 			dbus_error_free (_dbus_error_);				\
-		else								\
-			fprintf (stderr,					\
-				 "%s %d : INFO: called LIBHAL_FREE_DBUS_ERROR "	\
-				 "but dbusError was not set.\n", 		\
-				 __FILE__, __LINE__);				\
 	} while (0)
 
 


More information about the hal-commit mailing list