From 9db7081d83d56cd2523b03f9eb9d67ef1c93c55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 28 Mar 2023 18:42:24 +0200 Subject: [PATCH 1/3] Revert "udev_rules_parse_file: do not skip ENOENT" This reverts commit 42a467b55219384c7c3b137ab3cc8b6a309a8a14. We need to skip -ENOENT when loading udev rules because new files with rules may be added or removed at any time, and the loading of rules is triggered asynchronously. Even though the window is fairly narrow, udev shouldn't throw an error if a rules file is removed. --- src/udev/udev-rules.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index f7a1bb3bb00..a019f64c6c7 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -1436,8 +1436,12 @@ int udev_rules_parse_file(UdevRules *rules, const char *filename, bool extra_che assert(filename); f = fopen(filename, "re"); - if (!f) + if (!f) { + if (errno == ENOENT) + return 0; + return log_warning_errno(errno, "Failed to open %s, ignoring: %m", filename); + } if (fstat(fileno(f), &st) < 0) return log_warning_errno(errno, "Failed to stat %s, ignoring: %m", filename); From 3e2d73532812ab4f3b5cce11cf5dcc5a57af9163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 28 Mar 2023 18:44:40 +0200 Subject: [PATCH 2/3] basic/stat-util: remove unused null_or_empty_fd() --- src/basic/stat-util.c | 11 ----------- src/basic/stat-util.h | 1 - 2 files changed, 12 deletions(-) diff --git a/src/basic/stat-util.c b/src/basic/stat-util.c index 150605e86d5..6eaa3da4592 100644 --- a/src/basic/stat-util.c +++ b/src/basic/stat-util.c @@ -152,17 +152,6 @@ int null_or_empty_path_with_root(const char *fn, const char *root) { return null_or_empty(&st); } -int null_or_empty_fd(int fd) { - struct stat st; - - assert(fd >= 0); - - if (fstat(fd, &st) < 0) - return -errno; - - return null_or_empty(&st); -} - static int fd_is_read_only_fs(int fd) { struct statvfs st; diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index 4bf15a731d9..24684d5794a 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -30,7 +30,6 @@ static inline int dir_is_empty(const char *path, bool ignore_hidden_or_backup) { bool null_or_empty(struct stat *st) _pure_; int null_or_empty_path_with_root(const char *fn, const char *root); -int null_or_empty_fd(int fd); static inline int null_or_empty_path(const char *fn) { return null_or_empty_path_with_root(fn, NULL); From 7d0c47dad0d4282c3924a654a8fe18fc5d7766f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 28 Mar 2023 18:50:31 +0200 Subject: [PATCH 3/3] shared/exec-util: null_or_empty_path() does not return boolean We shouldn't report that the file is empty if the stating fails. Let's do the same as in other places, and just ignore the error and let the subsequent operation fail. --- src/shared/exec-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index ac68cbc4cb1..a2e8f428e69 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -39,7 +39,7 @@ static int do_spawn(const char *path, char *argv[], int stdout_fd, pid_t *pid, b pid_t _pid; int r; - if (null_or_empty_path(path)) { + if (null_or_empty_path(path) > 0) { log_debug("%s is empty (a mask).", path); return 0; }