libmount: support for namespaces for helpers
Signed-off-by: Vaclav Dolezal <vdolezal@redhat.com>
This commit is contained in:
parent
de7ccabdfd
commit
65ca7b5a9b
|
@ -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]));
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue