|
|
4eda52 |
From 969b05b3f1dc644e821756205450b06a30c79d7f Mon Sep 17 00:00:00 2001
|
|
|
4295f9 |
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
|
4295f9 |
Date: Sun, 12 Sep 2021 16:14:27 +0900
|
|
|
4295f9 |
Subject: [PATCH] udev-node: do not ignore unexpected errors on removing
|
|
|
4295f9 |
symlink in stack directory
|
|
|
4295f9 |
|
|
|
4295f9 |
Only acceptable error here is -ENOENT.
|
|
|
4295f9 |
|
|
|
4295f9 |
(cherry picked from commit 0706cdf4ec92d6bd40391da0e81a30d9bf851663)
|
|
|
4295f9 |
|
|
|
4eda52 |
Related: #2005024
|
|
|
4295f9 |
---
|
|
|
4295f9 |
src/udev/udev-node.c | 23 ++++++++++++++---------
|
|
|
4295f9 |
1 file changed, 14 insertions(+), 9 deletions(-)
|
|
|
4295f9 |
|
|
|
4295f9 |
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c
|
|
|
4295f9 |
index 61cb9a449b..e1fb387cb9 100644
|
|
|
4295f9 |
--- a/src/udev/udev-node.c
|
|
|
4295f9 |
+++ b/src/udev/udev-node.c
|
|
|
4295f9 |
@@ -334,25 +334,30 @@ static int update_stack_directory(sd_device *dev, const char *dirname, bool add)
|
|
|
4295f9 |
return log_oom_debug();
|
|
|
4295f9 |
|
|
|
4295f9 |
if (!add) {
|
|
|
4295f9 |
- bool unlink_failed = false;
|
|
|
4295f9 |
+ int unlink_error = 0, stat_error = 0;
|
|
|
4295f9 |
|
|
|
4295f9 |
if (stat(dirname, &st) < 0) {
|
|
|
4295f9 |
if (errno == ENOENT)
|
|
|
4295f9 |
return 0; /* The stack directory is already removed. That's OK. */
|
|
|
4295f9 |
- log_device_debug_errno(dev, errno, "Failed to stat %s, ignoring: %m", dirname);
|
|
|
4295f9 |
+ stat_error = -errno;
|
|
|
4295f9 |
}
|
|
|
4295f9 |
|
|
|
4295f9 |
- if (unlink(filename) < 0) {
|
|
|
4295f9 |
- unlink_failed = true;
|
|
|
4295f9 |
- if (errno != ENOENT)
|
|
|
4295f9 |
- log_device_debug_errno(dev, errno, "Failed to remove %s, ignoring: %m", filename);
|
|
|
4295f9 |
- }
|
|
|
4295f9 |
+ if (unlink(filename) < 0)
|
|
|
4295f9 |
+ unlink_error = -errno;
|
|
|
4295f9 |
|
|
|
4295f9 |
if (rmdir(dirname) >= 0 || errno == ENOENT)
|
|
|
4295f9 |
return 0;
|
|
|
4295f9 |
|
|
|
4295f9 |
- if (unlink_failed)
|
|
|
4295f9 |
- return 0; /* If we failed to remove the symlink, there is almost nothing we can do. */
|
|
|
4295f9 |
+ if (unlink_error < 0) {
|
|
|
4295f9 |
+ if (unlink_error == -ENOENT)
|
|
|
4295f9 |
+ return 0;
|
|
|
4295f9 |
+
|
|
|
4295f9 |
+ /* If we failed to remove the symlink, then there is almost nothing we can do. */
|
|
|
4295f9 |
+ return log_device_debug_errno(dev, unlink_error, "Failed to remove %s: %m", filename);
|
|
|
4295f9 |
+ }
|
|
|
4295f9 |
+
|
|
|
4295f9 |
+ if (stat_error < 0)
|
|
|
4295f9 |
+ return log_device_debug_errno(dev, stat_error, "Failed to stat %s: %m", dirname);
|
|
|
4295f9 |
|
|
|
4295f9 |
/* The symlink was removed. Check if the timestamp of directory is changed. */
|
|
|
4295f9 |
r = update_timestamp(dev, dirname, &st);
|