FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
filesystem.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <filesystem>
12#include <unistd.h>
13
14#include "../lib/fuse.hpp"
15
25namespace ns_filesystem
26{
27
28
30{
31 protected:
32 pid_t m_pid_to_die_for;
33 std::filesystem::path m_path_dir_mount;
34 std::filesystem::path m_path_file_log;
35 std::unique_ptr<ns_subprocess::Child> m_child;
36 Filesystem(pid_t pid_to_die_for
37 , std::filesystem::path const& path_dir_mount
38 , std::filesystem::path const& path_file_log
39 );
40
41 public:
42 virtual ~Filesystem();
43 [[nodiscard]] virtual Value<void> mount() = 0;
44 Filesystem(Filesystem&&) = default;
45 Filesystem(Filesystem const&) = delete;
46 Filesystem& operator=(Filesystem&&) = default;
47 Filesystem& operator=(Filesystem const&) = delete;
48};
49
57inline Filesystem::Filesystem(pid_t pid_to_die_for
58 , std::filesystem::path const& path_dir_mount
59 , std::filesystem::path const& path_file_log
60)
61 : m_pid_to_die_for(pid_to_die_for)
62 , m_path_dir_mount(path_dir_mount)
63 , m_path_file_log(path_file_log)
64 , m_child(nullptr)
65{
66}
67
73{
74 // Un-mount the fuse file system
75 ns_fuse::unmount(m_path_dir_mount).discard("E::Could not un-mount filesystem '{}'", m_path_dir_mount);
76 // Check for subprocess
77 return_if(not m_child,,"E::No fuse sub-process for '{}'", m_path_dir_mount.string());
78 // Tell process to exit with SIGTERM
79 if (pid_t pid = m_child->get_pid().value_or(-1); pid > 0)
80 {
81 kill(pid, SIGTERM);
82 }
83 // Wait for process to exit and log result
84 std::ignore = m_child->wait();
85}
86
87} // namespace ns_filesystem
88
89/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Filesystem(pid_t pid_to_die_for, std::filesystem::path const &path_dir_mount, std::filesystem::path const &path_file_log)
Construct a new Filesystem object.
virtual ~Filesystem()
Destroy the Filesystem:: Filesystem object, it un-mounts the filesystem and sends a termination signa...
A library for operations on fuse filesystems.
Base filesystem interface and abstraction.
Value< int > unmount(fs::path const &path_dir_mount)
Un-mounts the given fuse mount point.
Definition fuse.hpp:90
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44