summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2018-04-27 18:11:26 +0200
committerFranck Bui <fbui@suse.com>2018-07-30 15:54:03 +0200
commita2fc2f8dd30c17ad1e23a31fc6ff2aeba4c6fa27 (patch)
treeba1223bab3bce21a47359934d152fba9bdc00d03
parent5494602195f5300db8b2eac7c2b77b922d0ceddf (diff)
downloadsystemd-a2fc2f8dd30c17ad1e23a31fc6ff2aeba4c6fa27.tar.gz
systemd-a2fc2f8dd30c17ad1e23a31fc6ff2aeba4c6fa27.tar.bz2
systemd-a2fc2f8dd30c17ad1e23a31fc6ff2aeba4c6fa27.zip
tmpfiles: introduce create_fifo()
-rw-r--r--src/tmpfiles/tmpfiles.c85
1 files changed, 46 insertions, 39 deletions
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 7b8c4bb53f..a934cbff91 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -1714,6 +1714,49 @@ static int create_device(Item *i, mode_t file_type) {
return fd_set_perms(i, fd, NULL);
}
+static int create_fifo(Item *i, const char *path) {
+ CreationMode creation;
+ struct stat st;
+ int r;
+
+ RUN_WITH_UMASK(0000) {
+ mac_selinux_create_file_prepare(path, S_IFIFO);
+ r = mkfifo(path, i->mode);
+ mac_selinux_create_file_clear();
+ }
+
+ if (r < 0) {
+ if (errno != EEXIST)
+ return log_error_errno(errno, "Failed to create fifo %s: %m", path);
+
+ if (lstat(path, &st) < 0)
+ return log_error_errno(errno, "stat(%s) failed: %m", path);
+
+ if (!S_ISFIFO(st.st_mode)) {
+
+ if (i->force) {
+ RUN_WITH_UMASK(0000) {
+ mac_selinux_create_file_prepare(path, S_IFIFO);
+ r = mkfifo_atomic(path, i->mode);
+ mac_selinux_create_file_clear();
+ }
+
+ if (r < 0)
+ return log_error_errno(r, "Failed to create fifo %s: %m", path);
+ creation = CREATION_FORCE;
+ } else {
+ log_warning("\"%s\" already exists and is not a fifo.", path);
+ return 0;
+ }
+ } else
+ creation = CREATION_EXISTING;
+ } else
+ creation = CREATION_NORMAL;
+ log_debug("%s fifo \"%s\".", creation_mode_verb_to_string(creation), path);
+
+ return path_set_perms(i, path);
+}
+
typedef int (*action_t)(Item *, const char *);
typedef int (*fdaction_t)(Item *, int fd, const struct stat *st);
@@ -1827,9 +1870,8 @@ static int glob_item_recursively(Item *i, fdaction_t action) {
}
static int create_item(Item *i) {
- struct stat st;
- int r = 0;
CreationMode creation;
+ int r = 0;
assert(i);
@@ -1905,47 +1947,12 @@ static int create_item(Item *i) {
break;
case CREATE_FIFO:
- RUN_WITH_UMASK(0000) {
+ RUN_WITH_UMASK(0000)
(void) mkdir_parents_label(i->path, 0755);
- mac_selinux_create_file_prepare(i->path, S_IFIFO);
- r = mkfifo(i->path, i->mode);
- mac_selinux_create_file_clear();
- }
-
- if (r < 0) {
- if (errno != EEXIST)
- return log_error_errno(errno, "Failed to create fifo %s: %m", i->path);
-
- if (lstat(i->path, &st) < 0)
- return log_error_errno(errno, "stat(%s) failed: %m", i->path);
-
- if (!S_ISFIFO(st.st_mode)) {
-
- if (i->force) {
- RUN_WITH_UMASK(0000) {
- mac_selinux_create_file_prepare(i->path, S_IFIFO);
- r = mkfifo_atomic(i->path, i->mode);
- mac_selinux_create_file_clear();
- }
-
- if (r < 0)
- return log_error_errno(r, "Failed to create fifo %s: %m", i->path);
- creation = CREATION_FORCE;
- } else {
- log_warning("\"%s\" already exists and is not a fifo.", i->path);
- return 0;
- }
- } else
- creation = CREATION_EXISTING;
- } else
- creation = CREATION_NORMAL;
- log_debug("%s fifo \"%s\".", creation_mode_verb_to_string(creation), i->path);
-
- r = path_set_perms(i, i->path);
+ r = create_fifo(i, i->path);
if (r < 0)
return r;
-
break;
case CREATE_SYMLINK: {