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/udev-rules.c | |
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/udev-rules.c')
-rw-r--r-- | src/udev/udev-rules.c | 24 |
1 files changed, 7 insertions, 17 deletions
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: |