openbsd-ports/devel/glib2/patches/patch-gio_gunixmounts_c
ajacoutot d5e540e2e4 Update to glib2-2.29.92 (2.30 coming in the next few days).
Committing now (along with upcoming atk, pango and gtk+3 updates) during
the hackathon where we have time to fix all the eventual fallout (bulk
running).

ok jasper@ robert@
2011-09-20 21:09:34 +00:00

167 lines
4.7 KiB
Plaintext

$OpenBSD: patch-gio_gunixmounts_c,v 1.4 2011/09/20 21:09:34 ajacoutot Exp $
https://bugzilla.gnome.org/show_bug.cgi?id=583330
From FreeBSD: poll the list of mounted filesystems since we can't rely
on checking for mtab updates like other systems.
From 0db338bdb0e9a0216681b6db7286ffb0f1711db1 Mon Sep 17 00:00:00 2001
From: Antoine Jacoutot <ajacoutot@openbsd.org>
Date: Mon, 19 Sep 2011 23:18:45 +0000
Subject: gunixmounts: Fix compilation on BSD
--- gio/gunixmounts.c.orig Thu Sep 15 02:10:44 2011
+++ gio/gunixmounts.c Tue Sep 20 01:14:25 2011
@@ -153,6 +153,9 @@ struct _GUnixMountMonitor {
GFileMonitor *fstab_monitor;
GFileMonitor *mtab_monitor;
+
+ guint mount_poller_source;
+ GList *mount_poller_mounts;
};
struct _GUnixMountMonitorClass {
@@ -164,6 +167,8 @@ static GUnixMountMonitor *the_mount_monitor = NULL;
static GList *_g_get_unix_mounts (void);
static GList *_g_get_unix_mount_points (void);
+static guint64 mount_poller_time = 0;
+
G_DEFINE_TYPE (GUnixMountMonitor, g_unix_mount_monitor, G_TYPE_OBJECT);
#define MOUNT_POLL_INTERVAL 4000
@@ -190,6 +195,7 @@ G_DEFINE_TYPE (GUnixMountMonitor, g_unix_mount_monitor
#endif
#if (defined(HAVE_GETVFSSTAT) || defined(HAVE_GETFSSTAT)) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
+#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#include <fstab.h>
@@ -240,11 +246,14 @@ g_unix_is_mount_path_system_internal (const char *moun
"/", /* we already have "Filesystem root" in Nautilus */
"/bin",
"/boot",
+ "/compat/linux/proc",
+ "/compat/linux/sys",
"/dev",
"/etc",
"/home",
"/lib",
"/lib64",
+ "/libexec",
"/live/cow",
"/live/image",
"/media",
@@ -255,7 +264,12 @@ g_unix_is_mount_path_system_internal (const char *moun
"/srv",
"/tmp",
"/usr",
+ "/usr/X11R6",
"/usr/local",
+ "/usr/obj",
+ "/usr/ports",
+ "/usr/xobj",
+ "/usr/src",
"/var",
"/var/crash",
"/var/local",
@@ -1023,6 +1037,7 @@ _g_get_unix_mount_points (void)
GList *return_list;
#ifdef HAVE_SYS_SYSCTL_H
int usermnt = 0;
+ size_t len = sizeof(usermnt);
struct stat sb;
#endif
@@ -1108,6 +1123,10 @@ get_mounts_timestamp (void)
if (stat (monitor_file, &buf) == 0)
return (guint64)buf.st_mtime;
}
+ else
+ {
+ return mount_poller_time;
+ }
return 0;
}
@@ -1250,6 +1269,13 @@ g_unix_mount_monitor_finalize (GObject *object)
g_object_unref (monitor->mtab_monitor);
}
+ if (monitor->mount_poller_source > 0)
+ {
+ g_source_remove (monitor->mount_poller_source);
+ g_list_foreach (monitor->mount_poller_mounts, (GFunc)g_unix_mount_free, NULL);
+ g_list_free (monitor->mount_poller_mounts);
+ }
+
the_mount_monitor = NULL;
G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize (object);
@@ -1330,6 +1356,51 @@ mtab_file_changed (GFileMonitor *monitor,
g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0);
}
+static gboolean
+mount_change_poller (gpointer user_data)
+{
+ GUnixMountMonitor *mount_monitor;
+ GList *current_mounts;
+ gboolean has_changed = FALSE;
+
+ mount_monitor = user_data;
+ current_mounts = _g_get_unix_mounts ();
+
+ if (g_list_length (current_mounts) != g_list_length (mount_monitor->mount_poller_mounts))
+ {
+ g_list_foreach (mount_monitor->mount_poller_mounts, (GFunc)g_unix_mount_free, NULL);
+ has_changed = TRUE;
+ }
+ else
+ {
+ int i;
+
+ for (i = 0; i < g_list_length (current_mounts); i++)
+ {
+ GUnixMountEntry *m1;
+ GUnixMountEntry *m2;
+
+ m1 = (GUnixMountEntry *)g_list_nth_data (current_mounts, i);
+ m2 = (GUnixMountEntry *)g_list_nth_data (mount_monitor->mount_poller_mounts, i);
+ if (! has_changed && g_unix_mount_compare (m1, m2) != 0)
+ has_changed = TRUE;
+
+ g_unix_mount_free (m2);
+ }
+ }
+
+ g_list_free (mount_monitor->mount_poller_mounts);
+ mount_monitor->mount_poller_mounts = current_mounts;
+
+ if (has_changed)
+ {
+ mount_poller_time = (guint64)time (NULL);
+ g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0);
+ }
+
+ return TRUE;
+}
+
static void
g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
{
@@ -1351,6 +1422,12 @@ g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
g_object_unref (file);
g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);
+ }
+ else
+ {
+ monitor->mount_poller_mounts = _g_get_unix_mounts ();
+ mount_poller_time = (guint64)time (NULL);
+ monitor->mount_poller_source = g_timeout_add_seconds (3, (GSourceFunc)mount_change_poller, monitor);
}
}