aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-22 01:31:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-22 01:31:12 +0200
commit2f86ca135069e457bb16ab9e062a10e0775717a6 (patch)
tree876df9ba3cf6ac39403cc0f210c0ffab05672049
parentb0bee2b0da4b3270ee5ae6d556c71a6b5ff844bf (diff)
downloadbusybox-w32-2f86ca135069e457bb16ab9e062a10e0775717a6.tar.gz
busybox-w32-2f86ca135069e457bb16ab9e062a10e0775717a6.tar.bz2
busybox-w32-2f86ca135069e457bb16ab9e062a10e0775717a6.zip
mdev: fix the case when move rule deletes node with name == device_name
Signed-off-by: Jean Wolter <jw5@os.inf.tu-dresden.de> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-xtestsuite/mdev.tests26
-rw-r--r--util-linux/mdev.c36
2 files changed, 43 insertions, 19 deletions
diff --git a/testsuite/mdev.tests b/testsuite/mdev.tests
index a1750076e..912785ece 100755
--- a/testsuite/mdev.tests
+++ b/testsuite/mdev.tests
@@ -162,6 +162,32 @@ brw-r--r-- 1 0 1 8,0 sda
162" \ 162" \
163 "" "" 163 "" ""
164 164
165# continuing to use directory structure from prev test
166rm -rf mdev.testdir/dev/*
167mkdir -p mdev.testdir/sys/class/tty/capi
168echo "191:0" >mdev.testdir/sys/class/tty/capi/dev
169mkdir -p mdev.testdir/sys/class/tty/capi1
170echo "191:1" >mdev.testdir/sys/class/tty/capi1/dev
171mkdir -p mdev.testdir/sys/class/tty/capi20
172echo "191:20" >mdev.testdir/sys/class/tty/capi20/dev
173echo "capi 0:0 0660 =capi20" >mdev.testdir/etc/mdev.conf
174echo "capi([0-9]) 0:0 0660 =capi20.0%1" >>mdev.testdir/etc/mdev.conf
175echo "capi([0-9]*) 0:0 0660 =capi20.%1" >>mdev.testdir/etc/mdev.conf
176# mdev invocation with DEVPATH=/class/tty/capi20 was deleting /dev/capi20
177testing "move rule does not delete node with name == device_name" \
178 "\
179 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi chroot mdev.testdir /mdev 2>&1;
180 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi1 chroot mdev.testdir /mdev 2>&1;
181 env - PATH=$PATH ACTION=add DEVPATH=/class/tty/capi20 chroot mdev.testdir /mdev 2>&1;
182 ls -lnR mdev.testdir/dev | $FILTER_LS" \
183"\
184mdev.testdir/dev:
185crw-rw---- 1 0 0 191,0 capi20
186crw-rw---- 1 0 0 191,1 capi20.01
187crw-rw---- 1 0 0 191,20 capi20.20
188" \
189 "" ""
190
165# clean up 191# clean up
166rm -rf mdev.testdir 192rm -rf mdev.testdir
167 193
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 7508930f7..c68c0a5e7 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -319,22 +319,20 @@ static void make_device(char *path, int delete)
319 /* "Execute" the line we found */ 319 /* "Execute" the line we found */
320 320
321 if (!delete && major >= 0) { 321 if (!delete && major >= 0) {
322 if (ENABLE_FEATURE_MDEV_RENAME) 322 char *node_name = (char *)device_name;
323 unlink(device_name); 323 if (ENABLE_FEATURE_MDEV_RENAME && alias)
324 if (mknod(device_name, mode | type, makedev(major, minor)) && errno != EEXIST) 324 alias = node_name = build_alias(alias, device_name);
325 bb_perror_msg_and_die("mknod %s", device_name); 325 if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST)
326 bb_perror_msg_and_die("mknod %s", node_name);
326 if (major == root_major && minor == root_minor) 327 if (major == root_major && minor == root_minor)
327 symlink(device_name, "root"); 328 symlink(node_name, "root");
328 if (ENABLE_FEATURE_MDEV_CONF) { 329 if (ENABLE_FEATURE_MDEV_CONF) {
329 chmod(device_name, mode); 330 chmod(node_name, mode);
330 chown(device_name, ugid.uid, ugid.gid); 331 chown(node_name, ugid.uid, ugid.gid);
331 } 332 }
332 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 333 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
333 alias = build_alias(alias, device_name); 334 if (aliaslink == '>')
334 /* move the device, and optionally 335 symlink(node_name, device_name);
335 * make a symlink to moved device node */
336 if (rename(device_name, alias) == 0 && aliaslink == '>')
337 symlink(alias, device_name);
338 free(alias); 336 free(alias);
339 } 337 }
340 } 338 }
@@ -355,15 +353,15 @@ static void make_device(char *path, int delete)
355 } 353 }
356 354
357 if (delete) { 355 if (delete) {
358 unlink(device_name); 356 char *node_name = (char *)device_name;
359 /* At creation time, device might have been moved
360 * and a symlink might have been created. Undo that. */
361
362 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 357 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
363 alias = build_alias(alias, device_name); 358 alias = node_name = build_alias(alias, device_name);
364 unlink(alias); 359 if (aliaslink == '>')
365 free(alias); 360 unlink(device_name);
366 } 361 }
362 unlink(node_name);
363 if (ENABLE_FEATURE_MDEV_RENAME)
364 free(alias);
367 } 365 }
368 366
369 /* We found matching line. 367 /* We found matching line.