diff options
author | Alice Frosi <afrosi@redhat.com> | 2023-03-24 10:07:48 +0100 |
---|---|---|
committer | Alice Frosi <afrosi@redhat.com> | 2023-03-24 15:38:07 +0100 |
commit | 069009f8e39238ec1a67fba6cfb287b9a0cac83e (patch) | |
tree | 77f817eb7b96178b71f3d573a83cec19f7fba09c /src/common/common.c | |
parent | 06b0f6d323c396ca1df000af96fdd07cc69b06e0 (diff) | |
download | seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.tar seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.tar.gz seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.tar.bz2 seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.tar.lz seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.tar.xz seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.tar.zst seitan-069009f8e39238ec1a67fba6cfb287b9a0cac83e.zip |
Re-organize project and add license header
Diffstat (limited to 'src/common/common.c')
-rw-r--r-- | src/common/common.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/common/common.c b/src/common/common.c new file mode 100644 index 0000000..a8f79a2 --- /dev/null +++ b/src/common/common.c @@ -0,0 +1,51 @@ +#include <stddef.h> +#include <stdio.h> +#include <string.h> +#include <dirent.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/stat.h> + +int find_fd_seccomp_notifier(const char *path) +{ + char entry[2 * PATH_MAX + 1]; + char buf[PATH_MAX + 1]; + struct dirent *dp; + ssize_t nbytes; + struct stat sb; + DIR *dirp; + + if ((dirp = opendir(path)) == NULL) { + fprintf(stderr, "failed reading fds from proc: %s \n", path); + return -1; + } + while ((dp = readdir(dirp)) != NULL) { + snprintf(entry, sizeof(entry), "%s/%s", path, dp->d_name); + if (lstat(entry, &sb) == -1) { + perror("lstat"); + } + /* Skip the entry if it isn't a symbolic link */ + if (!S_ISLNK(sb.st_mode)) + continue; + + nbytes = readlink(entry, buf, PATH_MAX); + if (nbytes == -1) { + perror("readlink"); + } + if (nbytes == PATH_MAX) { + perror("buffer overflow"); + continue; + } + /* + * From man proc: For file descriptors that have no + * corresponding inode (e.g., file descriptors produced by + * bpf(2)..), the entry will be a symbolic link with contents + * of the form: + * anon_inode:<file-type> + */ + if (strstr(buf, "anon_inode:seccomp notify") != NULL) + return atoi(dp->d_name); + } + fprintf(stderr, "seccomp notifier not found in %s\n", path); + return -1; +} |