From dcb6be5a9911b0dfa0ba9c42097cb1f6c578b3ee Mon Sep 17 00:00:00 2001 From: Bilal Khan Date: Mon, 8 May 2023 19:12:36 +0500 Subject: [PATCH] Fix: Preserve /sys hierarchy in network namespaces by removing /sys unmount and mount calls Signed-off-by: Bilal Khan --- lib/namespace.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/lib/namespace.c b/lib/namespace.c index 1202fa85..0f6a585f 100644 --- a/lib/namespace.c +++ b/lib/namespace.c @@ -46,8 +46,6 @@ int netns_switch(char *name) { char net_path[PATH_MAX]; int netns; - unsigned long mountflags = 0; - struct statvfs fsstat; snprintf(net_path, sizeof(net_path), "%s/%s", NETNS_RUN_DIR, name); netns = open(net_path, O_RDONLY | O_CLOEXEC); @@ -76,22 +74,6 @@ int netns_switch(char *name) return -1; } - /* Mount a version of /sys that describes the network namespace */ - - if (umount2("/sys", MNT_DETACH) < 0) { - /* If this fails, perhaps there wasn't a sysfs instance mounted. Good. */ - if (statvfs("/sys", &fsstat) == 0) { - /* We couldn't umount the sysfs, we'll attempt to overlay it. - * A read-only instance can't be shadowed with a read-write one. */ - if (fsstat.f_flag & ST_RDONLY) - mountflags = MS_RDONLY; - } - } - if (mount(name, "/sys", "sysfs", mountflags, NULL) < 0) { - fprintf(stderr, "mount of /sys failed: %s\n",strerror(errno)); - return -1; - } - /* Setup bind mounts for config files in /etc */ bind_etc(name); return 0; -- 2.25.1