chiark / gitweb /
main: log to the console in a container
[elogind.git] / src / nspawn.c
index 82b0ce4f133bb318d49337bf1cba4208c0b45cb0..f340805f38339835d8162d291dfd33a73961ef9d 100644 (file)
@@ -254,7 +254,7 @@ static int copy_devnodes(const char *dest) {
                                         r = -errno;
                         }
 
                                         r = -errno;
                         }
 
-                        if (mount(from, to, "bind", MS_BIND, NULL) < 0) {
+                        if (mount(from, to, "bind", MS_BIND|MS_RDONLY, NULL) < 0) {
                                 log_error("bind mount for /dev/console failed: %m");
 
                                 if (r == 0)
                                 log_error("bind mount for /dev/console failed: %m");
 
                                 if (r == 0)
@@ -390,6 +390,11 @@ int main(int argc, char *argv[]) {
 
         if (pid == 0) {
                 const char *hn;
 
         if (pid == 0) {
                 const char *hn;
+                const char *envp[] = {
+                        "HOME=/root",
+                        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
+                        NULL
+                };
 
                 /* child */
 
 
                 /* child */
 
@@ -425,9 +430,11 @@ int main(int argc, char *argv[]) {
                         sethostname(hn, strlen(hn));
 
                 if (argc > optind)
                         sethostname(hn, strlen(hn));
 
                 if (argc > optind)
-                        execvp(argv[optind], argv + optind);
-                else
-                        execl("/bin/bash", "/bin/bash", NULL);
+                        execvpe(argv[optind], argv + optind, (char**) envp);
+                else {
+                        chdir("/root");
+                        execle("/bin/bash", "-bash", NULL, (char**) envp);
+                }
 
                 log_error("execv() failed: %m");
 
 
                 log_error("execv() failed: %m");