Skip to content

Commit b09869e

Browse files
authored
Merge pull request systemd#22172 from yuwata/udev-sd-device-more-debugging-logs
udev, sd-device: more debugging logs
2 parents 30b6f7d + 5ab9add commit b09869e

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/libsystemd/sd-device/sd-device.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
152152
if (verify) {
153153
r = chase_symlinks(_syspath, NULL, 0, &syspath, NULL);
154154
if (r == -ENOENT)
155-
return -ENODEV; /* the device does not exist (any more?) */
155+
/* the device does not exist (any more?) */
156+
return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
157+
"sd-device: Failed to chase symlinks in \"%s\".", _syspath);
156158
if (r < 0)
157159
return log_debug_errno(r, "sd-device: Failed to get target of '%s': %m", _syspath);
158160

@@ -173,7 +175,7 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
173175

174176
new_syspath = path_join("/sys", p);
175177
if (!new_syspath)
176-
return -ENOMEM;
178+
return log_oom_debug();
177179

178180
free_and_replace(syspath, new_syspath);
179181
path_simplify(syspath);
@@ -187,30 +189,31 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
187189
if (access(path, F_OK) < 0) {
188190
if (errno == ENOENT)
189191
/* this is not a valid device */
190-
return -ENODEV;
192+
return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
193+
"sd-device: the uevent file \"%s\" does not exist.", path);
191194

192195
return log_debug_errno(errno, "sd-device: cannot access uevent file for %s: %m", syspath);
193196
}
194197
} else {
195198
/* everything else just needs to be a directory */
196199
if (!is_dir(syspath, false))
197-
return -ENODEV;
200+
return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
201+
"sd-device: the syspath \"%s\" is not a directory.", syspath);
198202
}
199203
} else {
200204
syspath = strdup(_syspath);
201205
if (!syspath)
202-
return -ENOMEM;
206+
return log_oom_debug();
203207
}
204208

205209
devpath = syspath + STRLEN("/sys");
206210

207211
if (devpath[0] != '/')
208-
/* '/sys' alone is not a valid device path */
209-
return -ENODEV;
212+
return log_debug_errno(SYNTHETIC_ERRNO(ENODEV), "sd-device: \"/sys\" alone is not a valid device path.");
210213

211214
r = device_add_property_internal(device, "DEVPATH", devpath);
212215
if (r < 0)
213-
return r;
216+
return log_debug_errno(r, "sd-device: Failed to add \"DEVPATH\" property for device \"%s\": %m", syspath);
214217

215218
free_and_replace(device->syspath, syspath);
216219
device->devpath = devpath;

src/shared/udev-util.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "errno-util.h"
1414
#include "escape.h"
1515
#include "fd-util.h"
16+
#include "id128-util.h"
1617
#include "log.h"
1718
#include "macro.h"
1819
#include "parse-util.h"
@@ -337,16 +338,20 @@ bool device_for_action(sd_device *dev, sd_device_action_t a) {
337338

338339
void log_device_uevent(sd_device *device, const char *str) {
339340
sd_device_action_t action = _SD_DEVICE_ACTION_INVALID;
341+
sd_id128_t event_id = SD_ID128_NULL;
340342
uint64_t seqnum = 0;
341343

342344
if (!DEBUG_LOGGING)
343345
return;
344346

345347
(void) sd_device_get_seqnum(device, &seqnum);
346348
(void) sd_device_get_action(device, &action);
347-
log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s)",
349+
(void) sd_device_get_trigger_uuid(device, &event_id);
350+
log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s%s%s)",
348351
strempty(str), isempty(str) ? "" : " ",
349-
seqnum, strna(device_action_to_string(action)));
352+
seqnum, strna(device_action_to_string(action)),
353+
sd_id128_is_null(event_id) ? "" : ", UUID=",
354+
sd_id128_is_null(event_id) ? "" : id128_to_uuid_string(event_id, (char[ID128_UUID_STRING_MAX]){}));
350355
}
351356

352357
int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos) {

test/units/testsuite-17.03.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ setup() {
1111
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", OPTIONS="log_level=debug"
1212
ACTION=="add", SUBSYSTEM=="mem", KERNEL=="null", PROGRAM=="/bin/sleep 60"
1313
EOF
14-
echo "event_timeout=10" >>/etc/udev/udev.conf
15-
echo "timeout_signal=SIGABRT" >>/etc/udev/udev.conf
14+
cat >>/etc/udev/udev.conf <<EOF
15+
event_timeout=10
16+
timeout_signal=SIGABRT
17+
EOF
1618

1719
systemctl restart systemd-udevd.service
1820
}

0 commit comments

Comments
 (0)