1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

Merge pull request #19791 from yuwata/udev-node-logs

udev: update several log messages
This commit is contained in:
Yu Watanabe 2021-06-03 01:32:29 +09:00 committed by GitHub
commit 63b8a781b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 10 deletions

View File

@ -298,8 +298,11 @@ static int builtin_blkid(sd_device *dev, int argc, char *argv[], bool test) {
return log_device_debug_errno(dev, r, "Failed to get device name: %m");
fd = open(devnode, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
if (fd < 0)
return log_device_debug_errno(dev, errno, "Failed to open block device %s: %m", devnode);
if (fd < 0) {
log_device_debug_errno(dev, errno, "Failed to open block device %s%s: %m",
devnode, errno == ENOENT ? ", ignoring" : "");
return errno == ENOENT ? 0 : -errno;
}
errno = 0;
r = blkid_probe_set_device(pr, fd, offset, 0);

View File

@ -228,18 +228,23 @@ static size_t escape_path(const char *src, char *dest, size_t size) {
/* manage "stack of names" with possibly specified device priorities */
static int link_update(sd_device *dev, const char *slink, bool add) {
_cleanup_free_ char *filename = NULL, *dirname = NULL;
const char *slink_name, *id;
char name_enc[PATH_MAX];
const char *id;
int i, r, retries;
assert(dev);
assert(slink);
slink_name = path_startswith(slink, "/dev");
if (!slink_name)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL),
"Invalid symbolic link of device node: %s", slink);
r = device_get_device_id(dev, &id);
if (r < 0)
return log_device_debug_errno(dev, r, "Failed to get device id: %m");
escape_path(slink + STRLEN("/dev"), name_enc, sizeof(name_enc));
escape_path(slink_name, name_enc, sizeof(name_enc));
dirname = path_join("/run/udev/links/", name_enc);
if (!dirname)
return log_oom();
@ -339,7 +344,11 @@ int udev_node_update_old_links(sd_device *dev, sd_device *dev_old) {
log_device_debug(dev, "Updating old name, '%s' no longer belonging to '%s'",
name, devpath);
link_update(dev, name, false);
r = link_update(dev, name, false);
if (r < 0)
log_device_warning_errno(dev, r,
"Failed to update device symlink '%s', ignoring: %m",
name);
}
return 0;
@ -530,7 +539,9 @@ int udev_node_add(sd_device *dev, bool apply,
FOREACH_DEVICE_DEVLINK(dev, devlink) {
r = link_update(dev, devlink, true);
if (r < 0)
log_device_info_errno(dev, r, "Failed to update device symlinks: %m");
log_device_warning_errno(dev, r,
"Failed to update device symlink '%s', ignoring: %m",
devlink);
}
return 0;
@ -547,7 +558,9 @@ int udev_node_remove(sd_device *dev) {
FOREACH_DEVICE_DEVLINK(dev, devlink) {
r = link_update(dev, devlink, false);
if (r < 0)
log_device_info_errno(dev, r, "Failed to update device symlinks: %m");
log_device_warning_errno(dev, r,
"Failed to update device symlink '%s', ignoring: %m",
devlink);
}
r = xsprintf_dev_num_path_from_sd_device(dev, &filename);

View File

@ -83,11 +83,14 @@ int udev_watch_begin(int inotify_fd, sd_device *dev) {
log_device_debug(dev, "Adding watch on '%s'", devnode);
wd = inotify_add_watch(inotify_fd, devnode, IN_CLOSE_WRITE);
if (wd < 0) {
r = log_device_full_errno(dev, errno == ENOENT ? LOG_DEBUG : LOG_WARNING,
errno, "Failed to add device '%s' to watch: %m", devnode);
bool ignore = errno == ENOENT;
r = log_device_full_errno(dev, ignore ? LOG_DEBUG : LOG_WARNING, errno,
"Failed to add device '%s' to watch%s: %m",
devnode, ignore ? ", ignoring" : "");
(void) device_set_watch_handle(dev, -1);
return r;
return ignore ? 0 : r;
}
r = device_set_watch_handle(dev, wd);