Commit 35ad233f authored by Andrei Vagin's avatar Andrei Vagin

test/zdtm/static/netns_sub_veth.c

parent 98b5542c
#define _GNU_SOURCE
#include <sched.h>
#include <errno.h>
#include <stdlib.h>
......@@ -23,39 +22,6 @@
const char *test_doc = "Check dump and restore a few network namespaces";
#define ID_MAP "0 0 1"
static int init_proc_id_maps(pid_t pid)
{
char path[128];
int fd;
snprintf(path, sizeof(path), "/proc/%d/uid_map", pid);
fd = open(path, O_WRONLY);
if (fd < 0) {
pr_perror("Unable to open %s", path);
return -1;
}
if (write(fd, ID_MAP, sizeof(ID_MAP)) != sizeof(ID_MAP)) {
pr_perror("Unable to write into %s", path);
return -1;
}
close(fd);
snprintf(path, sizeof(path), "/proc/%d/gid_map", pid);
fd = open(path, O_WRONLY);
if (fd < 0) {
pr_perror("Unable to open %s", path);
return -1;
}
if (write(fd, ID_MAP, sizeof(ID_MAP)) != sizeof(ID_MAP)) {
pr_perror("Unable to write into %s", path);
return -1;
}
close(fd);
return 0;
}
#ifndef NSIO
#define NSIO 0xb7
#define NS_GET_USERNS _IO(NSIO, 0x1)
......@@ -70,27 +36,10 @@ int main(int argc, char **argv)
struct rtnl_link *link = NULL, *new;
struct nl_sock *sk;
int has_index = 1;
bool userns;
test_init(argc, argv);
task_waiter_init(&lock);
userns = getenv("ZDTM_USERNS") != NULL;
if (userns) {
int fd, ufd;
fd = open("/proc/self/ns/net", O_RDONLY);
if (fd < 0) {
pr_perror("Unable to open /proc/self/ns/net");
return 1;
}
ufd = ioctl(fd, NS_GET_USERNS);
if (ufd < 0) {
userns = false;
} else
close(ufd);
close(fd);
}
for (i = 0; i < 2; i++) {
pid[i] = fork();
if (pid[i] < 0) {
......@@ -98,8 +47,6 @@ int main(int argc, char **argv)
return -1;
}
if (pid[i] == 0) {
if (userns && unshare(CLONE_NEWUSER))
return 1;
if (unshare(CLONE_NEWNET))
return 1;
......@@ -109,8 +56,6 @@ int main(int argc, char **argv)
return 0;
}
task_waiter_wait4(&lock, i);
if (userns && init_proc_id_maps(pid[i]))
return 1;
}
sk = nl_socket_alloc();
......
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