ryantimwilson / rpms / systemd

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