diff options
author | Vaclav Dolezal | 2018-03-06 12:30:27 +0100 |
---|---|---|
committer | Karel Zak | 2018-06-11 16:08:44 +0200 |
commit | 65ca7b5a9b3270b71804f3de988322e19941a02b (patch) | |
tree | c470efaba1be883aabc316be5960bf25743af883 /libmount/src | |
parent | libmount: make errno usable after mnt_context_set_target_ns() (diff) | |
download | kernel-qcow2-util-linux-65ca7b5a9b3270b71804f3de988322e19941a02b.tar.gz kernel-qcow2-util-linux-65ca7b5a9b3270b71804f3de988322e19941a02b.tar.xz kernel-qcow2-util-linux-65ca7b5a9b3270b71804f3de988322e19941a02b.zip |
libmount: support for namespaces for helpers
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
Diffstat (limited to 'libmount/src')
-rw-r--r-- | libmount/src/context_mount.c | 22 | ||||
-rw-r--r-- | libmount/src/context_umount.c | 20 |
2 files changed, 37 insertions, 5 deletions
diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 9245d73dd..572395811 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -578,6 +578,10 @@ int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg) if (arg) rc = mnt_context_set_fstype(cxt, arg); break; + case 'N': + if (arg) + rc = mnt_context_set_target_ns(cxt, arg); + break; default: return 1; } @@ -587,7 +591,8 @@ int mnt_context_mount_setopt(struct libmnt_context *cxt, int c, char *arg) static int exec_helper(struct libmnt_context *cxt) { - char *o = NULL; + char *o = NULL, *namespace = NULL; + struct libmnt_ns *ns_tgt = mnt_context_get_target_ns(cxt); int rc; pid_t pid; @@ -602,13 +607,20 @@ static int exec_helper(struct libmnt_context *cxt) if (rc) return -EINVAL; + if (ns_tgt->fd != -1 + && asprintf(&namespace, "/proc/%i/fd/%i", + getpid(), ns_tgt->fd) == -1) { + free(o); + return -ENOMEM; + } + DBG_FLUSH; pid = fork(); switch (pid) { case 0: { - const char *args[12], *type; + const char *args[14], *type; int i = 0; if (setgid(getgid()) < 0) @@ -641,7 +653,11 @@ static int exec_helper(struct libmnt_context *cxt) args[i++] = "-t"; /* 10 */ args[i++] = type; /* 11 */ } - args[i] = NULL; /* 12 */ + if (namespace) { + args[i++] = "-N"; /* 11 */ + args[i++] = namespace; /* 12 */ + } + args[i] = NULL; /* 13 */ for (i = 0; args[i]; i++) DBG(CXT, ul_debugobj(cxt, "argv[%d] = \"%s\"", i, args[i])); diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index 3e320bec9..70628b6cb 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -520,6 +520,8 @@ eperm: static int exec_helper(struct libmnt_context *cxt) { + char *namespace = NULL; + struct libmnt_ns *ns_tgt = mnt_context_get_target_ns(cxt); int rc; pid_t pid; @@ -535,13 +537,19 @@ static int exec_helper(struct libmnt_context *cxt) return rc; } + if (ns_tgt->fd != -1 + && asprintf(&namespace, "/proc/%i/fd/%i", + getpid(), ns_tgt->fd) == -1) { + return -ENOMEM; + } + DBG_FLUSH; pid = fork(); switch (pid) { case 0: { - const char *args[10], *type; + const char *args[12], *type; int i = 0; if (setgid(getgid()) < 0) @@ -571,8 +579,12 @@ static int exec_helper(struct libmnt_context *cxt) args[i++] = "-t"; /* 8 */ args[i++] = (char *) type; /* 9 */ } + if (namespace) { + args[i++] = "-N"; /* 10 */ + args[i++] = namespace; /* 11 */ + } - args[i] = NULL; /* 10 */ + args[i] = NULL; /* 12 */ for (i = 0; args[i]; i++) DBG(CXT, ul_debugobj(cxt, "argv[%d] = \"%s\"", i, args[i])); @@ -643,6 +655,10 @@ int mnt_context_umount_setopt(struct libmnt_context *cxt, int c, char *arg) if (arg) rc = mnt_context_set_fstype(cxt, arg); break; + case 'N': + if (arg) + rc = mnt_context_set_target_ns(cxt, arg); + break; default: return 1; } |