aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-03-29 15:11:07 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-03-29 15:11:07 +0000
commitcae11b51aac9f52d35f2446a26acafbe7be8e9bd (patch)
tree6284f6c5979f6a001f7086fcfdbfe656a14382e9
parent4461564c77260351fe3d82386eebf81085347b34 (diff)
downloadbusybox-w32-cae11b51aac9f52d35f2446a26acafbe7be8e9bd.tar.gz
busybox-w32-cae11b51aac9f52d35f2446a26acafbe7be8e9bd.tar.bz2
busybox-w32-cae11b51aac9f52d35f2446a26acafbe7be8e9bd.zip
mdev: fix "foo 0:0 444 >bar/baz" rule handling. make_device() +23 bytes
-rwxr-xr-xtestsuite/mdev.tests36
-rw-r--r--util-linux/mdev.c27
2 files changed, 51 insertions, 12 deletions
diff --git a/testsuite/mdev.tests b/testsuite/mdev.tests
index 1ee762828..777c5c540 100755
--- a/testsuite/mdev.tests
+++ b/testsuite/mdev.tests
@@ -8,6 +8,8 @@
8# sed: (1) "maj, min" -> "maj,min" (2) coalesce spaces 8# sed: (1) "maj, min" -> "maj,min" (2) coalesce spaces
9# cut: remove date 9# cut: remove date
10FILTER_LS="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-" 10FILTER_LS="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-"
11# cut: remove size+date
12FILTER_LS2="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-"
11 13
12# testing "test name" "options" "expected result" "file input" "stdin" 14# testing "test name" "options" "expected result" "file input" "stdin"
13 15
@@ -31,7 +33,7 @@ brw-rw---- 1 0 0 8,0 sda
31 "" "" 33 "" ""
32 34
33# continuing to use directory structure from prev test 35# continuing to use directory structure from prev test
34rm mdev.testdir/dev/sda 36rm -rf mdev.testdir/dev/*
35echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf 37echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf
36echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf 38echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf
37testing "mdev stops on first rule" \ 39testing "mdev stops on first rule" \
@@ -42,6 +44,38 @@ brw-rw-rw- 1 1 1 8,0 sda
42" \ 44" \
43 "" "" 45 "" ""
44 46
47# continuing to use directory structure from prev test
48rm -rf mdev.testdir/dev/*
49echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf
50testing "mdev move/symlink rule '>bar/baz'" \
51 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
52 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
53"\
54mdev.testdir/dev:
55drwxr-xr-x 2 0 0 disk
56lrwxrwxrwx 1 0 0 sda -> disk/scsiA
57
58mdev.testdir/dev/disk:
59br--r--r-- 1 0 0 scsiA
60" \
61 "" ""
62
63# continuing to use directory structure from prev test
64rm -rf mdev.testdir/dev/*
65echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf
66testing "mdev move/symlink rule '>bar/'" \
67 "env - ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
68 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
69"\
70mdev.testdir/dev:
71drwxr-xr-x 2 0 0 disk
72lrwxrwxrwx 1 0 0 sda -> disk/sda
73
74mdev.testdir/dev/disk:
75br--r--r-- 1 0 0 sda
76" \
77 "" ""
78
45# clean up 79# clean up
46rm -rf mdev.testdir 80rm -rf mdev.testdir
47 81
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index a2866054c..c4c4350a4 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -203,21 +203,26 @@ static void make_device(char *path, int delete)
203 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 203 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
204 char *dest; 204 char *dest;
205 205
206 /* ">bar/": rename to bar/device_name */
207 /* ">bar[/]baz": rename to bar[/]baz */
206 dest = strrchr(alias, '/'); 208 dest = strrchr(alias, '/');
207 if (dest) { 209 if (dest) { /* ">bar/[baz]" ? */
208 if (dest[1] != '\0') 210 *dest = '\0'; /* mkdir bar */
209 /* given a file name, so rename it */
210 *dest = '\0';
211 bb_make_directory(alias, 0755, FILEUTILS_RECUR); 211 bb_make_directory(alias, 0755, FILEUTILS_RECUR);
212 dest = concat_path_file(alias, device_name); 212 *dest = '/';
213 free(alias); 213 if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
214 } else 214 dest = alias;
215 dest = alias; 215 alias = concat_path_file(alias, device_name);
216 free(dest);
217 }
218 }
216 219
217 rename(device_name, dest); 220 /* recreate device_name as a symlink to moved device node */
218 symlink(dest, device_name); 221 if (rename(device_name, alias) == 0) {
222 symlink(alias, device_name);
223 }
219 224
220 free(dest); 225 free(alias);
221 } 226 }
222 } 227 }
223 } 228 }