chiark / gitweb /
preserve 'sticky bit' on 'add/change' events
[elogind.git] / udev / udev-node.c
index dc7d9c365a64efaa6b53eff9b75d8b0077104f07..71488c93ad00f4ffd7303f583f804c153e568600 100644 (file)
@@ -52,7 +52,9 @@ int udev_node_mknod(struct udev_device *dev, const char *file, mode_t mode, uid_
        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);
-                       if (stats.st_mode != mode || stats.st_uid != uid || stats.st_gid != gid) {
+                       if ((stats.st_mode & 0777) != (mode & 0777) || stats.st_uid != uid || stats.st_gid != gid) {
+                               /* preserve 'sticky' bit, if already set */
+                               mode |= stats.st_mode & 01000;
                                info(udev, "set permissions %s, %#o, uid=%u, gid=%u\n", file, mode, uid, gid);
                                chmod(file, mode);
                                chown(file, uid, gid);
@@ -425,6 +427,11 @@ int udev_node_remove(struct udev_device *dev)
                goto out;
        }
 
+       if (stats.st_mode & 01000) {
+               info(udev, "device node '%s' has sticky bit set, skip removal\n", devnode);
+               goto out;
+       }
+
        dev_check = udev_device_new_from_syspath(udev, udev_device_get_syspath(dev));
        if (dev_check != NULL) {
                /* do not remove device node if the same sys-device is re-created in the meantime */