diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-02 09:51:11 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-11-02 09:51:11 -0400 |
commit | 5fcd4e4d3564affe2595dc6fe0db9f61264c0b9e (patch) | |
tree | 01fa76922c426190f794c916d7f5f39549e1b969 /src/nspawn/nspawn.c | |
parent | 0c250999c59c38a23fd7429fbe25032b4bf51293 (diff) |
Diffstat (limited to 'src/nspawn/nspawn.c')
-rw-r--r-- | src/nspawn/nspawn.c | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index fcc042f28e..72be2cef43 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -17,15 +17,15 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <fcntl.h> #include <sched.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/wait.h> #include "fd-util.h" /* _cleanup_close_ */ -#include "mount-util.h" /* mount_verbose */ +#include "path-util.h" /* prefix_roota */ -static char *arg_directory = NULL; static char **arg_parameters = NULL; static int outer_child( @@ -36,6 +36,7 @@ static int outer_child( pid_t pid; ssize_t l; int r; + const char *to; assert(directory); assert(console); @@ -45,6 +46,11 @@ static int outer_child( if (r < 0) return log_error_errno(r, "Failed to open console: %m"); + + to = prefix_roota(directory, "/dev/console"); + if (mount(console, to, NULL, MS_BIND, NULL) < 0) + return log_error_errno(errno, "mount /dev/console: %m"); + if (chdir(directory) < 0) return log_error_errno(errno, "Failed to chdir: %m"); if (chroot(".") < 0) @@ -60,9 +66,8 @@ static int outer_child( pid_socket = safe_close(pid_socket); printf("a\n"); - r = mount_verbose(LOG_ERR, "proc", "/proc", "proc", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL); - if (r < 0) - return r; + if (mount("proc", "/proc", "proc", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL) < 0) + return log_error_errno(errno, "mount /proc: %m"); printf("b\n"); execvp(arg_parameters[0], arg_parameters); @@ -82,8 +87,9 @@ static int outer_child( } } -static int run(int master, - const char* console, +static int run(const char *directory, + int master, + const char *console, int *ret) { pid_t pid; @@ -110,7 +116,7 @@ static int run(int master, pid_socket_pair[0] = safe_close(pid_socket_pair[0]); - r = outer_child(arg_directory, + r = outer_child(directory, console, pid_socket_pair[1]); if (r < 0) @@ -151,6 +157,7 @@ int main(int argc, char *argv[]) { char *console = NULL; _cleanup_close_ int master = -1; int r, ret = EXIT_SUCCESS; + char *arg_directory = NULL; log_parse_environment(); log_open(); @@ -183,7 +190,8 @@ int main(int argc, char *argv[]) { goto finish; } - r = run(master, + r = run(arg_directory, + master, console, &ret); |