#include <dlog.h>
#include "dir_backend_fixed_size.hpp"
+#include "os_ops.hpp"
#include <sys/mount.h>
#include <sys/wait.h>
void DirBackendFixedSize::SwitchSubsessionInto (const std::filesystem::path& subsession_path) const
{
const auto image_path = GetImagePathFromSubsessionPath(subsession_path);
+
+ if (OS::is_mountpoint(subsession_path)) {
+ LOGW("Session image already mounted (maybe earlier sessiond instance died?), reusing");
+ return;
+ }
+
do_mount(image_path, subsession_path);
}
#include "os_ops.hpp"
+#include <optional>
+
#include <grp.h>
#include <pwd.h>
#include <sys/smack.h>
#include <sys/stat.h>
+#include <sys/sysmacros.h>
#include <unistd.h>
namespace fs = std::filesystem;
if (!is_symlink(info))
fs::permissions(dest_path, permissions);
}
+
+static std::optional <dev_t> get_stat_dev(fs::path path)
+{
+ struct stat info;
+ const int ret = lstat(path.c_str(), &info);
+ if (ret != 0) {
+ if (errno == ENOENT)
+ return {};
+ else
+ throw std::system_error(errno, std::system_category(), "Couldn't lstat("s + path.native() + ")");
+ }
+ return info.st_dev;
+}
+
+bool OS::is_mountpoint(fs::path path)
+{
+ const auto path_dev = get_stat_dev(path);
+ if (!path_dev)
+ return false;
+
+ const auto parent_dev = get_stat_dev(path.parent_path());
+ if (!parent_dev)
+ return false; // somewhat worrisome
+
+ return major(*path_dev) != major(*parent_dev)
+ || minor(*path_dev) != minor(*parent_dev);
+}
void set_ownership_and_perms(fs::path src_path, fs::path dest_path, fs::perms permissions,
const int session_uid, const int gid, bool copy_perms_from_skel);
+
+ bool is_mountpoint(fs::path path);
}