From 8d092c2be9083319e1c9e05dd5da1e9b7caf9fe6 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Wed, 31 May 2017 13:43:54 -0700 Subject: [PATCH] notify_store_retrieve(): fix race on unmount 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 | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/example/notify_store_retrieve.c b/example/notify_store_retrieve.c index 0ed22bb..c7e2957 100644 --- a/example/notify_store_retrieve.c +++ b/example/notify_store_retrieve.c @@ -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; } -- 2.30.2