就我而言,我需要每天从一个单独的文件系统启动一个进程,其根目录位于子目录中。因为它是文件系统上唯一需要卸载的东西。
另一个问题是我无法fork()
/clone()
该进程,因为它在特权环内运行。
我想到了以下解决方案:
char *argv [] = {"/path2/sbin/the_program_to_be_launched","-option","value of option",NULL};
char *envp [] = {"HOME=/","SHELL=no_shell_available","LC_ALL=C",NULL};
mount(name, "/path/", fs, flags, data);
chroot("/path/");
execve("/path2/sbin/the_program_to_be_launched",argv,envp); // would not work because the program won’t be able find his libraries
umount("/"); // would never be called if execve() would have been called correctly
像这样不执行进程的事情也不会起作用。
mount(name, "/path/", fs, flags, data);
chroot("/path/path2/"):
umount("/"); // would not work since "/" is not the root of the device.
那么如何在不更改父进程的情况下启动具有不同根目录的不同子进程呢?
最佳答案
crom 可以启动启动实际程序的 shell 脚本。
在 Linux 中,“/”目录是所有文件系统的根目录。所以你绝对不想卸载它。请阅读有关安装/卸载的手册页。
您可以在 fstab 中为用户可安装的文件系统放置适当的条目。那么安装/卸载就会相对简单。
您可以创建脚本登录/注销的“受限”用户。
该用户可用于运行目标程序并执行安装/卸载操作。
由crom运行的shell可以执行所有CD等
为了让应用程序能够在无法看到其库的情况下执行,可以将其链接为“静态”。也许让用户的 .profile 包含 $PATH 变量的开发,以包含库的路径。
用户的登录可以使用只包含用户运行目标程序所需的命令的 busybox 版本。
关于c - 使用不同的根目录启动单独的进程,而无需 fork /克隆它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29474870/