diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-06-02 15:29:29 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-07-20 17:46:40 +0200 |
commit | 8a20311c6d145b0d6738a54d827b9df0b34f187e (patch) | |
tree | 2d22d240c12b2385020ea58a35a058b68fcaa027 | |
parent | 1733a1fbb6aa30531445145f2b0e761c8363ba7d (diff) | |
download | systemd-8a20311c6d145b0d6738a54d827b9df0b34f187e.tar.gz |
pid1: reduce log noise generated by devices with overly long sysfs paths
This basically does what 2c905207db37c691d4abef868165ad5ea2dd0f4f did
for mount units
Fixes: #16161
(cherry picked from commit ad172d19d5ef8b5a3631a8484cc3d1a28dba26c2)
(cherry picked from commit 7f035c549fdc0660431d48f1f7dcb7fc41bad22c)
-rw-r--r-- | src/core/device.c | 31 | ||||
-rw-r--r-- | src/systemd/sd-messages.h | 4 |
2 files changed, 33 insertions, 2 deletions
diff --git a/src/core/device.c b/src/core/device.c index 9a1d88270d..a3a3bdf157 100644 --- a/src/core/device.c +++ b/src/core/device.c @@ -3,6 +3,8 @@ #include <errno.h> #include <sys/epoll.h> +#include "sd-messages.h" + #include "alloc-util.h" #include "bus-error.h" #include "dbus-device.h" @@ -13,6 +15,7 @@ #include "log.h" #include "parse-util.h" #include "path-util.h" +#include "ratelimit.h" #include "serialize.h" #include "stat-util.h" #include "string-util.h" @@ -499,8 +502,32 @@ static int device_setup_unit(Manager *m, sd_device *dev, const char *path, bool } r = unit_name_from_path(path, ".device", &e); - if (r < 0) - return log_device_error_errno(dev, r, "Failed to generate unit name from device path: %m"); + if (r < 0) { + /* Let's complain about overly long device names only at most once every 5s or so. This is + * something we should mention, since relevant devices are not manageable by systemd, but not + * flood the log about. */ + static RateLimit rate_limit = { + .interval = 5 * USEC_PER_SEC, + .burst = 1, + }; + + /* If we cannot convert a device name to a unit name then let's ignore the device. So far, + * devices with such long names weren't really the kind you want to manage with systemd + * anyway, hence this shouldn't be a problem. */ + + if (r == -ENAMETOOLONG) + return log_struct_errno( + ratelimit_below(&rate_limit) ? LOG_WARNING : LOG_DEBUG, r, + "MESSAGE_ID=" SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE_STR, + "DEVICE=%s", path, + LOG_MESSAGE("Device path '%s' too long to fit into unit name, ignoring device.", path)); + + return log_struct_errno( + ratelimit_below(&rate_limit) ? LOG_WARNING : LOG_DEBUG, r, + "MESSAGE_ID=" SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE_STR, + "DEVICE=%s", path, + LOG_MESSAGE("Failed to generate valid unit name from device path '%s', ignoring device: %m", path)); + } u = manager_get_unit(m, e); if (u) { diff --git a/src/systemd/sd-messages.h b/src/systemd/sd-messages.h index 97ba02ffa8..aee0ddb686 100644 --- a/src/systemd/sd-messages.h +++ b/src/systemd/sd-messages.h @@ -170,6 +170,10 @@ _SD_BEGIN_DECLARATIONS; SD_ID128_MAKE(1b,3b,b9,40,37,f0,4b,bf,81,02,8e,13,5a,12,d2,93) #define SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE_STR \ SD_ID128_MAKE_STR(1b,3b,b9,40,37,f0,4b,bf,81,02,8e,13,5a,12,d2,93) +#define SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE \ + SD_ID128_MAKE(01,01,90,13,8f,49,4e,29,a0,ef,66,69,74,95,31,aa) +#define SD_MESSAGE_DEVICE_PATH_NOT_SUITABLE_STR \ + SD_ID128_MAKE_STR(01,01,90,13,8f,49,4e,29,a0,ef,66,69,74,95,31,aa) #define SD_MESSAGE_NOBODY_USER_UNSUITABLE SD_ID128_MAKE(b4,80,32,5f,9c,39,4a,7b,80,2c,23,1e,51,a2,75,2c) #define SD_MESSAGE_NOBODY_USER_UNSUITABLE_STR \ |