I`ll be glad to get an explanation how unshar mount namespace works for the following code:
unshare (mount_ns)
int pid = fork()
if (pid ==0)
{
makedir("myDir");
mount("path", "myDir", 0);
int fd = open("myDir/myFile.txt", O_CREATE|O_RDWR);
wrte(fd, "123\n",4);
close(fd);
}
sleep(100000);
if(pid == 0)
{
if (open("myDir/myFile.txt", O_RDONLY) < 0)
printf ("son proc failed to read file\n");
else
printf ("son proc ok to read file\n");
}
else
{
if (open("myDir/myFile.txt", O_RDONLY) < 0)
printf ("parent proc failed to read file\n");
else
printf ("parent proc failed to read file\n");
}
I expected to see son proc ok to read file
, parent proc failed to read file
but both success. How can it be after unshare?