就我而言,我需要每天从一个单独的文件系统启动一个进程,它的根目录位于一个子目录中。因为它是文件系统上唯一需要卸载它的东西。
另一个问题是我不能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.
那么如何在不改变父进程的情况下启动具有不同根目录的不同子进程呢?