|
|
2aacef |
From 2f79547e8bbb5434a84c0b07c30fff63b351590c Mon Sep 17 00:00:00 2001
|
|
|
2aacef |
From: Luca Boccassi <bluca@debian.org>
|
|
|
2aacef |
Date: Thu, 10 Nov 2022 15:47:19 +0000
|
|
|
2aacef |
Subject: [PATCH] tmpfiles: log at info level when some allowed failures occur
|
|
|
2aacef |
|
|
|
2aacef |
In provision.conf we ship:
|
|
|
2aacef |
|
|
|
2aacef |
d- /root :0700 root :root -
|
|
|
2aacef |
d- /root/.ssh :0700 root :root -
|
|
|
2aacef |
|
|
|
2aacef |
These are allowed to fail, for example on a read-only filesystem. But they still
|
|
|
2aacef |
log at error level, which is annoying and gets flagged. Tune those specific errors
|
|
|
2aacef |
down to info.
|
|
|
2aacef |
|
|
|
2aacef |
There are likely more that could be tuned down, but the important thing is to cover
|
|
|
2aacef |
the tmpfiles.d that we ship right now.
|
|
|
2aacef |
|
|
|
2aacef |
Before:
|
|
|
2aacef |
|
|
|
2aacef |
$ echo -e "d- /root :0700 root :root - \nd- /root/.ssh :0700 root :root -" | SYSTEMD_LOG_LEVEL=err build/systemd-tmpfiles --root=/tmp/img --create -
|
|
|
2aacef |
Failed to create directory or subvolume "/tmp/img/root": Read-only file system
|
|
|
2aacef |
Failed to open path '/tmp/img/root': No such file or directory
|
|
|
2aacef |
$
|
|
|
2aacef |
|
|
|
2aacef |
After:
|
|
|
2aacef |
|
|
|
2aacef |
$ echo -e "d- /root :0700 root :root - \nd- /root/.ssh :0700 root :root -" | SYSTEMD_LOG_LEVEL=err build/systemd-tmpfiles --root=/tmp/img --create -
|
|
|
2aacef |
$
|
|
|
2aacef |
|
|
|
2aacef |
(cherry picked from commit 244c2a8344c01e94cd9bdf835de998b89bc53179)
|
|
|
2aacef |
|
|
|
2aacef |
Related: #2138081
|
|
|
2aacef |
---
|
|
|
2aacef |
src/tmpfiles/tmpfiles.c | 49 +++++++++++++++++++++++++++--------------
|
|
|
2aacef |
1 file changed, 33 insertions(+), 16 deletions(-)
|
|
|
2aacef |
|
|
|
2aacef |
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
|
|
|
2aacef |
index 784b895577..18bb75715b 100644
|
|
|
2aacef |
--- a/src/tmpfiles/tmpfiles.c
|
|
|
2aacef |
+++ b/src/tmpfiles/tmpfiles.c
|
|
|
2aacef |
@@ -961,22 +961,34 @@ shortcut:
|
|
|
2aacef |
return label_fix_full(fd, /* inode_path= */ NULL, /* label_path= */ path, 0);
|
|
|
2aacef |
}
|
|
|
2aacef |
|
|
|
2aacef |
-static int path_open_parent_safe(const char *path) {
|
|
|
2aacef |
+static int path_open_parent_safe(const char *path, bool allow_failure) {
|
|
|
2aacef |
_cleanup_free_ char *dn = NULL;
|
|
|
2aacef |
int r, fd;
|
|
|
2aacef |
|
|
|
2aacef |
if (!path_is_normalized(path))
|
|
|
2aacef |
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to open parent of '%s': path not normalized.", path);
|
|
|
2aacef |
+ return log_full_errno(allow_failure ? LOG_INFO : LOG_ERR,
|
|
|
2aacef |
+ SYNTHETIC_ERRNO(EINVAL),
|
|
|
2aacef |
+ "Failed to open parent of '%s': path not normalized%s.",
|
|
|
2aacef |
+ path,
|
|
|
2aacef |
+ allow_failure ? ", ignoring" : "");
|
|
|
2aacef |
|
|
|
2aacef |
r = path_extract_directory(path, &dn;;
|
|
|
2aacef |
if (r < 0)
|
|
|
2aacef |
- return log_error_errno(r, "Unable to determine parent directory of '%s': %m", path);
|
|
|
2aacef |
+ return log_full_errno(allow_failure ? LOG_INFO : LOG_ERR,
|
|
|
2aacef |
+ r,
|
|
|
2aacef |
+ "Unable to determine parent directory of '%s'%s: %m",
|
|
|
2aacef |
+ path,
|
|
|
2aacef |
+ allow_failure ? ", ignoring" : "");
|
|
|
2aacef |
|
|
|
2aacef |
- r = chase_symlinks(dn, arg_root, CHASE_SAFE|CHASE_WARN, NULL, &fd;;
|
|
|
2aacef |
+ r = chase_symlinks(dn, arg_root, allow_failure ? CHASE_SAFE : CHASE_SAFE|CHASE_WARN, NULL, &fd;;
|
|
|
2aacef |
if (r == -ENOLINK) /* Unsafe symlink: already covered by CHASE_WARN */
|
|
|
2aacef |
return r;
|
|
|
2aacef |
if (r < 0)
|
|
|
2aacef |
- return log_error_errno(r, "Failed to open path '%s': %m", dn);
|
|
|
2aacef |
+ return log_full_errno(allow_failure ? LOG_INFO : LOG_ERR,
|
|
|
2aacef |
+ r,
|
|
|
2aacef |
+ "Failed to open path '%s'%s: %m",
|
|
|
2aacef |
+ dn,
|
|
|
2aacef |
+ allow_failure ? ", ignoring" : "");
|
|
|
2aacef |
|
|
|
2aacef |
return fd;
|
|
|
2aacef |
}
|
|
|
2aacef |
@@ -1431,7 +1443,7 @@ static int write_one_file(Item *i, const char *path, CreationMode creation) {
|
|
|
2aacef |
|
|
|
2aacef |
/* Validate the path and keep the fd on the directory for opening the file so we're sure that it
|
|
|
2aacef |
* can't be changed behind our back. */
|
|
|
2aacef |
- dir_fd = path_open_parent_safe(path);
|
|
|
2aacef |
+ dir_fd = path_open_parent_safe(path, i->allow_failure);
|
|
|
2aacef |
if (dir_fd < 0)
|
|
|
2aacef |
return dir_fd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1481,7 +1493,7 @@ static int create_file(Item *i, const char *path) {
|
|
|
2aacef |
|
|
|
2aacef |
/* Validate the path and keep the fd on the directory for opening the file so we're sure that it
|
|
|
2aacef |
* can't be changed behind our back. */
|
|
|
2aacef |
- dir_fd = path_open_parent_safe(path);
|
|
|
2aacef |
+ dir_fd = path_open_parent_safe(path, i->allow_failure);
|
|
|
2aacef |
if (dir_fd < 0)
|
|
|
2aacef |
return dir_fd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1549,7 +1561,7 @@ static int truncate_file(Item *i, const char *path) {
|
|
|
2aacef |
|
|
|
2aacef |
/* Validate the path and keep the fd on the directory for opening the file so we're sure that it
|
|
|
2aacef |
* can't be changed behind our back. */
|
|
|
2aacef |
- dir_fd = path_open_parent_safe(path);
|
|
|
2aacef |
+ dir_fd = path_open_parent_safe(path, i->allow_failure);
|
|
|
2aacef |
if (dir_fd < 0)
|
|
|
2aacef |
return dir_fd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1628,7 +1640,7 @@ static int copy_files(Item *i) {
|
|
|
2aacef |
|
|
|
2aacef |
/* Validate the path and use the returned directory fd for copying the target so we're sure that the
|
|
|
2aacef |
* path can't be changed behind our back. */
|
|
|
2aacef |
- dfd = path_open_parent_safe(i->path);
|
|
|
2aacef |
+ dfd = path_open_parent_safe(i->path, i->allow_failure);
|
|
|
2aacef |
if (dfd < 0)
|
|
|
2aacef |
return dfd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1664,6 +1676,7 @@ static int create_directory_or_subvolume(
|
|
|
2aacef |
const char *path,
|
|
|
2aacef |
mode_t mode,
|
|
|
2aacef |
bool subvol,
|
|
|
2aacef |
+ bool allow_failure,
|
|
|
2aacef |
struct stat *ret_st,
|
|
|
2aacef |
CreationMode *ret_creation) {
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1679,7 +1692,7 @@ static int create_directory_or_subvolume(
|
|
|
2aacef |
if (r < 0)
|
|
|
2aacef |
return log_error_errno(r, "Failed to extract filename from path '%s': %m", path);
|
|
|
2aacef |
|
|
|
2aacef |
- pfd = path_open_parent_safe(path);
|
|
|
2aacef |
+ pfd = path_open_parent_safe(path, allow_failure);
|
|
|
2aacef |
if (pfd < 0)
|
|
|
2aacef |
return pfd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1720,7 +1733,11 @@ static int create_directory_or_subvolume(
|
|
|
2aacef |
|
|
|
2aacef |
/* Then look at the original error */
|
|
|
2aacef |
if (r < 0)
|
|
|
2aacef |
- return log_error_errno(r, "Failed to create directory or subvolume \"%s\": %m", path);
|
|
|
2aacef |
+ return log_full_errno(allow_failure ? LOG_INFO : LOG_ERR,
|
|
|
2aacef |
+ r,
|
|
|
2aacef |
+ "Failed to create directory or subvolume \"%s\"%s: %m",
|
|
|
2aacef |
+ path,
|
|
|
2aacef |
+ allow_failure ? ", ignoring" : "");
|
|
|
2aacef |
|
|
|
2aacef |
return log_error_errno(errno, "Failed to open directory/subvolume we just created '%s': %m", path);
|
|
|
2aacef |
}
|
|
|
2aacef |
@@ -1748,7 +1765,7 @@ static int create_directory(Item *i, const char *path) {
|
|
|
2aacef |
assert(i);
|
|
|
2aacef |
assert(IN_SET(i->type, CREATE_DIRECTORY, TRUNCATE_DIRECTORY));
|
|
|
2aacef |
|
|
|
2aacef |
- fd = create_directory_or_subvolume(path, i->mode, /* subvol= */ false, &st, &creation);
|
|
|
2aacef |
+ fd = create_directory_or_subvolume(path, i->mode, /* subvol= */ false, i->allow_failure, &st, &creation);
|
|
|
2aacef |
if (fd == -EEXIST)
|
|
|
2aacef |
return 0;
|
|
|
2aacef |
if (fd < 0)
|
|
|
2aacef |
@@ -1766,7 +1783,7 @@ static int create_subvolume(Item *i, const char *path) {
|
|
|
2aacef |
assert(i);
|
|
|
2aacef |
assert(IN_SET(i->type, CREATE_SUBVOLUME, CREATE_SUBVOLUME_NEW_QUOTA, CREATE_SUBVOLUME_INHERIT_QUOTA));
|
|
|
2aacef |
|
|
|
2aacef |
- fd = create_directory_or_subvolume(path, i->mode, /* subvol = */ true, &st, &creation);
|
|
|
2aacef |
+ fd = create_directory_or_subvolume(path, i->mode, /* subvol = */ true, i->allow_failure, &st, &creation);
|
|
|
2aacef |
if (fd == -EEXIST)
|
|
|
2aacef |
return 0;
|
|
|
2aacef |
if (fd < 0)
|
|
|
2aacef |
@@ -1845,7 +1862,7 @@ static int create_device(Item *i, mode_t file_type) {
|
|
|
2aacef |
|
|
|
2aacef |
/* Validate the path and use the returned directory fd for copying the target so we're sure that the
|
|
|
2aacef |
* path can't be changed behind our back. */
|
|
|
2aacef |
- dfd = path_open_parent_safe(i->path);
|
|
|
2aacef |
+ dfd = path_open_parent_safe(i->path, i->allow_failure);
|
|
|
2aacef |
if (dfd < 0)
|
|
|
2aacef |
return dfd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -1947,7 +1964,7 @@ static int create_fifo(Item *i) {
|
|
|
2aacef |
if (r == O_DIRECTORY)
|
|
|
2aacef |
return log_error_errno(SYNTHETIC_ERRNO(EISDIR), "Cannot open path '%s' for creating FIFO, is a directory.", i->path);
|
|
|
2aacef |
|
|
|
2aacef |
- pfd = path_open_parent_safe(i->path);
|
|
|
2aacef |
+ pfd = path_open_parent_safe(i->path, i->allow_failure);
|
|
|
2aacef |
if (pfd < 0)
|
|
|
2aacef |
return pfd;
|
|
|
2aacef |
|
|
|
2aacef |
@@ -2032,7 +2049,7 @@ static int create_symlink(Item *i) {
|
|
|
2aacef |
if (r == O_DIRECTORY)
|
|
|
2aacef |
return log_error_errno(SYNTHETIC_ERRNO(EISDIR), "Cannot open path '%s' for creating FIFO, is a directory.", i->path);
|
|
|
2aacef |
|
|
|
2aacef |
- pfd = path_open_parent_safe(i->path);
|
|
|
2aacef |
+ pfd = path_open_parent_safe(i->path, i->allow_failure);
|
|
|
2aacef |
if (pfd < 0)
|
|
|
2aacef |
return pfd;
|
|
|
2aacef |
|