if (cap_from_name(t, &cap) < 0) {
log_error("Failed to parse capability %s.", t);
if (cap_from_name(t, &cap) < 0) {
log_error("Failed to parse capability %s.", t);
int t;
if (asprintf(&where, "%s/%s", dest, mount_table[k].where) < 0) {
int t;
if (asprintf(&where, "%s/%s", dest, mount_table[k].where) < 0) {
- if (asprintf(&where, "%s/etc/localtime", dest) < 0) {
- log_error("Out of memory");
- return -ENOMEM;
- }
+ if (asprintf(&where, "%s/etc/localtime", dest) < 0)
+ return log_oom();
if (mount("/etc/localtime", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
free(where);
if (mount("/etc/localtime", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/localtime", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
free(where);
- if (asprintf(&where, "%s/etc/timezone", dest) < 0) {
- log_error("Out of memory");
- return -ENOMEM;
- }
+ if (asprintf(&where, "%s/etc/timezone", dest) < 0)
+ return log_oom();
if (mount("/etc/timezone", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/timezone", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
if (mount("/etc/timezone", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/timezone", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
/* Fix resolv.conf, if possible */
if (asprintf(&where, "%s/etc/resolv.conf", dest) < 0) {
/* Fix resolv.conf, if possible */
if (asprintf(&where, "%s/etc/resolv.conf", dest) < 0) {
}
if (mount("/etc/resolv.conf", where, "bind", MS_BIND, NULL) >= 0)
}
if (mount("/etc/resolv.conf", where, "bind", MS_BIND, NULL) >= 0)
* avoid any problems with containers deadlocking due to this
* we simply make /dev/kmsg unavailable to the container. */
if (asprintf(&from, "%s/dev/kmsg", dest) < 0) {
* avoid any problems with containers deadlocking due to this
* we simply make /dev/kmsg unavailable to the container. */
if (asprintf(&from, "%s/dev/kmsg", dest) < 0) {
p = strappend("/var/log/journal/", l);
q = strjoin(directory, "/var/log/journal/", l, NULL);
if (!p || !q) {
p = strappend("/var/log/journal/", l);
q = strjoin(directory, "/var/log/journal/", l, NULL);
if (!p || !q) {
- if ((nfds = epoll_wait(ep, ev, ELEMENTSOF(ev), -1)) < 0) {
+ nfds = epoll_wait(ep, ev, ELEMENTSOF(ev), -1);
+ if (nfds < 0) {
- if ((n = read(signal_fd, &sfsi, sizeof(sfsi))) != sizeof(sfsi)) {
+ n = read(signal_fd, &sfsi, sizeof(sfsi));
+ if (n != sizeof(sfsi)) {
k = cg_create_and_attach(*controller, newcg, 0);
if (k < 0)
log_warning("Failed to create cgroup in controller %s: %s", *controller, strerror(-k));
}
k = cg_create_and_attach(*controller, newcg, 0);
if (k < 0)
log_warning("Failed to create cgroup in controller %s: %s", *controller, strerror(-k));
}
assert_se(sigemptyset(&mask) == 0);
assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
assert_se(sigemptyset(&mask) == 0);
assert_se(sigprocmask(SIG_SETMASK, &mask, NULL) == 0);
+ if (open_terminal(console, O_RDWR) != STDIN_FILENO ||
+ dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO ||
+ dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
+ goto child_fail;
+
+ if (setsid() < 0) {
+ log_error("setsid() failed: %m");
- if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) < 0)
+ if (mount(NULL, "/", NULL, MS_PRIVATE|MS_REC, NULL) < 0) {
+ log_error("MS_PRIVATE|MS_REC failed: %m");
/* Turn directory into bind mount */
if (mount(arg_directory, arg_directory, "bind", MS_BIND, NULL) < 0) {
/* Turn directory into bind mount */
if (mount(arg_directory, arg_directory, "bind", MS_BIND, NULL) < 0) {
- if (open_terminal("dev/console", O_RDWR) != STDIN_FILENO ||
- dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO ||
- dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
- goto child_fail;
-
if (mount(arg_directory, "/", "bind", MS_MOVE, NULL) < 0) {
log_error("mount(MS_BIND) failed: %m");
goto child_fail;
if (mount(arg_directory, "/", "bind", MS_MOVE, NULL) < 0) {
log_error("mount(MS_BIND) failed: %m");
goto child_fail;
if ((asprintf((char**)(envp + 3), "HOME=%s", home ? home: "/root") < 0) ||
(asprintf((char**)(envp + 4), "USER=%s", arg_user ? arg_user : "root") < 0) ||
(asprintf((char**)(envp + 5), "LOGNAME=%s", arg_user ? arg_user : "root") < 0)) {
if ((asprintf((char**)(envp + 3), "HOME=%s", home ? home: "/root") < 0) ||
(asprintf((char**)(envp + 4), "USER=%s", arg_user ? arg_user : "root") < 0) ||
(asprintf((char**)(envp + 5), "LOGNAME=%s", arg_user ? arg_user : "root") < 0)) {