diff --git a/src/dwarfs_main.cpp b/src/dwarfs_main.cpp index cb439c47..0a30bf8e 100644 --- a/src/dwarfs_main.cpp +++ b/src/dwarfs_main.cpp @@ -31,6 +31,16 @@ #include #include +#ifndef WIN32 +#if __has_include() +#define BOOST_PROCESS_VERSION 2 +#include +#else +#define BOOST_PROCESS_VERSION 1 +#include +#endif +#endif + #include #include @@ -226,6 +236,33 @@ void checked_reply_err(LogProxy& log_, fuse_req_t req, T&& f) { *reinterpret_cast(fuse_get_context()->private_data) #endif +void check_fusermount(dwarfs_userdata& userdata) { +#ifndef WIN32 + +#if FUSE_USE_VERSION >= 30 + static constexpr std::string_view const fusermount_name = "fusermount3"; + static constexpr std::string_view const fuse_pkg = "fuse3"; +#else + static constexpr std::string_view const fusermount_name = "fusermount"; + static constexpr std::string_view const fuse_pkg = "fuse/fuse2"; +#endif + +#if BOOST_PROCESS_VERSION == 2 + auto fusermount = + boost::process::v2::environment::find_executable(fusermount_name); +#else + auto fusermount = boost::process::search_path(std::string(fusermount_name)); +#endif + + if (fusermount.empty() || !boost::filesystem::exists(fusermount)) { + LOG_PROXY(prod_logger_policy, userdata.lgr); + LOG_ERROR << "Could not find `" << fusermount_name << "' in PATH"; + LOG_WARN << "Do you need to install the `" << fuse_pkg << "' package?"; + } + +#endif +} + template void op_init_common(void* data) { auto& userdata = *reinterpret_cast(data); @@ -1058,6 +1095,8 @@ int run_fuse(struct fuse_args& args, } } fuse_session_unmount(session); + } else { + check_fusermount(userdata); } fuse_remove_signal_handlers(session); } @@ -1067,6 +1106,10 @@ int run_fuse(struct fuse_args& args, ::free(fuse_opts.mountpoint); #else err = fuse_main(args.argc, args.argv, &fsops, &userdata); + + if (err != 0) { + check_fusermount(userdata); + } #endif fuse_opt_free_args(&args); @@ -1103,6 +1146,8 @@ int run_fuse(struct fuse_args& args, char* mountpoint, int mt, int fg, fuse_session_destroy(se); } fuse_unmount(mountpoint, ch); + } else { + check_fusermount(userdata); } ::free(mountpoint);