From: Lennart Poettering Date: Fri, 17 Feb 2023 09:32:18 +0000 (+0100) Subject: sync-util: port fsync_directory_of_file() to fd_is_opath() X-Git-Tag: v254-rc1~1248 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ac55dfb46494a602209027864a82e6f62511ddf;p=thirdparty%2Fsystemd.git sync-util: port fsync_directory_of_file() to fd_is_opath() As suggested here: https://github.com/systemd/systemd/pull/26450#pullrequestreview-1302922404 --- diff --git a/src/basic/sync-util.c b/src/basic/sync-util.c index 52c8c417dee..a17ab2c890a 100644 --- a/src/basic/sync-util.c +++ b/src/basic/sync-util.c @@ -27,16 +27,12 @@ int fsync_directory_of_file(int fd) { } else if (!S_ISREG(st.st_mode)) { /* Regular files are OK regardless if O_PATH or not, for all other * types check O_PATH flag */ - int flags; - - flags = fcntl(fd, F_GETFL); - if (flags < 0) - return -errno; - - if (!FLAGS_SET(flags, O_PATH)) /* If O_PATH this refers to the inode in the fs, in which case - * we can sensibly do what is requested. Otherwise this refers - * to a socket, fifo or device node, where the concept of a - * containing directory doesn't make too much sense. */ + r = fd_is_opath(fd); + if (r < 0) + return r; + if (!r) /* If O_PATH this refers to the inode in the fs, in which case we can sensibly do + * what is requested. Otherwise this refers to a socket, fifo or device node, where + * the concept of a containing directory doesn't make too much sense. */ return -ENOTTY; }