This repository has been archived on 2022-05-27. You can view files and clone it, but cannot push or open issues or pull requests.
ocaml-cgroups2/examples/dir_descriptor.c
2022-05-23 00:28:16 +01:00

24 lines
546 B
C

#include <fcntl.h>
#include <linux/types.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main() {
int dirfd;
if ((dirfd = open("/tmp", __O_DIRECTORY)) < 0)
perror("opendir");
if (openat(dirfd, "filethatdoesexist", O_RDONLY) < 0)
perror("openat0");
if (chroot("/tmp"))
perror("chroot");
if (open("/etc/passwd", O_RDONLY) < 0)
perror("open");
if (openat(dirfd, "../etc/passwd", O_RDONLY) < 0)
perror("openat1");
if (openat(dirfd, "filethatdoesexist", O_RDONLY) < 0)
perror("openat2");
}