After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660511 - Use /proc/mounts for monitoring mounts, not /etc/mtab
Use /proc/mounts for monitoring mounts, not /etc/mtab
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gio
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2011-09-29 19:12 UTC by David Zeuthen (not reading bugmail)
Modified: 2011-09-29 19:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (3.71 KB, patch)
2011-09-29 19:14 UTC, David Zeuthen (not reading bugmail)
reviewed Details | Review

Description David Zeuthen (not reading bugmail) 2011-09-29 19:12:01 UTC
On recent Linux distros /etc/mtab is just a symlink to /proc/mounts and GFileMonitor does not work there because of how the kernel conveys that the file changes. I will attach a patch for this.
Comment 1 David Zeuthen (not reading bugmail) 2011-09-29 19:14:02 UTC
Created attachment 197801 [details] [review]
Patch

Tested with 'gvfs-mount -oi' on F15
Comment 2 David Zeuthen (not reading bugmail) 2011-09-29 19:17:36 UTC
Committed on master:

 http://git.gnome.org/browse/glib/commit/?id=55065461bfc5ace53e736dfa8181909e918c161b
Comment 3 David Zeuthen (not reading bugmail) 2011-09-29 19:19:13 UTC
Matthias, Ryan: we probably want this on the glib-2-30 branch but I'm deferring to you to cherry pick it. From what I can tell, this has been broken for all of F15...
Comment 4 Colin Walters 2011-09-29 19:28:25 UTC
Review of attachment 197801 [details] [review]:

::: gio/gunixmounts.c
@@ +1352,3 @@
+{
+  GUnixMountMonitor *mount_monitor = G_UNIX_MOUNT_MONITOR (user_data);
+  if (cond & ~G_IO_ERR)

This makes more sense to me as: if (!(cond & G_IO_ERR)) personally.

@@ +1353,3 @@
+  GUnixMountMonitor *mount_monitor = G_UNIX_MOUNT_MONITOR (user_data);
+  if (cond & ~G_IO_ERR)
+    goto out;

Why the goto?  Just seems weird in a 4 line function, you could just as easily put the g_signal_emit() under the if().

@@ +1378,3 @@
+
+      mtab_path = get_mtab_monitor_file ();
+      /* /proc/mounts monitoring is special - can't just use GFileMonitor */

You could say "man proc" here.

@@ +1381,3 @@
+      if (g_strcmp0 (mtab_path, "/proc/mounts") == 0)
+        {
+          monitor->proc_mounts_channel = g_io_channel_new_file ("/proc/mounts", "r", NULL);

Do we need to keep around the GIOChannel?  I don't see it being used after you've attached the source (which holds a reference itself).

Eventually we'll get that g_source_new_pollfd() API and won't have to indirect through GIOChannel...

@@ +1382,3 @@
+        {
+          monitor->proc_mounts_channel = g_io_channel_new_file ("/proc/mounts", "r", NULL);
+          monitor->proc_mounts_watch_source = g_io_create_watch (monitor->proc_mounts_channel, G_IO_ERR);

So if /proc isn't mounted here we segfault or g_return_if_fail spew (since monitor->proc_mounts_channel) will be NULL.  

Possibly at least guard this with if (!monitor->proc_mounts_channel) g_warning ("Failed to open /proc/mounts") ?
Comment 5 Colin Walters 2011-09-29 19:28:55 UTC
(In reply to comment #2)
> Committed on master:
> 
> 
> http://git.gnome.org/browse/glib/commit/?id=55065461bfc5ace53e736dfa8181909e918c161b

Hmm...did you get review from anyone first?
Comment 6 David Zeuthen (not reading bugmail) 2011-09-29 19:35:02 UTC
(In reply to comment #4)
> Review of attachment 197801 [details] [review]:
> 
> ::: gio/gunixmounts.c
> @@ +1352,3 @@
> +{
> +  GUnixMountMonitor *mount_monitor = G_UNIX_MOUNT_MONITOR (user_data);
> +  if (cond & ~G_IO_ERR)
> 
> This makes more sense to me as: if (!(cond & G_IO_ERR)) personally.
> 
> @@ +1353,3 @@
> +  GUnixMountMonitor *mount_monitor = G_UNIX_MOUNT_MONITOR (user_data);
> +  if (cond & ~G_IO_ERR)
> +    goto out;
> 
> Why the goto?  Just seems weird in a 4 line function, you could just as easily
> put the g_signal_emit() under the if().

I prefer it the way I wrote it.

> 
> @@ +1378,3 @@
> +
> +      mtab_path = get_mtab_monitor_file ();
> +      /* /proc/mounts monitoring is special - can't just use GFileMonitor */
> 
> You could say "man proc" here.

That's pretty useless since that man page does not tell you why it is the way it is.

> 
> @@ +1381,3 @@
> +      if (g_strcmp0 (mtab_path, "/proc/mounts") == 0)
> +        {
> +          monitor->proc_mounts_channel = g_io_channel_new_file
> ("/proc/mounts", "r", NULL);
> 
> Do we need to keep around the GIOChannel?  I don't see it being used after
> you've attached the source (which holds a reference itself).

Not really. Feel free to remove it if you want.

> 
> Eventually we'll get that g_source_new_pollfd() API and won't have to indirect
> through GIOChannel...
> 
> @@ +1382,3 @@
> +        {
> +          monitor->proc_mounts_channel = g_io_channel_new_file
> ("/proc/mounts", "r", NULL);
> +          monitor->proc_mounts_watch_source = g_io_create_watch
> (monitor->proc_mounts_channel, G_IO_ERR);
> 
> So if /proc isn't mounted here we segfault or g_return_if_fail spew (since
> monitor->proc_mounts_channel) will be NULL.  
> 
> Possibly at least guard this with if (!monitor->proc_mounts_channel) g_warning
> ("Failed to open /proc/mounts") ?

I don't think the rest of glib really works if /proc is not mounted. But, sure, feel free to do that.
Comment 7 David Zeuthen (not reading bugmail) 2011-09-29 19:35:32 UTC
(In reply to comment #5)
> (In reply to comment #2)
> > Committed on master:
> > 
> > 
> > http://git.gnome.org/browse/glib/commit/?id=55065461bfc5ace53e736dfa8181909e918c161b
> 
> Hmm...did you get review from anyone first?

<davidz> mclasen: I'm committing this to master
<davidz> from what I can tell it's been broken in F15
<davidz> all along
<mclasen> davidz: looks good to me
Comment 8 David Zeuthen (not reading bugmail) 2011-09-29 19:40:31 UTC
Actually, the proc man page does have an reference to this. Let me prepare a patch.
Comment 9 David Zeuthen (not reading bugmail) 2011-09-29 19:51:37 UTC
OK, committed the cleanups that Colin requested:

 http://git.gnome.org/browse/glib/commit/?id=934e0a7470fbcfccfd7c4d3e589d59e8778fa973

Thanks for the review.