From 8eaff5673d8e133e72e20cf4409ab4c901831424 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 5 Mar 2013 14:58:46 -0600 Subject: [PATCH] wimlib_mount_image(): Send final status after fuse_main() returns --- src/mount_image.c | 20 ++++++++++++++++---- src/util.c | 10 +++++++--- src/wimlib.h | 3 +++ tests/test-imagex-mount | 4 ++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/mount_image.c b/src/mount_image.c index b9b63450..6c5ec885 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -109,6 +109,9 @@ struct wimfs_context { uid_t default_uid; gid_t default_gid; + + int status; + bool have_status; }; static void init_wimfs_context(struct wimfs_context *ctx) @@ -1236,7 +1239,8 @@ out: status = ret; } } - send_unmount_finished_msg(wimfs_ctx->daemon_to_unmount_mq, status); + wimfs_ctx->status = status; + wimfs_ctx->have_status = true; return MSG_BREAK_LOOP; } @@ -1565,7 +1569,6 @@ static void wimfs_destroy(void *p) message_loop(wimfs_ctx->unmount_to_daemon_mq, &daemon_msg_handler_callbacks, &handler_ctx.hdr); - close_message_queues(wimfs_ctx); } } @@ -2530,14 +2533,23 @@ WIMLIBAPI int wimlib_mount_image(WIMStruct *wim, int image, const char *dir, DEBUG("Returned from fuse_main() (ret = %d)", ret); - if (ret) + if (ret) { ret = WIMLIB_ERR_FUSE; + } else { + if (ctx.have_status) + ret = ctx.status; + else + ret = WIMLIB_ERR_TIMEOUT; + } + if (ctx.daemon_to_unmount_mq != (mqd_t)(-1)) { + send_unmount_finished_msg(ctx.daemon_to_unmount_mq, ret); + close_message_queues(&ctx); + } /* Try to delete the staging directory if a deletion wasn't yet * attempted due to an earlier error */ if (ctx.staging_dir_name) delete_staging_dir(&ctx); - out_free_dir_copy: FREE(dir_copy); out_unlock: diff --git a/src/util.c b/src/util.c index f915f2fe..f19f5a58 100644 --- a/src/util.c +++ b/src/util.c @@ -137,6 +137,9 @@ static const char *error_strings[] = { [WIMLIB_ERR_FUSERMOUNT] = "Could not execute the `fusermount' program, or it exited " "with a failure status", + [WIMLIB_ERR_ICONV_NOT_AVAILABLE] + = "The iconv() function does not seem to work. " + "Maybe check to make sure the directory /usr/lib/gconv exists", [WIMLIB_ERR_IMAGE_COUNT] = "Inconsistent image count among the metadata " "resources, the WIM header, and/or the XML data", @@ -168,11 +171,10 @@ static const char *error_strings[] = { = "The part number or total parts of the WIM is invalid", [WIMLIB_ERR_INVALID_RESOURCE_HASH] = "The SHA1 message digest of a WIM resource did not match the expected value", - [WIMLIB_ERR_ICONV_NOT_AVAILABLE] - = "The iconv() function does not seem to work. " - "Maybe check to make sure the directory /usr/lib/gconv exists", [WIMLIB_ERR_INVALID_RESOURCE_SIZE] = "A resource entry in the WIM has an invalid size", + [WIMLIB_ERR_INVALID_SECURITY_DATA] + = "The table of security descriptors in the WIM is invalid", [WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE] = "The version of wimlib that has mounted a WIM image is incompatible with the " "version being used to unmount it", @@ -223,6 +225,8 @@ static const char *error_strings[] = { = "The WIM is part of a split WIM, which is not supported for this operation", [WIMLIB_ERR_STAT] = "Could not read the metadata for a file or directory", + [WIMLIB_ERR_TIMEOUT] + = "Timed out while waiting for a message to arrive from another process", [WIMLIB_ERR_UNKNOWN_VERSION] = "The WIM file is marked with an unknown version number", [WIMLIB_ERR_UNSUPPORTED] diff --git a/src/wimlib.h b/src/wimlib.h index 43956643..d1ee1221 100644 --- a/src/wimlib.h +++ b/src/wimlib.h @@ -711,6 +711,9 @@ typedef int (*wimlib_progress_func_t)(enum wimlib_progress_msg msg_type, * See the documentation for each wimlib function to see specifically what error * codes can be returned by a given function, and what they mean. */ +/* Note: these are currently in alphabetic order, but new error codes should be + * added at the end to maintain a compatible ABI, except when it's being broken + * anyway. */ enum wimlib_error_code { WIMLIB_ERR_SUCCESS = 0, WIMLIB_ERR_ALREADY_LOCKED, diff --git a/tests/test-imagex-mount b/tests/test-imagex-mount index 088e08b5..906a3d65 100755 --- a/tests/test-imagex-mount +++ b/tests/test-imagex-mount @@ -54,8 +54,8 @@ for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do fi mkdir tmp if ! imagex mount dir.wim dir tmp; then - error "Failed to mount test WIM read-only" \ - "Please read any error messages above before reporting this test failure."\ + error "Failed to mount test WIM read-only. " \ + "Please read any error messages above before reporting this test failure. "\ "Perhaps you don't have FUSE installed, or the FUSE kernel module isn't" \ "loaded, or you aren't a member of the FUSE group?" fi -- 2.43.0