diff options
author | Krzysztof Richert <krzysztof.richert@intel.com> | 2021-10-27 15:07:45 +0300 |
---|---|---|
committer | Krzysztof Richert <krzysztof.richert@intel.com> | 2021-10-28 17:21:37 +0300 |
commit | 90e0e1648c3ee168deb7615450f3a2771c04b8eb (patch) | |
tree | 7d6297d9ca228b211467bf32c7d673911ef7e6e0 /src/state | |
parent | a5176f324cf5d9cbdb15fa57a6c3f54bcb6e6f48 (diff) | |
download | virtual-media-90e0e1648c3ee168deb7615450f3a2771c04b8eb.tar.xz |
Cleanup mounted resources after application crash.
On initial state application cleans mounted resources which
were allocated by user befor application crashed.
Without that busy slot is not avaialble anymore for user.
Tested:
1. Mount CIFS share.
2. Send terminate signal to virtual-media (kill -9).
3. Mount CIFS share on the same slot as during step 1.
Change-Id: I7088e94832fb7bec171a56f73bd66cd29e9b246f
Signed-off-by: Krzysztof Richert <krzysztof.richert@intel.com>
Diffstat (limited to 'src/state')
-rw-r--r-- | src/state/initial_state.hpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/state/initial_state.hpp b/src/state/initial_state.hpp index 7fcc10b..02fe479 100644 --- a/src/state/initial_state.hpp +++ b/src/state/initial_state.hpp @@ -25,6 +25,10 @@ struct InitialState : public BasicStateT<InitialState> "Legacy mode is not supported"); } #endif + if (isLegacy) + { + cleanUpMountPoint(); + } addMountPointInterface(event); addProcessInterface(event); addServiceInterface(event, isLegacy); @@ -79,6 +83,47 @@ struct InitialState : public BasicStateT<InitialState> processIface->initialize(); } + void cleanUpMountPoint() + { + if (UsbGadget::isConfigured(std::string(machine.getName()))) + { + int result = UsbGadget::configure(std::string(machine.getName()), + machine.getConfig().nbdDevice, + StateChange::removed); + LogMsg(Logger::Info, "UsbGadget cleanup"); + + if (result != 0) + { + LogMsg(Logger::Critical, machine.getName(), + "Some serious failure happened! Cleanup failed."); + } + } + + auto localFile = std::filesystem::temp_directory_path() / + std::string(machine.getName()); + + if (fs::exists(localFile)) + { + if (0 == ::umount2(localFile.c_str(), MNT_FORCE)) + { + LogMsg(Logger::Info, "Cleanup directory ", localFile); + std::error_code ec; + if (!std::filesystem::remove(localFile, ec)) + { + LogMsg(Logger::Error, ec, + "Cleanup failed - unable to remove directory ", + localFile); + } + } + else + { + LogMsg(Logger::Error, + "Cleanup failed - unable to unmount directory ", + localFile); + } + } + } + void addMountPointInterface(const RegisterDbusEvent& event) { std::string objPath = getObjectPath(machine); |