aboutsummaryrefslogtreecommitdiff
path: root/toys/pending/mdev.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-10-04 06:45:08 -0500
committerRob Landley <rob@landley.net>2015-10-04 06:45:08 -0500
commit9cc78770dc593b58e2ac0b24c42c3948c09d5eec (patch)
tree2034c9e58a34395f1fbdf9ac0189ee05b300a576 /toys/pending/mdev.c
parent73acb3a0f4ea7204f149c964adcd8938e09cb9f4 (diff)
downloadtoybox-9cc78770dc593b58e2ac0b24c42c3948c09d5eec.tar.gz
Minor cleanup and add "MODALIAS" handler (suggested by Isaac Dunham).
Diffstat (limited to 'toys/pending/mdev.c')
-rw-r--r--toys/pending/mdev.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/toys/pending/mdev.c b/toys/pending/mdev.c
index a13a53df..e7adc993 100644
--- a/toys/pending/mdev.c
+++ b/toys/pending/mdev.c
@@ -24,7 +24,7 @@ config MDEV_CONF
hd[a-z][0-9]* 0:3 660
Each line must contain three whitespace separated fields. The first
- field is a regular expression matching one or more device names, and
+ field is a regular expression matching one or more device names,
the second and third fields are uid:gid and file permissions for
matching devies.
*/
@@ -34,9 +34,8 @@ config MDEV_CONF
// mknod in /dev based on a path like "/sys/block/hda/hda1"
static void make_device(char *path)
{
- char *device_name = NULL, *s, *temp;
- int major = 0, minor = 0, type, len, fd;
- int mode = 0660;
+ char *device_name = 0, *s, *temp;
+ int major = 0, minor = 0, type, len, fd, mode = 0660;
uid_t uid = 0;
gid_t gid = 0;
@@ -45,7 +44,7 @@ static void make_device(char *path)
temp = strrchr(path, '/');
fd = open(path, O_RDONLY);
- *temp=0;
+ *temp = 0;
len = read(fd, toybuf, 64);
close(fd);
if (len<1) return;
@@ -58,19 +57,15 @@ static void make_device(char *path)
} else {
// if (!path), do hotplug
- if (!(temp = getenv("SUBSYSTEM")))
- return;
+ if (!(temp = getenv("MODALIAS"))) xrun((char *[]){"modprobe", temp, 0});
+ if (!(temp = getenv("SUBSYSTEM"))) return;
type = strcmp(temp, "block") ? S_IFCHR : S_IFBLK;
- if (!(temp = getenv("MAJOR")))
- return;
+ if (!(temp = getenv("MAJOR"))) return;
sscanf(temp, "%u", &major);
- if (!(temp = getenv("MINOR")))
- return;
+ if (!(temp = getenv("MINOR"))) return;
sscanf(temp, "%u", &minor);
- path = getenv("DEVPATH");
+ if (!(path = getenv("DEVPATH"))) return;
device_name = getenv("DEVNAME");
- if (!path)
- return;
}
if (!device_name)
device_name = strrchr(path, '/') + 1;