diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-01-21 01:22:12 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-01-21 01:22:12 +0100 |
commit | 4609f477c7e043a4f6147dfe6e86b775da2ef784 (patch) | |
tree | c4e51b6214438008026cd22744e57d3cb1cb27ba | |
parent | 31dc8603eedc0140c798c9af3404a35ea190af2c (diff) | |
download | busybox-w32-4609f477c7e043a4f6147dfe6e86b775da2ef784.tar.gz busybox-w32-4609f477c7e043a4f6147dfe6e86b775da2ef784.tar.bz2 busybox-w32-4609f477c7e043a4f6147dfe6e86b775da2ef784.zip |
mdev: fix mode of dir1 in =dir1/dir2/file rule
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-x | testsuite/mdev.tests | 22 | ||||
-rw-r--r-- | util-linux/mdev.c | 16 |
2 files changed, 35 insertions, 3 deletions
diff --git a/testsuite/mdev.tests b/testsuite/mdev.tests index 7320e17dd..48d3dcc2c 100755 --- a/testsuite/mdev.tests +++ b/testsuite/mdev.tests | |||
@@ -11,7 +11,7 @@ FILTER_LS="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f | |||
11 | # cut: remove size+date | 11 | # cut: remove size+date |
12 | FILTER_LS2="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-" | 12 | FILTER_LS2="grep -v '^total ' | sed -e 's/, */,/g' -e 's/ */ /g' | cut -d' ' -f 1-4,9-" |
13 | 13 | ||
14 | # testing "test name" "options" "expected result" "file input" "stdin" | 14 | # testing "test name" "commands" "expected result" "file input" "stdin" |
15 | 15 | ||
16 | rm -rf mdev.testdir | 16 | rm -rf mdev.testdir |
17 | mkdir mdev.testdir | 17 | mkdir mdev.testdir |
@@ -128,6 +128,26 @@ SKIP= | |||
128 | 128 | ||
129 | # continuing to use directory structure from prev test | 129 | # continuing to use directory structure from prev test |
130 | rm -rf mdev.testdir/dev/* | 130 | rm -rf mdev.testdir/dev/* |
131 | echo "sda 0:0 444 =disk/sd/a" >mdev.testdir/etc/mdev.conf | ||
132 | optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME | ||
133 | testing "mdev move rule '=bar/baz/fname'" \ | ||
134 | "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; | ||
135 | ls -lnR mdev.testdir/dev | $FILTER_LS2" \ | ||
136 | "\ | ||
137 | mdev.testdir/dev: | ||
138 | drwxr-xr-x 3 0 0 disk | ||
139 | |||
140 | mdev.testdir/dev/disk: | ||
141 | drwxr-xr-x 2 0 0 sd | ||
142 | |||
143 | mdev.testdir/dev/disk/sd: | ||
144 | br--r--r-- 1 0 0 a | ||
145 | " \ | ||
146 | "" "" | ||
147 | SKIP= | ||
148 | |||
149 | # continuing to use directory structure from prev test | ||
150 | rm -rf mdev.testdir/dev/* | ||
131 | # here we complicate things by having non-matching group 1 and using %0 | 151 | # here we complicate things by having non-matching group 1 and using %0 |
132 | echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf | 152 | echo "s([0-9])*d([a-z]+) 0:0 644 >sd/%2_%0" >mdev.testdir/etc/mdev.conf |
133 | optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES | 153 | optional STATIC FEATURE_MDEV_CONF FEATURE_MDEV_RENAME FEATURE_MDEV_RENAME_REGEXP FEATURE_LS_RECURSIVE FEATURE_LS_TIMESTAMPS FEATURE_LS_USERNAME FEATURE_LS_SORTFILES |
diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 79871d30e..75de14ff1 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c | |||
@@ -429,6 +429,18 @@ static const struct rule *next_rule(void) | |||
429 | 429 | ||
430 | #endif | 430 | #endif |
431 | 431 | ||
432 | static void mkdir_recursive(char *name) | ||
433 | { | ||
434 | /* if name has many levels ("dir1/dir2"), | ||
435 | * bb_make_directory() will create dir1 according to umask, | ||
436 | * not according to its "mode" parameter. | ||
437 | * Since we run with umask=0, need to temporarily switch it. | ||
438 | */ | ||
439 | umask(022); /* "dir1" (if any) will be 0755 too */ | ||
440 | bb_make_directory(name, 0755, FILEUTILS_RECUR); | ||
441 | umask(0); | ||
442 | } | ||
443 | |||
432 | /* Builds an alias path. | 444 | /* Builds an alias path. |
433 | * This function potentionally reallocates the alias parameter. | 445 | * This function potentionally reallocates the alias parameter. |
434 | * Only used for ENABLE_FEATURE_MDEV_RENAME | 446 | * Only used for ENABLE_FEATURE_MDEV_RENAME |
@@ -442,7 +454,7 @@ static char *build_alias(char *alias, const char *device_name) | |||
442 | dest = strrchr(alias, '/'); | 454 | dest = strrchr(alias, '/'); |
443 | if (dest) { /* ">bar/[baz]" ? */ | 455 | if (dest) { /* ">bar/[baz]" ? */ |
444 | *dest = '\0'; /* mkdir bar */ | 456 | *dest = '\0'; /* mkdir bar */ |
445 | bb_make_directory(alias, 0755, FILEUTILS_RECUR); | 457 | mkdir_recursive(alias); |
446 | *dest = '/'; | 458 | *dest = '/'; |
447 | if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */ | 459 | if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */ |
448 | dest = alias; | 460 | dest = alias; |
@@ -641,7 +653,7 @@ static void make_device(char *device_name, char *path, int operation) | |||
641 | char *slash = strrchr(node_name, '/'); | 653 | char *slash = strrchr(node_name, '/'); |
642 | if (slash) { | 654 | if (slash) { |
643 | *slash = '\0'; | 655 | *slash = '\0'; |
644 | bb_make_directory(node_name, 0755, FILEUTILS_RECUR); | 656 | mkdir_recursive(node_name); |
645 | *slash = '/'; | 657 | *slash = '/'; |
646 | } | 658 | } |
647 | if (G.verbose) | 659 | if (G.verbose) |