notify_store_retrieve(): fix race on unmount
authorNikolaus Rath <Nikolaus@rath.org>
Wed, 31 May 2017 20:43:54 +0000 (13:43 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Wed, 31 May 2017 20:43:54 +0000 (13:43 -0700)
update_fs_loop() is still running when the filesystem unmounts,
but it that case calls to fuse_lowlevel_notify_* will fail.

Fixes: #105.
example/notify_store_retrieve.c

index 0ed22bbd8875caa6af0036bdd42c1473460cbad2..c7e29574938494bcdb485bc20bb50ce116056ef1 100644 (file)
@@ -317,7 +317,11 @@ static void* update_fs_loop(void *data) {
             /* This shouldn't fail, but apparenly it sometimes
                does - see https://github.com/libfuse/libfuse/issues/105 */
             ret = fuse_lowlevel_notify_store(se, FILE_INO, 0, &bufv, 0);
-            if (ret != 0) {
+            if (-ret == ENODEV) {
+                // File system was unmounted
+                break;
+            }
+            else if (ret != 0) {
                 fprintf(stderr, "ERROR: fuse_lowlevel_notify_store() failed with %s (%d)\n",
                         strerror(-ret), -ret);
                 abort();
@@ -325,9 +329,12 @@ static void* update_fs_loop(void *data) {
 
             /* To make sure that everything worked correctly, ask the
                kernel to send us back the stored data */
-            assert(fuse_lowlevel_notify_retrieve
-                   (se, FILE_INO, MAX_STR_LEN, 0,
-                    (void*) strdup(file_contents)) == 0);
+            ret = fuse_lowlevel_notify_retrieve(se, FILE_INO, MAX_STR_LEN,
+                                                0, (void*) strdup(file_contents));
+            if (-ret == ENODEV) { // File system was unmounted
+                break;
+            }
+            assert(ret == 0);
             if(retrieve_status == 0)
                 retrieve_status = 1;
         }