/*
* Copyright © 2015 Wolfgang Bumiller <w.bumiller@proxmox.com>.
* Copyright © 2015 Proxmox Server Solutions GmbH
*
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* --
*
* This stop-hook unmounts everything in the container's namespace, and thereby
* waits for all calls commands to finish. This is useful when one needs to be
* sure that network filesystems are finished unmounting in the namespace
* before continuing with other tasks. Without this hook the cleanup of mounts
* is done by the kernel in the background after all the references to the
* namespaces are gone.
*/
#include <stdio.h> /* fdopen, getmntent, endmntent */
#include <stdlib.h> /* malloc, qsort */
#include <unistd.h> /* close */
#include <string.h> /* strcmp, strncmp, strdup, strerror */
#include <sched.h> /* setns */
#include <fcntl.h> /* openat, open */
#include <errno.h> /* errno */
#if IS_BIONIC
#else
#include <mntent.h>
#endif
#ifndef O_PATH
#endif
/* Define setns() if missing from the C library */
#ifndef HAVE_SETNS
{
#ifdef __NR_setns
#elif defined(__NR_set_ns)
#else
return -1;
#endif
}
#endif
struct mount {
char *dst;
};
}
}
*/
}
* Before entering the container we open a handle to /proc on the host as we
* our /self. We then use openat(2) to avoid having to mount a temporary /proc.
*/
int fd;
if (!mounts) {
return 0;
}
*countp = 0;
if (fd < 0) {
return 0;
}
if (!mf) {
return 0;
}
capacity *= 2;
if (!new)
goto out_alloc_entry;
}
goto out_alloc_entry;
}
return 1;
while (count--) {
}
return 0;
}
return 2;
}
return 0;
for (i = 4; i != argc; ++i) {
break;
}
}
if (!mntns) {
return 3;
}
* and the container's /proc doesn't contain our /self. See read_mounts().
*/
if (procfd < 0) {
return 4;
}
/* Open the mount namespace and enter it. */
if (ctmntfd < 0) {
return 5;
}
return 6;
}
return 7;
}
/* Just sort to get a sane unmount-order... */
/* fprintf(stderr, "Unmount: %s\n", mounts[zi].dst); */
}
}
}
return 0;
}