summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2010-03-17 09:15:18 +0100
committerKay Sievers <kay.sievers@vrfy.org>2010-03-17 09:15:18 +0100
commit578cc8a8085a47c963b5940459e475ac5f07219c (patch)
tree604ad09b1da00f19375d5aba3f0cfb5174ac4b49 /udev
parent2b463cb050cbf77d9c6b51e0f5a9d89bf7eb1bc3 (diff)
do not reset SELinux context when the node was not touched
Diffstat (limited to 'udev')
-rw-r--r--udev/udev-node.c42
1 files changed, 17 insertions, 25 deletions
diff --git a/udev/udev-node.c b/udev/udev-node.c
index 4314cceb79..3aee15b584 100644
--- a/udev/udev-node.c
+++ b/udev/udev-node.c
@@ -37,7 +37,6 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
{
struct udev *udev = udev_device_get_udev(dev);
struct stat stats;
- int preserve = 0;
int err = 0;
if (major(devnum) == 0)
@@ -54,9 +53,15 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
if (lstat(file, &stats) == 0) {
if (((stats.st_mode & S_IFMT) == (mode & S_IFMT)) && (stats.st_rdev == devnum)) {
info(udev, "preserve file '%s', because it has correct dev_t\n", file);
- preserve = 1;
- udev_selinux_lsetfilecon(udev, file, mode);
- /* update time stamp when we re-use the node, like on media change events */
+ if (stats.st_mode != mode || stats.st_uid != uid || stats.st_gid != gid) {
+ info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid);
+ chmod(file, mode);
+ chown(file, uid, gid);
+ udev_selinux_lsetfilecon(udev, file, mode);
+ } else {
+ info(udev, "preserve permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid);
+ }
+ /* always update timestamp when we re-use the node, like on media change events */
utimensat(AT_FDCWD, file, NULL, 0);
} else {
char file_tmp[UTIL_PATH_SIZE + sizeof(TMP_FILE_EXT)];
@@ -76,7 +81,11 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
if (err != 0) {
err(udev, "rename(%s, %s) failed: %m\n", file_tmp, file);
unlink(file_tmp);
+ goto exit;
}
+ info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid);
+ chmod(file, mode);
+ chown(file, uid, gid);
}
} else {
info(udev, "mknod(%s, %#o, (%u,%u))\n", file, mode, major(devnum), minor(devnum));
@@ -90,28 +99,11 @@ int udev_node_mknod(struct udev_device *dev, const char *file, dev_t devnum, mod
err = -errno;
udev_selinux_resetfscreatecon(udev);
} while (err == -ENOENT);
- if (err != 0) {
+ if (err != 0)
err(udev, "mknod(%s, %#o, (%u,%u) failed: %m\n", file, mode, major(devnum), minor(devnum));
- goto exit;
- }
- }
-
- if (!preserve || stats.st_mode != mode) {
- info(udev, "chmod(%s, %#o)\n", file, mode);
- err = chmod(file, mode);
- if (err != 0) {
- err(udev, "chmod(%s, %#o) failed: %m\n", file, mode);
- goto exit;
- }
- }
-
- if (!preserve || stats.st_uid != uid || stats.st_gid != gid) {
- info(udev, "chown(%s, %u, %u)\n", file, uid, gid);
- err = chown(file, uid, gid);
- if (err != 0) {
- err(udev, "chown(%s, %u, %u) failed: %m\n", file, uid, gid);
- goto exit;
- }
+ info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid);
+ chmod(file, mode);
+ chown(file, uid, gid);
}
exit:
return err;