summaryrefslogtreecommitdiffstats
path: root/sys-utils/mount.c
diff options
context:
space:
mode:
authorVaclav Dolezal2018-04-20 17:57:39 +0200
committerKarel Zak2018-06-11 16:16:32 +0200
commitd59766a64806d3acc409bd27cdd6a58e2d6e405f (patch)
tree75c61629e662808350a67429083688fe58802404 /sys-utils/mount.c
parentmount: document --namespace in man/help (diff)
downloadkernel-qcow2-util-linux-d59766a64806d3acc409bd27cdd6a58e2d6e405f.tar.gz
kernel-qcow2-util-linux-d59766a64806d3acc409bd27cdd6a58e2d6e405f.tar.xz
kernel-qcow2-util-linux-d59766a64806d3acc409bd27cdd6a58e2d6e405f.zip
mount: allow PID as --namespace argument
[[kzak@redhat.com: - update code] Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Diffstat (limited to 'sys-utils/mount.c')
-rw-r--r--sys-utils/mount.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/sys-utils/mount.c b/sys-utils/mount.c
index a0dba721a..5e139e896 100644
--- a/sys-utils/mount.c
+++ b/sys-utils/mount.c
@@ -512,6 +512,19 @@ static long osrc2mask(const char *str, size_t len)
return -EINVAL;
}
+static pid_t parse_pid(const char *str)
+{
+ char *end;
+ pid_t ret;
+
+ errno = 0;
+ ret = strtoul(str, &end, 10);
+
+ if (ret < 0 || errno || end == str || (end && *end))
+ return 0;
+ return ret;
+}
+
int main(int argc, char **argv)
{
int c, rc = MNT_EX_SUCCESS, all = 0, show_labels = 0;
@@ -694,9 +707,17 @@ int main(int argc, char **argv)
append_option(cxt, "rbind");
break;
case 'N':
- if (mnt_context_set_target_ns(cxt, optarg))
- err(MNT_EX_SYSERR, _("failed to set target namespace"));
+ {
+ char path[PATH_MAX];
+ pid_t pid = parse_pid(optarg);
+
+ if (pid)
+ snprintf(path, sizeof(path), "/proc/%i/ns/mnt", pid);
+
+ if (mnt_context_set_target_ns(cxt, pid ? path : optarg))
+ err(MNT_EX_SYSERR, _("failed to set target namespace to %s"), pid ? path : optarg);
break;
+ }
case MOUNT_OPT_SHARED:
append_option(cxt, "shared");
propa = 1;