aboutsummaryrefslogtreecommitdiffstats
path: root/udev.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-10-18 19:11:51 -0700
committerGreg KH <gregkh@suse.de>2005-04-26 22:02:46 -0700
commit7a947ce51586fd4212447643df90580542777ab9 (patch)
treed9d30236cf65e489b9bc2c5003ef9e1fa838f53e /udev.c
parent8e0871196c916be60a9d0327ce8483c4f9763c17 (diff)
downloadudev-7a947ce51586fd4212447643df90580542777ab9.tar.gz
[PATCH] big cleanup of internal udev api
Here is the first patch to cleanup the internal processing of the various stages of an udev event. It should not change any behavior, but if your system depends on udev, please always test it before reboot :) We pass only one generic structure around between add, remove, namedev, db and dev_d handling and make all relevant data available to all internal stages. All udev structures are renamed to "udev". We replace the fake parameter by a flag in the udev structure. We open the class device in the main binaries and not in udev_add, to make it possible to use libsysfs for udevstart directory crawling. The last sleep parameters are removed.
Diffstat (limited to 'udev.c')
-rw-r--r--udev.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/udev.c b/udev.c
index 10a937e4..8d5be054 100644
--- a/udev.c
+++ b/udev.c
@@ -107,9 +107,9 @@ static int subsystem_without_dev(const char *subsystem)
int main(int argc, char *argv[], char *envp[])
{
struct sigaction act;
- char *action;
- char *devpath = "";
- char *subsystem = "";
+ struct sysfs_class_device *class_dev;
+ struct udevice udev;
+ char path[SYSFS_PATH_MAX];
int retval = -EINVAL;
enum {
ADD,
@@ -129,7 +129,10 @@ int main(int argc, char *argv[], char *envp[])
if (strstr(argv[0], "udevstart")) {
act_type = UDEVSTART;
} else {
- action = get_action();
+ const char *action = get_action();
+ const char *devpath = get_devpath();
+ const char *subsystem = get_subsystem(main_argv[1]);
+
if (!action) {
dbg("no action?");
goto exit;
@@ -139,16 +142,15 @@ int main(int argc, char *argv[], char *envp[])
} else if (strcmp(action, "remove") == 0) {
act_type = REMOVE;
} else {
- dbg("unknown action '%s'", action);
+ dbg("no action '%s' for us", action);
goto exit;
}
- devpath = get_devpath();
if (!devpath) {
dbg("no devpath?");
goto exit;
}
- dbg("looking at '%s'", devpath);
+ dbg("looking at '%s'", udev.devpath);
/* we only care about class devices and block stuff */
if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
@@ -156,17 +158,18 @@ int main(int argc, char *argv[], char *envp[])
goto exit;
}
- subsystem = get_subsystem(main_argv[1]);
if (!subsystem) {
- dbg("no subsystem?");
+ dbg("no subsystem");
goto exit;
}
/* skip blacklisted subsystems */
if (subsystem_without_dev(subsystem)) {
dbg("don't care about '%s' devices", subsystem);
- exit(0);
+ goto exit;
};
+
+ udev_set_values(&udev, devpath, subsystem);
}
/* set signal handlers */
@@ -192,12 +195,25 @@ int main(int argc, char *argv[], char *envp[])
break;
case ADD:
dbg("udev add");
+
+ /* init rules */
namedev_init();
- retval = udev_add_device(devpath, subsystem, NOFAKE);
+
+ /* open the device */
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
+ class_dev = sysfs_open_class_device_path(path);
+ if (class_dev == NULL) {
+ dbg ("sysfs_open_class_device_path failed");
+ break;
+ }
+ dbg("opened class_dev->name='%s'", class_dev->name);
+
+ /* name, create node, store in db */
+ retval = udev_add_device(&udev, class_dev);
break;
case REMOVE:
dbg("udev remove");
- retval = udev_remove_device(devpath, subsystem);
+ retval = udev_remove_device(&udev);
}
udevdb_exit();