aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-16 21:42:12 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-16 21:42:12 +0000
commit6dda5dec238e35d7e760091aee061e5fc51e0e30 (patch)
tree7271cf5ed5489149e0e28d066b7b3b55e816c90e /util-linux
parentea4f0847c3d765a782eb9afe3b0f9fb0659cd1bc (diff)
downloadbusybox-6dda5dec238e35d7e760091aee061e5fc51e0e30.tar.gz
mdev: change subsystem syntax from /subsystem to subsystem/devname
Diffstat (limited to 'util-linux')
-rw-r--r--util-linux/mdev.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 2451cca05..f965b6069 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -90,21 +90,24 @@ static void make_device(char *path, int delete)
device_name = bb_basename(path);
/* http://kernel.org/doc/pending/hotplug.txt says that only
* "/sys/block/..." is for block devices. "/sys/bus" etc is not.
- * But since 2.6.25 block devices are also in /sys/class/block.
- * We use strstr("/block/") to forestall future surprises. */
+ * But since 2.6.25 block devices are also in /sys/class/block,
+ * we use strstr("/block/") to forestall future surprises. */
type = S_IFCHR;
if (strstr(path, "/block/"))
type = S_IFBLK;
+ /* Make path point to subsystem/device_name */
+ path += sizeof("/sys/class/") - 1;
+
#if !ENABLE_FEATURE_MDEV_CONF
mode = 0660;
#else
/* If we have config file, look up user settings */
parser = config_open2("/etc/mdev.conf", fopen_for_read);
while (1) {
- regmatch_t off[1 + 9*ENABLE_FEATURE_MDEV_RENAME_REGEXP];
+ regmatch_t off[1 + 9 * ENABLE_FEATURE_MDEV_RENAME_REGEXP];
int keep_matching;
- char *val;
+ char *val, *name;
struct bb_uidgid_t ugid;
char *tokens[4];
# if ENABLE_FEATURE_MDEV_EXEC
@@ -128,6 +131,10 @@ static void make_device(char *path, int delete)
keep_matching = ('-' == val[0]);
val += keep_matching; /* swallow leading dash */
+ /* Match against either subsystem/device_name
+ * or device_name alone */
+ name = strchr(val, '/') ? path : (char *) device_name;
+
/* Fields: regex uid:gid mode [alias] [cmd] */
/* 1st field: @<numeric maj,min>... */
@@ -149,15 +156,10 @@ static void make_device(char *path, int delete)
} else { /* ... or regex to match device name */
regex_t match;
int result;
- const char *dev_name_or_subsystem = device_name;
- if ('/' == val[0] && subsystem) {
- dev_name_or_subsystem = subsystem;
- val++;
- }
/* Is this it? */
xregcomp(&match, val, REG_EXTENDED);
- result = regexec(&match, dev_name_or_subsystem, ARRAY_SIZE(off), off, 0);
+ result = regexec(&match, name, ARRAY_SIZE(off), off, 0);
regfree(&match);
//bb_error_msg("matches:");
@@ -171,7 +173,7 @@ static void make_device(char *path, int delete)
/* If not this device, skip rest of line */
/* (regexec returns whole pattern as "range" 0) */
if (result || off[0].rm_so
- || ((int)off[0].rm_eo != (int)strlen(dev_name_or_subsystem))
+ || ((int)off[0].rm_eo != (int)strlen(name))
) {
continue; /* this line doesn't match */
}
@@ -214,7 +216,7 @@ static void make_device(char *path, int delete)
if (*s++ == '%')
n++;
- p = alias = xzalloc(strlen(a) + n * strlen(device_name));
+ p = alias = xzalloc(strlen(a) + n * strlen(name));
s = a + 1;
while (*s) {
*p = *s;
@@ -222,7 +224,7 @@ static void make_device(char *path, int delete)
i = (s[1] - '0');
if (i <= 9 && off[i].rm_so >= 0) {
n = off[i].rm_eo - off[i].rm_so;
- strncpy(p, device_name + off[i].rm_so, n);
+ strncpy(p, name + off[i].rm_so, n);
p += n - 1;
s++;
}