1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-25 18:50:18 +03:00

udevadm-trigger: do not return immediately on EACCES

Prompted by https://github.com/systemd/systemd/pull/18559.
This commit is contained in:
Yu Watanabe 2021-02-20 16:30:23 +09:00
parent 21012e20a4
commit 0e789e6d48

View File

@ -45,13 +45,39 @@ static int exec_list(sd_device_enumerator *e, sd_device_action_t action, Set **s
r = sd_device_trigger(d, action);
if (r < 0) {
bool ignore = IN_SET(r, -ENOENT, -ENODEV);
/* ENOENT may be returned when a device does not have /uevent or is already
* removed. Hence, this is logged at debug level and ignored.
*
* ENODEV may be returned by some buggy device drivers e.g. /sys/devices/vio.
* See,
* https://github.com/systemd/systemd/issues/13652#issuecomment-535129791 and
* https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1845319.
* So, this error is ignored, but logged at warning level to encourage people to
* fix the driver.
*
* EROFS is returned when /sys is read only. In that case, all subsequent
* writes will also fail, hence return immediately.
*
* EACCES or EPERM may be returned when this is invoked by non-priviledged user.
* We do NOT return immediately, but continue operation and propagate the error.
* Why? Some device can be owned by a user, e.g., network devices configured in
* a network namespace. See, https://github.com/systemd/systemd/pull/18559 and
* https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ebb4a4bf76f164457184a3f43ebc1552416bc823
*
* All other errors are logged at error level, but let's continue the operation,
* and propagate the error.
*/
log_device_full_errno(d, ignore ? LOG_DEBUG : LOG_ERR, r,
bool ignore = IN_SET(r, -ENOENT, -ENODEV);
int level =
r == -ENOENT ? LOG_DEBUG :
r == -ENODEV ? LOG_WARNING : LOG_ERR;
log_device_full_errno(d, level, r,
"Failed to write '%s' to '%s/uevent'%s: %m",
action_str, syspath, ignore ? ", ignoring" : "");
if (IN_SET(r, -EACCES, -EROFS))
/* Inovoked by unprivileged user, or read only filesystem. Return earlier. */
if (r == -EROFS)
return r;
if (ret == 0 && !ignore)
ret = r;