hal: Branch 'origin' - 5 commits

Richard Hughes hughsient at kemper.freedesktop.org
Sat Dec 16 04:04:20 PST 2006


 configure.in              |   16 +++++++++++-----
 hald/hald.c               |   17 ++++++++++++++++-
 hald/linux/blockdev.c     |   13 +++++--------
 hald/linux/coldplug.c     |    3 +--
 hald/linux/hotplug.c      |    6 ++++--
 hald/linux/osspec.c       |    4 ++--
 hald/util.c               |   11 +++++++++++
 hald/util.h               |    2 ++
 tools/hal-storage-mount.c |    8 ++++++--
 9 files changed, 58 insertions(+), 22 deletions(-)

New commits:
diff-tree e543d270ef4113a7d6a1cb51b56391b2794658d9 (from 0ad8decdb9923754bb1fd8e25f9be4b3b90f2840)
Author: David Zeuthen <davidz at redhat.com>
Date:   Thu Dec 14 22:14:29 2006 -0500

    fix for freeing static memory + move hal_util_readlink() into hald/util.c

diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index 97097b7..7d11ad2 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -564,16 +564,15 @@ canonicalize_filename (gchar *filename)
 static char *
 resolve_symlink (const char *file)
 {
-	GError *error;
 	char *dir;
-	gchar link[HAL_PATH_MAX] ;
+	gchar link[HAL_PATH_MAX];
 	char *f;
 	char *f1;
 
 	f = g_strdup (file);
 	memset(link, 0, HAL_PATH_MAX);
 	while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
-		if(readlink(f, link, HAL_PATH_MAX-1)<0) {
+		if(readlink(f, link, HAL_PATH_MAX - 1) < 0) {
 			g_warning ("Cannot resolve symlink %s: %s", f, strerror(errno));
 			g_free (f);
 			f = NULL;
diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 7a089da..b5e62bf 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -135,7 +135,6 @@ hotplug_event_begin_sysfs (HotplugEvent 
 				HAL_INFO (("%s is a device (subsystem)", hotplug_event->sysfs.sysfs_path));
 				hotplug_event->type = HOTPLUG_EVENT_SYSFS_DEVICE;
 			}
-			g_free (subsystem_target);
 		}
 	}
 
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 9fcfd51..a09debe 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -694,17 +694,6 @@ static gboolean get_parent_device(char *
 		return FALSE;
 	return TRUE;
 }
-static gchar path_buffer [HAL_PATH_MAX];
-
-gchar *
-hal_util_readlink(gchar * link)
-{
- memset(path_buffer, 0, HAL_PATH_MAX);
- if(readlink(link, path_buffer, HAL_PATH_MAX-1)<0)
-    return NULL;
-    
- return path_buffer;
-}
 
 /* return the first already known parent device */
 gboolean
diff --git a/hald/util.c b/hald/util.c
index 9ff42c3..522e824 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -1087,3 +1087,14 @@ out:
 }
 
 
+static gchar path_buffer [HAL_PATH_MAX];
+
+char *
+hal_util_readlink (const char *link)
+{
+	memset (path_buffer, 0, HAL_PATH_MAX);
+	if(readlink(link, path_buffer, HAL_PATH_MAX-1) < 0)
+		return NULL;
+	
+	return path_buffer;
+}
diff --git a/hald/util.h b/hald/util.h
index b410453..85f0ab6 100644
--- a/hald/util.h
+++ b/hald/util.h
@@ -106,4 +106,6 @@ void hal_util_hexdump (const void *buf, 
 
 gboolean hal_util_is_mounted_by_hald (const char *mount_point);
 
+char *hal_util_readlink (const char *link);
+
 #endif /* UTIL_H */
diff-tree 0ad8decdb9923754bb1fd8e25f9be4b3b90f2840 (from 14e949f7903a3b58eee38541d0f59f05b7b74140)
Author: Sergey Lapin <slapinid at gmail.com>
Date:   Thu Dec 14 21:53:58 2006 -0500

    reduce memory fragmentation by using POSIX readlink rather than glib
    
    Replaces all calls to g_file_read_link with POSIX readlink
    and uses static buffers where possible.
    Reduces memory fragmentation.

diff --git a/hald/linux/blockdev.c b/hald/linux/blockdev.c
index b7b2b86..97097b7 100644
--- a/hald/linux/blockdev.c
+++ b/hald/linux/blockdev.c
@@ -36,6 +36,7 @@
 #include <sys/stat.h>
 #include <syslog.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
@@ -565,17 +566,15 @@ resolve_symlink (const char *file)
 {
 	GError *error;
 	char *dir;
-	char *link;
+	gchar link[HAL_PATH_MAX] ;
 	char *f;
 	char *f1;
 
 	f = g_strdup (file);
-
+	memset(link, 0, HAL_PATH_MAX);
 	while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
-		link = g_file_read_link (f, &error);
-		if (link == NULL) {
-			g_warning ("Cannot resolve symlink %s: %s", f, error->message);
-			g_error_free (error);
+		if(readlink(f, link, HAL_PATH_MAX-1)<0) {
+			g_warning ("Cannot resolve symlink %s: %s", f, strerror(errno));
 			g_free (f);
 			f = NULL;
 			goto out;
@@ -584,7 +583,6 @@ resolve_symlink (const char *file)
 		dir = g_path_get_dirname (f);
 		f1 = g_strdup_printf ("%s/%s", dir, link);
 		g_free (dir);
-		g_free (link);
 		g_free (f);
 		f = f1;
 	}
diff --git a/hald/linux/coldplug.c b/hald/linux/coldplug.c
index 177f05a..fd81e6a 100644
--- a/hald/linux/coldplug.c
+++ b/hald/linux/coldplug.c
@@ -310,13 +310,12 @@ static int device_list_insert(const char
 	if (S_ISLNK(statbuf.st_mode)) {
 		gchar *target;
 
-		if ((target = g_file_read_link (path, NULL)) != NULL) {
+		if ((target = hal_util_readlink (path)) != NULL) {
 			gchar *normalized_target;
 
 			g_strlcpy(filename, path, sizeof(filename));
 			hal_util_path_ascend (filename);
 			normalized_target = hal_util_get_normalized_path (filename, target);
-			g_free (target);
 			sysfs_dev->path = normalized_target;
 			goto found;
 		}
diff --git a/hald/linux/hotplug.c b/hald/linux/hotplug.c
index 1b9282a..7a089da 100644
--- a/hald/linux/hotplug.c
+++ b/hald/linux/hotplug.c
@@ -123,7 +123,10 @@ hotplug_event_begin_sysfs (HotplugEvent 
 	 */
 	if (hotplug_event->type == HOTPLUG_EVENT_SYSFS) {
 		g_snprintf (subsystem, HAL_PATH_MAX, "%s/subsystem", hotplug_event->sysfs.sysfs_path);
-		subsystem_target = g_file_read_link (subsystem, NULL);
+		/* g_file_read_link leaks memory. We alloc lots of trash here but return NULL, damn
+		   Re-implemented this using POSIX readlink() */
+		/* subsystem_target = g_file_read_link (subsystem, NULL); */
+		subsystem_target = hal_util_readlink(subsystem);
 		if (subsystem_target != NULL) {
 			if (strstr(subsystem_target, "/block") != NULL) {
 				HAL_INFO (("%s is a block device (subsystem)", hotplug_event->sysfs.sysfs_path));
diff --git a/hald/linux/osspec.c b/hald/linux/osspec.c
index 991dadf..9fcfd51 100644
--- a/hald/linux/osspec.c
+++ b/hald/linux/osspec.c
@@ -694,6 +694,18 @@ static gboolean get_parent_device(char *
 		return FALSE;
 	return TRUE;
 }
+static gchar path_buffer [HAL_PATH_MAX];
+
+gchar *
+hal_util_readlink(gchar * link)
+{
+ memset(path_buffer, 0, HAL_PATH_MAX);
+ if(readlink(link, path_buffer, HAL_PATH_MAX-1)<0)
+    return NULL;
+    
+ return path_buffer;
+}
+
 /* return the first already known parent device */
 gboolean
 hal_util_find_known_parent (const gchar *sysfs_path, HalDevice **parent, gchar **parent_path)
@@ -720,9 +732,8 @@ hal_util_find_known_parent (const gchar 
 
 	/* try if the parent chain is constructed by the device-link */
 	g_snprintf (parentdevpath, HAL_PATH_MAX, "%s/device", sysfs_path);
-	if (((target = g_file_read_link (parentdevpath, NULL)) != NULL)) {
+	if ((target = hal_util_readlink (parentdevpath)) != NULL) {
 		parent_devpath = hal_util_get_normalized_path (sysfs_path, target);
-		g_free (target);
 
 		while (TRUE) {
 			parent_dev = hal_device_store_match_key_value_string (hald_get_gdl (),
diff-tree 14e949f7903a3b58eee38541d0f59f05b7b74140 (from 9d607e21cac65dddaf0c8cb2443865d9ae509393)
Author: Sergey Lapin <slapinid at gmail.com>
Date:   Thu Dec 14 21:49:25 2006 -0500

    use mallopt since we mostly allocate small chunks
    
    A patch attached is about optimization of malloc usage for small
    chunks.  Reduces memory fragmentation. Uses mallopt for that.  Mostly
    targeted for small-memory embedded devices.

diff --git a/configure.in b/configure.in
index af075ae..8a5e786 100644
--- a/configure.in
+++ b/configure.in
@@ -359,6 +359,7 @@ fi
 
 AC_CHECK_FUNCS(getgrouplist)
 AC_CHECK_FUNCS(asprintf)
+AC_CHECK_FUNCS(mallopt)
 
 # DocBook Documentation
 
diff --git a/hald/hald.c b/hald/hald.c
index 4e3c8da..d946c4e 100644
--- a/hald/hald.c
+++ b/hald/hald.c
@@ -41,7 +41,9 @@
 #include <signal.h>
 #include <grp.h>
 #include <syslog.h>
-
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <malloc.h>
 #include <dbus/dbus.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
@@ -374,6 +376,19 @@ main (int argc, char *argv[])
 
 	openlog ("hald", LOG_PID, LOG_DAEMON);
 
+#ifdef HAVE_MALLOPT
+
+#define HAL_MMAP_THRESHOLD 100
+#define HAL_TRIM_THRESHOLD 100
+
+	/* We use memory in small chunks, thus optimize
+	   it this way.
+	 */
+	mallopt(M_MMAP_THRESHOLD, HAL_MMAP_THRESHOLD);
+	mallopt(M_TRIM_THRESHOLD, HAL_TRIM_THRESHOLD);
+
+#endif
+
 #ifdef HALD_MEMLEAK_DBG
 	/*g_mem_set_vtable (glib_mem_profiler_table);*/
 #endif
diff-tree 9d607e21cac65dddaf0c8cb2443865d9ae509393 (from d49163c2d28478288d1a2fb0813f4069f7087116)
Author: Martin Pitt <martin at piware.de>
Date:   Thu Dec 14 21:38:50 2006 -0500

    without PolicyKit, allow only root to mount fixed disks
    
    When building hal without policykit, the mount backend solely relies
    on volume.ignore=true. This seems a bit fragile to me, and since we
    want to integrate mounting of fixed hard disks into the desktop, too
    [1], I added a policy check to the backend.

diff --git a/tools/hal-storage-mount.c b/tools/hal-storage-mount.c
index 12b15db..a69cdb3 100644
--- a/tools/hal-storage-mount.c
+++ b/tools/hal-storage-mount.c
@@ -143,7 +143,6 @@ cannot_remount (const char *device)
 	exit (1);
 }
 
-#ifdef HAVE_POLKIT
 static void
 permission_denied_privilege (const char *privilege, const char *uid)
 {
@@ -151,7 +150,6 @@ permission_denied_privilege (const char 
 	fprintf (stderr, "%s refused uid %s\n", privilege, uid);
 	exit (1);
 }
-#endif
 
 
 /* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
@@ -769,6 +767,12 @@ handle_mount (LibHalContext *hal_ctx, 
 		printf ("caller don't possess privilege\n");
 		permission_denied_privilege (privilege, invoked_by_uid);
 	}
+#else
+        /* root can do everything; only allow handling removable devices
+         * without uid change to non-root users */
+        if (!invoked_by_uid || strcmp(invoked_by_uid, "0"))
+                if (!privilege || strcmp (privilege, "hal-storage-removable-mount"))
+                        permission_denied_privilege (privilege, invoked_by_uid);
 #endif
 
 #ifdef DEBUG
diff-tree d49163c2d28478288d1a2fb0813f4069f7087116 (from 7602464b92f9617b34ea5606426061fe3077820e)
Author: David Zeuthen <davidz at redhat.com>
Date:   Thu Dec 14 21:28:53 2006 -0500

    misc build fixes for libparted and libpci

diff --git a/configure.in b/configure.in
index b01cae7..af075ae 100644
--- a/configure.in
+++ b/configure.in
@@ -108,7 +108,7 @@ if test "x$use_parted" = "xyes" ; then
    AC_DEFINE(USE_PARTED,1,[Whether libparted is to be used])
    AC_CHECK_LIB(uuid, uuid_generate, [], AC_MSG_ERROR([*** uuid library (libuuid) not found]))
    AC_CHECK_LIB(dl, dlopen,          [], AC_MSG_ERROR([*** dl library (libdl) not found]))
-   AC_MSG_CHECKING(for libparted == 1.7.1)
+   AC_MSG_CHECKING(for libparted == 1.7.1, 1.8.0, 1.8.1)
    LDFLAGS=-lparted
    AC_TRY_RUN(
    #include <stdio.h>
@@ -122,7 +122,12 @@ if test "x$use_parted" = "xyes" ; then
 	if ( sscanf( ped_get_version(), "%d.%d.%d", &major, &minor, &micro ) == 3 )
 		printf( "Found libparted %s", ped_get_version() ) ;
 
-        return ! ( major == 1 && minor == 7 && micro == 1 ) ;
+	if ((major == 1 && minor == 7 && micro == 1) ||
+	    (major == 1 && minor == 8 && micro == 0)
+	    (major == 1 && minor == 8 && micro == 1))
+	   return 0;
+
+	return 1;
     }
 	,AC_MSG_RESULT( ),AC_MSG_ERROR(*** Requires libparted == 1.7.1) )
     PARTED_LIBS=-lparted
@@ -243,9 +248,9 @@ fi
 dnl Check for libpci
 AC_CHECK_HEADERS(pci/pci.h, [
 	AC_CHECK_LIB(pci, pci_init, [
-		USE_LIBPCI=yes AM_CONDITIONAL(HAVE_LIBPCI,true)], [
-		USE_LIBPCI=no AM_CONDITIONAL(HAVE_LIBPCI,false)])], [
-	USE_LIBPCI=no AM_CONDITIONAL(HAVE_LIBPCI,false)])
+		USE_LIBPCI=yes; AM_CONDITIONAL(HAVE_LIBPCI,true)], [
+		USE_LIBPCI=no; AM_CONDITIONAL(HAVE_LIBPCI,false)])], [
+	USE_LIBPCI=no; AM_CONDITIONAL(HAVE_LIBPCI,false)])
 
 AC_ARG_WITH(backend, [  --with-backend=<name>   backend to use (linux/solaris/freebsd/dummy)],
                       [


More information about the hal-commit mailing list