#include "log.h"
#include "util.h"
+#include "missing.h"
static char *arg_directory = NULL;
int r = 0, k;
char *tty = NULL;
dev_t tty_devnum;
+ mode_t u;
+
+ u = umask(0000);
NULSTR_FOREACH(d, devnodes) {
char *from = NULL, *to = NULL;
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)
free(tty);
+ umask(u);
+
return r;
}
}
if (path_equal(arg_directory, "/")) {
- log_error("Spawning constainer on root directory not supported.");
+ log_error("Spawning container on root directory not supported.");
goto finish;
}
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 */
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");
_exit(EXIT_FAILURE);
}
- r = wait_for_terminate_and_warn("container", pid);
+ r = wait_for_terminate_and_warn(argc > optind ? argv[optind] : "bash", pid);
if (r < 0)
r = EXIT_FAILURE;