]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pid1: reduce log noise generated by devices with overly long sysfs paths
authorLennart Poettering <lennart@poettering.net>
Wed, 2 Jun 2021 13:29:29 +0000 (15:29 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Jun 2021 13:01:05 +0000 (15:01 +0200)
This basically does what 2c905207db37c691d4abef868165ad5ea2dd0f4f did
for mount units

Fixes: #16161
src/core/device.c
src/systemd/sd-messages.h

index d188b0cd2227b3c1ba91ea82e80b030741e82685..03a2a9f22a2ddca9f9277e40ea0d607eead996b1 100644 (file)
@@ -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"
@@ -12,6 +14,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"
@@ -497,8 +500,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) {
index 97ba02ffa83c3ae6a5df11e06b7bb9e1e8c78e77..aee0ddb686314fcd7c15b1190cbdbae3a4a95815 100644 (file)
@@ -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 \