[glib/glib-2-56] inotify: fix segfault on watching hard links



commit 3f66ab2ede4d637c7c9bf4c0ee7a98d062994cd0
Author: Ryan Lortie <desrt desrt ca>
Date:   Tue Sep 29 16:48:29 2015 -0400

    inotify: fix segfault on watching hard links
    
    The call to _start() fills in the dirname, basename, and filename
    arguments according to the following rules:
    
      dir watches: dirname filled
    
      file watches: dirname and basename filled
    
      hardlink: filename filled
    
    This doesn't map to how the current inotify backend works very nicely,
    so we need to adjust things a bit when creating our "sub" objects.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755721

 gio/inotify/ginotifyfilemonitor.c |  2 +-
 gio/inotify/inotify-sub.c         | 19 +++++++++++++++----
 gio/inotify/inotify-sub.h         |  2 +-
 3 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/gio/inotify/ginotifyfilemonitor.c b/gio/inotify/ginotifyfilemonitor.c
index 9bd19d0c1..4c95e87fb 100644
--- a/gio/inotify/ginotifyfilemonitor.c
+++ b/gio/inotify/ginotifyfilemonitor.c
@@ -61,7 +61,7 @@ g_inotify_file_monitor_start (GLocalFileMonitor  *local_monitor,
   success = _ih_startup ();
   g_assert (success);
 
-  inotify_monitor->sub = _ih_sub_new (dirname, basename, filename != NULL, source);
+  inotify_monitor->sub = _ih_sub_new (dirname, basename, filename, source);
   _ih_sub_add (inotify_monitor->sub);
 }
 
diff --git a/gio/inotify/inotify-sub.c b/gio/inotify/inotify-sub.c
index feb63fae2..b161557db 100644
--- a/gio/inotify/inotify-sub.c
+++ b/gio/inotify/inotify-sub.c
@@ -44,16 +44,27 @@ dup_dirname (const gchar *dirname)
 
 inotify_sub*
 _ih_sub_new (const gchar *dirname, 
+             const gchar *basename,
              const gchar *filename,
-             gboolean     watch_hardlinks,
              gpointer     user_data)
 {
   inotify_sub *sub = NULL;
   
   sub = g_new0 (inotify_sub, 1);
-  sub->dirname = dup_dirname (dirname);
-  sub->filename = g_strdup (filename);
-  sub->hardlinks = watch_hardlinks;
+
+  if (filename)
+    {
+      sub->dirname = g_path_get_dirname (filename);
+      sub->filename = g_path_get_basename (filename);
+      sub->hardlinks = TRUE;
+    }
+  else
+    {
+      sub->dirname = dup_dirname (dirname);
+      sub->filename = g_strdup (basename);
+      sub->hardlinks = FALSE;
+    }
+
   sub->user_data = user_data;
 
   IS_W ("new subscription for %s being setup\n", sub->dirname);
diff --git a/gio/inotify/inotify-sub.h b/gio/inotify/inotify-sub.h
index b0844fd99..fcde4f4cd 100644
--- a/gio/inotify/inotify-sub.h
+++ b/gio/inotify/inotify-sub.h
@@ -33,8 +33,8 @@ typedef struct
 } inotify_sub;
 
 inotify_sub *_ih_sub_new (const gchar  *dirname,
+                         const gchar  *basename,
                          const gchar  *filename,
-                         gboolean      watch_hardlinks,
                          gpointer      user_data);
 void         _ih_sub_free (inotify_sub *sub);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]