summaryrefslogtreecommitdiffstats
path: root/sys-utils/umount.c
diff options
context:
space:
mode:
authorVaclav Dolezal2018-04-20 17:57:39 +0200
committerKarel Zak2018-06-11 16:18:06 +0200
commitc1e70afedf53e70768372b30a997630235771f56 (patch)
tree9c78887761efefaf6ae2b022fb86a57fde58a1cd /sys-utils/umount.c
parentmount: allow PID as --namespace argument (diff)
downloadkernel-qcow2-util-linux-c1e70afedf53e70768372b30a997630235771f56.tar.gz
kernel-qcow2-util-linux-c1e70afedf53e70768372b30a997630235771f56.tar.xz
kernel-qcow2-util-linux-c1e70afedf53e70768372b30a997630235771f56.zip
umount: 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/umount.c')
-rw-r--r--sys-utils/umount.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/sys-utils/umount.c b/sys-utils/umount.c
index 991adf760..244080598 100644
--- a/sys-utils/umount.c
+++ b/sys-utils/umount.c
@@ -398,6 +398,19 @@ static char *sanitize_path(const char *path)
return p;
}
+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 = 0, all = 0, recursive = 0, alltargets = 0;
@@ -512,8 +525,15 @@ int main(int argc, char **argv)
print_version();
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;
}
default: