I am implementing a container which is cloned with a new namespace including mount, pid, user namespaces, etc. The first step the child does is to mount several important points such as /proc
, /sys
and /tmp
using mount
system call.
if(::mount("proc", "/proc", "proc", 0, NULL)==-1) {
printf("Failed on mount: %s\n", strerror(errno));
return -1;
}
if(::mount("sysfs", "/sys", "sysfs", 0, NULL)==-1) {
printf("Failed on mount: %s\n", strerror(errno));
return -1;
}
if(::mount("tmp", "/tmp", "tmpfs", 0, NULL)==-1) {
printf("Failed on mount: %s\n", strerror(errno));
return -1;
}
However, I am a bit confused by the source
field in the argument list passed to mount
.
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
What does the source mean exactly? For example, mounting /tmp
seems have nothing to do with the source char string. I can still see a new /tmp
folder created under the new namespace even using ::mount(nullptr, "/tmp", "tmpfs", 0, NULL)
. Am I missing something?