diff options
-rwxr-xr-x | testsuite/mdev.tests | 36 | ||||
-rw-r--r-- | util-linux/mdev.c | 27 |
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 |
10 | FILTER_LS="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-" | 10 | FILTER_LS="sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-5,9-" |
11 | # cut: remove size+date | ||
12 | FILTER_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 |
34 | rm mdev.testdir/dev/sda | 36 | rm -rf mdev.testdir/dev/* |
35 | echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf | 37 | echo ".* 1:1 666" >mdev.testdir/etc/mdev.conf |
36 | echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf | 38 | echo "sda 2:2 444" >>mdev.testdir/etc/mdev.conf |
37 | testing "mdev stops on first rule" \ | 39 | testing "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 | ||
48 | rm -rf mdev.testdir/dev/* | ||
49 | echo "sda 0:0 444 >disk/scsiA" >mdev.testdir/etc/mdev.conf | ||
50 | testing "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 | "\ | ||
54 | mdev.testdir/dev: | ||
55 | drwxr-xr-x 2 0 0 disk | ||
56 | lrwxrwxrwx 1 0 0 sda -> disk/scsiA | ||
57 | |||
58 | mdev.testdir/dev/disk: | ||
59 | br--r--r-- 1 0 0 scsiA | ||
60 | " \ | ||
61 | "" "" | ||
62 | |||
63 | # continuing to use directory structure from prev test | ||
64 | rm -rf mdev.testdir/dev/* | ||
65 | echo "sda 0:0 444 >disk/" >mdev.testdir/etc/mdev.conf | ||
66 | testing "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 | "\ | ||
70 | mdev.testdir/dev: | ||
71 | drwxr-xr-x 2 0 0 disk | ||
72 | lrwxrwxrwx 1 0 0 sda -> disk/sda | ||
73 | |||
74 | mdev.testdir/dev/disk: | ||
75 | br--r--r-- 1 0 0 sda | ||
76 | " \ | ||
77 | "" "" | ||
78 | |||
45 | # clean up | 79 | # clean up |
46 | rm -rf mdev.testdir | 80 | rm -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 | } |