0

我目前正在尝试使用不同的名称空间进行测试。为此,我尝试实现一个 MNT 命名空间(与 PID 命名空间相结合),以便该命名空间内的程序无法看到系统上的其他进程。

当尝试像这样使用 umount 系统调用时(与 umount("/proc") 或 umount2 和 Force-option 一样):

  if (umount2("/proc", 0)!= 0) 
{
    fprintf(stderr, "Error when unmounting /proc: %s\n",strerror(errno));
    printf("\tKernel version might be incorrect\n");
    exit(-1);
}

系统调用执行以错误号 22“无效参数”结束。

这段代码在一个函数中调用,该函数在创建具有命名空间的子进程时被调用:

 pid_t child_pid = clone(child_exec, child_stack+1024*1024, Child_Flags,&args);

(child_exec 函数)。标志设置如下:

int Child_Flags = CLONE_NEWIPC | CLONE_NEWUSER  | CLONE_NEWUTS | CLONE_NEWNET |CLONE_NEWPID |  CLONE_NEWNS |SIGCHLD  ;

将 CLONE_NEWNS 用于新的挂载命名空间 ( http://man7.org/linux/man-pages/man7/namespaces.7.html )

程序的输出如下:

Testing with Isolation
Starting Container engine
In-Child-PID: 1
Error number 22
Error when unmounting /proc: Invalid argument

有人可以指出我的错误,以便我可以卸载文件夹吗?先感谢您

4

1 回答 1

0

pivot_root除了 using后跟umountto unmount之外,您无法卸载已安装在不同用户命名空间中的内容/。您可以在/proc不卸载旧的/proc.

于 2019-01-08T10:22:47.347 回答