This allows us to drop the hack for recursive includes.
return st.st_ino == namespace_info[type].root_inode;
}
+int namespace_get_leader(pid_t pid, NamespaceType type, pid_t *ret) {
+ int r;
+
+ assert(pid >= 0);
+ assert(type >= 0 && type < _NAMESPACE_TYPE_MAX);
+ assert(ret);
+
+ for (;;) {
+ pid_t ppid;
+
+ r = get_process_ppid(pid, &ppid);
+ if (r < 0)
+ return r;
+
+ r = in_same_namespace(pid, ppid, type);
+ if (r < 0)
+ return r;
+ if (r == 0) {
+ /* If the parent and the child are not in the same namespace, then the child is
+ * the leader we are looking for. */
+ *ret = pid;
+ return 0;
+ }
+
+ pid = ppid;
+ }
+}
+
int detach_mount_namespace(void) {
/* Detaches the mount namespace, disabling propagation from our namespace to the host. Sets
* propagation first to MS_SLAVE for all mounts (disabling propagation), and then back to MS_SHARED
#include <sys/types.h>
-typedef enum NamespaceType NamespaceType;
-
#include "pidref.h"
-enum NamespaceType {
+typedef enum NamespaceType {
NAMESPACE_CGROUP,
NAMESPACE_IPC,
NAMESPACE_NET,
NAMESPACE_TIME,
_NAMESPACE_TYPE_MAX,
_NAMESPACE_TYPE_INVALID = -EINVAL,
-};
+} NamespaceType;
extern const struct namespace_info {
const char *proc_name;
int namespace_is_init(NamespaceType type);
+int namespace_get_leader(pid_t pid, NamespaceType type, pid_t *ret);
+
int detach_mount_namespace(void);
int detach_mount_namespace_harder(uid_t target_uid, gid_t target_gid);
int detach_mount_namespace_userns(int userns_fd);
return 0;
}
-int namespace_get_leader(pid_t pid, NamespaceType type, pid_t *ret) {
- int r;
-
- assert(ret);
-
- for (;;) {
- pid_t ppid;
-
- r = get_process_ppid(pid, &ppid);
- if (r < 0)
- return r;
-
- r = in_same_namespace(pid, ppid, type);
- if (r < 0)
- return r;
- if (r == 0) {
- /* If the parent and the child are not in the same
- * namespace, then the child is the leader we are
- * looking for. */
- *ret = pid;
- return 0;
- }
-
- pid = ppid;
- }
-}
-
int pid_is_kernel_thread(pid_t pid) {
_cleanup_free_ char *line = NULL;
unsigned long long flags;
#include "alloc-util.h"
#include "format-util.h"
#include "macro.h"
-#include "namespace-util.h"
#include "pidref.h"
#include "time-util.h"
int container_get_leader(const char *machine, pid_t *pid);
-int namespace_get_leader(pid_t pid, NamespaceType type, pid_t *ret);
-
int wait_for_terminate(pid_t pid, siginfo_t *status);
typedef enum WaitFlags {