summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2021-11-17 10:33:32 +0100
committerMatthew Heon <mheon@redhat.com>2021-12-06 15:00:23 -0500
commita92b71333e1040f8ac5131e4f5fd41fd6fa18b30 (patch)
tree6319a4a5deae96453d0679fee0809ad2f0d36e63
parent8e6ee43bb29b5e0ec7d467b45278e3cc3b4e242d (diff)
downloadpodman-a92b71333e1040f8ac5131e4f5fd41fd6fa18b30.tar.gz
podman-a92b71333e1040f8ac5131e4f5fd41fd6fa18b30.tar.bz2
podman-a92b71333e1040f8ac5131e4f5fd41fd6fa18b30.zip
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>
-rw-r--r--pkg/rootless/rootless_linux.c38
1 files changed, 18 insertions, 20 deletions
diff --git a/pkg/rootless/rootless_linux.c b/pkg/rootless/rootless_linux.c
index b60aea855..1dd5ad0a1 100644
--- a/pkg/rootless/rootless_linux.c
+++ b/pkg/rootless/rootless_linux.c
@@ -249,6 +249,22 @@ can_use_shortcut ()
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
is_fd_inherited(int fd)
{
@@ -386,13 +402,11 @@ static void __attribute__((constructor)) init()
uid = geteuid ();
gid = getegid ();
- sprintf (path, "/proc/%ld/ns/user", pid);
- userns_fd = open (path, O_RDONLY);
+ userns_fd = open_namespace (pid, "user");
if (userns_fd < 0)
return;
- sprintf (path, "/proc/%ld/ns/mnt", pid);
- mntns_fd = open (path, O_RDONLY);
+ mntns_fd = open_namespace (pid, "mnt");
if (mntns_fd < 0)
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
join_namespace_or_die (const char *name, int ns_fd)
{