]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util-lib: split out file attribute calls to chattr-util.[ch]
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Oct 2015 19:39:23 +0000 (20:39 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 12:25:56 +0000 (13:25 +0100)
12 files changed:
Makefile.am
src/basic/chattr-util.c [new file with mode: 0644]
src/basic/chattr-util.h [new file with mode: 0644]
src/basic/copy.c
src/basic/util.c
src/basic/util.h
src/import/import-raw.c
src/import/pull-raw.c
src/journal/journal-file.c
src/journal/journalctl.c
src/shared/machine-image.c
src/tmpfiles/tmpfiles.c

index 33d66d4dd0162e80262c247e7b311ac05f57ac38..15aace196a8b61e5149afc92b9c95008f410fc20 100644 (file)
@@ -797,6 +797,8 @@ libbasic_la_SOURCES = \
        src/basic/dirent-util.h \
        src/basic/xattr-util.c \
        src/basic/xattr-util.h \
+       src/basic/chattr-util.c \
+       src/basic/chattr-util.h \
        src/basic/mount-util.c \
        src/basic/mount-util.h \
        src/basic/hexdecoct.c \
diff --git a/src/basic/chattr-util.c b/src/basic/chattr-util.c
new file mode 100644 (file)
index 0000000..d49ca05
--- /dev/null
@@ -0,0 +1,107 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <linux/fs.h>
+
+#include "chattr-util.h"
+#include "fd-util.h"
+#include "util.h"
+
+int chattr_fd(int fd, unsigned value, unsigned mask) {
+        unsigned old_attr, new_attr;
+        struct stat st;
+
+        assert(fd >= 0);
+
+        if (fstat(fd, &st) < 0)
+                return -errno;
+
+        /* Explicitly check whether this is a regular file or
+         * directory. If it is anything else (such as a device node or
+         * fifo), then the ioctl will not hit the file systems but
+         * possibly drivers, where the ioctl might have different
+         * effects. Notably, DRM is using the same ioctl() number. */
+
+        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
+                return -ENOTTY;
+
+        if (mask == 0)
+                return 0;
+
+        if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0)
+                return -errno;
+
+        new_attr = (old_attr & ~mask) | (value & mask);
+        if (new_attr == old_attr)
+                return 0;
+
+        if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0)
+                return -errno;
+
+        return 1;
+}
+
+int chattr_path(const char *p, unsigned value, unsigned mask) {
+        _cleanup_close_ int fd = -1;
+
+        assert(p);
+
+        if (mask == 0)
+                return 0;
+
+        fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+        if (fd < 0)
+                return -errno;
+
+        return chattr_fd(fd, value, mask);
+}
+
+int read_attr_fd(int fd, unsigned *ret) {
+        struct stat st;
+
+        assert(fd >= 0);
+
+        if (fstat(fd, &st) < 0)
+                return -errno;
+
+        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
+                return -ENOTTY;
+
+        if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0)
+                return -errno;
+
+        return 0;
+}
+
+int read_attr_path(const char *p, unsigned *ret) {
+        _cleanup_close_ int fd = -1;
+
+        assert(p);
+        assert(ret);
+
+        fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
+        if (fd < 0)
+                return -errno;
+
+        return read_attr_fd(fd, ret);
+}
diff --git a/src/basic/chattr-util.h b/src/basic/chattr-util.h
new file mode 100644 (file)
index 0000000..ba6b8eb
--- /dev/null
@@ -0,0 +1,28 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+int chattr_fd(int fd, unsigned value, unsigned mask);
+int chattr_path(const char *p, unsigned value, unsigned mask);
+
+int read_attr_fd(int fd, unsigned *ret);
+int read_attr_path(const char *p, unsigned *ret);
index 60a4bee0fe22f80925b0dba9d8653c592f07133b..89100521164844c5c83b2885a5dae5bb2d48337d 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/xattr.h>
 
 #include "btrfs-util.h"
+#include "chattr-util.h"
 #include "copy.h"
 #include "dirent-util.h"
 #include "fd-util.h"
index dfebff7ec19fa4fbe7aee9d26a9c0e331bcc64d8..889ca288fced1335e00247e92422b1d9cbf8a7ca 100644 (file)
@@ -1962,85 +1962,6 @@ int is_device_node(const char *path) {
         return !!(S_ISBLK(info.st_mode) || S_ISCHR(info.st_mode));
 }
 
-int chattr_fd(int fd, unsigned value, unsigned mask) {
-        unsigned old_attr, new_attr;
-        struct stat st;
-
-        assert(fd >= 0);
-
-        if (fstat(fd, &st) < 0)
-                return -errno;
-
-        /* Explicitly check whether this is a regular file or
-         * directory. If it is anything else (such as a device node or
-         * fifo), then the ioctl will not hit the file systems but
-         * possibly drivers, where the ioctl might have different
-         * effects. Notably, DRM is using the same ioctl() number. */
-
-        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
-                return -ENOTTY;
-
-        if (mask == 0)
-                return 0;
-
-        if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0)
-                return -errno;
-
-        new_attr = (old_attr & ~mask) | (value & mask);
-        if (new_attr == old_attr)
-                return 0;
-
-        if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) < 0)
-                return -errno;
-
-        return 1;
-}
-
-int chattr_path(const char *p, unsigned value, unsigned mask) {
-        _cleanup_close_ int fd = -1;
-
-        assert(p);
-
-        if (mask == 0)
-                return 0;
-
-        fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
-        if (fd < 0)
-                return -errno;
-
-        return chattr_fd(fd, value, mask);
-}
-
-int read_attr_fd(int fd, unsigned *ret) {
-        struct stat st;
-
-        assert(fd >= 0);
-
-        if (fstat(fd, &st) < 0)
-                return -errno;
-
-        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
-                return -ENOTTY;
-
-        if (ioctl(fd, FS_IOC_GETFLAGS, ret) < 0)
-                return -errno;
-
-        return 0;
-}
-
-int read_attr_path(const char *p, unsigned *ret) {
-        _cleanup_close_ int fd = -1;
-
-        assert(p);
-        assert(ret);
-
-        fd = open(p, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
-        if (fd < 0)
-                return -errno;
-
-        return read_attr_fd(fd, ret);
-}
-
 int syslog_parse_priority(const char **p, int *priority, bool with_facility) {
         int a = 0, b = 0, c = 0;
         int k;
index 8f9f3f8fe6a0c21deb313227e24df55ab89cd175..30c88d38ad743e04d2a5fb33f280690de95d6fa9 100644 (file)
@@ -500,12 +500,6 @@ union inotify_event_buffer {
 
 #define laccess(path, mode) faccessat(AT_FDCWD, (path), (mode), AT_SYMLINK_NOFOLLOW)
 
-int chattr_fd(int fd, unsigned value, unsigned mask);
-int chattr_path(const char *p, unsigned value, unsigned mask);
-
-int read_attr_fd(int fd, unsigned *ret);
-int read_attr_path(const char *p, unsigned *ret);
-
 int syslog_parse_priority(const char **p, int *priority, bool with_facility);
 
 int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath);
index d94d8ab4ae64f21b9097f3e7a015ea3f1fdb185b..0c81001dbec4cb6598b1963d3c9db82e4b496381 100644 (file)
@@ -25,6 +25,7 @@
 #include "sd-event.h"
 
 #include "btrfs-util.h"
+#include "chattr-util.h"
 #include "copy.h"
 #include "fd-util.h"
 #include "fileio.h"
index 4d0ac770aab55c8b7becb3638a75bec9d68c6072..39759b50b04210d1e881833a7ba547d25c17b224 100644 (file)
@@ -26,6 +26,7 @@
 #include "sd-daemon.h"
 
 #include "btrfs-util.h"
+#include "chattr-util.h"
 #include "copy.h"
 #include "curl-util.h"
 #include "fd-util.h"
index a3b09dddff54430d5f699c8b3b85c9226f1eef0e..6f9b8a2915059ce560cbd1dc72fdcfe628c31cf3 100644 (file)
@@ -29,6 +29,7 @@
 #include <unistd.h>
 
 #include "btrfs-util.h"
+#include "chattr-util.h"
 #include "compress.h"
 #include "fd-util.h"
 #include "journal-authenticate.h"
index 5b3b6cd143f7a3fc7bf8b823e574451f43242ed2..ef5518136a52ba273c70c5ac3e3177db99bba31a 100644 (file)
@@ -42,6 +42,7 @@
 #include "bus-error.h"
 #include "bus-util.h"
 #include "catalog.h"
+#include "chattr-util.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fsprg.h"
index ca85e2609518890b5ab6cd04ef0d393d83d70f96..c5444ee0102abc12ee7fb7ab7909ef8f002af751 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/statfs.h>
 
 #include "btrfs-util.h"
+#include "chattr-util.h"
 #include "copy.h"
 #include "dirent-util.h"
 #include "fd-util.h"
index 85a2d6c2f5e0b41d5c4d3fb2f6cca355c7cb9360..8cf327a15f5d275d87be3d13c32fffcb4850584d 100644 (file)
@@ -41,6 +41,7 @@
 #include "acl-util.h"
 #include "btrfs-util.h"
 #include "capability.h"
+#include "chattr-util.h"
 #include "conf-files.h"
 #include "copy.h"
 #include "escape.h"