aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-05-19 22:37:07 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-05-19 22:37:07 +0200
commitaaf827203d3742c6a2768b7c0a26bd494e28ed3f (patch)
tree18048a782fcaefd3419c75512f581b7d2591eea9 /util-linux
parent8d118546785bf20963fee979e85fc9393b095082 (diff)
parent044610413767eda4350c5adf35cf5e69a6d6df8f (diff)
downloadbusybox-w32-aaf827203d3742c6a2768b7c0a26bd494e28ed3f.tar.gz
busybox-w32-aaf827203d3742c6a2768b7c0a26bd494e28ed3f.tar.bz2
busybox-w32-aaf827203d3742c6a2768b7c0a26bd494e28ed3f.zip
Merge branch 'master' of git+ssh://vda@busybox.net/var/lib/git/busybox
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/mdev.c51
1 files changed, 14 insertions, 37 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 17355bf62..84e72e2e6 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -236,7 +236,6 @@ enum { OP_add, OP_remove };
236struct rule { 236struct rule {
237 bool keep_matching; 237 bool keep_matching;
238 bool regex_compiled; 238 bool regex_compiled;
239 bool regex_has_slash;
240 mode_t mode; 239 mode_t mode;
241 int maj, min0, min1; 240 int maj, min0, min1;
242 struct bb_uidgid_t ugid; 241 struct bb_uidgid_t ugid;
@@ -340,7 +339,6 @@ static void parse_next_rule(void)
340 } 339 }
341 xregcomp(&G.cur_rule.match, val, REG_EXTENDED); 340 xregcomp(&G.cur_rule.match, val, REG_EXTENDED);
342 G.cur_rule.regex_compiled = 1; 341 G.cur_rule.regex_compiled = 1;
343 G.cur_rule.regex_has_slash = (strchr(val, '/') != NULL);
344 } 342 }
345 343
346 /* 2nd field: uid:gid - device ownership */ 344 /* 2nd field: uid:gid - device ownership */
@@ -467,11 +465,10 @@ static char *build_alias(char *alias, const char *device_name)
467 */ 465 */
468static void make_device(char *device_name, char *path, int operation) 466static void make_device(char *device_name, char *path, int operation)
469{ 467{
470 char *subsystem_slash_devname;
471 int major, minor, type, len; 468 int major, minor, type, len;
472 469
473 if (G.verbose) 470 if (G.verbose)
474 bb_error_msg("make_device: %s, %s, op:%d", device_name, path, operation); 471 bb_error_msg("device: %s, %s", device_name, path);
475 472
476 /* Try to read major/minor string. Note that the kernel puts \n after 473 /* Try to read major/minor string. Note that the kernel puts \n after
477 * the data, so we don't need to worry about null terminating the string 474 * the data, so we don't need to worry about null terminating the string
@@ -479,7 +476,7 @@ static void make_device(char *device_name, char *path, int operation)
479 * We also depend on path having writeable space after it. 476 * We also depend on path having writeable space after it.
480 */ 477 */
481 major = -1; 478 major = -1;
482 if (operation != OP_remove) { 479 if (operation == OP_add) {
483 char *dev_maj_min = path + strlen(path); 480 char *dev_maj_min = path + strlen(path);
484 481
485 strcpy(dev_maj_min, "/dev"); 482 strcpy(dev_maj_min, "/dev");
@@ -490,7 +487,10 @@ static void make_device(char *device_name, char *path, int operation)
490 return; 487 return;
491 /* no "dev" file, but we can still run scripts 488 /* no "dev" file, but we can still run scripts
492 * based on device name */ 489 * based on device name */
493 } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) != 2) { 490 } else if (sscanf(++dev_maj_min, "%u:%u", &major, &minor) == 2) {
491 if (G.verbose)
492 bb_error_msg("maj,min: %u,%u", major, minor);
493 } else {
494 major = -1; 494 major = -1;
495 } 495 }
496 } 496 }
@@ -502,29 +502,12 @@ static void make_device(char *device_name, char *path, int operation)
502 /* http://kernel.org/doc/pending/hotplug.txt says that only 502 /* http://kernel.org/doc/pending/hotplug.txt says that only
503 * "/sys/block/..." is for block devices. "/sys/bus" etc is not. 503 * "/sys/block/..." is for block devices. "/sys/bus" etc is not.
504 * But since 2.6.25 block devices are also in /sys/class/block. 504 * But since 2.6.25 block devices are also in /sys/class/block.
505 * We use strstr("/block/") to forestall future surprises. */ 505 * We use strstr("/block/") to forestall future surprises.
506 */
506 type = S_IFCHR; 507 type = S_IFCHR;
507 if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0)) 508 if (strstr(path, "/block/") || (G.subsystem && strncmp(G.subsystem, "block", 5) == 0))
508 type = S_IFBLK; 509 type = S_IFBLK;
509 510
510 /* Make path point to "subsystem/device_name" */
511 subsystem_slash_devname = NULL;
512 /* Check for coldplug invocations first */
513 if (strncmp(path, "/sys/block/", 11) == 0) /* legacy case */
514 path += sizeof("/sys/") - 1;
515 else if (strncmp(path, "/sys/class/", 11) == 0)
516 path += sizeof("/sys/class/") - 1;
517 else {
518 /* Example of a hotplug invocation:
519 * SUBSYSTEM="block"
520 * DEVPATH="/sys" + "/devices/virtual/mtd/mtd3/mtdblock3"
521 * ("/sys" is added by mdev_main)
522 * - path does not contain subsystem
523 */
524 subsystem_slash_devname = concat_path_file(G.subsystem, device_name);
525 path = subsystem_slash_devname;
526 }
527
528#if ENABLE_FEATURE_MDEV_CONF 511#if ENABLE_FEATURE_MDEV_CONF
529 G.rule_idx = 0; /* restart from the beginning (think mdev -s) */ 512 G.rule_idx = 0; /* restart from the beginning (think mdev -s) */
530#endif 513#endif
@@ -537,7 +520,7 @@ static void make_device(char *device_name, char *path, int operation)
537 char *node_name; 520 char *node_name;
538 const struct rule *rule; 521 const struct rule *rule;
539 522
540 str_to_match = ""; 523 str_to_match = device_name;
541 524
542 rule = next_rule(); 525 rule = next_rule();
543 526
@@ -555,12 +538,8 @@ static void make_device(char *device_name, char *path, int operation)
555 dbg("getenv('%s'):'%s'", rule->envvar, str_to_match); 538 dbg("getenv('%s'):'%s'", rule->envvar, str_to_match);
556 if (!str_to_match) 539 if (!str_to_match)
557 continue; 540 continue;
558 } else {
559//TODO: $DEVNAME can have slashes too,
560// we should stop abusing '/' as a special syntax in our regex'es
561 /* regex to match [subsystem/]device_name */
562 str_to_match = (rule->regex_has_slash ? path : device_name);
563 } 541 }
542 /* else: str_to_match = device_name */
564 543
565 if (rule->regex_compiled) { 544 if (rule->regex_compiled) {
566 int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0); 545 int regex_match = regexec(&rule->match, str_to_match, ARRAY_SIZE(off), off, 0);
@@ -669,12 +648,12 @@ static void make_device(char *device_name, char *path, int operation)
669 bb_error_msg("mknod: %s (%d,%d) %o", node_name, major, minor, rule->mode | type); 648 bb_error_msg("mknod: %s (%d,%d) %o", node_name, major, minor, rule->mode | type);
670 if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST) 649 if (mknod(node_name, rule->mode | type, makedev(major, minor)) && errno != EEXIST)
671 bb_perror_msg("can't create '%s'", node_name); 650 bb_perror_msg("can't create '%s'", node_name);
672 if (major == G.root_major && minor == G.root_minor)
673 symlink(node_name, "root");
674 if (ENABLE_FEATURE_MDEV_CONF) { 651 if (ENABLE_FEATURE_MDEV_CONF) {
675 chmod(node_name, rule->mode); 652 chmod(node_name, rule->mode);
676 chown(node_name, rule->ugid.uid, rule->ugid.gid); 653 chown(node_name, rule->ugid.uid, rule->ugid.gid);
677 } 654 }
655 if (major == G.root_major && minor == G.root_minor)
656 symlink(node_name, "root");
678 if (ENABLE_FEATURE_MDEV_RENAME && alias) { 657 if (ENABLE_FEATURE_MDEV_RENAME && alias) {
679 if (aliaslink == '>') { 658 if (aliaslink == '>') {
680//TODO: on devtmpfs, device_name already exists and symlink() fails. 659//TODO: on devtmpfs, device_name already exists and symlink() fails.
@@ -723,8 +702,6 @@ static void make_device(char *device_name, char *path, int operation)
723 if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching) 702 if (!ENABLE_FEATURE_MDEV_CONF || !rule->keep_matching)
724 break; 703 break;
725 } /* for (;;) */ 704 } /* for (;;) */
726
727 free(subsystem_slash_devname);
728} 705}
729 706
730/* File callback for /sys/ traversal */ 707/* File callback for /sys/ traversal */
@@ -890,13 +867,13 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
890 * DEVPATH is like "/block/sda" or "/class/input/mice" 867 * DEVPATH is like "/block/sda" or "/class/input/mice"
891 */ 868 */
892 action = getenv("ACTION"); 869 action = getenv("ACTION");
870 op = index_in_strings(keywords, action);
893 env_devname = getenv("DEVNAME"); /* can be NULL */ 871 env_devname = getenv("DEVNAME"); /* can be NULL */
894 env_devpath = getenv("DEVPATH"); 872 env_devpath = getenv("DEVPATH");
895 G.subsystem = getenv("SUBSYSTEM"); 873 G.subsystem = getenv("SUBSYSTEM");
896 if (!action || !env_devpath /*|| !G.subsystem*/) 874 if (!action || !env_devpath /*|| !G.subsystem*/)
897 bb_show_usage(); 875 bb_show_usage();
898 fw = getenv("FIRMWARE"); 876 fw = getenv("FIRMWARE");
899 op = index_in_strings(keywords, action);
900 /* If it exists, does /dev/mdev.seq match $SEQNUM? 877 /* If it exists, does /dev/mdev.seq match $SEQNUM?
901 * If it does not match, earlier mdev is running 878 * If it does not match, earlier mdev is running
902 * in parallel, and we need to wait */ 879 * in parallel, and we need to wait */
@@ -927,7 +904,7 @@ int mdev_main(int argc UNUSED_PARAM, char **argv)
927 if (logfd >= 0) { 904 if (logfd >= 0) {
928 xmove_fd(logfd, STDERR_FILENO); 905 xmove_fd(logfd, STDERR_FILENO);
929 G.verbose = 1; 906 G.verbose = 1;
930 bb_error_msg("pid: %u seq: %s action: %s", getpid(), seq, action); 907 bb_error_msg("seq: %s action: %s", seq, action);
931 } 908 }
932 } 909 }
933 910