From d7cb60daf6d3769f1e26753195d62e8fcee025fa Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 19 Jan 2022 16:07:26 +0900 Subject: [PATCH 1/3] sd-device: add more debugging logs in device_set_syspath() On failure, the function previously sometimes logs in debug level, but sometimes does not. Let's always log the error cause. --- src/libsystemd/sd-device/sd-device.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index ece01e35f73..92a7ededf6d 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -152,7 +152,9 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { if (verify) { r = chase_symlinks(_syspath, NULL, 0, &syspath, NULL); if (r == -ENOENT) - return -ENODEV; /* the device does not exist (any more?) */ + /* the device does not exist (any more?) */ + return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), + "sd-device: Failed to chase symlinks in \"%s\".", _syspath); if (r < 0) return log_debug_errno(r, "sd-device: Failed to get target of '%s': %m", _syspath); @@ -173,7 +175,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { new_syspath = path_join("/sys", p); if (!new_syspath) - return -ENOMEM; + return log_oom_debug(); free_and_replace(syspath, new_syspath); path_simplify(syspath); @@ -187,30 +189,31 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) { if (access(path, F_OK) < 0) { if (errno == ENOENT) /* this is not a valid device */ - return -ENODEV; + return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), + "sd-device: the uevent file \"%s\" does not exist.", path); return log_debug_errno(errno, "sd-device: cannot access uevent file for %s: %m", syspath); } } else { /* everything else just needs to be a directory */ if (!is_dir(syspath, false)) - return -ENODEV; + return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), + "sd-device: the syspath \"%s\" is not a directory.", syspath); } } else { syspath = strdup(_syspath); if (!syspath) - return -ENOMEM; + return log_oom_debug(); } devpath = syspath + STRLEN("/sys"); if (devpath[0] != '/') - /* '/sys' alone is not a valid device path */ - return -ENODEV; + return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), "sd-device: \"/sys\" alone is not a valid device path."); r = device_add_property_internal(device, "DEVPATH", devpath); if (r < 0) - return r; + return log_debug_errno(r, "sd-device: Failed to add \"DEVPATH\" property for device \"%s\": %m", syspath); free_and_replace(device->syspath, syspath); device->devpath = devpath; From e91627601623ab9990fcd3cdefa4ed2d83109269 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 19 Jan 2022 18:20:49 +0900 Subject: [PATCH 2/3] udev-util: add event UUID to debugging logs --- src/shared/udev-util.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 56c28773ced..32dfcdafc47 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -13,6 +13,7 @@ #include "errno-util.h" #include "escape.h" #include "fd-util.h" +#include "id128-util.h" #include "log.h" #include "macro.h" #include "parse-util.h" @@ -337,6 +338,7 @@ bool device_for_action(sd_device *dev, sd_device_action_t a) { void log_device_uevent(sd_device *device, const char *str) { sd_device_action_t action = _SD_DEVICE_ACTION_INVALID; + sd_id128_t event_id = SD_ID128_NULL; uint64_t seqnum = 0; if (!DEBUG_LOGGING) @@ -344,9 +346,12 @@ void log_device_uevent(sd_device *device, const char *str) { (void) sd_device_get_seqnum(device, &seqnum); (void) sd_device_get_action(device, &action); - log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s)", + (void) sd_device_get_trigger_uuid(device, &event_id); + log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s%s%s)", strempty(str), isempty(str) ? "" : " ", - seqnum, strna(device_action_to_string(action))); + seqnum, strna(device_action_to_string(action)), + sd_id128_is_null(event_id) ? "" : ", UUID=", + sd_id128_is_null(event_id) ? "" : id128_to_uuid_string(event_id, (char[ID128_UUID_STRING_MAX]){})); } int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos) { From 5ab9addd68ee9e7003b4ddbf8162fc89f5e3922f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 19 Jan 2022 19:03:52 +0900 Subject: [PATCH 3/3] test: replace multiple echo with cat Suggested by shell check SC2129. --- test/units/testsuite-17.03.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/units/testsuite-17.03.sh b/test/units/testsuite-17.03.sh index 91f0211bca1..4c2a0410dac 100755 --- a/test/units/testsuite-17.03.sh +++ b/test/units/testsuite-17.03.sh @@ -11,8 +11,10 @@ setup() { ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug" ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", PROGRAM=="/bin/sleep 60" EOF - echo "event_timeout=10" >>/etc/udev/udev.conf - echo "timeout_signal=SIGABRT" >>/etc/udev/udev.conf + cat >>/etc/udev/udev.conf <