summaryrefslogtreecommitdiffstats
path: root/man2/close_range.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/close_range.2')
-rw-r--r--man2/close_range.226
1 files changed, 13 insertions, 13 deletions
diff --git a/man2/close_range.2 b/man2/close_range.2
index 782719de0..1df68c91d 100644
--- a/man2/close_range.2
+++ b/man2/close_range.2
@@ -207,9 +207,9 @@ result from the calls to
#include <stdlib.h>
#include <sys/syscall.h>
#include <unistd.h>
-
+\&
/* Show the contents of the symbolic links in /proc/self/fd */
-
+\&
static void
show_fds(void)
{
@@ -217,35 +217,35 @@ show_fds(void)
char path[PATH_MAX], target[PATH_MAX];
ssize_t len;
struct dirent *dp;
-
+\&
dirp = opendir("/proc/self/fd");
if (dirp == NULL) {
perror("opendir");
exit(EXIT_FAILURE);
}
-
+\&
for (;;) {
dp = readdir(dirp);
if (dp == NULL)
break;
-
+\&
if (dp\->d_type == DT_LNK) {
snprintf(path, sizeof(path), "/proc/self/fd/%s",
dp\->d_name);
-
+\&
len = readlink(path, target, sizeof(target));
printf("%s ==> %.*s\en", path, (int) len, target);
}
}
-
+\&
closedir(dirp);
}
-
+\&
int
main(int argc, char *argv[])
{
int fd;
-
+\&
for (size_t j = 1; j < argc; j++) {
fd = open(argv[j], O_RDONLY);
if (fd == \-1) {
@@ -254,16 +254,16 @@ main(int argc, char *argv[])
}
printf("%s opened as FD %d\en", argv[j], fd);
}
-
+\&
show_fds();
-
+\&
printf("========= About to call close_range() =======\en");
-
+\&
if (syscall(SYS_close_range, 3, \[ti]0U, 0) == \-1) {
perror("close_range");
exit(EXIT_FAILURE);
}
-
+\&
show_fds();
exit(EXIT_FAILURE);
}