mdev: set $MDEV correctly for renamed nodes

function                                             old     new   delta
make_device                                         1467    1502     +35
build_alias                                           78       -     -78

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-07-02 13:07:11 +02:00
parent cf4e503875
commit 90db359972
2 changed files with 43 additions and 41 deletions

View File

@ -136,12 +136,12 @@ brw-r--r-- 1 0 0 8,0 sda
# continuing to use directory structure from prev test
rm -rf mdev.testdir/dev/*
echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf
echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
testing "mdev move and command" \
"env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
ls -lnR mdev.testdir/dev | $FILTER_LS2" \
"\
@echo TEST
@echo TEST:block/sda
mdev.testdir/dev:
drwxr-xr-x 2 0 0 block

View File

@ -317,11 +317,14 @@ static void make_device(char *path, int delete)
/* End of field parsing */
/* "Execute" the line we found */
{
const char *node_name;
node_name = device_name;
if (ENABLE_FEATURE_MDEV_RENAME && alias)
node_name = alias = build_alias(alias, device_name);
if (!delete && major >= 0) {
char *node_name = (char *)device_name;
if (ENABLE_FEATURE_MDEV_RENAME && alias)
alias = node_name = build_alias(alias, 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)
@ -333,13 +336,12 @@ static void make_device(char *path, int delete)
if (ENABLE_FEATURE_MDEV_RENAME && alias) {
if (aliaslink == '>')
symlink(node_name, device_name);
free(alias);
}
}
if (ENABLE_FEATURE_MDEV_EXEC && command) {
/* setenv will leak memory, use putenv/unsetenv/free */
char *s = xasprintf("%s=%s", "MDEV", device_name);
char *s = xasprintf("%s=%s", "MDEV", node_name);
char *s1 = xasprintf("%s=%s", "SUBSYSTEM", subsystem);
putenv(s);
putenv(s1);
@ -353,13 +355,13 @@ static void make_device(char *path, int delete)
}
if (delete) {
char *node_name = (char *)device_name;
if (ENABLE_FEATURE_MDEV_RENAME && alias) {
alias = node_name = build_alias(alias, device_name);
if (aliaslink == '>')
unlink(device_name);
}
unlink(node_name);
}
if (ENABLE_FEATURE_MDEV_RENAME)
free(alias);
}