summaryrefslogtreecommitdiffstats
path: root/man2/memfd_create.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/memfd_create.2')
-rw-r--r--man2/memfd_create.246
1 files changed, 23 insertions, 23 deletions
diff --git a/man2/memfd_create.2 b/man2/memfd_create.2
index 3274b3983..873163719 100644
--- a/man2/memfd_create.2
+++ b/man2/memfd_create.2
@@ -414,7 +414,7 @@ Existing seals: WRITE SHRINK
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
-
+\&
int
main(int argc, char *argv[])
{
@@ -422,7 +422,7 @@ main(int argc, char *argv[])
char *name, *seals_arg;
ssize_t len;
unsigned int seals;
-
+\&
if (argc < 3) {
fprintf(stderr, "%s name size [seals]\en", argv[0]);
fprintf(stderr, "\et\[aq]seals\[aq] can contain any of the "
@@ -434,35 +434,35 @@ main(int argc, char *argv[])
fprintf(stderr, "\et\etS \- F_SEAL_SEAL\en");
exit(EXIT_FAILURE);
}
-
+\&
name = argv[1];
len = atoi(argv[2]);
seals_arg = argv[3];
-
+\&
/* Create an anonymous file in tmpfs; allow seals to be
placed on the file. */
-
+\&
fd = memfd_create(name, MFD_ALLOW_SEALING);
if (fd == \-1)
err(EXIT_FAILURE, "memfd_create");
-
+\&
/* Size the file as specified on the command line. */
-
+\&
if (ftruncate(fd, len) == \-1)
err(EXIT_FAILURE, "truncate");
-
+\&
printf("PID: %jd; fd: %d; /proc/%jd/fd/%d\en",
(intmax_t) getpid(), fd, (intmax_t) getpid(), fd);
-
+\&
/* Code to map the file and populate the mapping with data
omitted. */
-
+\&
/* If a \[aq]seals\[aq] command\-line argument was supplied, set some
seals on the file. */
-
+\&
if (seals_arg != NULL) {
seals = 0;
-
+\&
if (strchr(seals_arg, \[aq]g\[aq]) != NULL)
seals |= F_SEAL_GROW;
if (strchr(seals_arg, \[aq]s\[aq]) != NULL)
@@ -473,16 +473,16 @@ main(int argc, char *argv[])
seals |= F_SEAL_FUTURE_WRITE;
if (strchr(seals_arg, \[aq]S\[aq]) != NULL)
seals |= F_SEAL_SEAL;
-
+\&
if (fcntl(fd, F_ADD_SEALS, seals) == \-1)
err(EXIT_FAILURE, "fcntl");
}
-
+\&
/* Keep running, so that the file created by memfd_create()
continues to exist. */
-
+\&
pause();
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -496,26 +496,26 @@ main(int argc, char *argv[])
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
-
+\&
int
main(int argc, char *argv[])
{
int fd;
unsigned int seals;
-
+\&
if (argc != 2) {
fprintf(stderr, "%s /proc/PID/fd/FD\en", argv[0]);
exit(EXIT_FAILURE);
}
-
+\&
fd = open(argv[1], O_RDWR);
if (fd == \-1)
err(EXIT_FAILURE, "open");
-
+\&
seals = fcntl(fd, F_GET_SEALS);
if (seals == \-1)
err(EXIT_FAILURE, "fcntl");
-
+\&
printf("Existing seals:");
if (seals & F_SEAL_SEAL)
printf(" SEAL");
@@ -528,10 +528,10 @@ main(int argc, char *argv[])
if (seals & F_SEAL_SHRINK)
printf(" SHRINK");
printf("\en");
-
+\&
/* Code to map the file and access the contents of the
resulting mapping omitted. */
-
+\&
exit(EXIT_SUCCESS);
}
.EE