mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +03:00
remove device node, when type block/char has changed
Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
parent
e33d1515e2
commit
57663b364b
3
README
3
README
@ -10,8 +10,7 @@ To use:
|
||||
|
||||
- Your 2.6 kernel must have had CONFIG_HOTPLUG enabled when it was built.
|
||||
|
||||
- Make sure sysfs is mounted. udev will figure out where sysfs is mounted, but
|
||||
the traditional place for it is at /sys. You can mount it by hand by running:
|
||||
- Make sure sysfs is mounted at /sys. You can mount it by running:
|
||||
mount -t sysfs none /sys
|
||||
|
||||
- Make sure you have the latest version of the linux-hotplug scripts. They are
|
||||
|
33
udev_add.c
33
udev_add.c
@ -52,23 +52,6 @@ int udev_make_node(struct udevice *udev, const char *file, dev_t devt, mode_t mo
|
||||
struct stat stats;
|
||||
int retval = 0;
|
||||
|
||||
if (stat(file, &stats) != 0)
|
||||
goto create;
|
||||
|
||||
/* preserve node with already correct numbers, to not change the inode number */
|
||||
if (((stats.st_mode & S_IFMT) == S_IFBLK || (stats.st_mode & S_IFMT) == S_IFCHR) &&
|
||||
(stats.st_rdev == devt)) {
|
||||
info("preserve file '%s', cause it has correct dev_t", file);
|
||||
selinux_setfilecon(file, udev->kernel_name, stats.st_mode);
|
||||
goto perms;
|
||||
}
|
||||
|
||||
if (unlink(file) != 0)
|
||||
dbg("unlink(%s) failed with error '%s'", file, strerror(errno));
|
||||
else
|
||||
dbg("already present file '%s' unlinked", file);
|
||||
|
||||
create:
|
||||
switch (udev->type) {
|
||||
case DEV_BLOCK:
|
||||
mode |= S_IFBLK;
|
||||
@ -81,6 +64,22 @@ create:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (stat(file, &stats) != 0)
|
||||
goto create;
|
||||
|
||||
/* preserve node with already correct numbers, to not change the inode number */
|
||||
if ((stats.st_mode & S_IFMT) == (mode & S_IFMT) && (stats.st_rdev == devt)) {
|
||||
info("preserve file '%s', cause it has correct dev_t", file);
|
||||
selinux_setfilecon(file, udev->kernel_name, stats.st_mode);
|
||||
goto perms;
|
||||
}
|
||||
|
||||
if (unlink(file) != 0)
|
||||
dbg("unlink(%s) failed with error '%s'", file, strerror(errno));
|
||||
else
|
||||
dbg("already present file '%s' unlinked", file);
|
||||
|
||||
create:
|
||||
selinux_setfscreatecon(file, udev->kernel_name, mode);
|
||||
retval = mknod(file, mode, devt);
|
||||
selinux_resetfscreatecon();
|
||||
|
Loading…
Reference in New Issue
Block a user