- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
如何将在子命名空间中创建的挂载传播到父命名空间?
我正在尝试创建一个利用 overlayfs
的工具来允许在只读目录上进行写入。棘手的一点是我希望任何用户都能够在没有 root 权限的情况下使用它。因此,我希望这可以通过挂载命名空间来实现,前提是管理员挂载了一个共享目录,然后任何用户都应该能够在该树下创建一个从父命名空间可见的覆盖(因此任何用户登录shell 可以看到覆盖安装)。
这是我尝试过的,但没有用:
# admin creates a shared tree for users to mount under
sudo mkdir /overlays
# bind mount over itself with MS_REC | MS_SHARED
sudo mount --bind --rshared /overlays /overlays
假设用户想要在 /some/readonly/dir
上创建覆盖,他们应该创建 /overlays/user/{upper,work,mnt}
。我希望他们能够在使用以下代码传播的 /overlays
目录下安装覆盖。
// user_overlay.c
#define _GNU_SOURCE
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <linux/capability.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int child(void *args)
{
pid_t p;
p = mount("overlay", "/overlays/user/mnt", "overlay", 0, "lowerdir=/some/readonly/dir,upperdir=/overlays/user/upper,workdir=/overlays/user/work");
if (p == -1){
perror("Failed to mount overlay");
exit(1);
}
// Expose the mount to the parent namespace
p = mount("none", "/overlays/user/mnt", NULL, MS_SHARED, NULL);
if (p == -1){
perror("Failed to mark mount as shared");
exit(1);
}
// Exec bash so I can ensure that the mnt was created
// though in practice I would just daemonize this proc
// such that the mount is visible in the parent
// until this proc is killed
char *newargv[] = { "/bin/bash", NULL };
execv("/bin/bash", newargv);
perror("exec");
exit(EXIT_FAILURE);
return 0;
}
int main()
{
pid_t p = clone(child, malloc(4096) + 4096, CLONE_NEWNS | CLONE_NEWUSER | SIGCHLD, NULL);
if (p == -1) {
perror("clone");
exit(1);
}
// Wait until the bash proc in the child finishes
waitpid(p, NULL, 0);
return 0;
}
执行 gcc user_overlay.c -o user_overlay && ./user_overlay
确实会在该子进程中安装覆盖,但 /overlays/user/mnt
不会传播到 parent 。但是,对 /overlays/user/upper
的修改对父子都可见。
最佳答案
您试图实现的目标似乎是不可能的,至少不能使用上述方法。您希望通过 CLONE_NEWUSER
创建新的用户命名空间来向非特权用户授予安装权限。但是,引用 mount_namespaces(7)
(强调我的):
Restrictions on mount namespaces
Note the following points with respect to mount namespaces:
* A mount namespace has an owner user namespace. A mount namespace whose owner user namespace is different from the owner user namespace of its parent mount namespace is considered a less privileged mount namespace.* When creating a less privileged mount namespace, shared mounts are reduced to slave mounts. (Shared and slave mounts are discussed below.) This ensures that mappings performed in less privileged mount namespaces will not propagate to more privileged mount namespaces.
这意味着您正在创建的挂载实际上具有 slave
传播类型,而不是您期望的 shared
。这会导致挂载事件不会传播到父挂载命名空间。
关于c - 将挂载从子命名空间传播到父命名空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48156663/
我面临以下问题: 我有一个命名空间 Exception\* , 其中包含多种类型 异常(exception)。 我有一个命名空间 Exception\User\* ,其中包含一个 特定类型的异常 (
新的 Highcharts v3.0 气泡图看起来很棒。是否可以用名称/一些文本注释和显示每个气泡? 谢谢,奈杰尔。 最佳答案 您需要做两件事。 首先,命名每个数据点(气泡): data: [ {
我通过使用 EVP_get_cipherbyname("AES-256-CTR") 获得了 EVP_CIPHER*,现在我想找到一种方法从 EVP_CIPHER* 返回到原始名称,在本例中为“AES-
为了避免 JavaScript 堆问题,我使用多个数组:family1、family2、family3 ...、dogs1、dogs2、dogs3 ... 使用示例:“family1 和 dogs1”
我很难理解这段代码。这不是我熟悉的典型 Javascript 函数语法。这是一个命名函数吗?或者这是更新事件的回调?抱歉,我对新手问题很陌生,我对 JS 还很陌生。我了解正在发生的一切,除了这个函数语
是否可以在 python 中执行以下操作? i=1 while True: w = open("POSCAR_i","w") i=i+1 if i<10:
我问这个是因为我刚刚在一段代码上看到它: var myVar = function func(arg){ console.log(arg); } 我不明白为什么函数在为 myVar 定义之前被“
我正在尝试为 ActiveDirectory 创建上下文(客户端和服务器都是 Windows),使用我的 Windows 凭据和 NTLM。 这是我的代码: public void func() {
我正在运行一个使用 JBoss5 容器的 ejb 示例。我正在使用一个例子 from here(Part one) . 在示例中,我在 JBoss 中部署了 bean,在 Tomcat 中部署了一个应
我希望能够命名一个 BackgroundWorker 以便于调试。这可能吗? 最佳答案 我必须尝试,但你不能只设置 Name BackgroundWorker 执行的 DoWork() 方法中的线程?
我在 Android Activity 和其他类之间遇到了越来越多的命名冲突。我想知道你能不能告诉我你是如何避免这些的。遗憾的是,关于 SO 的相关问题并未涵盖我的特定命名问题。 第一个例子 我有一个
当我尝试使用 loadChildren 加载模块以在命名 socket 中加载模块的组件时,出现抛出错误。 有没有办法在命名的路由器 socket 中延迟加载模块? //html //routing
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。如需帮助澄清这个问题以便重新打开它,visit the help center .
在 Type Driven Development with Idris 第 6 章的代码中,我对这段代码感到困惑: data DataStore : Type -> Type where M
通常,如果有一个属性可以获取/设置状态值,我会使用“Is”,例如: Visibility: .IsVisible 但是对于获取/设置操作的属性,最好使用什么?喜欢: Casting shadows:
好的,所以如果你可以很容易地想到一个名词,那么命名一个接口(interface)(或类)很容易:用户、窗口、数据库、流等。 形容词或形容词的概念呢?例如有时间戳的东西(HasTimestamp、Tim
我刚开始学习 PowerShell,我想知道 Posh 中的 cmdlet(或高级功能,无论它们在 CTP3 中称为什么)是否有一些好的动词指南。 如果我做一个get-verb,我可以看到很多。但我仍
$(".song").live('click', function songClick() { //do stuff }); 你能像上面那样命名一个函数,然后稍后再调用它吗?我尝试过,但没有成
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 7年前关闭。 Improve this
我的 Spring 应用程序中有两组类 - DTO 和实体。 在阅读了 Bob 叔叔的 Clean Code 之后,我比以往任何时候都更喜欢正确命名事物。 我坐下来重构我的一个 Spring 项目,但
我是一名优秀的程序员,十分优秀!