hal: Branch 'origin' - 4 commits
Holger Macht
homac at kemper.freedesktop.org
Tue Feb 20 01:14:22 PST 2007
configure.in | 11 +++
libhal-storage/libhal-storage.c | 47 +++++++++++++
libhal-storage/libhal-storage.h | 2
libhal/libhal.h | 5 -
tools/Makefile.am | 8 ++
tools/hal-storage-mount.c | 4 +
tools/umount-hal.c | 137 ++++++++++++++++++++++++++++++++++++++++
7 files changed, 209 insertions(+), 5 deletions(-)
New commits:
diff-tree e30c3d6de8da910f2547c5c12b1cbb3dfe99261d (from fd62ece9c0bce992d3b7ef09ab5ed74105ee25b7)
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Feb 20 03:12:28 2007 -0500
make /sbin/umount.hal handle mounts points as well
Add some new API to libhal-storage to make this easy to do.
diff --git a/libhal-storage/libhal-storage.c b/libhal-storage/libhal-storage.c
index caae4b2..5c62803 100644
--- a/libhal-storage/libhal-storage.c
+++ b/libhal-storage/libhal-storage.c
@@ -1356,6 +1356,53 @@ out:
}
+/** Get the volume object for a given mount point
+ *
+ * @param hal_ctx libhal context to use
+ * @param device_file Name of mount point without terminting slash, e.g. '/media/disk'
+ * @return LibHalVolume object or NULL if it doesn't exist
+ */
+LibHalVolume *
+libhal_volume_from_mount_point (LibHalContext *hal_ctx,
+ const char *mount_point)
+{
+ int i;
+ char **hal_udis;
+ int num_hal_udis;
+ LibHalVolume *result;
+ char *found_udi;
+ DBusError error;
+
+ LIBHAL_CHECK_LIBHALCONTEXT(hal_ctx, NULL);
+
+ result = NULL;
+ found_udi = NULL;
+
+ dbus_error_init (&error);
+ if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, "volume.mount_point",
+ mount_point, &num_hal_udis, &error)) == NULL)
+ goto out;
+
+ for (i = 0; i < num_hal_udis; i++) {
+ char *udi;
+ udi = hal_udis[i];
+ if (libhal_device_query_capability (hal_ctx, udi, "volume", &error)) {
+ found_udi = strdup (udi);
+ break;
+ }
+ }
+
+ libhal_free_string_array (hal_udis);
+
+ if (found_udi != NULL)
+ result = libhal_volume_from_udi (hal_ctx, found_udi);
+
+ free (found_udi);
+out:
+ LIBHAL_FREE_DBUS_ERROR(&error);
+ return result;
+}
+
/** Get the volume object for a given device file.
*
* @param hal_ctx libhal context to use
diff --git a/libhal-storage/libhal-storage.h b/libhal-storage/libhal-storage.h
index c88a389..39fec6d 100644
--- a/libhal-storage/libhal-storage.h
+++ b/libhal-storage/libhal-storage.h
@@ -279,6 +279,8 @@ LibHalVolume *libhal_volume_from_udi
const char *udi);
LibHalVolume *libhal_volume_from_device_file (LibHalContext *hal_ctx,
const char *device_file);
+LibHalVolume *libhal_volume_from_mount_point (LibHalContext *hal_ctx,
+ const char *mount_point);
void libhal_volume_free (LibHalVolume *volume);
dbus_uint64_t libhal_volume_get_size (LibHalVolume *volume);
dbus_uint64_t libhal_volume_get_disc_capacity (LibHalVolume *volume);
diff --git a/tools/umount-hal.c b/tools/umount-hal.c
index e16b96d..719943c 100644
--- a/tools/umount-hal.c
+++ b/tools/umount-hal.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <libhal.h>
#include <libhal-storage.h>
@@ -35,7 +36,7 @@ int
main (int argc, char *argv[])
{
int ret;
- char *device_file;
+ char *device_file_or_mount_point;
DBusError error;
DBusConnection *con;
LibHalContext *hal_ctx;
@@ -48,16 +49,16 @@ main (int argc, char *argv[])
ret = 1;
- if (argc < 2) {
+ if (argc < 2 || strlen (argv[1]) == 0) {
fprintf (stderr, "%s: this program is only supposed to be invoked by umount(8).\n", argv[0]);
goto out;
}
- /* it appears the device file is always the first argument.
- * TODO XXX FIXME: we ought to honor umount(8) options like
- * -v for verbose.
+ /* it appears the device file / mount point is always the
+ * first argument. TODO XXX FIXME: we ought to honor
+ * umount(8) options like -v for verbose.
*/
- device_file = argv[1];
+ device_file_or_mount_point = argv[1];
dbus_error_init (&error);
con = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
@@ -72,14 +73,24 @@ main (int argc, char *argv[])
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);
+ } else {
+ fprintf (stderr, "%s: libhal_ctx_init failed. Is hald running?\n", argv[0]);
}
goto out;
}
- vol = libhal_volume_from_device_file (hal_ctx, device_file);
+ vol = libhal_volume_from_device_file (hal_ctx, device_file_or_mount_point);
if (vol == NULL) {
- fprintf (stderr, "%s: %s is not recognized by hal\n", argv[0], device_file);
- goto out;
+
+ /* it might be a mount point! */
+ if (device_file_or_mount_point[strlen (device_file_or_mount_point) - 1] == '/') {
+ device_file_or_mount_point[strlen (device_file_or_mount_point) - 1] = '\0';
+ }
+ vol = libhal_volume_from_mount_point (hal_ctx, device_file_or_mount_point);
+ if (vol == NULL) {
+ fprintf (stderr, "%s: %s is not recognized by hal\n", argv[0], device_file_or_mount_point);
+ goto out;
+ }
}
message = dbus_message_new_method_call ("org.freedesktop.Hal",
@@ -102,7 +113,7 @@ main (int argc, char *argv[])
-1,
&error)) || dbus_error_is_set (&error)) {
fprintf (stderr, "%s: Unmounting %s failed: %s: %s\n",
- argv[0], device_file, error.name, error.message);
+ argv[0], device_file_or_mount_point, error.name, error.message);
goto out;
}
diff-tree fd62ece9c0bce992d3b7ef09ab5ed74105ee25b7 (from 184afb9acb61816203c852ab3559a849248362d3)
Author: David Zeuthen <davidz at redhat.com>
Date: Tue Feb 20 02:58:22 2007 -0500
make umount.hal work when options like -v are passed to umount
diff --git a/tools/umount-hal.c b/tools/umount-hal.c
index 60f7231..e16b96d 100644
--- a/tools/umount-hal.c
+++ b/tools/umount-hal.c
@@ -48,11 +48,15 @@ main (int argc, char *argv[])
ret = 1;
- if (argc != 2) {
- fprintf (stderr, "%s: program is supposed to be called with only one argument.", argv[0]);
+ if (argc < 2) {
+ fprintf (stderr, "%s: this program is only supposed to be invoked by umount(8).\n", argv[0]);
goto out;
}
+ /* it appears the device file is always the first argument.
+ * TODO XXX FIXME: we ought to honor umount(8) options like
+ * -v for verbose.
+ */
device_file = argv[1];
dbus_error_init (&error);
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