+ const gchar *mtab_path;
+
+ mtab_path = get_mtab_monitor_file ();
+ /* /proc/mounts monitoring is special - can't just use GFileMonitor.
+ * See 'man proc' for more details.
+ */
+ if (g_strcmp0 (mtab_path, "/proc/mounts") == 0)
+ {
+ GIOChannel *proc_mounts_channel;
+ GError *error = NULL;
+ proc_mounts_channel = g_io_channel_new_file ("/proc/mounts", "r", &error);
+ if (proc_mounts_channel == NULL)
+ {
+ g_warning ("Error creating IO channel for /proc/mounts: %s (%s, %d)",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ }
+ else
+ {
+ monitor->proc_mounts_watch_source = g_io_create_watch (proc_mounts_channel, G_IO_ERR);
+ g_source_set_callback (monitor->proc_mounts_watch_source,
+ (GSourceFunc) proc_mounts_changed,
+ monitor,
+ NULL);
+ g_source_attach (monitor->proc_mounts_watch_source,
+ g_main_context_get_thread_default ());
+ g_source_unref (monitor->proc_mounts_watch_source);
+ g_io_channel_unref (proc_mounts_channel);
+ }
+ }
+ else
+ {
+ file = g_file_new_for_path (mtab_path);
+ monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL, NULL);
+ g_object_unref (file);
+ g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);
+ }
+ }
+ else
+ {
+ monitor->proc_mounts_watch_source = g_timeout_source_new_seconds (3);
+ monitor->mount_poller_mounts = _g_get_unix_mounts ();
+ mount_poller_time = (guint64)g_get_monotonic_time ();
+ g_source_set_callback (monitor->proc_mounts_watch_source,
+ (GSourceFunc)mount_change_poller,
+ monitor, NULL);
+ g_source_attach (monitor->proc_mounts_watch_source,
+ g_main_context_get_thread_default ());
+ g_source_unref (monitor->proc_mounts_watch_source);