diff --git a/repertory/librepertory/include/drives/fuse/remotefuse/remote_client.hpp b/repertory/librepertory/include/drives/fuse/remotefuse/remote_client.hpp index 42bc76e4..92577046 100644 --- a/repertory/librepertory/include/drives/fuse/remotefuse/remote_client.hpp +++ b/repertory/librepertory/include/drives/fuse/remotefuse/remote_client.hpp @@ -24,7 +24,6 @@ #include "comm/packet/packet_client.hpp" #include "drives/fuse/remotefuse/i_remote_instance.hpp" -#include "events/event_system.hpp" #include "types/remote.hpp" namespace repertory { diff --git a/repertory/librepertory/src/drives/fuse/fuse_base.cpp b/repertory/librepertory/src/drives/fuse/fuse_base.cpp index ee894b3b..63be455c 100644 --- a/repertory/librepertory/src/drives/fuse/fuse_base.cpp +++ b/repertory/librepertory/src/drives/fuse/fuse_base.cpp @@ -448,8 +448,7 @@ auto fuse_base::mount(std::vector args) -> int { } repertory::project_cleanup(); - exit(utils::create_daemon(main_func)); - return 0; + return utils::create_daemon(main_func); } auto fuse_base::open_(const char *path, struct fuse_file_info *f_info) -> int { diff --git a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp index 2a099869..d3ce5e2b 100644 --- a/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp +++ b/repertory/librepertory/src/drives/fuse/remotefuse/remote_fuse_drive.cpp @@ -137,9 +137,10 @@ auto remote_fuse_drive::fgetattr_impl(std::string api_path, struct stat *u_stat, } #if defined(__APPLE__) -api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path, - struct setattr_x *attr, - struct fuse_file_info *f_info) { +auto remote_fuse_drive::fsetattr_x_impl(std::string api_path, + struct setattr_x *attr, + struct fuse_file_info *f_info) + -> api_error { remote::setattr_x attributes{}; attributes.valid = attr->valid; attributes.mode = attr->mode; diff --git a/repertory/librepertory/src/utils/unix/unix_utils.cpp b/repertory/librepertory/src/utils/unix/unix_utils.cpp index 2b4227e0..049aacef 100644 --- a/repertory/librepertory/src/utils/unix/unix_utils.cpp +++ b/repertory/librepertory/src/utils/unix/unix_utils.cpp @@ -230,45 +230,48 @@ auto create_daemon(std::function main_func) -> int { return 1; } - if (pid == 0) { - signal(SIGCHLD, SIG_DFL); - if (setsid() < 0) { - return 1; - } - - auto second_pid = fork(); - if (second_pid < 0) { - return 1; - } - - if (second_pid > 0) { - exit(0); - } - - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - - auto file_desc = open("/dev/null", O_RDWR); - if (file_desc < 0) { - return 1; - } - - dup2(file_desc, STDIN_FILENO); - dup2(file_desc, STDOUT_FILENO); - dup2(file_desc, STDERR_FILENO); - - if (file_desc > STDERR_FILENO) { - close(file_desc); - } - - umask(0); - chdir("/"); - return main_func(); + if (pid > 0) { + return 0; } - signal(SIGCHLD, SIG_IGN); - return 0; + if (setsid() < 0) { + return 1; + } + + pid = fork(); + if (pid < 0) { + return 1; + } + + if (pid > 0) { + _exit(0); + } + + close(STDIN_FILENO); + close(STDOUT_FILENO); + close(STDERR_FILENO); + + auto file_desc = open("/dev/null", O_RDWR); + if (file_desc < 0) { + return 1; + } + + dup2(file_desc, STDIN_FILENO); + dup2(file_desc, STDOUT_FILENO); + dup2(file_desc, STDERR_FILENO); + + if (file_desc > STDERR_FILENO) { + close(file_desc); + } + + signal(SIGCHLD, SIG_DFL); + signal(SIGHUP, SIG_DFL); + signal(SIGPIPE, SIG_IGN); + + umask(0); + chdir("/"); + + return main_func(); } } // namespace repertory::utils diff --git a/repertory/repertory/include/cli/mount.hpp b/repertory/repertory/include/cli/mount.hpp index ca03a4ea..9a865f12 100644 --- a/repertory/repertory/include/cli/mount.hpp +++ b/repertory/repertory/include/cli/mount.hpp @@ -23,6 +23,7 @@ #define REPERTORY_INCLUDE_CLI_MOUNT_HPP_ #include "cli/common.hpp" +#include "initialize.hpp" namespace repertory::cli::actions { [[nodiscard]] inline auto @@ -121,13 +122,12 @@ mount(std::vector args, std::string data_directory, << " Drive" << std::endl; if (prov == provider_type::remote) { try { - constexpr const std::uint8_t retry_count{30U}; - auto remote_cfg = config.get_remote_config(); remote_cfg.host_name_or_ip = remote_host; remote_cfg.api_port = remote_port; config.set_remote_config(remote_cfg); + constexpr const std::uint8_t retry_count{30U}; std::cout << "Connecting to remote [" << remote_host << ':' << remote_port << "] ..." << std::flush; auto online{false}; diff --git a/repertory/repertory/src/ui/handlers.cpp b/repertory/repertory/src/ui/handlers.cpp index 181d1f33..602bd4e2 100644 --- a/repertory/repertory/src/ui/handlers.cpp +++ b/repertory/repertory/src/ui/handlers.cpp @@ -760,11 +760,11 @@ auto handlers::launch_process(provider_type prov, std::string_view name, } exec_args.push_back(nullptr); - exit(utils::create_daemon([&]() -> int { + [[maybe_unused]] auto ret = utils::create_daemon([&]() -> int { chdir(utils::path::get_parent_path(repertory_binary_).c_str()); return execvp(exec_args.at(0U), const_cast(exec_args.data())); - })); + }); #endif // defined(_WIN32) return {};