unmount-namespace.c revision 36dd8426cbfc3262eddf38c0480c7ed0a8d811e9
2ronwalf * Copyright © 2015 Wolfgang Bumiller <w.bumiller@proxmox.com>. 2ronwalf * Copyright © 2015 Proxmox Server Solutions GmbH 2ronwalf * This program is free software; you can redistribute it and/or modify 2ronwalf * it under the terms of the GNU General Public License version 2, as 2ronwalf * published by the Free Software Foundation. 2ronwalf * This program is distributed in the hope that it will be useful, 2ronwalf * but WITHOUT ANY WARRANTY; without even the implied warranty of 2ronwalf * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2ronwalf * GNU General Public License for more details. 2ronwalf * You should have received a copy of the GNU General Public License along 2ronwalf * with this program; if not, write to the Free Software Foundation, Inc., 2ronwalf * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 2ronwalf * This stop-hook unmounts everything in the container's namespace, and thereby 2ronwalf * waits for all calls commands to finish. This is useful when one needs to be 2ronwalf * sure that network filesystems are finished unmounting in the namespace 2ronwalf * before continuing with other tasks. Without this hook the cleanup of mounts 2ronwalf * is done by the kernel in the background after all the references to the 2ronwalf/* Define setns() if missing from the C library */ 2ronwalf/* Unmounting /dev/pts fails, and so /dev also fails, but /dev is not what /* Read mounts from 'self/mounts' relative to a directory filedescriptor. * Before entering the container we open a handle to /proc on the host as we * need to access /proc/self/mounts and the container's /proc doesn't contain * our /self. We then use openat(2) to avoid having to mount a temporary /proc. for (i =
4; i !=
argc; ++i) {
/* Open a handle to /proc on the host as we need to access /proc/self/mounts * and the container's /proc doesn't contain our /self. See read_mounts(). /* Open the mount namespace and enter it. */ /* Just sort to get a sane unmount-order... */ /* fprintf(stderr, "Unmount: %s\n", mounts[zi].dst); */