diff options
author | Artem Kachitchkine <artem.kachitchkin@sun.com> | 2006-08-14 22:41:30 -0700 |
---|---|---|
committer | Artem Kachitchkine <artem.kachitchkin@sun.com> | 2006-08-14 22:41:30 -0700 |
commit | 87698568312d659ac244898257d5ee8ee36ceac0 (patch) | |
tree | afcc9fb60b19b79b38b671b05db0e7de31af7f8e | |
parent | aa84d37830b9fdf140db88d88edab548f6159f33 (diff) |
share is_mounted_by_hald() and non-gcc nits
Moved linux2/blockdev.c:is_mounted_by_hald() to
util.c:hal_util_is_mounted_by_hald() so all backends can use it.
Fixed some compilation warnings when compiling with non-GNU
compiler and libc.
-rw-r--r-- | hald/device_info.c | 6 | ||||
-rw-r--r-- | hald/device_store.c | 4 | ||||
-rw-r--r-- | hald/linux2/blockdev.c | 113 | ||||
-rw-r--r-- | hald/logger.c | 2 | ||||
-rw-r--r-- | hald/util.c | 115 | ||||
-rw-r--r-- | hald/util.h | 2 | ||||
-rw-r--r-- | libhal/libhal.c | 36 | ||||
-rw-r--r-- | tools/Makefile.am | 2 | ||||
-rw-r--r-- | tools/hal-device.c | 2 | ||||
-rw-r--r-- | tools/hal-storage-eject.c | 4 | ||||
-rw-r--r-- | tools/hal-storage-mount.c | 4 | ||||
-rw-r--r-- | tools/hal-storage-shared.h | 4 | ||||
-rw-r--r-- | tools/hal-storage-unmount.c | 4 | ||||
-rw-r--r-- | tools/hal_find_by_capability.c | 2 | ||||
-rw-r--r-- | tools/hal_find_by_property.c | 2 | ||||
-rw-r--r-- | tools/hal_get_property.c | 2 | ||||
-rw-r--r-- | tools/hal_set_property.c | 2 | ||||
-rw-r--r-- | tools/lshal.c | 2 |
18 files changed, 159 insertions, 149 deletions
diff --git a/hald/device_info.c b/hald/device_info.c index 17751d39..478c94a1 100644 --- a/hald/device_info.c +++ b/hald/device_info.c @@ -1453,8 +1453,12 @@ out: -static int +static int +#ifdef __GLIBC__ my_alphasort(const void *a, const void *b) +#else +my_alphasort(const struct dirent **a, const struct dirent **b) +#endif { return -alphasort (a, b); } diff --git a/hald/device_store.c b/hald/device_store.c index 96ca58f1..d11cf6ed 100644 --- a/hald/device_store.c +++ b/hald/device_store.c @@ -203,10 +203,10 @@ hal_device_store_remove (HalDeviceStore *store, HalDevice *device) store->devices = g_slist_remove (store->devices, device); g_signal_handlers_disconnect_by_func (device, - emit_device_property_changed, + (gpointer)emit_device_property_changed, store); g_signal_handlers_disconnect_by_func (device, - emit_device_capability_added, + (gpointer)emit_device_capability_added, store); g_signal_emit (store, signals[STORE_CHANGED], 0, device, FALSE); diff --git a/hald/linux2/blockdev.c b/hald/linux2/blockdev.c index e9713aab..f01787da 100644 --- a/hald/linux2/blockdev.c +++ b/hald/linux2/blockdev.c @@ -172,117 +172,6 @@ cleanup_mountpoint_cb (HalDevice *d, guint32 exit_type, g_free (mount_point); } -static gboolean -is_mounted_by_hald (const char *mount_point) -{ - int i; - FILE *hal_mtab; - int hal_mtab_len; - int num_read; - char *hal_mtab_buf; - char **lines; - gboolean found; - int lock_mtab_fd; - - hal_mtab = NULL; - hal_mtab_buf = NULL; - found = FALSE; - - /* take the lock on /media/.hal-mtab-lock so we don't race with the Mount() and Unmount() methods */ - - /* do not attempt to create the file; tools/hal-storage-shared.c will create it and - * set the correct ownership so this unprivileged process (running as haldaemon) can - * lock it too - */ - lock_mtab_fd = open ("/media/.hal-mtab-lock", 0); - if (lock_mtab_fd < 0) { - HAL_INFO (("Cannot open /media/.hal-mtab for locking")); - goto out; - } - -tryagain: - if (flock (lock_mtab_fd, LOCK_EX) != 0) { - if (errno == EINTR) - goto tryagain; - HAL_ERROR (("Cannot obtain lock on /media/.hal-mtab")); - goto out; - } - - /*HAL_DEBUG (("examining /media/.hal-mtab for %s", mount_point));*/ - - hal_mtab = fopen ("/media/.hal-mtab", "r"); - if (hal_mtab == NULL) { - HAL_ERROR (("Cannot open /media/.hal-mtab")); - goto out; - } - if (fseek (hal_mtab, 0L, SEEK_END) != 0) { - HAL_ERROR (("Cannot seek to end of /media/.hal-mtab")); - goto out; - } - hal_mtab_len = ftell (hal_mtab); - if (hal_mtab_len < 0) { - HAL_ERROR (("Cannot determine size of /media/.hal-mtab")); - goto out; - } - rewind (hal_mtab); - - hal_mtab_buf = g_new0 (char, hal_mtab_len + 1); - num_read = fread (hal_mtab_buf, 1, hal_mtab_len, hal_mtab); - if (num_read != hal_mtab_len) { - HAL_ERROR (("Cannot read from /media/.hal-mtab")); - goto out; - } - fclose (hal_mtab); - hal_mtab = NULL; - - /*HAL_DEBUG (("hal_mtab = '%s'\n", hal_mtab_buf));*/ - - lines = g_strsplit (hal_mtab_buf, "\n", 0); - g_free (hal_mtab_buf); - hal_mtab_buf = NULL; - - /* find the entry we're going to unmount */ - for (i = 0; lines[i] != NULL && !found; i++) { - char **line_elements; - - /*HAL_DEBUG ((" line = '%s'", lines[i]));*/ - - if ((lines[i])[0] == '#') - continue; - - line_elements = g_strsplit (lines[i], "\t", 6); - if (g_strv_length (line_elements) == 6) { -/* - HAL_DEBUG ((" devfile = '%s'", line_elements[0])); - HAL_DEBUG ((" uid = '%s'", line_elements[1])); - HAL_DEBUG ((" session id = '%s'", line_elements[2])); - HAL_DEBUG ((" fs = '%s'", line_elements[3])); - HAL_DEBUG ((" options = '%s'", line_elements[4])); - HAL_DEBUG ((" mount_point = '%s'", line_elements[5])); - HAL_DEBUG ((" (comparing against '%s')", mount_point)); -*/ - - if (strcmp (line_elements[5], mount_point) == 0) { - found = TRUE; - /*HAL_INFO (("device at '%s' is indeed mounted by HAL's Mount()", mount_point));*/ - } - - } - - g_strfreev (line_elements); - } - -out: - if (lock_mtab_fd >= 0) - close (lock_mtab_fd); - if (hal_mtab != NULL) - fclose (hal_mtab); - if (hal_mtab_buf != NULL) - g_free (hal_mtab_buf); - - return found; -} - void blockdev_refresh_mount_state (HalDevice *d) { @@ -409,7 +298,7 @@ blockdev_refresh_mount_state (HalDevice *d) } /* look up in /media/.hal-mtab to see if we mounted this one */ - if (mount_point != NULL && strlen (mount_point) > 0 && is_mounted_by_hald (mount_point)) { + if (mount_point != NULL && strlen (mount_point) > 0 && hal_util_is_mounted_by_hald (mount_point)) { char *cleanup_stdin; char *extra_env[2]; diff --git a/hald/logger.c b/hald/logger.c index 2dc1cc46..f3a5cde6 100644 --- a/hald/logger.c +++ b/hald/logger.c @@ -33,7 +33,7 @@ #include <stdarg.h> #include <time.h> #include <sys/time.h> -#include <sys/syslog.h> +#include <syslog.h> #include "logger.h" diff --git a/hald/util.c b/hald/util.c index 786b2691..9a3fca09 100644 --- a/hald/util.c +++ b/hald/util.c @@ -36,6 +36,7 @@ #include <stdint.h> #include <sys/stat.h> #include <unistd.h> +#include <fcntl.h> #include <signal.h> #include <sys/wait.h> @@ -1124,3 +1125,117 @@ hal_util_hexdump (const void *mem, unsigned int size) } } +gboolean +hal_util_is_mounted_by_hald (const char *mount_point) +{ + int i; + FILE *hal_mtab; + int hal_mtab_len; + int num_read; + char *hal_mtab_buf; + char **lines; + gboolean found; + int lock_mtab_fd; + + hal_mtab = NULL; + hal_mtab_buf = NULL; + found = FALSE; + + /* take the lock on /media/.hal-mtab-lock so we don't race with the Mount() and Unmount() methods */ + + /* do not attempt to create the file; tools/hal-storage-shared.c will create it and + * set the correct ownership so this unprivileged process (running as haldaemon) can + * lock it too + */ + lock_mtab_fd = open ("/media/.hal-mtab-lock", 0); + if (lock_mtab_fd < 0) { + HAL_INFO (("Cannot open /media/.hal-mtab for locking")); + goto out; + } + +tryagain: +#ifdef sun + if (lockf (lock_mtab_fd, F_LOCK, 0) != 0) { +#else + if (flock (lock_mtab_fd, LOCK_EX) != 0) { +#endif + if (errno == EINTR) + goto tryagain; + HAL_ERROR (("Cannot obtain lock on /media/.hal-mtab")); + goto out; + } + + /*HAL_DEBUG (("examining /media/.hal-mtab for %s", mount_point));*/ + + hal_mtab = fopen ("/media/.hal-mtab", "r"); + if (hal_mtab == NULL) { + HAL_ERROR (("Cannot open /media/.hal-mtab")); + goto out; + } + if (fseek (hal_mtab, 0L, SEEK_END) != 0) { + HAL_ERROR (("Cannot seek to end of /media/.hal-mtab")); + goto out; + } + hal_mtab_len = ftell (hal_mtab); + if (hal_mtab_len < 0) { + HAL_ERROR (("Cannot determine size of /media/.hal-mtab")); + goto out; + } + rewind (hal_mtab); + + hal_mtab_buf = g_new0 (char, hal_mtab_len + 1); + num_read = fread (hal_mtab_buf, 1, hal_mtab_len, hal_mtab); + if (num_read != hal_mtab_len) { + HAL_ERROR (("Cannot read from /media/.hal-mtab")); + goto out; + } + fclose (hal_mtab); + hal_mtab = NULL; + + /*HAL_DEBUG (("hal_mtab = '%s'\n", hal_mtab_buf));*/ + + lines = g_strsplit (hal_mtab_buf, "\n", 0); + g_free (hal_mtab_buf); + hal_mtab_buf = NULL; + + /* find the entry we're going to unmount */ + for (i = 0; lines[i] != NULL && !found; i++) { + char **line_elements; + + /*HAL_DEBUG ((" line = '%s'", lines[i]));*/ + + if ((lines[i])[0] == '#') + continue; + + line_elements = g_strsplit (lines[i], "\t", 6); + if (g_strv_length (line_elements) == 6) { +/* + HAL_DEBUG ((" devfile = '%s'", line_elements[0])); + HAL_DEBUG ((" uid = '%s'", line_elements[1])); + HAL_DEBUG ((" session id = '%s'", line_elements[2])); + HAL_DEBUG ((" fs = '%s'", line_elements[3])); + HAL_DEBUG ((" options = '%s'", line_elements[4])); + HAL_DEBUG ((" mount_point = '%s'", line_elements[5])); + HAL_DEBUG ((" (comparing against '%s')", mount_point)); +*/ + + if (strcmp (line_elements[5], mount_point) == 0) { + found = TRUE; + /*HAL_INFO (("device at '%s' is indeed mounted by HAL's Mount()", mount_point));*/ + } + + } + + g_strfreev (line_elements); + } + +out: + if (lock_mtab_fd >= 0) + close (lock_mtab_fd); + if (hal_mtab != NULL) + fclose (hal_mtab); + if (hal_mtab_buf != NULL) + g_free (hal_mtab_buf); + + return found; +} diff --git a/hald/util.h b/hald/util.h index 98ca5fa6..98d0ea34 100644 --- a/hald/util.h +++ b/hald/util.h @@ -109,4 +109,6 @@ gchar *hal_util_strdup_valid_utf8 (const char *str); void hal_util_hexdump (const void *buf, unsigned int size); +gboolean hal_util_is_mounted_by_hald (const char *mount_point); + #endif /* UTIL_H */ diff --git a/libhal/libhal.c b/libhal/libhal.c index b7eae2ec..ecc5df95 100644 --- a/libhal/libhal.c +++ b/libhal/libhal.c @@ -375,7 +375,7 @@ libhal_device_get_all_properties (LibHalContext *ctx, const char *udi, DBusError DBusError _error; LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL); - + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "GetAllProperties"); @@ -911,8 +911,8 @@ libhal_device_get_property_type (LibHalContext *ctx, const char *udi, const char int type; DBusError _error; - LIBHAL_CHECK_LIBHALCONTEXT(ctx, LIBHAL_PROPERTY_TYPE_INVALID); // or return NULL? - + LIBHAL_CHECK_LIBHALCONTEXT(ctx, LIBHAL_PROPERTY_TYPE_INVALID); /* or return NULL? */ + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "GetPropertyType"); @@ -1398,7 +1398,7 @@ libhal_device_set_property_helper (LibHalContext *ctx, char *method_name = NULL; LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + /** @todo sanity check incoming params */ switch (type) { case DBUS_TYPE_INVALID: @@ -3070,7 +3070,7 @@ dbus_bool_t libhal_ctx_set_device_added (LibHalContext *ctx, LibHalDeviceAdded callback) { LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + ctx->device_added = callback; return TRUE; } @@ -3088,7 +3088,7 @@ dbus_bool_t libhal_ctx_set_device_removed (LibHalContext *ctx, LibHalDeviceRemoved callback) { LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + ctx->device_removed = callback; return TRUE; } @@ -3106,7 +3106,7 @@ dbus_bool_t libhal_ctx_set_device_new_capability (LibHalContext *ctx, LibHalDeviceNewCapability callback) { LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + ctx->device_new_capability = callback; return TRUE; } @@ -3124,7 +3124,7 @@ dbus_bool_t libhal_ctx_set_device_lost_capability (LibHalContext *ctx, LibHalDeviceLostCapability callback) { LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + ctx->device_lost_capability = callback; return TRUE; } @@ -3142,7 +3142,7 @@ dbus_bool_t libhal_ctx_set_device_property_modified (LibHalContext *ctx, LibHalDevicePropertyModified callback) { LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + ctx->device_property_modified = callback; return TRUE; } @@ -3160,7 +3160,7 @@ dbus_bool_t libhal_ctx_set_device_condition (LibHalContext *ctx, LibHalDeviceCondition callback) { LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - + ctx->device_condition = callback; return TRUE; } @@ -3201,13 +3201,13 @@ libhal_string_array_length (char **str_array) dbus_bool_t libhal_device_rescan (LibHalContext *ctx, const char *udi, DBusError *error) { - LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - DBusMessage *message; DBusMessageIter reply_iter; DBusMessage *reply; dbus_bool_t result; + LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "Rescan"); @@ -3260,13 +3260,13 @@ libhal_device_rescan (LibHalContext *ctx, const char *udi, DBusError *error) dbus_bool_t libhal_device_reprobe (LibHalContext *ctx, const char *udi, DBusError *error) { - LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - DBusMessage *message; DBusMessageIter reply_iter; DBusMessage *reply; dbus_bool_t result; + LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", @@ -3326,14 +3326,14 @@ dbus_bool_t libhal_device_emit_condition (LibHalContext *ctx, const char *condition_details, DBusError *error) { - LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - DBusMessage *message; DBusMessageIter iter; DBusMessageIter reply_iter; DBusMessage *reply; dbus_bool_t result; + LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", @@ -3399,14 +3399,14 @@ libhal_device_claim_interface (LibHalContext *ctx, const char *introspection_xml, DBusError *error) { - LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); - DBusMessage *message; DBusMessageIter iter; DBusMessageIter reply_iter; DBusMessage *reply; dbus_bool_t result; + LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE); + message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", diff --git a/tools/Makefile.am b/tools/Makefile.am index 888d03e3..bcfbf59c 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -20,7 +20,7 @@ INCLUDES = \ -DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \ -DPACKAGE_SCRIPT_DIR=\""$(datadir)/hal/scripts"\" \ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \ - -I$(top_srcdir) -I$(top_srcdir)/libhal \ + -I$(top_srcdir) -I$(top_srcdir)/libhal -I$(top_srcdir)/libhal-storage \ @DBUS_CFLAGS@ @GLIB_CFLAGS@ @POLKIT_CFLAGS@ bin_PROGRAMS = \ diff --git a/tools/hal-device.c b/tools/hal-device.c index 9bc57a65..a37d2d6e 100644 --- a/tools/hal-device.c +++ b/tools/hal-device.c @@ -45,7 +45,7 @@ #endif #include <dbus/dbus.h> -#include <libhal/libhal.h> +#include <libhal.h> typedef struct { char *udi; diff --git a/tools/hal-storage-eject.c b/tools/hal-storage-eject.c index 6cb8ab42..516d078e 100644 --- a/tools/hal-storage-eject.c +++ b/tools/hal-storage-eject.c @@ -34,8 +34,8 @@ #include <sys/types.h> #include <unistd.h> -#include <libhal/libhal.h> -#include <libhal-storage/libhal-storage.h> +#include <libhal.h> +#include <libhal-storage.h> #ifdef HAVE_POLKIT #include <libpolkit.h> #endif diff --git a/tools/hal-storage-mount.c b/tools/hal-storage-mount.c index 37d7d6b5..3da83b81 100644 --- a/tools/hal-storage-mount.c +++ b/tools/hal-storage-mount.c @@ -49,8 +49,8 @@ #include <errno.h> #include <syslog.h> -#include <libhal/libhal.h> -#include <libhal-storage/libhal-storage.h> +#include <libhal.h> +#include <libhal-storage.h> #ifdef HAVE_POLKIT #include <libpolkit.h> #endif diff --git a/tools/hal-storage-shared.h b/tools/hal-storage-shared.h index 34b9f1ee..f87d5d18 100644 --- a/tools/hal-storage-shared.h +++ b/tools/hal-storage-shared.h @@ -24,8 +24,8 @@ #ifndef HAL_STORAGE_SHARED_H #define HAL_STORAGE_SHARED_H -#include <libhal/libhal.h> -#include <libhal-storage/libhal-storage.h> +#include <libhal.h> +#include <libhal-storage.h> #ifdef HAVE_POLKIT #include <libpolkit.h> #endif diff --git a/tools/hal-storage-unmount.c b/tools/hal-storage-unmount.c index 112adc20..d1239f70 100644 --- a/tools/hal-storage-unmount.c +++ b/tools/hal-storage-unmount.c @@ -48,8 +48,8 @@ #include <sys/types.h> #include <unistd.h> -#include <libhal/libhal.h> -#include <libhal-storage/libhal-storage.h> +#include <libhal.h> +#include <libhal-storage.h> #ifdef HAVE_POLKIT #include <libpolkit.h> #endif diff --git a/tools/hal_find_by_capability.c b/tools/hal_find_by_capability.c index a4b95ef1..20a7666e 100644 --- a/tools/hal_find_by_capability.c +++ b/tools/hal_find_by_capability.c @@ -33,7 +33,7 @@ #include <unistd.h> #include <getopt.h> -#include <libhal/libhal.h> +#include <libhal.h> /** Print out program usage. diff --git a/tools/hal_find_by_property.c b/tools/hal_find_by_property.c index 8c25710d..f9344fd3 100644 --- a/tools/hal_find_by_property.c +++ b/tools/hal_find_by_property.c @@ -33,7 +33,7 @@ #include <unistd.h> #include <getopt.h> -#include <libhal/libhal.h> +#include <libhal.h> /** Print out program usage. diff --git a/tools/hal_get_property.c b/tools/hal_get_property.c index 6df4a161..c2ec717d 100644 --- a/tools/hal_get_property.c +++ b/tools/hal_get_property.c @@ -33,7 +33,7 @@ #include <unistd.h> #include <getopt.h> -#include <libhal/libhal.h> +#include <libhal.h> /** * @defgroup HalGetProperty Get HAL device property diff --git a/tools/hal_set_property.c b/tools/hal_set_property.c index 7bb6094d..eaeb7fc5 100644 --- a/tools/hal_set_property.c +++ b/tools/hal_set_property.c @@ -34,7 +34,7 @@ #include <unistd.h> #include <getopt.h> -#include "libhal/libhal.h" +#include <libhal.h> static LibHalContext *hal_ctx; diff --git a/tools/lshal.c b/tools/lshal.c index c837c7f0..cb4fd157 100644 --- a/tools/lshal.c +++ b/tools/lshal.c @@ -38,7 +38,7 @@ #include <glib.h> #include <dbus/dbus-glib-lowlevel.h> #include <dbus/dbus-glib.h> -#include <libhal/libhal.h> +#include <libhal.h> #ifdef __SUNPRO_C #define __FUNCTION__ __func__ |