From: Michal Sekletar Date: Thu, 31 Aug 2017 10:45:25 +0000 (+0200) Subject: tmpfiles: with "e" don't attempt to set permissions when file doesn't exist (#6682) X-Git-Tag: v235~190 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=780e2ee187e373565f9ded2859f8c6c7760b814a;p=platform%2Fupstream%2Fsystemd.git tmpfiles: with "e" don't attempt to set permissions when file doesn't exist (#6682) tmpfiles.d option "e" when run through systemd-tmpfiles --create should apply configured permissions (uid,gid) only to already existing files. When file doesn't exist we bail out with error. Instead we should silently ignore non-existing files. $ useradd test $ cat /etc/tmpfiles.d/foobar.conf e /tmp/test - test test 1d $ ls -l /tmp/test ls: cannot access '/tmp/test': No such file or directory Before: $ systemd-tmpfiles --create /etc/tmpfiles.d/foobar.conf Adjusting owner and mode for /tmp/test failed: No such file or directory $ echo $? 1 After: $ systemd-tmpfiles --create /etc/tmpfiles.d/foobar.conf $ echo $? 0 --- diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 2ab0cd1..8f960cc 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -617,8 +617,20 @@ static int path_set_perms(Item *i, const char *path) { * O_PATH. */ fd = open(path, O_NOFOLLOW|O_CLOEXEC|O_PATH); - if (fd < 0) - return log_error_errno(errno, "Adjusting owner and mode for %s failed: %m", path); + if (fd < 0) { + int level = LOG_ERR, r = -errno; + + /* Option "e" operates only on existing objects. Do not + * print errors about non-existent files or directories */ + if (i->type == EMPTY_DIRECTORY && errno == ENOENT) { + level = LOG_DEBUG; + r = 0; + } + + log_full_errno(level, errno, "Adjusting owner and mode for %s failed: %m", path); + + return r; + } if (fstatat(fd, "", &st, AT_EMPTY_PATH) < 0) return log_error_errno(errno, "Failed to fstat() file %s: %m", path);