mirror of
https://github.com/sheumann/hush.git
synced 2024-11-05 21:04:56 +00:00
mdev: change subsystem syntax from /subsystem to subsystem/devname
This commit is contained in:
parent
ea4f0847c3
commit
6dda5dec23
@ -90,21 +90,24 @@ static void make_device(char *path, int delete)
|
|||||||
device_name = bb_basename(path);
|
device_name = bb_basename(path);
|
||||||
/* http://kernel.org/doc/pending/hotplug.txt says that only
|
/* http://kernel.org/doc/pending/hotplug.txt says that only
|
||||||
* "/sys/block/..." is for block devices. "/sys/bus" etc is not.
|
* "/sys/block/..." is for block devices. "/sys/bus" etc is not.
|
||||||
* But since 2.6.25 block devices are also in /sys/class/block.
|
* But since 2.6.25 block devices are also in /sys/class/block,
|
||||||
* We use strstr("/block/") to forestall future surprises. */
|
* we use strstr("/block/") to forestall future surprises. */
|
||||||
type = S_IFCHR;
|
type = S_IFCHR;
|
||||||
if (strstr(path, "/block/"))
|
if (strstr(path, "/block/"))
|
||||||
type = S_IFBLK;
|
type = S_IFBLK;
|
||||||
|
|
||||||
|
/* Make path point to subsystem/device_name */
|
||||||
|
path += sizeof("/sys/class/") - 1;
|
||||||
|
|
||||||
#if !ENABLE_FEATURE_MDEV_CONF
|
#if !ENABLE_FEATURE_MDEV_CONF
|
||||||
mode = 0660;
|
mode = 0660;
|
||||||
#else
|
#else
|
||||||
/* If we have config file, look up user settings */
|
/* If we have config file, look up user settings */
|
||||||
parser = config_open2("/etc/mdev.conf", fopen_for_read);
|
parser = config_open2("/etc/mdev.conf", fopen_for_read);
|
||||||
while (1) {
|
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;
|
int keep_matching;
|
||||||
char *val;
|
char *val, *name;
|
||||||
struct bb_uidgid_t ugid;
|
struct bb_uidgid_t ugid;
|
||||||
char *tokens[4];
|
char *tokens[4];
|
||||||
# if ENABLE_FEATURE_MDEV_EXEC
|
# if ENABLE_FEATURE_MDEV_EXEC
|
||||||
@ -128,6 +131,10 @@ static void make_device(char *path, int delete)
|
|||||||
keep_matching = ('-' == val[0]);
|
keep_matching = ('-' == val[0]);
|
||||||
val += keep_matching; /* swallow leading dash */
|
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] */
|
/* Fields: regex uid:gid mode [alias] [cmd] */
|
||||||
|
|
||||||
/* 1st field: @<numeric maj,min>... */
|
/* 1st field: @<numeric maj,min>... */
|
||||||
@ -149,15 +156,10 @@ static void make_device(char *path, int delete)
|
|||||||
} else { /* ... or regex to match device name */
|
} else { /* ... or regex to match device name */
|
||||||
regex_t match;
|
regex_t match;
|
||||||
int result;
|
int result;
|
||||||
const char *dev_name_or_subsystem = device_name;
|
|
||||||
if ('/' == val[0] && subsystem) {
|
|
||||||
dev_name_or_subsystem = subsystem;
|
|
||||||
val++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Is this it? */
|
/* Is this it? */
|
||||||
xregcomp(&match, val, REG_EXTENDED);
|
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);
|
regfree(&match);
|
||||||
|
|
||||||
//bb_error_msg("matches:");
|
//bb_error_msg("matches:");
|
||||||
@ -171,7 +173,7 @@ static void make_device(char *path, int delete)
|
|||||||
/* If not this device, skip rest of line */
|
/* If not this device, skip rest of line */
|
||||||
/* (regexec returns whole pattern as "range" 0) */
|
/* (regexec returns whole pattern as "range" 0) */
|
||||||
if (result || off[0].rm_so
|
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 */
|
continue; /* this line doesn't match */
|
||||||
}
|
}
|
||||||
@ -214,7 +216,7 @@ static void make_device(char *path, int delete)
|
|||||||
if (*s++ == '%')
|
if (*s++ == '%')
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
p = alias = xzalloc(strlen(a) + n * strlen(device_name));
|
p = alias = xzalloc(strlen(a) + n * strlen(name));
|
||||||
s = a + 1;
|
s = a + 1;
|
||||||
while (*s) {
|
while (*s) {
|
||||||
*p = *s;
|
*p = *s;
|
||||||
@ -222,7 +224,7 @@ static void make_device(char *path, int delete)
|
|||||||
i = (s[1] - '0');
|
i = (s[1] - '0');
|
||||||
if (i <= 9 && off[i].rm_so >= 0) {
|
if (i <= 9 && off[i].rm_so >= 0) {
|
||||||
n = off[i].rm_eo - off[i].rm_so;
|
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;
|
p += n - 1;
|
||||||
s++;
|
s++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user