From ecc1709c2c216ef9e3035dac3b40abfcc6609094 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Jan 2018 15:29:30 +0100 Subject: [PATCH 1/6] tmpfiles: fold five lines into two log_full_errno() has all these nice benefits, let's make use of them to shorten five lines into two. --- src/tmpfiles/tmpfiles.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 96ffa42089..66dabc74f1 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -547,11 +547,8 @@ static int dir_cleanup( continue; /* FUSE, NFS mounts, SELinux might return EACCES */ - if (errno == EACCES) - log_debug_errno(errno, "stat(%s/%s) failed: %m", p, dent->d_name); - else - log_error_errno(errno, "stat(%s/%s) failed: %m", p, dent->d_name); - r = -errno; + r = log_full_errno(errno == EACCES ? LOG_DEBUG : LOG_ERR, errno, + "stat(%s/%s) failed: %m", p, dent->d_name); continue; } From 920ce828524afee08a01a73f63205df5dc2c134b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Jan 2018 15:31:01 +0100 Subject: [PATCH 2/6] tmpfiles: in dir_cleanup() take benefit that log_error_errno() returns the error code passed in --- src/tmpfiles/tmpfiles.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 66dabc74f1..128abb835e 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -652,10 +652,8 @@ static int dir_cleanup( log_debug("Removing directory \"%s\".", sub_path); if (unlinkat(dirfd(d), dent->d_name, AT_REMOVEDIR) < 0) - if (!IN_SET(errno, ENOENT, ENOTEMPTY)) { - log_error_errno(errno, "rmdir(%s): %m", sub_path); - r = -errno; - } + if (!IN_SET(errno, ENOENT, ENOTEMPTY)) + r = log_error_errno(errno, "rmdir(%s): %m", sub_path); } else { /* Skip files for which the sticky bit is From 201be4265ff8ce4e66f8a071ca588b2ed8869f61 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Jan 2018 15:31:50 +0100 Subject: [PATCH 3/6] tmpfiles: avoid using wrong type for strlen() result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The result of strlen is size_t, hence let's not store it in an "int" just to pass it on as as size_t right-away. In fact let's not store it at all… --- src/tmpfiles/tmpfiles.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 128abb835e..f96f400aa0 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -877,11 +877,8 @@ static int path_set_xattrs(Item *i, const char *path) { assert(path); STRV_FOREACH_PAIR(name, value, i->xattrs) { - int n; - - n = strlen(*value); log_debug("Setting extended attribute '%s=%s' on %s.", *name, *value, path); - if (lsetxattr(path, *name, *value, n, 0) < 0) + if (lsetxattr(path, *name, *value, strlen(*value), 0) < 0) return log_error_errno(errno, "Setting extended attribute %s=%s on %s failed: %m", *name, *value, path); } From 07982ed1efcf7c1d3eee7fe15731e6bd24b5d176 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Jan 2018 15:32:57 +0100 Subject: [PATCH 4/6] tmpfiles: add missing OOM check --- src/tmpfiles/tmpfiles.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index f96f400aa0..d4a606ffbc 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -2261,6 +2261,9 @@ static int parse_line(const char *fname, unsigned line, const char *buffer, bool } } else { existing = new0(ItemArray, 1); + if (!existing) + return log_oom(); + r = ordered_hashmap_put(h, i.path, existing); if (r < 0) return log_oom(); From 79c91cecc78eb435c92640109ebbbbc5467501f2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Jan 2018 15:33:13 +0100 Subject: [PATCH 5/6] tmpfiles: use the DEBUG_LOGGING macro where applicable --- src/tmpfiles/tmpfiles.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index d4a606ffbc..a090d86a6c 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -2524,7 +2524,7 @@ int main(int argc, char *argv[]) { } } - { + if (DEBUG_LOGGING) { _cleanup_free_ char *t = NULL; t = strv_join(config_dirs, "\n\t"); From 586a8e93a0ea0f99d685ce01017e79cf8833547c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 22 Jan 2018 15:33:26 +0100 Subject: [PATCH 6/6] update TODO --- TODO | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TODO b/TODO index ae6791df7f..dde2cbb4f7 100644 --- a/TODO +++ b/TODO @@ -24,6 +24,8 @@ Janitorial Clean-ups: Features: +* there should be path_hash_ops and we should use it in tmpfiles' hashmap object to deal with identical but differently spelt paths + * rework pid watching logic, allow any number of units watch the same pid * be stricter with fds we receive for the fdstore: close them asynchronously