setns.2: EXAMPLE: use O_CLOEXEC when opening namespace file descriptor

Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
This commit is contained in:
Michael Kerrisk 2020-07-17 09:22:52 +02:00
parent 7cb61821b9
commit 298743a573
1 changed files with 5 additions and 1 deletions

View File

@ -396,7 +396,11 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
fd = open(argv[1], O_RDONLY); /* Get file descriptor for namespace */
/* Get file descriptor for namespace; the file descriptor is opened with
O_CLOEXEC so as to ensure that it is not inherited by the program that
is later executed. */
fd = open(argv[1], O_RDONLY | O_CLOEXEC);
if (fd == \-1)
errExit("open");