aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-07-02 13:07:11 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-07-02 13:07:11 +0200
commit90db359972643801300d4139025a25e0ba47c278 (patch)
tree064f7f299265c1037c0e5d8aff6fe429be77ba4f
parentcf4e503875814ce6e4ff8666fb4a0350ca72c6e4 (diff)
downloadbusybox-w32-90db359972643801300d4139025a25e0ba47c278.tar.gz
busybox-w32-90db359972643801300d4139025a25e0ba47c278.tar.bz2
busybox-w32-90db359972643801300d4139025a25e0ba47c278.zip
mdev: set $MDEV correctly for renamed nodes
function old new delta make_device 1467 1502 +35 build_alias 78 - -78 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-xtestsuite/mdev.tests4
-rw-r--r--util-linux/mdev.c76
2 files changed, 41 insertions, 39 deletions
diff --git a/testsuite/mdev.tests b/testsuite/mdev.tests
index 912785ece..d52f3b10b 100755
--- a/testsuite/mdev.tests
+++ b/testsuite/mdev.tests
@@ -136,12 +136,12 @@ brw-r--r-- 1 0 0 8,0 sda
136 136
137# continuing to use directory structure from prev test 137# continuing to use directory structure from prev test
138rm -rf mdev.testdir/dev/* 138rm -rf mdev.testdir/dev/*
139echo "sda 0:0 644 =block/ @echo @echo TEST" >mdev.testdir/etc/mdev.conf 139echo "sda 0:0 644 =block/ @echo @echo TEST:\$MDEV" >mdev.testdir/etc/mdev.conf
140testing "mdev move and command" \ 140testing "mdev move and command" \
141 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1; 141 "env - PATH=$PATH ACTION=add DEVPATH=/block/sda chroot mdev.testdir /mdev 2>&1;
142 ls -lnR mdev.testdir/dev | $FILTER_LS2" \ 142 ls -lnR mdev.testdir/dev | $FILTER_LS2" \
143"\ 143"\
144@echo TEST 144@echo TEST:block/sda
145mdev.testdir/dev: 145mdev.testdir/dev:
146drwxr-xr-x 2 0 0 block 146drwxr-xr-x 2 0 0 block
147 147
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index c68c0a5e7..f9ecf3cd6 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -317,49 +317,51 @@ static void make_device(char *path, int delete)
317 /* End of field parsing */ 317 /* End of field parsing */
318 318
319 /* "Execute" the line we found */ 319 /* "Execute" the line we found */
320 {
321 const char *node_name;
320 322
321 if (!delete && major >= 0) { 323 node_name = device_name;
322 char *node_name = (char *)device_name;
323 if (ENABLE_FEATURE_MDEV_RENAME && alias) 324 if (ENABLE_FEATURE_MDEV_RENAME && alias)
324 alias = node_name = build_alias(alias, device_name); 325 node_name = alias = build_alias(alias, device_name);
325 if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST) 326
326 bb_perror_msg_and_die("mknod %s", node_name); 327 if (!delete && major >= 0) {
327 if (major == root_major && minor == root_minor) 328 if (mknod(node_name, mode | type, makedev(major, minor)) && errno != EEXIST)
328 symlink(node_name, "root"); 329 bb_perror_msg_and_die("mknod %s", node_name);
329 if (ENABLE_FEATURE_MDEV_CONF) { 330 if (major == root_major && minor == root_minor)
330 chmod(node_name, mode); 331 symlink(node_name, "root");
331 chown(node_name, ugid.uid, ugid.gid); 332 if (ENABLE_FEATURE_MDEV_CONF) {
332 } 333 chmod(node_name, mode);
333 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 334 chown(node_name, ugid.uid, ugid.gid);
334 if (aliaslink == '>') 335 }
335 symlink(node_name, device_name); 336 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
336 free(alias); 337 if (aliaslink == '>')
338 symlink(node_name, device_name);
339 }
337 } 340 }
338 }
339 341
340 if (ENABLE_FEATURE_MDEV_EXEC && command) { 342 if (ENABLE_FEATURE_MDEV_EXEC && command) {
341 /* setenv will leak memory, use putenv/unsetenv/free */ 343 /* setenv will leak memory, use putenv/unsetenv/free */
342 char *s = xasprintf("%s=%s", "MDEV", device_name); 344 char *s = xasprintf("%s=%s", "MDEV", node_name);
343 char *s1 = xasprintf("%s=%s", "SUBSYSTEM", subsystem); 345 char *s1 = xasprintf("%s=%s", "SUBSYSTEM", subsystem);
344 putenv(s); 346 putenv(s);
345 putenv(s1); 347 putenv(s1);
346 if (system(command) == -1) 348 if (system(command) == -1)
347 bb_perror_msg_and_die("can't run '%s'", command); 349 bb_perror_msg_and_die("can't run '%s'", command);
348 unsetenv("SUBSYSTEM"); 350 unsetenv("SUBSYSTEM");
349 free(s1); 351 free(s1);
350 unsetenv("MDEV"); 352 unsetenv("MDEV");
351 free(s); 353 free(s);
352 free(command); 354 free(command);
353 } 355 }
354 356
355 if (delete) { 357 if (delete) {
356 char *node_name = (char *)device_name; 358 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
357 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 359 if (aliaslink == '>')
358 alias = node_name = build_alias(alias, device_name); 360 unlink(device_name);
359 if (aliaslink == '>') 361 }
360 unlink(device_name); 362 unlink(node_name);
361 } 363 }
362 unlink(node_name); 364
363 if (ENABLE_FEATURE_MDEV_RENAME) 365 if (ENABLE_FEATURE_MDEV_RENAME)
364 free(alias); 366 free(alias);
365 } 367 }