aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
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 /util-linux/mdev.c
parent4461564c77260351fe3d82386eebf81085347b34 (diff)
downloadbusybox-cae11b51aac9f52d35f2446a26acafbe7be8e9bd.tar.gz
mdev: fix "foo 0:0 444 >bar/baz" rule handling. make_device() +23 bytes
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c27
1 files changed, 16 insertions, 11 deletions
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)
if (ENABLE_FEATURE_MDEV_RENAME && alias) {
char *dest;
+ /* ">bar/": rename to bar/device_name */
+ /* ">bar[/]baz": rename to bar[/]baz */
dest = strrchr(alias, '/');
- if (dest) {
- if (dest[1] != '\0')
- /* given a file name, so rename it */
- *dest = '\0';
+ if (dest) { /* ">bar/[baz]" ? */
+ *dest = '\0'; /* mkdir bar */
bb_make_directory(alias, 0755, FILEUTILS_RECUR);
- dest = concat_path_file(alias, device_name);
- free(alias);
- } else
- dest = alias;
+ *dest = '/';
+ if (dest[1] == '\0') { /* ">bar/" => ">bar/device_name" */
+ dest = alias;
+ alias = concat_path_file(alias, device_name);
+ free(dest);
+ }
+ }
- rename(device_name, dest);
- symlink(dest, device_name);
+ /* recreate device_name as a symlink to moved device node */
+ if (rename(device_name, alias) == 0) {
+ symlink(alias, device_name);
+ }
- free(dest);
+ free(alias);
}
}
}