]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: introduce a simple helper to check a file descriptor has O_PATH
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 Feb 2023 22:18:42 +0000 (07:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 16 Feb 2023 22:18:42 +0000 (07:18 +0900)
src/basic/fd-util.c
src/basic/fd-util.h

index 4d6d01cd9928d69af955471f6992f8f9a40b0354..430db0c87907b8b61a40fad431b96aa4e0e6f1f8 100644 (file)
@@ -808,6 +808,18 @@ int fd_reopen_condition(
         return new_fd;
 }
 
+int fd_is_opath(int fd) {
+        int r;
+
+        assert(fd >= 0);
+
+        r = fcntl(fd, F_GETFL);
+        if (r < 0)
+                return -errno;
+
+        return FLAGS_SET(r, O_PATH);
+}
+
 int read_nr_open(void) {
         _cleanup_free_ char *nr_open = NULL;
         int r;
index 952afdd64f0054755790dd2861f93254e0c21239..f5357860f55b58b7568fb8abce7b099b25ee8430 100644 (file)
@@ -104,6 +104,7 @@ static inline int make_null_stdio(void) {
 
 int fd_reopen(int fd, int flags);
 int fd_reopen_condition(int fd, int flags, int mask, int *ret_new_fd);
+int fd_is_opath(int fd);
 int read_nr_open(void);
 int fd_get_diskseq(int fd, uint64_t *ret);