]> git.ipfire.org Git - thirdparty/util-linux.git/blob - include/procfs.h
Merge branch 'ci/cache-openwrt-sdk' of https://github.com/t-8ch/util-linux
[thirdparty/util-linux.git] / include / procfs.h
1 /*
2 * No copyright is claimed. This code is in the public domain; do with
3 * it what you wish.
4 *
5 * Copyright (C) 2021 Karel Zak <kzak@redhat.com>
6 */
7 #ifndef UTIL_LINUX_PROCFS_H
8 #define UTIL_LINUX_PROCFS_H
9
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <stdint.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <string.h>
18 #include <inttypes.h>
19 #include <dirent.h>
20
21 #include "path.h"
22
23 struct procfs_process {
24 pid_t pid;
25 };
26
27 extern void ul_procfs_init_debug(void);
28 extern struct path_cxt *ul_new_procfs_path(pid_t pid, const char *prefix);
29 extern int procfs_process_init_path(struct path_cxt *pc, pid_t pid);
30
31 extern int procfs_process_get_uid(struct path_cxt *pc, uid_t *uid);
32 extern ssize_t procfs_process_get_cmdline(struct path_cxt *pc, char *buf, size_t bufsz);
33 extern ssize_t procfs_process_get_cmdname(struct path_cxt *pc, char *buf, size_t bufsz);
34 extern ssize_t procfs_process_get_stat(struct path_cxt *pc, char *buf, size_t bufsz);
35 extern ssize_t procfs_process_get_syscall(struct path_cxt *pc, char *buf, size_t bufsz);
36
37 extern int procfs_process_get_stat_nth(struct path_cxt *pc, int n, uintmax_t *re);
38
39 static inline ssize_t procfs_process_get_exe(struct path_cxt *pc, char *buf, size_t bufsz)
40 {
41 return ul_path_readlink(pc, buf, bufsz, "exe");
42 }
43
44 static inline ssize_t procfs_process_get_root(struct path_cxt *pc, char *buf, size_t bufsz)
45 {
46 return ul_path_readlink(pc, buf, bufsz, "root");
47 }
48
49 static inline ssize_t procfs_process_get_cwd(struct path_cxt *pc, char *buf, size_t bufsz)
50 {
51 return ul_path_readlink(pc, buf, bufsz, "cwd");
52 }
53
54 extern int procfs_process_next_tid(struct path_cxt *pc, DIR **sub, pid_t *tid);
55 extern int procfs_process_next_fd(struct path_cxt *pc, DIR **sub, int *fd);
56
57 extern int procfs_dirent_is_process(struct dirent *d);
58 extern int procfs_dirent_get_pid(struct dirent *d, pid_t *pid);
59 extern int procfs_dirent_get_uid(DIR *procfs, struct dirent *d, uid_t *uid);
60 extern int procfs_dirent_match_uid(DIR *procfs, struct dirent *d, uid_t uid);
61 extern int procfs_dirent_get_name(DIR *procfs, struct dirent *d, char *buf, size_t bufsz);
62 extern int procfs_dirent_match_name(DIR *procfs, struct dirent *d, const char *name);
63
64 extern int fd_is_procfs(int fd);
65 extern char *pid_get_cmdname(pid_t pid);
66 extern char *pid_get_cmdline(pid_t pid);
67
68 #endif /* UTIL_LINUX_PROCFS_H */