Commit 0ecd6c33 authored by Pavel Emelyanov's avatar Pavel Emelyanov

zdtm: Introduce explicit prepare_namespaces() routine

This one is to set up uids for userns, do ip l s lo up for netns
and do the prepare_mntns(). BTW, the latter's code is shifted one
tab left as this is where it should be.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent de8fd000
......@@ -19,7 +19,7 @@
#include "ns.h"
extern int pivot_root(const char *new_root, const char *put_old);
static int prepare_mntns()
static int prepare_mntns(void)
{
int dfd, ret;
char *root;
......@@ -124,6 +124,21 @@ static int prepare_mntns()
return 0;
}
static int prepare_namespaces(void)
{
if (setuid(0) || setgid(0) || setgroups(0, NULL)) {
fprintf(stderr, "set*id failed: %m\n");
return -1;
}
system("ip link set up dev lo");
if (prepare_mntns())
return -1;
return 0;
}
#define NS_STACK_SIZE 4096
/* All arguments should be above stack, because it grows down */
......@@ -193,14 +208,8 @@ static int ns_exec(void *_arg)
close(args->status_pipe[1]);
read(STATUS_FD, buf, sizeof(buf));
shutdown(STATUS_FD, SHUT_RD);
if (setuid(0) || setgid(0) || setgroups(0, NULL)) {
fprintf(stderr, "set*id failed: %m\n");
return -1;
}
system("ip link set up dev lo");
if (prepare_mntns())
if (prepare_namespaces())
return -1;
setenv("ZDTM_NEWNS", "2", 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment