Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
session_lineage.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <optional>
8#include <sys/types.h>
9
10namespace platf::session_devices {
11
25 template<class MountNs, class Parent>
26 bool belongs_to_session(pid_t pid, ino_t ns, MountNs mount_ns, Parent parent) {
27 // Deep enough for any launcher chain; a cycle would be a kernel bug.
28 for (int depth = 0; depth < 64 && pid > 1; ++depth) {
29 const std::optional<ino_t> mnt = mount_ns(pid);
30 if (!mnt) {
31 return false;
32 }
33 if (*mnt == ns) {
34 return true;
35 }
36 const std::optional<pid_t> up = parent(pid);
37 if (!up) {
38 return false;
39 }
40 pid = *up;
41 }
42 return false;
43 }
44
45} // namespace platf::session_devices
bool belongs_to_session(pid_t pid, ino_t ns, MountNs mount_ns, Parent parent)