summaryrefslogtreecommitdiff
path: root/util-linux/mdev.c
diff options
context:
space:
mode:
authorRob Landley2006-01-12 06:13:50 +0000
committerRob Landley2006-01-12 06:13:50 +0000
commit29e08ffcdf8de6eb57b280d587796642259fc66e (patch)
treeffdf21a624a71e92c1db8e3a917f5fcf18c2f79b /util-linux/mdev.c
parent1c19deed17f21792fcc485038b6173b9b4c186f1 (diff)
downloadbusybox-29e08ffcdf8de6eb57b280d587796642259fc66e.zip
busybox-29e08ffcdf8de6eb57b280d587796642259fc66e.tar.gz
Frank Sorenson added hotplug support to mdev. (I tweaked it a bit. Need
to come up with a test suite for all the stuff that requires root access. Something involving User Mode Linux or QEMU, probably...)
Diffstat (limited to 'util-linux/mdev.c')
-rw-r--r--util-linux/mdev.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index 10369de..1358435 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -18,6 +18,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
+#include <stdlib.h>
#include "busybox.h"
#include "xregex.h"
@@ -209,20 +210,34 @@ static void find_dev(char *path)
int mdev_main(int argc, char *argv[])
{
- if (argc > 1) {
- if (argc == 2 && !strcmp(argv[1],"-s")) {
- RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
- strcpy(temp,"/sys/block");
- find_dev(temp);
- strcpy(temp,"/sys/class");
- find_dev(temp);
- if(ENABLE_FEATURE_CLEAN_UP)
- RELEASE_CONFIG_BUFFER(temp);
- return 0;
- } else bb_show_usage();
- }
-
-/* hotplug support goes here */
+ char *action;
+ char *env_path;
+ RESERVE_CONFIG_BUFFER(temp,PATH_MAX);
+
+ /* Scan */
+ if (argc == 2 && !strcmp(argv[1],"-s")) {
+ strcpy(temp,"/sys/block");
+ find_dev(temp);
+ strcpy(temp,"/sys/class");
+ find_dev(temp);
+
+ /* Hotplug */
+
+ } else {
+ action = getenv("ACTION");
+ env_path = getenv("DEVPATH");
+ if (!action || !env_path) bb_show_usage();
+
+ if (!strcmp(action, "add")) {
+ sprintf(temp, "/sys%s", env_path);
+ make_device(temp);
+ } else if (!strcmp(action, "remove")) {
+ sprintf(temp, "%s/%s", DEV_PATH, strrchr(env_path, '/') + 1);
+ unlink(temp);
+ }
+ }
+
+ if(ENABLE_FEATURE_CLEAN_UP) RELEASE_CONFIG_BUFFER(temp);
return 0;
}