2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2008
7 * Daniel Lezcano <daniel.lezcano at free.fr>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
39 #include <sys/mount.h>
40 #include <sys/param.h>
41 #include <sys/prctl.h>
42 #include <sys/socket.h>
44 #include <sys/syscall.h>
45 #include <sys/types.h>
50 #include <sys/capability.h>
53 #ifndef HAVE_DECL_PR_CAPBSET_DROP
54 #define PR_CAPBSET_DROP 24
57 #ifndef HAVE_DECL_PR_SET_NO_NEW_PRIVS
58 #define PR_SET_NO_NEW_PRIVS 38
61 #ifndef HAVE_DECL_PR_GET_NO_NEW_PRIVS
62 #define PR_GET_NO_NEW_PRIVS 39
75 #include "lxcseccomp.h"
79 #include "namespace.h"
85 lxc_log_define(lxc_start
, lxc
);
87 extern void mod_all_rdeps(struct lxc_container
*c
, bool inc
);
88 static bool do_destroy_container(struct lxc_conf
*conf
);
89 static int lxc_rmdir_onedev_wrapper(void *data
);
90 static void lxc_destroy_container_on_signal(struct lxc_handler
*handler
,
93 static void print_top_failing_dir(const char *path
)
95 size_t len
= strlen(path
);
96 char *copy
= alloca(len
+ 1), *p
, *e
, saved
;
102 while (p
< e
&& *p
== '/')
104 while (p
< e
&& *p
!= '/')
108 if (access(copy
, X_OK
)) {
109 SYSERROR("Could not access %s. Please grant it x "
110 "access, or add an ACL for the container "
118 static void close_ns(int ns_fd
[LXC_NS_MAX
])
122 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
130 /* preserve_ns: open /proc/@pid/ns/@ns for each namespace specified
132 * Return true on success, false on failure.
134 static bool preserve_ns(int ns_fd
[LXC_NS_MAX
], int clone_flags
, pid_t pid
)
138 for (i
= 0; i
< LXC_NS_MAX
; i
++)
141 ret
= lxc_preserve_ns(pid
, "");
143 SYSERROR("Kernel does not support attaching to namespaces.");
149 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
150 if ((clone_flags
& ns_info
[i
].clone_flag
) == 0)
152 ns_fd
[i
] = lxc_preserve_ns(pid
, ns_info
[i
].proc_name
);
161 SYSERROR("Kernel does not support attaching to %s namespaces.", ns_info
[i
].proc_name
);
163 SYSERROR("Failed to open file descriptor for %s namespace: %s.", ns_info
[i
].proc_name
, strerror(errno
));
168 static int attach_ns(const int ns_fd
[LXC_NS_MAX
]) {
171 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
175 if (setns(ns_fd
[i
], 0) != 0)
181 SYSERROR("Failed to attach %s namespace.", ns_info
[i
].proc_name
);
185 static int match_fd(int fd
)
187 return (fd
== 0 || fd
== 1 || fd
== 2);
190 /* Check for any fds we need to close.
191 * - If fd_to_ignore != -1, then if we find that fd open we will ignore it.
192 * - By default we warn about open fds we find.
193 * - If closeall is true, we will close open fds.
194 * - If lxc-start was passed "-C", then conf->close_all_fds will be true, in
195 * which case we also close all open fds.
196 * - A daemonized container will always pass closeall=true.
198 int lxc_check_inherited(struct lxc_conf
*conf
, bool closeall
, int fd_to_ignore
)
200 struct dirent
*direntp
;
204 if (conf
&& conf
->close_all_fds
)
208 dir
= opendir("/proc/self/fd");
210 WARN("Failed to open directory: %m.");
216 while ((direntp
= readdir(dir
))) {
220 if (!strcmp(direntp
->d_name
, "."))
223 if (!strcmp(direntp
->d_name
, ".."))
226 if (lxc_safe_int(direntp
->d_name
, &fd
) < 0) {
227 INFO("Could not parse file descriptor for: %s", direntp
->d_name
);
231 if (fd
== fddir
|| fd
== lxc_log_fd
|| fd
== fd_to_ignore
)
234 if (current_config
&& fd
== current_config
->logfd
)
243 INFO("Closed inherited fd: %d.", fd
);
246 WARN("Inherited fd: %d.", fd
);
249 /* Only enable syslog at this point to avoid the above logging function
250 * to open a new fd and make the check_inherited function enter an
253 lxc_log_enable_syslog();
255 closedir(dir
); /* cannot fail */
259 static int setup_signal_fd(sigset_t
*oldmask
)
264 /* Block everything except serious error signals. */
265 if (sigfillset(&mask
) ||
266 sigdelset(&mask
, SIGILL
) ||
267 sigdelset(&mask
, SIGSEGV
) ||
268 sigdelset(&mask
, SIGBUS
) ||
269 sigdelset(&mask
, SIGWINCH
) ||
270 sigprocmask(SIG_BLOCK
, &mask
, oldmask
)) {
271 SYSERROR("Failed to set signal mask.");
275 fd
= signalfd(-1, &mask
, 0);
277 SYSERROR("Failed to create signal file descriptor.");
281 if (fcntl(fd
, F_SETFD
, FD_CLOEXEC
)) {
282 SYSERROR("Failed to set FD_CLOEXEC on the signal file descriptor: %d.", fd
);
287 DEBUG("Set SIGCHLD handler with file descriptor: %d.", fd
);
292 static int signal_handler(int fd
, uint32_t events
, void *data
,
293 struct lxc_epoll_descr
*descr
)
295 struct signalfd_siginfo siginfo
;
299 bool init_died
= false;
301 ret
= read(fd
, &siginfo
, sizeof(siginfo
));
303 ERROR("Failed to read signal info from signal file descriptor: %d.", fd
);
307 if (ret
!= sizeof(siginfo
)) {
308 ERROR("Unexpected size for siginfo struct.");
312 /* Check whether init is running. */
314 ret
= waitid(P_PID
, *pid
, &info
, WEXITED
| WNOWAIT
| WNOHANG
);
315 if (ret
== 0 && info
.si_pid
== *pid
)
318 if (siginfo
.ssi_signo
!= SIGCHLD
) {
319 kill(*pid
, siginfo
.ssi_signo
);
320 INFO("Forwarded signal %d to pid %d.", siginfo
.ssi_signo
, *pid
);
321 return init_died
? 1 : 0;
324 if (siginfo
.ssi_code
== CLD_STOPPED
) {
325 INFO("Container init process was stopped.");
326 return init_died
? 1 : 0;
327 } else if (siginfo
.ssi_code
== CLD_CONTINUED
) {
328 INFO("Container init process was continued.");
329 return init_died
? 1 : 0;
332 /* More robustness, protect ourself from a SIGCHLD sent
333 * by a process different from the container init.
335 if (siginfo
.ssi_pid
!= *pid
) {
336 NOTICE("Received SIGCHLD from pid %d instead of container init %d.", siginfo
.ssi_pid
, *pid
);
337 return init_died
? 1 : 0;
340 DEBUG("Container init process %d exited.", *pid
);
344 int lxc_set_state(const char *name
, struct lxc_handler
*handler
,
348 struct lxc_list
*cur
, *next
;
349 struct state_client
*client
;
350 struct lxc_msg msg
= {.type
= lxc_msg_state
, .value
= state
};
353 /* Only set state under process lock held so that we don't cause
354 * lxc_cmd_state_server() to miss a state.
356 handler
->state
= state
;
357 TRACE("set container state to %s", lxc_state2str(state
));
359 if (lxc_list_empty(&handler
->state_clients
)) {
360 TRACE("no state clients registered");
365 strncpy(msg
.name
, name
, sizeof(msg
.name
));
366 msg
.name
[sizeof(msg
.name
) - 1] = 0;
368 lxc_list_for_each_safe(cur
, &handler
->state_clients
, next
) {
371 if (!client
->states
[state
]) {
372 TRACE("state %s not registered for state client %d",
373 lxc_state2str(state
), client
->clientfd
);
377 TRACE("sending state %s to state client %d",
378 lxc_state2str(state
), client
->clientfd
);
381 ret
= send(client
->clientfd
, &msg
, sizeof(msg
), 0);
386 ERROR("failed to send message to client");
389 /* kick client from list */
390 close(client
->clientfd
);
397 /* This function will try to connect to the legacy lxc-monitord state
398 * server and only exists for backwards compatibility.
400 lxc_monitor_send_state(name
, state
, handler
->lxcpath
);
405 int lxc_poll(const char *name
, struct lxc_handler
*handler
)
407 int sigfd
= handler
->sigfd
;
408 int pid
= handler
->pid
;
409 struct lxc_epoll_descr descr
;
411 if (lxc_mainloop_open(&descr
)) {
412 ERROR("Failed to create LXC mainloop.");
416 if (lxc_mainloop_add_handler(&descr
, sigfd
, signal_handler
, &pid
)) {
417 ERROR("Failed to add signal handler with file descriptor %d to LXC mainloop.", sigfd
);
418 goto out_mainloop_open
;
421 if (lxc_console_mainloop_add(&descr
, handler
->conf
)) {
422 ERROR("Failed to add console handler to LXC mainloop.");
423 goto out_mainloop_open
;
426 if (lxc_cmd_mainloop_add(name
, &descr
, handler
)) {
427 ERROR("Failed to add command handler to LXC mainloop.");
428 goto out_mainloop_open
;
431 if (handler
->conf
->need_utmp_watch
) {
433 if (lxc_utmp_mainloop_add(&descr
, handler
)) {
434 ERROR("Failed to add utmp handler to LXC mainloop.");
435 goto out_mainloop_open
;
438 DEBUG("Not starting utmp handler as CAP_SYS_BOOT cannot be dropped without capabilities support.");
441 TRACE("lxc mainloop is ready");
443 return lxc_mainloop(&descr
, -1);
446 lxc_mainloop_close(&descr
);
454 struct lxc_handler
*lxc_init_handler(const char *name
, struct lxc_conf
*conf
,
458 struct lxc_handler
*handler
;
460 handler
= malloc(sizeof(*handler
));
462 ERROR("failed to allocate memory");
466 memset(handler
, 0, sizeof(*handler
));
468 handler
->ttysock
[0] = handler
->ttysock
[1] = -1;
469 handler
->conf
= conf
;
470 handler
->lxcpath
= lxcpath
;
472 lxc_list_init(&handler
->state_clients
);
474 for (i
= 0; i
< LXC_NS_MAX
; i
++)
475 handler
->nsfd
[i
] = -1;
477 handler
->name
= strdup(name
);
478 if (!handler
->name
) {
479 ERROR("failed to allocate memory");
480 goto do_partial_cleanup
;
483 if (lxc_cmd_init(name
, handler
, lxcpath
)) {
484 ERROR("failed to set up command socket");
485 goto do_full_cleanup
;
488 TRACE("unix domain socket %d for command server is ready",
489 handler
->conf
->maincmd_fd
);
502 int lxc_init(const char *name
, struct lxc_handler
*handler
)
504 struct lxc_conf
*conf
= handler
->conf
;
507 TRACE("initialized LSM");
509 if (lxc_read_seccomp_config(conf
) != 0) {
510 ERROR("Failed loading seccomp policy.");
511 goto out_close_maincmd_fd
;
513 TRACE("read seccomp policy");
515 /* Begin by setting the state to STARTING. */
516 if (lxc_set_state(name
, handler
, STARTING
)) {
517 ERROR("Failed to set state for container \"%s\" to \"%s\".", name
, lxc_state2str(STARTING
));
518 goto out_close_maincmd_fd
;
520 TRACE("set container state to \"STARTING\"");
522 /* Start of environment variable setup for hooks. */
523 if (name
&& setenv("LXC_NAME", name
, 1))
524 SYSERROR("Failed to set environment variable: LXC_NAME=%s.", name
);
526 if (conf
->rcfile
&& setenv("LXC_CONFIG_FILE", conf
->rcfile
, 1))
527 SYSERROR("Failed to set environment variable: LXC_CONFIG_FILE=%s.", conf
->rcfile
);
529 if (conf
->rootfs
.mount
&& setenv("LXC_ROOTFS_MOUNT", conf
->rootfs
.mount
, 1))
530 SYSERROR("Failed to set environment variable: LXC_ROOTFS_MOUNT=%s.", conf
->rootfs
.mount
);
532 if (conf
->rootfs
.path
&& setenv("LXC_ROOTFS_PATH", conf
->rootfs
.path
, 1))
533 SYSERROR("Failed to set environment variable: LXC_ROOTFS_PATH=%s.", conf
->rootfs
.path
);
535 if (conf
->console
.path
&& setenv("LXC_CONSOLE", conf
->console
.path
, 1))
536 SYSERROR("Failed to set environment variable: LXC_CONSOLE=%s.", conf
->console
.path
);
538 if (conf
->console
.log_path
&& setenv("LXC_CONSOLE_LOGPATH", conf
->console
.log_path
, 1))
539 SYSERROR("Failed to set environment variable: LXC_CONSOLE_LOGPATH=%s.", conf
->console
.log_path
);
541 if (setenv("LXC_CGNS_AWARE", "1", 1))
542 SYSERROR("Failed to set environment variable LXC_CGNS_AWARE=1.");
543 /* End of environment variable setup for hooks. */
545 TRACE("set environment variables");
547 if (run_lxc_hooks(name
, "pre-start", conf
, handler
->lxcpath
, NULL
)) {
548 ERROR("Failed to run lxc.hook.pre-start for container \"%s\".", name
);
551 TRACE("ran pre-start hooks");
553 /* The signal fd has to be created before forking otherwise if the child
554 * process exits before we setup the signal fd, the event will be lost
555 * and the command will be stuck.
557 handler
->sigfd
= setup_signal_fd(&handler
->oldmask
);
558 if (handler
->sigfd
< 0) {
559 ERROR("Failed to setup SIGCHLD fd handler.");
562 TRACE("set up signal fd");
564 /* Do this after setting up signals since it might unblock SIGWINCH. */
565 if (lxc_console_create(conf
)) {
566 ERROR("Failed to create console for container \"%s\".", name
);
567 goto out_restore_sigmask
;
569 TRACE("created console");
571 if (lxc_ttys_shift_ids(conf
) < 0) {
572 ERROR("Failed to shift tty into container.");
573 goto out_restore_sigmask
;
575 TRACE("shifted tty ids");
577 INFO("container \"%s\" is initialized", name
);
581 sigprocmask(SIG_SETMASK
, &handler
->oldmask
, NULL
);
583 lxc_delete_tty(&conf
->tty_info
);
585 lxc_set_state(name
, handler
, ABORTING
);
586 out_close_maincmd_fd
:
587 close(conf
->maincmd_fd
);
588 conf
->maincmd_fd
= -1;
592 void lxc_fini(const char *name
, struct lxc_handler
*handler
)
595 struct lxc_list
*cur
, *next
;
596 pid_t self
= getpid();
597 char *namespaces
[LXC_NS_MAX
+ 1];
598 size_t namespace_count
= 0;
600 /* The STOPPING state is there for future cleanup code which can take
603 lxc_set_state(name
, handler
, STOPPING
);
605 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
606 if (handler
->nsfd
[i
] != -1) {
607 rc
= asprintf(&namespaces
[namespace_count
], "%s:/proc/%d/fd/%d",
608 ns_info
[i
].proc_name
, self
, handler
->nsfd
[i
]);
610 SYSERROR("Failed to allocate memory.");
616 namespaces
[namespace_count
] = NULL
;
618 if (handler
->conf
->reboot
&& setenv("LXC_TARGET", "reboot", 1))
619 SYSERROR("Failed to set environment variable: LXC_TARGET=reboot.");
621 if (!handler
->conf
->reboot
&& setenv("LXC_TARGET", "stop", 1))
622 SYSERROR("Failed to set environment variable: LXC_TARGET=stop.");
624 if (run_lxc_hooks(name
, "stop", handler
->conf
, handler
->lxcpath
, namespaces
))
625 ERROR("Failed to run lxc.hook.stop for container \"%s\".", name
);
627 while (namespace_count
--)
628 free(namespaces
[namespace_count
]);
629 for (i
= 0; i
< LXC_NS_MAX
; i
++) {
630 if (handler
->nsfd
[i
] != -1) {
631 close(handler
->nsfd
[i
]);
632 handler
->nsfd
[i
] = -1;
636 if (handler
->netnsfd
>= 0) {
637 close(handler
->netnsfd
);
638 handler
->netnsfd
= -1;
641 lxc_set_state(name
, handler
, STOPPED
);
643 if (run_lxc_hooks(name
, "post-stop", handler
->conf
, handler
->lxcpath
, NULL
)) {
644 ERROR("Failed to run lxc.hook.post-stop for container \"%s\".", name
);
645 if (handler
->conf
->reboot
) {
646 WARN("Container will be stopped instead of rebooted.");
647 handler
->conf
->reboot
= 0;
648 if (setenv("LXC_TARGET", "stop", 1))
649 WARN("Failed to set environment variable: LXC_TARGET=stop.");
653 /* Reset mask set by setup_signal_fd. */
654 if (sigprocmask(SIG_SETMASK
, &handler
->oldmask
, NULL
))
655 WARN("Failed to restore signal mask.");
657 lxc_console_delete(&handler
->conf
->console
);
658 lxc_delete_tty(&handler
->conf
->tty_info
);
660 /* close the command socket */
661 close(handler
->conf
->maincmd_fd
);
662 handler
->conf
->maincmd_fd
= -1;
664 /* The command socket is now closed, no more state clients can register
665 * themselves from now on. So free the list of state clients.
667 lxc_list_for_each_safe(cur
, &handler
->state_clients
, next
) {
668 struct state_client
*client
= cur
->elem
;
669 /* close state client socket */
670 close(client
->clientfd
);
677 if (handler
->ttysock
[0] != -1) {
678 close(handler
->ttysock
[0]);
679 close(handler
->ttysock
[1]);
682 if (handler
->conf
->ephemeral
== 1 && handler
->conf
->reboot
!= 1)
683 lxc_destroy_container_on_signal(handler
, name
);
685 cgroup_destroy(handler
);
689 void lxc_abort(const char *name
, struct lxc_handler
*handler
)
693 lxc_set_state(name
, handler
, ABORTING
);
694 if (handler
->pid
> 0)
695 kill(handler
->pid
, SIGKILL
);
696 while ((ret
= waitpid(-1, &status
, 0)) > 0) {
701 #include <sys/reboot.h>
702 #include <linux/reboot.h>
704 /* reboot(LINUX_REBOOT_CMD_CAD_ON) will return -EINVAL in a child pid namespace
705 * if container reboot support exists. Otherwise, it will either succeed or
708 static int container_reboot_supported(void *arg
)
714 if (ret
== -1 && errno
== EINVAL
)
719 static int must_drop_cap_sys_boot(struct lxc_conf
*conf
)
722 int ret
, cmd
, v
, flags
;
723 long stack_size
= 4096;
724 void *stack
= alloca(stack_size
);
728 f
= fopen("/proc/sys/kernel/ctrl-alt-del", "r");
730 DEBUG("failed to open /proc/sys/kernel/ctrl-alt-del");
734 ret
= fscanf(f
, "%d", &v
);
737 DEBUG("Failed to read /proc/sys/kernel/ctrl-alt-del.");
740 cmd
= v
? LINUX_REBOOT_CMD_CAD_ON
: LINUX_REBOOT_CMD_CAD_OFF
;
742 flags
= CLONE_NEWPID
| SIGCHLD
;
743 if (!lxc_list_empty(&conf
->id_map
))
744 flags
|= CLONE_NEWUSER
;
747 pid
= __clone2(container_reboot_supported
, stack
, stack_size
, flags
, &cmd
);
750 pid
= clone(container_reboot_supported
, stack
, flags
, &cmd
);
753 if (flags
& CLONE_NEWUSER
)
754 ERROR("Failed to clone (%#x): %s (includes CLONE_NEWUSER).", flags
, strerror(errno
));
756 ERROR("Failed to clone (%#x): %s.", flags
, strerror(errno
));
759 if (wait(&status
) < 0) {
760 SYSERROR("Unexpected wait error: %m.");
764 if (WEXITSTATUS(status
) != 1)
770 /* netpipe is used in the unprivileged case to transfer the ifindexes from
773 static int netpipe
= -1;
775 static inline int count_veths(struct lxc_list
*network
)
777 struct lxc_list
*iterator
;
778 struct lxc_netdev
*netdev
;
781 lxc_list_for_each(iterator
, network
) {
782 netdev
= iterator
->elem
;
783 if (netdev
->type
!= LXC_NET_VETH
)
790 static int read_unpriv_netifindex(struct lxc_list
*network
)
792 struct lxc_list
*iterator
;
793 struct lxc_netdev
*netdev
;
797 lxc_list_for_each(iterator
, network
) {
798 netdev
= iterator
->elem
;
799 if (netdev
->type
!= LXC_NET_VETH
)
801 if (!(netdev
->name
= malloc(IFNAMSIZ
))) {
802 ERROR("Out of memory.");
806 if (read(netpipe
, netdev
->name
, IFNAMSIZ
) != IFNAMSIZ
) {
815 static int do_start(void *data
)
817 struct lxc_list
*iterator
;
818 struct lxc_handler
*handler
= data
;
819 int devnull_fd
= -1, ret
;
822 if (sigprocmask(SIG_SETMASK
, &handler
->oldmask
, NULL
)) {
823 SYSERROR("Failed to set signal mask.");
827 /* This prctl must be before the synchro, so if the parent dies before
828 * we set the parent death signal, we will detect its death with the
829 * synchro right after, otherwise we have a window where the parent can
830 * exit before we set the pdeath signal leading to a unsupervized
833 if (prctl(PR_SET_PDEATHSIG
, SIGKILL
, 0, 0, 0)) {
834 SYSERROR("Failed to set PR_SET_PDEATHSIG to SIGKILL.");
838 lxc_sync_fini_parent(handler
);
840 /* Don't leak the pinfd to the container. */
841 if (handler
->pinfd
>= 0) {
842 close(handler
->pinfd
);
845 if (lxc_sync_wait_parent(handler
, LXC_SYNC_STARTUP
))
848 /* Unshare CLONE_NEWNET after CLONE_NEWUSER. See
849 * https://github.com/lxc/lxd/issues/1978.
851 if ((handler
->clone_flags
& (CLONE_NEWNET
| CLONE_NEWUSER
)) ==
852 (CLONE_NEWNET
| CLONE_NEWUSER
)) {
853 ret
= unshare(CLONE_NEWNET
);
855 SYSERROR("Failed to unshare CLONE_NEWNET.");
856 goto out_warn_father
;
858 INFO("Unshared CLONE_NEWNET.");
861 /* Tell the parent task it can begin to configure the container and wait
864 if (lxc_sync_barrier_parent(handler
, LXC_SYNC_CONFIGURE
))
867 if (read_unpriv_netifindex(&handler
->conf
->network
) < 0)
868 goto out_warn_father
;
870 /* If we are in a new user namespace, become root there to have
871 * privilege over our namespace.
873 if (!lxc_list_empty(&handler
->conf
->id_map
)) {
874 if (lxc_switch_uid_gid(0, 0) < 0)
875 goto out_warn_father
;
877 /* Drop groups only after we switched to a valid gid in the new
880 if (lxc_setgroups(0, NULL
) < 0)
881 goto out_warn_father
;
884 if (access(handler
->lxcpath
, X_OK
)) {
885 print_top_failing_dir(handler
->lxcpath
);
886 goto out_warn_father
;
890 if (handler
->conf
->need_utmp_watch
) {
891 if (prctl(PR_CAPBSET_DROP
, CAP_SYS_BOOT
, 0, 0, 0)) {
892 SYSERROR("Failed to remove the CAP_SYS_BOOT capability.");
893 goto out_warn_father
;
895 DEBUG("Dropped the CAP_SYS_BOOT capability.");
899 ret
= snprintf(path
, sizeof(path
), "%s/dev/null", handler
->conf
->rootfs
.mount
);
900 if (ret
< 0 || ret
>= sizeof(path
))
901 goto out_warn_father
;
903 /* In order to checkpoint restore, we need to have everything in the
904 * same mount namespace. However, some containers may not have a
905 * reasonable /dev (in particular, they may not have /dev/null), so we
906 * can't set init's std fds to /dev/null by opening it from inside the
909 * If that's the case, fall back to using the host's /dev/null. This
910 * means that migration won't work, but at least we won't spew output
911 * where it isn't wanted.
913 if (handler
->backgrounded
&& !handler
->conf
->autodev
&& access(path
, F_OK
) < 0) {
914 devnull_fd
= open_devnull();
917 goto out_warn_father
;
918 WARN("Using /dev/null from the host for container init's "
919 "standard file descriptors. Migration will not work.");
922 /* Setup the container, ip, names, utsname, ... */
923 if (lxc_setup(handler
)) {
924 ERROR("Failed to setup container \"%s\".", handler
->name
);
925 goto out_warn_father
;
928 /* Ask father to setup cgroups and wait for him to finish. */
929 if (lxc_sync_barrier_parent(handler
, LXC_SYNC_CGROUP
))
932 /* Unshare cgroup namespace after we have setup our cgroups. If we do it
933 * earlier we end up with a wrong view of /proc/self/cgroup. For
934 * example, assume we unshare(CLONE_NEWCGROUP) first, and then create
935 * the cgroup for the container, say /sys/fs/cgroup/cpuset/lxc/c, then
936 * /proc/self/cgroup would show us:
940 * whereas it should actually show
944 if (cgns_supported()) {
945 if (unshare(CLONE_NEWCGROUP
) < 0) {
946 INFO("Failed to unshare CLONE_NEWCGROUP.");
947 goto out_warn_father
;
949 INFO("Unshared CLONE_NEWCGROUP.");
952 /* Set the label to change to when we exec(2) the container's init. */
953 if (lsm_process_label_set(NULL
, handler
->conf
, 1, 1) < 0)
954 goto out_warn_father
;
956 /* Set PR_SET_NO_NEW_PRIVS after we changed the lsm label. If we do it
957 * before we aren't allowed anymore.
959 if (handler
->conf
->no_new_privs
) {
960 if (prctl(PR_SET_NO_NEW_PRIVS
, 1, 0, 0, 0) < 0) {
961 SYSERROR("Could not set PR_SET_NO_NEW_PRIVS to block execve() gainable privileges.");
962 goto out_warn_father
;
964 DEBUG("Set PR_SET_NO_NEW_PRIVS to block execve() gainable privileges.");
967 /* Some init's such as busybox will set sane tty settings on stdin,
968 * stdout, stderr which it thinks is the console. We already set them
969 * the way we wanted on the real terminal, and we want init to do its
970 * setup on its console ie. the pty allocated in lxc_console_create() so
971 * make sure that that pty is stdin,stdout,stderr.
973 if (lxc_console_set_stdfds(handler
->conf
->console
.slave
) < 0)
974 goto out_warn_father
;
976 /* If we mounted a temporary proc, then unmount it now. */
977 tmp_proc_unmount(handler
->conf
);
979 if (lxc_seccomp_load(handler
->conf
) != 0)
980 goto out_warn_father
;
982 if (run_lxc_hooks(handler
->name
, "start", handler
->conf
, handler
->lxcpath
, NULL
)) {
983 ERROR("Failed to run lxc.hook.start for container \"%s\".", handler
->name
);
984 goto out_warn_father
;
987 /* The container has been setup. We can now switch to an unprivileged
990 if (handler
->conf
->is_execute
) {
991 bool have_cap_setgid
;
992 uid_t new_uid
= handler
->conf
->init_uid
;
993 gid_t new_gid
= handler
->conf
->init_gid
;
995 /* If we are in a new user namespace we already dropped all
996 * groups when we switched to root in the new user namespace
997 * further above. Only drop groups if we can, so ensure that we
998 * have necessary privilege.
1001 have_cap_setgid
= lxc_proc_cap_is_set(CAP_SETGID
, CAP_EFFECTIVE
);
1003 have_cap_setgid
= false;
1005 if (lxc_list_empty(&handler
->conf
->id_map
) && have_cap_setgid
) {
1006 if (lxc_setgroups(0, NULL
) < 0)
1007 goto out_warn_father
;
1010 if (lxc_switch_uid_gid(new_uid
, new_gid
) < 0)
1011 goto out_warn_father
;
1014 /* The clearenv() and putenv() calls have been moved here to allow us to
1015 * use environment variables passed to the various hooks, such as the
1016 * start hook above. Not all of the variables like CONFIG_PATH or ROOTFS
1017 * are valid in this context but others are.
1020 SYSERROR("Failed to clear environment.");
1021 /* Don't error out though. */
1024 lxc_list_for_each(iterator
, &handler
->conf
->environment
) {
1025 if (putenv((char *)iterator
->elem
)) {
1026 SYSERROR("Failed to set environment variable: %s.", (char *)iterator
->elem
);
1027 goto out_warn_father
;
1031 if (putenv("container=lxc")) {
1032 SYSERROR("Failed to set environment variable: container=lxc.");
1033 goto out_warn_father
;
1036 if (handler
->conf
->pty_names
) {
1037 if (putenv(handler
->conf
->pty_names
)) {
1038 SYSERROR("Failed to set environment variable for container ptys.");
1039 goto out_warn_father
;
1043 close(handler
->sigfd
);
1045 if (devnull_fd
< 0) {
1046 devnull_fd
= open_devnull();
1049 goto out_warn_father
;
1052 if (handler
->backgrounded
&& set_stdfds(devnull_fd
))
1053 goto out_warn_father
;
1055 if (devnull_fd
>= 0) {
1062 /* After this call, we are in error because this ops should not return
1065 handler
->ops
->start(handler
, handler
->data
);
1068 /* We want the parent to know something went wrong, so we return a
1069 * special error code.
1071 lxc_sync_wake_parent(handler
, LXC_SYNC_ERROR
);
1074 if (devnull_fd
>= 0)
1080 static int save_phys_nics(struct lxc_conf
*conf
)
1082 struct lxc_list
*iterator
;
1083 int am_root
= (getuid() == 0);
1088 lxc_list_for_each(iterator
, &conf
->network
) {
1089 struct lxc_netdev
*netdev
= iterator
->elem
;
1091 if (netdev
->type
!= LXC_NET_PHYS
)
1093 conf
->saved_nics
= realloc(conf
->saved_nics
,
1094 (conf
->num_savednics
+1)*sizeof(struct saved_nic
));
1095 if (!conf
->saved_nics
)
1097 conf
->saved_nics
[conf
->num_savednics
].ifindex
= netdev
->ifindex
;
1098 conf
->saved_nics
[conf
->num_savednics
].orig_name
= strdup(netdev
->link
);
1099 if (!conf
->saved_nics
[conf
->num_savednics
].orig_name
)
1101 INFO("Stored saved_nic #%d idx %d name %s.", conf
->num_savednics
,
1102 conf
->saved_nics
[conf
->num_savednics
].ifindex
,
1103 conf
->saved_nics
[conf
->num_savednics
].orig_name
);
1104 conf
->num_savednics
++;
1110 static int lxc_recv_ttys_from_child(struct lxc_handler
*handler
)
1114 struct lxc_pty_info
*pty_info
;
1116 int sock
= handler
->ttysock
[1];
1117 struct lxc_conf
*conf
= handler
->conf
;
1118 struct lxc_tty_info
*tty_info
= &conf
->tty_info
;
1119 size_t num_ttyfds
= (2 * conf
->tty
);
1124 tty_info
->pty_info
= malloc(sizeof(*tty_info
->pty_info
) * conf
->tty
);
1125 if (!tty_info
->pty_info
)
1128 ttyfds
= malloc(num_ttyfds
* sizeof(int));
1132 ret
= lxc_abstract_unix_recv_fds(sock
, ttyfds
, num_ttyfds
, NULL
, 0);
1133 for (i
= 0; (ret
>= 0 && *ttyfds
!= -1) && (i
< num_ttyfds
); i
++) {
1134 pty_info
= &tty_info
->pty_info
[i
/ 2];
1136 pty_info
->slave
= ttyfds
[i
++];
1137 pty_info
->master
= ttyfds
[i
];
1138 TRACE("received pty with master fd %d and slave fd %d from "
1139 "parent", pty_info
->master
, pty_info
->slave
);
1142 tty_info
->nbtty
= conf
->tty
;
1147 ERROR("failed to receive %d ttys from child: %s", conf
->tty
,
1150 TRACE("received %d ttys from child", conf
->tty
);
1155 void resolve_clone_flags(struct lxc_handler
*handler
)
1157 handler
->clone_flags
= CLONE_NEWPID
| CLONE_NEWNS
;
1159 if (!lxc_list_empty(&handler
->conf
->id_map
))
1160 handler
->clone_flags
|= CLONE_NEWUSER
;
1162 if (handler
->conf
->inherit_ns_fd
[LXC_NS_NET
] == -1) {
1163 if (!lxc_requests_empty_network(handler
))
1164 handler
->clone_flags
|= CLONE_NEWNET
;
1166 INFO("Inheriting a NET namespace.");
1169 if (handler
->conf
->inherit_ns_fd
[LXC_NS_IPC
] == -1)
1170 handler
->clone_flags
|= CLONE_NEWIPC
;
1172 INFO("Inheriting an IPC namespace.");
1174 if (handler
->conf
->inherit_ns_fd
[LXC_NS_UTS
] == -1)
1175 handler
->clone_flags
|= CLONE_NEWUTS
;
1177 INFO("Inheriting a UTS namespace.");
1180 /* lxc_spawn() performs crucial setup tasks and clone()s the new process which
1181 * exec()s the requested container binary.
1182 * Note that lxc_spawn() runs in the parent namespaces. Any operations performed
1183 * right here should be double checked if they'd pose a security risk. (For
1184 * example, any {u}mount() operations performed here will be reflected on the
1187 static int lxc_spawn(struct lxc_handler
*handler
)
1189 int failed_before_rename
= 0;
1190 const char *name
= handler
->name
;
1191 bool cgroups_connected
= false;
1192 int saved_ns_fd
[LXC_NS_MAX
];
1193 int preserve_mask
= 0, i
, flags
;
1194 int netpipepair
[2], nveths
;
1195 bool wants_to_map_ids
;
1196 struct lxc_list
*id_map
;
1199 id_map
= &handler
->conf
->id_map
;
1200 wants_to_map_ids
= !lxc_list_empty(id_map
);
1202 for (i
= 0; i
< LXC_NS_MAX
; i
++)
1203 if (handler
->conf
->inherit_ns_fd
[i
] != -1)
1204 preserve_mask
|= ns_info
[i
].clone_flag
;
1206 if (lxc_sync_init(handler
))
1209 if (socketpair(AF_UNIX
, SOCK_DGRAM
, 0, handler
->ttysock
) < 0) {
1210 lxc_sync_fini(handler
);
1214 resolve_clone_flags(handler
);
1216 if (handler
->clone_flags
& CLONE_NEWNET
) {
1217 if (!lxc_list_empty(&handler
->conf
->network
)) {
1219 /* Find gateway addresses from the link device, which is
1220 * no longer accessible inside the container. Do this
1221 * before creating network interfaces, since goto
1222 * out_delete_net does not work before lxc_clone.
1224 if (lxc_find_gateway_addresses(handler
)) {
1225 ERROR("Failed to find gateway addresses.");
1226 lxc_sync_fini(handler
);
1230 /* That should be done before the clone because we will
1231 * fill the netdev index and use them in the child.
1233 if (lxc_create_network(handler
)) {
1234 ERROR("Failed to create the network.");
1235 lxc_sync_fini(handler
);
1240 if (save_phys_nics(handler
->conf
)) {
1241 ERROR("Failed to save physical nic info.");
1246 if (!cgroup_init(handler
)) {
1247 ERROR("Failed initializing cgroup support.");
1248 goto out_delete_net
;
1251 cgroups_connected
= true;
1253 if (!cgroup_create(handler
)) {
1254 ERROR("Failed creating cgroups.");
1255 goto out_delete_net
;
1258 /* If the rootfs is not a blockdev, prevent the container from marking
1260 * If the container is unprivileged then skip rootfs pinning.
1262 if (!wants_to_map_ids
) {
1263 handler
->pinfd
= pin_rootfs(handler
->conf
->rootfs
.path
);
1264 if (handler
->pinfd
== -1)
1265 INFO("Failed to pin the rootfs for container \"%s\".", handler
->name
);
1268 if (!preserve_ns(saved_ns_fd
, preserve_mask
, getpid()))
1269 goto out_delete_net
;
1271 if (attach_ns(handler
->conf
->inherit_ns_fd
) < 0)
1272 goto out_delete_net
;
1274 if (am_unpriv() && (nveths
= count_veths(&handler
->conf
->network
))) {
1275 if (pipe(netpipepair
) < 0) {
1276 SYSERROR("Failed to create pipe.");
1277 goto out_delete_net
;
1279 /* Store netpipe in the global var for do_start's use. */
1280 netpipe
= netpipepair
[0];
1283 /* Create a process in a new set of namespaces. */
1284 flags
= handler
->clone_flags
;
1285 if (handler
->clone_flags
& CLONE_NEWUSER
) {
1286 /* If CLONE_NEWUSER and CLONE_NEWNET was requested, we need to
1287 * clone a new user namespace first and only later unshare our
1288 * network namespace to ensure that network devices ownership is
1291 flags
&= ~CLONE_NEWNET
;
1293 handler
->pid
= lxc_clone(do_start
, handler
, flags
);
1294 if (handler
->pid
< 0) {
1295 SYSERROR("Failed to clone a new set of namespaces.");
1296 goto out_delete_net
;
1298 for (i
= 0; i
< LXC_NS_MAX
; i
++)
1299 if (flags
& ns_info
[i
].clone_flag
)
1300 INFO("Cloned %s.", ns_info
[i
].flag_name
);
1302 if (!preserve_ns(handler
->nsfd
, handler
->clone_flags
| preserve_mask
, handler
->pid
))
1303 INFO("Failed to preserve namespace for lxc.hook.stop.");
1305 if (attach_ns(saved_ns_fd
))
1306 WARN("Failed to restore saved namespaces.");
1308 lxc_sync_fini_child(handler
);
1310 /* Map the container uids. The container became an invalid userid the
1311 * moment it was cloned with CLONE_NEWUSER. This call doesn't change
1312 * anything immediately, but allows the container to setuid(0) (0 being
1313 * mapped to something else on the host.) later to become a valid uid
1316 if (wants_to_map_ids
&& lxc_map_ids(id_map
, handler
->pid
)) {
1317 ERROR("Failed to set up id mapping.");
1318 goto out_delete_net
;
1321 if (lxc_sync_wake_child(handler
, LXC_SYNC_STARTUP
)) {
1322 failed_before_rename
= 1;
1323 goto out_delete_net
;
1326 if (lxc_sync_wait_child(handler
, LXC_SYNC_CONFIGURE
)) {
1327 failed_before_rename
= 1;
1328 goto out_delete_net
;
1331 if (!cgroup_create_legacy(handler
)) {
1332 ERROR("Failed to setup legacy cgroups for container \"%s\".", name
);
1333 goto out_delete_net
;
1335 if (!cgroup_setup_limits(handler
, false)) {
1336 ERROR("Failed to setup cgroup limits for container \"%s\".", name
);
1337 goto out_delete_net
;
1340 if (!cgroup_enter(handler
))
1341 goto out_delete_net
;
1343 if (!cgroup_chown(handler
))
1344 goto out_delete_net
;
1346 if (failed_before_rename
)
1347 goto out_delete_net
;
1349 /* Create the network configuration. */
1350 if (handler
->clone_flags
& CLONE_NEWNET
) {
1351 if (lxc_assign_network(handler
->lxcpath
, handler
->name
,
1352 &handler
->conf
->network
, handler
->pid
)) {
1353 ERROR("Failed to create the configured network.");
1354 goto out_delete_net
;
1358 if (netpipe
!= -1) {
1359 struct lxc_list
*iterator
;
1360 struct lxc_netdev
*netdev
;
1363 lxc_list_for_each(iterator
, &handler
->conf
->network
) {
1364 netdev
= iterator
->elem
;
1365 if (netdev
->type
!= LXC_NET_VETH
)
1367 if (write(netpipepair
[1], netdev
->name
, IFNAMSIZ
) != IFNAMSIZ
) {
1368 ERROR("Error writing veth name to container.");
1369 goto out_delete_net
;
1372 close(netpipepair
[1]);
1375 /* Tell the child to continue its initialization. We'll get
1376 * LXC_SYNC_CGROUP when it is ready for us to setup cgroups.
1378 if (lxc_sync_barrier_child(handler
, LXC_SYNC_POST_CONFIGURE
))
1379 goto out_delete_net
;
1381 if (!lxc_list_empty(&handler
->conf
->limits
) && setup_resource_limits(&handler
->conf
->limits
, handler
->pid
)) {
1382 ERROR("failed to setup resource limits for '%s'", name
);
1383 goto out_delete_net
;
1386 if (!cgroup_setup_limits(handler
, true)) {
1387 ERROR("Failed to setup the devices cgroup for container \"%s\".", name
);
1388 goto out_delete_net
;
1391 cgroup_disconnect();
1392 cgroups_connected
= false;
1394 /* Read tty fds allocated by child. */
1395 if (lxc_recv_ttys_from_child(handler
) < 0) {
1396 ERROR("Failed to receive tty info from child process.");
1397 goto out_delete_net
;
1400 /* Tell the child to complete its initialization and wait for it to exec
1401 * or return an error. (The child will never return
1402 * LXC_SYNC_POST_CGROUP+1. It will either close the sync pipe, causing
1403 * lxc_sync_barrier_child to return success, or return a different
1404 * value, causing us to error out).
1406 if (lxc_sync_barrier_child(handler
, LXC_SYNC_POST_CGROUP
))
1409 if (handler
->ops
->post_start(handler
, handler
->data
))
1412 if (lxc_set_state(name
, handler
, RUNNING
)) {
1413 ERROR("Failed to set state for container \"%s\" to \"%s\".", name
,
1414 lxc_state2str(RUNNING
));
1418 lxc_sync_fini(handler
);
1419 handler
->netnsfd
= lxc_preserve_ns(handler
->pid
, "net");
1424 if (cgroups_connected
)
1425 cgroup_disconnect();
1426 if (handler
->clone_flags
& CLONE_NEWNET
)
1427 lxc_delete_network(handler
);
1429 lxc_abort(name
, handler
);
1430 lxc_sync_fini(handler
);
1431 if (handler
->pinfd
>= 0) {
1432 close(handler
->pinfd
);
1433 handler
->pinfd
= -1;
1439 int __lxc_start(const char *name
, struct lxc_handler
*handler
,
1440 struct lxc_operations
* ops
, void *data
, const char *lxcpath
,
1445 bool removed_all_netdevs
= true;
1446 struct lxc_conf
*conf
= handler
->conf
;
1448 if (lxc_init(name
, handler
) < 0) {
1449 ERROR("Failed to initialize container \"%s\".", name
);
1453 handler
->data
= data
;
1454 handler
->backgrounded
= backgrounded
;
1455 handler
->netnsfd
= -1;
1457 if (must_drop_cap_sys_boot(handler
->conf
)) {
1459 DEBUG("Dropping CAP_SYS_BOOT capability.");
1461 DEBUG("Not dropping CAP_SYS_BOOT capability as capabilities aren't supported.");
1464 DEBUG("Not dropping CAP_SYS_BOOT or watching utmp.");
1465 handler
->conf
->need_utmp_watch
= 0;
1468 if (!attach_block_device(handler
->conf
)) {
1469 ERROR("Failed to attach block device.");
1470 goto out_fini_nonet
;
1473 if (geteuid() == 0 && !lxc_list_empty(&conf
->id_map
)) {
1474 /* If the backing store is a device, mount it here and now. */
1475 if (rootfs_is_blockdev(conf
)) {
1476 if (unshare(CLONE_NEWNS
) < 0) {
1477 ERROR("Failed to unshare CLONE_NEWNS.");
1478 goto out_fini_nonet
;
1480 INFO("Unshared CLONE_NEWNS.");
1482 remount_all_slave();
1483 if (do_rootfs_setup(conf
, name
, lxcpath
) < 0) {
1484 ERROR("Error setting up rootfs mount as root before spawn.");
1485 goto out_fini_nonet
;
1487 INFO("Set up container rootfs as host root.");
1491 err
= lxc_spawn(handler
);
1493 ERROR("Failed to spawn container \"%s\".", name
);
1494 goto out_detach_blockdev
;
1497 handler
->conf
->reboot
= 0;
1499 err
= lxc_poll(name
, handler
);
1501 ERROR("LXC mainloop exited with error: %d.", err
);
1502 if (handler
->netnsfd
>= 0) {
1503 close(handler
->netnsfd
);
1504 handler
->netnsfd
= -1;
1509 while (waitpid(handler
->pid
, &status
, 0) < 0 && errno
== EINTR
)
1512 /* If the child process exited but was not signaled, it didn't call
1513 * reboot. This should mean it was an lxc-execute which simply exited.
1514 * In any case, treat it as a 'halt'.
1516 if (WIFSIGNALED(status
)) {
1517 switch(WTERMSIG(status
)) {
1518 case SIGINT
: /* halt */
1519 DEBUG("Container \"%s\" is halting.", name
);
1521 case SIGHUP
: /* reboot */
1522 DEBUG("Container \"%s\" is rebooting.", name
);
1523 handler
->conf
->reboot
= 1;
1525 case SIGSYS
: /* seccomp */
1526 DEBUG("Container \"%s\" violated its seccomp policy.", name
);
1529 DEBUG("Unknown exit status for container \"%s\" init %d.", name
, WTERMSIG(status
));
1534 DEBUG("Pushing physical nics back to host namespace");
1535 lxc_restore_phys_nics_to_netns(handler
->netnsfd
, handler
->conf
);
1537 DEBUG("Tearing down virtual network devices used by container \"%s\".", name
);
1538 removed_all_netdevs
= lxc_delete_network(handler
);
1540 if (handler
->pinfd
>= 0) {
1541 close(handler
->pinfd
);
1542 handler
->pinfd
= -1;
1545 lxc_monitor_send_exit_code(name
, status
, handler
->lxcpath
);
1546 err
= lxc_error_set_and_log(handler
->pid
, status
);
1548 if (!removed_all_netdevs
) {
1549 DEBUG("Failed tearing down network devices used by container. Trying again!");
1550 removed_all_netdevs
= lxc_delete_network(handler
);
1551 if (!removed_all_netdevs
)
1552 DEBUG("Failed tearing down network devices used by container. Not trying again!");
1555 out_detach_blockdev
:
1556 detach_block_device(handler
->conf
);
1559 lxc_fini(name
, handler
);
1563 lxc_abort(name
, handler
);
1571 static int start(struct lxc_handler
*handler
, void* data
)
1573 struct start_args
*arg
= data
;
1575 NOTICE("Exec'ing \"%s\".", arg
->argv
[0]);
1577 execvp(arg
->argv
[0], arg
->argv
);
1578 SYSERROR("Failed to exec \"%s\".", arg
->argv
[0]);
1582 static int post_start(struct lxc_handler
*handler
, void* data
)
1584 struct start_args
*arg
= data
;
1586 NOTICE("Started \"%s\" with pid \"%d\".", arg
->argv
[0], handler
->pid
);
1590 static struct lxc_operations start_ops
= {
1592 .post_start
= post_start
1595 int lxc_start(const char *name
, char *const argv
[], struct lxc_handler
*handler
,
1596 const char *lxcpath
, bool backgrounded
)
1598 struct start_args start_arg
= {
1602 handler
->conf
->need_utmp_watch
= 1;
1603 return __lxc_start(name
, handler
, &start_ops
, &start_arg
, lxcpath
, backgrounded
);
1606 static void lxc_destroy_container_on_signal(struct lxc_handler
*handler
,
1609 char destroy
[MAXPATHLEN
];
1612 struct lxc_container
*c
;
1613 if (handler
->conf
->rootfs
.path
&& handler
->conf
->rootfs
.mount
) {
1614 bret
= do_destroy_container(handler
->conf
);
1616 ERROR("Error destroying rootfs for container \"%s\".", name
);
1620 INFO("Destroyed rootfs for container \"%s\".", name
);
1622 ret
= snprintf(destroy
, MAXPATHLEN
, "%s/%s", handler
->lxcpath
, name
);
1623 if (ret
< 0 || ret
>= MAXPATHLEN
) {
1624 ERROR("Error destroying directory for container \"%s\".", name
);
1628 c
= lxc_container_new(name
, handler
->lxcpath
);
1630 if (container_disk_lock(c
)) {
1631 INFO("Could not update lxc_snapshots file.");
1632 lxc_container_put(c
);
1634 mod_all_rdeps(c
, false);
1635 container_disk_unlock(c
);
1636 lxc_container_put(c
);
1641 ret
= userns_exec_1(handler
->conf
, lxc_rmdir_onedev_wrapper
,
1642 destroy
, "lxc_rmdir_onedev_wrapper");
1644 ret
= lxc_rmdir_onedev(destroy
, NULL
);
1647 ERROR("Error destroying directory for container \"%s\".", name
);
1650 INFO("Destroyed directory for container \"%s\".", name
);
1653 static int lxc_rmdir_onedev_wrapper(void *data
)
1655 char *arg
= (char *) data
;
1656 return lxc_rmdir_onedev(arg
, NULL
);
1659 static bool do_destroy_container(struct lxc_conf
*conf
) {
1661 if (userns_exec_1(conf
, bdev_destroy_wrapper
, conf
,
1662 "bdev_destroy_wrapper") < 0)
1666 return bdev_destroy(conf
);