]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
umount: allow PID as --namespace argument
authorVaclav Dolezal <vdolezal@redhat.com>
Fri, 20 Apr 2018 15:57:39 +0000 (17:57 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 11 Jun 2018 14:18:06 +0000 (16:18 +0200)
[kzak@redhat.com: - update code]

Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
sys-utils/umount.8
sys-utils/umount.c

index f09b1eae69fd9427faa9afa81339dde9dc16d421..ff6ce24299f3454794e01ca62e4d0cd6c34e5947 100644 (file)
@@ -130,7 +130,9 @@ server or a network partition. Remounts of the share will not be possible.
 .TP
 .BR \-N , " \-\-namespace " \fIns
 Perform umount in namespace specified by \fIns\fR.
-\fIns\fR is typically in form \fI/proc/[pid]/ns/mnt\fR.
+\fIns\fR is either PID of process running in that namespace
+or special file representing that namespace.
+See \fBnamespaces\fR(7) for more information.
 .TP
 .BR \-n , " \-\-no\-mtab"
 Unmount without writing in
index 991adf7608e8041efc0d5fde931e3636d401ab2b..244080598bbfde852ff22086f710503d2f0114bb 100644 (file)
@@ -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: