diff options
author | Lennart Poettering <lennart@poettering.net> | 2019-04-30 19:25:29 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2019-05-24 15:07:55 +0200 |
commit | 4b3b5bc71b791a67d991389d8f59ab891b051b86 (patch) | |
tree | 58535e2b8d7658d76241b1403f191b1416421c2d /src/udev | |
parent | f8a8579e84bf5cb33d2c331efd74ffeaf8072539 (diff) | |
download | systemd-4b3b5bc71b791a67d991389d8f59ab891b051b86.tar.gz systemd-4b3b5bc71b791a67d991389d8f59ab891b051b86.tar.bz2 systemd-4b3b5bc71b791a67d991389d8f59ab891b051b86.zip |
tree-wide: port various places over to use chmod_and_chown()
Doing this properly is hard, hence let's unify the code.
Diffstat (limited to 'src/udev')
-rw-r--r-- | src/udev/udev-node.c | 8 | ||||
-rw-r--r-- | src/udev/udev-rules.c | 24 |
2 files changed, 11 insertions, 21 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index cfbbd7b283..67d573cf2b 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -310,10 +310,10 @@ static int node_permissions_apply(sd_device *dev, bool apply, if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) { log_device_debug(dev, "Setting permissions %s, %#o, uid=%u, gid=%u", devnode, mode, uid, gid); - if (chmod(devnode, mode) < 0) - r = log_device_warning_errno(dev, errno, "Failed to set mode of %s to %#o: %m", devnode, mode); - if (chown(devnode, uid, gid) < 0) - r = log_device_warning_errno(dev, errno, "Failed to set owner of %s to uid=%u, gid=%u: %m", devnode, uid, gid); + + r = chmod_and_chown(devnode, mode, uid, gid); + if (r < 0) + log_device_warning_errno(dev, r, "Failed to set owner/mode of %s to uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o: %m", devnode, uid, gid, mode); } else log_device_debug(dev, "Preserve permissions of %s, %#o, uid=%u, gid=%u", devnode, mode, uid, gid); diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index 96840b272c..696d98a40a 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -22,6 +22,7 @@ #include "escape.h" #include "fd-util.h" #include "fileio.h" +#include "format-util.h" #include "fs-util.h" #include "glob-util.h" #include "libudev-util.h" @@ -2591,25 +2592,14 @@ int udev_rules_apply_static_dev_perms(UdevRules *rules) { else mode = 0600; } - if (mode != (stats.st_mode & 01777)) { - r = chmod(device_node, mode); - if (r < 0) - return log_error_errno(errno, "Failed to chmod '%s' %#o: %m", - device_node, mode); - else - log_debug("chmod '%s' %#o", device_node, mode); - } - if ((uid != 0 && uid != stats.st_uid) || (gid != 0 && gid != stats.st_gid)) { - r = chown(device_node, uid, gid); - if (r < 0) - return log_error_errno(errno, "Failed to chown '%s' %u %u: %m", - device_node, uid, gid); - else - log_debug("chown '%s' %u %u", device_node, uid, gid); - } + r = chmod_and_chown(device_node, mode, uid, gid); + if (r < 0) + return log_error_errno(r, "Failed to chown/chmod '%s' uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o: %m", device_node, uid, gid, mode); + if (r > 0) + log_debug("chown/chmod '%s' uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o", device_node, uid, gid, mode); - utimensat(AT_FDCWD, device_node, NULL, 0); + (void) utimensat(AT_FDCWD, device_node, NULL, 0); break; } case TK_END: |