mirror of
https://github.com/containers/podman.git
synced 2025-09-21 19:55:08 +08:00
rootless: reuse existing open_namespace function
there is already a function for opening a namespace path, reuse it. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -249,6 +249,22 @@ can_use_shortcut ()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
open_namespace (int pid_to_join, const char *ns_file)
|
||||||
|
{
|
||||||
|
char ns_path[PATH_MAX];
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = snprintf (ns_path, PATH_MAX, "/proc/%d/ns/%s", pid_to_join, ns_file);
|
||||||
|
if (ret == PATH_MAX)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "internal error: namespace path too long\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return open (ns_path, O_CLOEXEC | O_RDONLY);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
is_fd_inherited(int fd)
|
is_fd_inherited(int fd)
|
||||||
{
|
{
|
||||||
@ -386,13 +402,11 @@ static void __attribute__((constructor)) init()
|
|||||||
uid = geteuid ();
|
uid = geteuid ();
|
||||||
gid = getegid ();
|
gid = getegid ();
|
||||||
|
|
||||||
sprintf (path, "/proc/%ld/ns/user", pid);
|
userns_fd = open_namespace (pid, "user");
|
||||||
userns_fd = open (path, O_RDONLY);
|
|
||||||
if (userns_fd < 0)
|
if (userns_fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
sprintf (path, "/proc/%ld/ns/mnt", pid);
|
mntns_fd = open_namespace (pid, "mnt");
|
||||||
mntns_fd = open (path, O_RDONLY);
|
|
||||||
if (mntns_fd < 0)
|
if (mntns_fd < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -592,22 +606,6 @@ create_pause_process (const char *pause_pid_file_path, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
open_namespace (int pid_to_join, const char *ns_file)
|
|
||||||
{
|
|
||||||
char ns_path[PATH_MAX];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = snprintf (ns_path, PATH_MAX, "/proc/%d/ns/%s", pid_to_join, ns_file);
|
|
||||||
if (ret == PATH_MAX)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "internal error: namespace path too long\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return open (ns_path, O_CLOEXEC | O_RDONLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
join_namespace_or_die (const char *name, int ns_fd)
|
join_namespace_or_die (const char *name, int ns_fd)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user