mdev: fix the case when move rule deletes node with name == device_name

Signed-off-by: Jean Wolter <jw5@os.inf.tu-dresden.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-06-22 01:31:12 +02:00
parent b0bee2b0da
commit 2f86ca1350
2 changed files with 43 additions and 19 deletions

View File

@ -162,6 +162,32 @@ brw-r--r-- 1 0 1 8,0 sda
" \ " \
"" "" "" ""
# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
mkdir -p mdev.testdir/sys/class/tty/capi
echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
mkdir -p mdev.testdir/sys/class/tty/capi1
echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
mkdir -p mdev.testdir/sys/class/tty/capi20
echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
# mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
testing "move rule does not delete node with name == device_name" \
"\
env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
ls -lnR mdev.testdir/dev | $FILTER_LS" \
"\
mdev.testdir/dev:
crw-rw---- 1 0 0 191,0 capi20
crw-rw---- 1 0 0 191,1 capi20.01
crw-rw---- 1 0 0 191,20 capi20.20
" \
"" ""
# clean up # clean up
rm -rf mdev.testdir rm -rf mdev.testdir

View File

@ -319,22 +319,20 @@ static void make_device(char *path, int delete)
/* "Execute" the line we found */ /* "Execute" the line we found */
if (!delete && major >= 0) { if (!delete && major >= 0) {
if (ENABLE_FEATURE_MDEV_RENAME) char *node_name = (char *)device_name;
unlink(device_name); if (ENABLE_FEATURE_MDEV_RENAME && alias)
if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST) alias = node_name = build_alias(alias, device_name);
bb_perror_msg_and_die("mknod %s", device_name); if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST)
bb_perror_msg_and_die("mknod %s", node_name);
if (major == root_major && minor == root_minor) if (major == root_major && minor == root_minor)
symlink(device_name, "root"); symlink(node_name, "root");
if (ENABLE_FEATURE_MDEV_CONF) { if (ENABLE_FEATURE_MDEV_CONF) {
chmod(device_name, mode); chmod(node_name, mode);
chown(device_name, ugid.uid, ugid.gid); chown(node_name, ugid.uid, ugid.gid);
} }
if (ENABLE_FEATURE_MDEV_RENAME && alias) { if (ENABLE_FEATURE_MDEV_RENAME && alias) {
alias = build_alias(alias, device_name); if (aliaslink == '>')
/* move the device, and optionally symlink(node_name, device_name);
* make a symlink to moved device node */
if (rename(device_name, alias) == 0 && aliaslink == '>')
symlink(alias, device_name);
free(alias); free(alias);
} }
} }
@ -355,15 +353,15 @@ static void make_device(char *path, int delete)
} }
if (delete) { if (delete) {
unlink(device_name); char *node_name = (char *)device_name;
/* At creation time, device might have been moved
* and a symlink might have been created. Undo that. */
if (ENABLE_FEATURE_MDEV_RENAME && alias) { if (ENABLE_FEATURE_MDEV_RENAME && alias) {
alias = build_alias(alias, device_name); alias = node_name = build_alias(alias, device_name);
unlink(alias); if (aliaslink == '>')
free(alias); unlink(device_name);
} }
unlink(node_name);
if (ENABLE_FEATURE_MDEV_RENAME)
free(alias);
} }
/* We found matching line. /* We found matching line.