teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0511-tmpfiles-with-e-don-t-attempt-to-set-permissions-whe.patch

ecbff1
From 797dafce1bb9c3bb16da043f654391dc29075a1a Mon Sep 17 00:00:00 2001
ecbff1
From: Michal Sekletar <msekleta@redhat.com>
ecbff1
Date: Mon, 28 Aug 2017 17:33:24 +0200
ecbff1
Subject: [PATCH] tmpfiles: with "e" don't attempt to set permissions when file
ecbff1
 doesn't exist
ecbff1
ecbff1
tmpfiles.d option "e" when run through systemd-tmpfiles --create should
ecbff1
apply configured permissions (uid,gid) only to already existing
ecbff1
files. When file doesn't exist we bail out with error. Instead we should
ecbff1
silently ignore non-existing files.
ecbff1
ecbff1
$ useradd test
ecbff1
$ cat /etc/tmpfiles.d/foobar.conf
ecbff1
e /tmp/test - test test 1d
ecbff1
$ ls -l /tmp/test
ecbff1
ls: cannot access '/tmp/test': No such file or directory
ecbff1
ecbff1
Before:
ecbff1
$ systemd-tmpfiles --create /etc/tmpfiles.d/foobar.conf
ecbff1
Adjusting owner and mode for /tmp/test failed: No such file or directory
ecbff1
$ echo $?
ecbff1
1
ecbff1
ecbff1
After:
ecbff1
$ systemd-tmpfiles --create /etc/tmpfiles.d/foobar.conf
ecbff1
$ echo $?
ecbff1
0
ecbff1
ecbff1
(cherry picked from commit 3caf791a1702c97b99d2647c9d465af404f2913d)
ecbff1
ecbff1
Conflicts:
ecbff1
	src/tmpfiles/tmpfiles.c
ecbff1
ecbff1
Resolves: #1445732
ecbff1
---
ecbff1
 src/tmpfiles/tmpfiles.c | 16 ++++++++++++++--
ecbff1
 1 file changed, 14 insertions(+), 2 deletions(-)
ecbff1
ecbff1
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
ecbff1
index df7676b57..ed35b8cf0 100644
ecbff1
--- a/src/tmpfiles/tmpfiles.c
ecbff1
+++ b/src/tmpfiles/tmpfiles.c
ecbff1
@@ -585,8 +585,20 @@ static int path_set_perms(Item *i, const char *path) {
ecbff1
          * O_PATH. */
ecbff1
 
ecbff1
         fd = open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH|O_NOATIME);
ecbff1
-        if (fd < 0)
ecbff1
-                return log_error_errno(errno, "Adjusting owner and mode for %s failed: %m", path);
ecbff1
+        if (fd < 0) {
ecbff1
+                int level = LOG_ERR, r = -errno;
ecbff1
+
ecbff1
+                /* Option "e" operates only on existing objects. Do not
ecbff1
+                 * print errors about non-existent files or directories */
ecbff1
+                if (i->type == EMPTY_DIRECTORY && errno == ENOENT) {
ecbff1
+                        level = LOG_DEBUG;
ecbff1
+                        r = 0;
ecbff1
+                }
ecbff1
+
ecbff1
+                log_full_errno(level, errno, "Adjusting owner and mode for %s failed: %m", path);
ecbff1
+
ecbff1
+                return r;
ecbff1
+        }
ecbff1
 
ecbff1
         if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0)
ecbff1
                 return log_error_errno(errno, "Failed to fstat() file %s: %m", path);