fd-util: add new FORMAT_PROC_PID_FD_PATH() helper

This is just like FORMAT_PROC_FD_PATH() but goes via the PID number
rather than the "self" symlink.

This is useful whenever we want to generate a path that is useful
outside of our local scope.
This commit is contained in:
Lennart Poettering
2023-11-02 14:09:23 +01:00
parent c13e6c720d
commit 61c062f896
2 changed files with 18 additions and 0 deletions
+8
View File
@@ -988,3 +988,11 @@ const char *accmode_to_string(int flags) {
return NULL;
}
}
char *format_proc_pid_fd_path(char buf[static PROC_PID_FD_PATH_MAX], pid_t pid, int fd) {
assert(buf);
assert(fd >= 0);
assert(pid >= 0);
assert_se(snprintf_ok(buf, PROC_PID_FD_PATH_MAX, "/proc/" PID_FMT "/fd/%i", pid == 0 ? getpid_cached() : pid, fd));
return buf;
}