diff options
author | David Zeuthen <david@fubar.dk> | 2006-02-12 22:38:45 +0000 |
---|---|---|
committer | David Zeuthen <david@fubar.dk> | 2006-02-12 22:38:45 +0000 |
commit | 6618c87f42bbda0d527ebc3a81ae3bc3333a56a9 (patch) | |
tree | afeabf72805ed2e95e0861e36ecb4c087540ac18 | |
parent | 7a0efac9deb78de3410e019c9ae6dc300aceecbe (diff) |
Add tools/hal-system-storage-cleanup-mountpoint
New file
Clean up mount point if we can see it was created by hal
-rw-r--r-- | ChangeLog | 16 | ||||
-rw-r--r-- | hald/linux2/blockdev.c | 37 | ||||
-rw-r--r-- | tools/Makefile.am | 1 | ||||
-rwxr-xr-x | tools/hal-system-storage-cleanup-mountpoint | 19 |
4 files changed, 70 insertions, 3 deletions
@@ -1,8 +1,18 @@ 2006-02-12 David Zeuthen <davidz@redhat.com> - * tools/hal-system-storage-unmount (MOUNT_POINT): Attempt to use - volume.mount_point if we cannot find - info.hal_mount.created_mount_point + * tools/Makefile.am (script_SCRIPTS): Add + tools/hal-system-storage-cleanup-mountpoint + + * tools/hal-system-storage-cleanup-mountpoint: New file + + * hald/linux2/blockdev.c (blockdev_refresh_mount_state) + (cleanup_mountpoint_cb): Clean up mount point if we can see it was + created by hal + +2006-02-12 David Zeuthen <davidz@redhat.com> + + * tools/hal-system-storage-unmount: Attempt to use volume.mount_point + if we cannot find info.hal_mount.created_mount_point * libhal/libhal.h: Export prototype for new function libhal_ctx_get_dbus_connection() diff --git a/hald/linux2/blockdev.c b/hald/linux2/blockdev.c index dc535fb8..bce441a8 100644 --- a/hald/linux2/blockdev.c +++ b/hald/linux2/blockdev.c @@ -162,6 +162,17 @@ blockdev_callouts_remove_done (HalDevice *d, gpointer userdata1, gpointer userda hotplug_event_end (end_token); } +static void +cleanup_mountpoint_cb (HalDevice *d, guint32 exit_type, + gint return_code, gchar **error, + gpointer data1, gpointer data2) +{ + char *mount_point = (char *) data1; + HAL_INFO (("In cleanup_mountpoint_cb for '%s'", mount_point)); + g_free (mount_point); +} + + void blockdev_refresh_mount_state (HalDevice *d) { @@ -229,13 +240,39 @@ blockdev_refresh_mount_state (HalDevice *d) /* all remaining volumes are not mounted */ for (volume = volumes; volume != NULL; volume = g_slist_next (volume)) { HalDevice *dev; + char *mount_point; + char *mount_point_hal_file; dev = HAL_DEVICE (volume->data); + mount_point = g_strdup (hal_device_property_get_string (dev, "volume.mount_point")); device_property_atomic_update_begin (); hal_device_property_set_bool (dev, "volume.is_mounted", FALSE); hal_device_property_set_string (dev, "volume.mount_point", ""); device_property_atomic_update_end (); HAL_INFO (("set %s to unmounted", hal_device_get_udi (dev))); + + mount_point_hal_file = g_strdup_printf ("%s/.created-by-hal", mount_point); + if (g_file_test (mount_point_hal_file, G_FILE_TEST_EXISTS)) { + char *cleanup_stdin; + char *extra_env[2]; + + HAL_INFO (("Cleaning up directory '%s' since it was created by hal Mount()", mount_point)); + + extra_env[0] = g_strdup_printf ("HALD_CLEANUP=%s", mount_point); + extra_env[1] = NULL; + cleanup_stdin = "\n"; + + hald_runner_run_method (dev, + "hal-system-storage-cleanup-mountpoint", + extra_env, + cleanup_stdin, TRUE, + 0, + cleanup_mountpoint_cb, + g_strdup (mount_point), NULL); + } + + g_free (mount_point_hal_file); + g_free (mount_point); } g_slist_free (volumes); exit: diff --git a/tools/Makefile.am b/tools/Makefile.am index 38c914e9..0f4563cb 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -53,6 +53,7 @@ script_SCRIPTS = \ hal-system-storage-mount \ hal-system-storage-unmount \ hal-system-storage-eject \ + hal-system-storage-cleanup-mountpoint \ hal-system-storage-cleanup-mountpoints EXTRA_DIST=$(man_MANS) $(MAN_IN_FILES) gen-libgphoto-hal-fdi $(script_SCRIPTS) diff --git a/tools/hal-system-storage-cleanup-mountpoint b/tools/hal-system-storage-cleanup-mountpoint new file mode 100755 index 00000000..1029dbbc --- /dev/null +++ b/tools/hal-system-storage-cleanup-mountpoint @@ -0,0 +1,19 @@ +#!/bin/sh + +# Copyright (C) 2006, David Zeuthen <davidz@redhat.com> +# +# 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 + echo Specify directory to clean up with the environment variable HALD_CLEANUP + exit 1 +fi + +# check if we created it +if [ ! -e "$HALD_CLEANUP/.created-by-hal" ]; then + exit 1 +fi + +rm -f "$HALD_CLEANUP/.created-by-hal" +rmdir --ignore-fail-on-non-empty "$HALD_CLEANUP" |