* [adventure] replace /sbin/hotplug by udevd
@ 2004-11-18 0:27 Kay Sievers
2004-11-18 1:25 ` Greg KH
` (8 more replies)
0 siblings, 9 replies; 10+ messages in thread
From: Kay Sievers @ 2004-11-18 0:27 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 2166 bytes --]
!!! Please, don't try this if you don't know how to bring your !!!
!!! system back if it does not boot anymore cause of a broken udev. !!!
This experimental patch changes udevd/udev to handle the _whole_ hotplug
event from the kernel up to the multiplexing of /etc/hotplug.d/. It
should solve most of the current shortcomings of the hotplug event handling:
- sysfs if not fully populated at event time
- at device disconnect/reconnect, the "remove" may beat the "add"
- an event may already work on the same DEVPATH
- the hotplug scripts don't know the device node name
- the total count of event processes can't be controlled
The architecture is very similar to udevd today, only that we wait for
_all_ sysfs devices internally and then also calls /etc/hotplug/* from
the forked udev process.
/sbin/hotplug is replaced by /sbin/udevsend. The kernel just calls this
small binary to place the event into the udevd daemon. We may also use
the netlink uevent in the future, so no fork at all is done from the
kernel for a hotplug event.
The daemon listens, reorders events and forks an instance for every event,
which:
-waits for sysfs (also for /sys/devices/*)
-creates/removes the device node
-exports interesting values to its environment
-calls/multiplexes /etc/hotplug.d/*
-calls/multiplexes /etc/dev.d/* (we don't really need that anymore)
-exits
This way get all what todays hotplug events can dream of:
-fully populated sysfs
-events in the right order (SEQNUM)
-delayed events for the _same_ DEVPATH, all others run in parallel
-all interesting values to the environment
-device node ready and its name available
-possibly limit the total count of events processes (not implemented now)
One single hotplug event for the creation of a partition now looks like this:
ACTION=add
SUBSYSTEM=block
DEVPATH=/block/sda/sda1
SEQNUM=1027
DEVNAME=/dev/sda1
PHYSDEVPATH=/devices/pci0000:00/0000:00:1d.1/usb3/3-1/3-1:1.0/host0/target0:0:0/0:0:0:0
PHYSDEVBUS=scsi
PHYSDEVDRIVER=sd
This patch applies on top of udev v045. /proc/sys/kernel/hotplug should be
set to /sbin/udevsend.
Any thoughts,
Kay
[-- Attachment #2: udev-as-hotplugd-02.patch --]
[-- Type: text/plain, Size: 11617 bytes --]
===== dev_d.c 1.20 vs edited =====
--- 1.20/dev_d.c 2004-11-11 22:32:18 +01:00
+++ edited/dev_d.c 2004-11-16 00:47:59 +01:00
@@ -37,6 +37,11 @@ static int run_program(const char *filen
int fd;
struct udevice *udev = data;
+ if (strstr(filename, "udev.hotplug") != NULL) {
+ dbg("prevent loop, don't call link pointing to ourself");
+ return 0;
+ }
+
dbg("running %s", filename);
pid = fork();
@@ -96,13 +101,17 @@ void dev_d_execute(struct udevice *udev,
temp = strchr(temp, '/');
}
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
- dirname[PATH_MAX-1] = '\0';
- call_foreach_file(run_program, dirname, suffix, udev);
-
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
- dirname[PATH_MAX-1] = '\0';
- call_foreach_file(run_program, dirname, suffix, udev);
+ if (udev->name[0] != '\0') {
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
+ }
+
+ if (udev->subsystem[0] != '\0') {
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
+ }
snprintf(dirname, PATH_MAX, "%s/default", basedir);
dirname[PATH_MAX-1] = '\0';
===== udev.c 1.82 vs edited =====
--- 1.82/udev.c 2004-11-13 06:51:09 +01:00
+++ edited/udev.c 2004-11-16 15:00:15 +01:00
@@ -4,6 +4,7 @@
* Userspace devfs
*
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -68,66 +69,19 @@ int main(int argc, char *argv[], char *e
{
struct sigaction act;
struct sysfs_class_device *class_dev;
+ struct sysfs_device *devices_dev;
struct udevice udev;
char path[SYSFS_PATH_MAX];
int retval = -EINVAL;
- enum {
- ADD,
- REMOVE,
- UDEVSTART,
- } act_type;
+ const char *error;
+ const char *action = getenv("ACTION");
+ const char *devpath = getenv("DEVPATH");
+ const char *subsystem = argv[1];
dbg("version %s", UDEV_VERSION);
logging_init("udev");
udev_init_config();
- if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
- act_type = UDEVSTART;
- } else {
- const char *action = getenv("ACTION");
- const char *devpath = getenv("DEVPATH");
- const char *subsystem = argv[1];
-
- if (!action) {
- dbg("no action?");
- goto exit;
- }
- if (strcmp(action, "add") == 0) {
- act_type = ADD;
- } else if (strcmp(action, "remove") == 0) {
- act_type = REMOVE;
- } else {
- dbg("no action '%s' for us", action);
- goto exit;
- }
-
- if (!devpath) {
- dbg("no devpath?");
- goto exit;
- }
- dbg("looking at '%s'", devpath);
-
- /* we only care about class devices and block stuff */
- if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
- dbg("not a block or class device");
- goto exit;
- }
-
- if (!subsystem) {
- dbg("no subsystem");
- goto exit;
- }
-
- udev_set_values(&udev, devpath, subsystem, action);
-
- /* skip blacklisted subsystems */
- if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) {
- dbg("don't care about '%s' devices", subsystem);
- goto exit;
- };
-
- }
-
/* set signal handlers */
act.sa_handler = (void (*) (int))sig_handler;
sigemptyset (&act.sa_mask);
@@ -137,51 +91,104 @@ int main(int argc, char *argv[], char *e
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
- /* trigger timout to interrupt blocking syscalls */
+ /* trigger timeout to interrupt blocking syscalls */
alarm(ALARM_TIMEOUT);
- switch(act_type) {
- case UDEVSTART:
- dbg("udevstart");
+ udev_set_values(&udev, devpath, subsystem, action);
+
+ if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
+ dbg("event: udevstart");
udev_log = 0;
namedev_init();
retval = udev_start();
- break;
- case ADD:
- dbg("udev add");
-
- /* 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);
+ goto exit;
+ }
- /* init rules */
- namedev_init();
+ if (!action) {
+ dbg("no action");
+ goto hotplug;
+ }
+
+ if (!subsystem) {
+ dbg("no subsystem");
+ goto hotplug;
+ }
+
+ if (!devpath) {
+ dbg("no devpath");
+ goto hotplug;
+ }
+
+ if ((strncmp(devpath, "/block/", 7) == 0) || (strncmp(devpath, "/class/", 7) == 0)) {
+ if (strcmp(action, "add") == 0) {
+ /* wait for sysfs and possibly add node */
+ dbg("event: udev add");
+
+ /* skip blacklisted subsystems */
+ if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
+ dbg("don't care about '%s' devices", udev.subsystem);
+ goto hotplug;
+ };
+
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
+ class_dev = wait_class_device_open(path);
+ if (class_dev == NULL) {
+ dbg ("sysfs_open_class_device_path failed");
+ goto hotplug;
+ }
+ dbg("opened class_dev->name='%s'", class_dev->name);
+
+ wait_for_class_device(class_dev, &error);
+
+ /* init rules, permissions */
+ namedev_init();
+
+ /* name, create node, store in db */
+ retval = udev_add_device(&udev, class_dev);
+
+ /* run dev.d/ scripts if we created a node or changed a netif name */
+ if (udev.devname[0] != '\0') {
+ setenv("DEVNAME", udev.devname, 1);
+ dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ }
- /* name, create node, store in db */
- retval = udev_add_device(&udev, class_dev);
+ sysfs_close_class_device(class_dev);
+ } else if (strcmp(action, "remove") == 0) {
+ /* possibly remove a node */
+ dbg("event: udev remove");
- /* run dev.d/ scripts if we created a node or changed a netif name */
- if (udev.devname[0] != '\0') {
- setenv("DEVNAME", udev.devname, 1);
+ /* get node from db, delete it */
+ retval = udev_remove_device(&udev);
+
+ /* run scripts */
dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
}
+ } else if ((strncmp(devpath, "/devices/", 9) == 0)) {
+ if (strcmp(action, "add") == 0) {
+ /* wait for sysfs */
+ dbg("event: devices add");
- sysfs_close_class_device(class_dev);
- break;
- case REMOVE:
- dbg("udev remove");
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath);
+ devices_dev = wait_devices_device_open(path);
+ if (!devices_dev) {
+ dbg("error: devices device unavailable (probably remove has beaten us)");
+ goto hotplug;
+ }
+ dbg("devices device opened '%s'", path);
- /* get node from db, delete it*/
- retval = udev_remove_device(&udev);
+ wait_for_devices_device(devices_dev, &error);
- /* run scripts */
- dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ sysfs_close_device(devices_dev);
+ } else if (strcmp(action, "remove") == 0) {
+ dbg("event: devices remove");
+ }
+ } else {
+ dbg("event: unhandled");
}
+
+hotplug:
+ /* call the hotplug scripts */
+ dev_d_execute(&udev, HOTPLUGD_DIR, HOTPLUG_SUFFIX);
exit:
logging_close();
===== udev.h 1.72 vs edited =====
--- 1.72/udev.h 2004-11-13 06:43:23 +01:00
+++ edited/udev.h 2004-11-16 00:29:14 +01:00
@@ -44,6 +44,9 @@
#define DEVD_DIR "/etc/dev.d"
#define DEVD_SUFFIX ".dev"
+#define HOTPLUGD_DIR "/etc/hotplug.d"
+#define HOTPLUG_SUFFIX ".hotplug"
+
struct udevice {
char devpath[DEVPATH_SIZE];
char subsystem[SUBSYSTEM_SIZE];
===== udev_lib.c 1.16 vs edited =====
--- 1.16/udev_lib.c 2004-11-13 04:36:46 +01:00
+++ edited/udev_lib.c 2004-11-16 01:54:09 +01:00
@@ -40,37 +40,32 @@
#define CLASS_PATH "/class/"
#define NET_PATH "/class/net/"
-char get_device_type(const char *path, const char *subsystem)
-{
- if (strcmp(subsystem, "block") == 0)
- return 'b';
-
- if (strcmp(subsystem, "net") == 0)
- return 'n';
-
- if (strncmp(path, BLOCK_PATH, strlen(BLOCK_PATH)) == 0 &&
- strlen(path) > strlen(BLOCK_PATH))
- return 'b';
-
- if (strncmp(path, NET_PATH, strlen(NET_PATH)) == 0 &&
- strlen(path) > strlen(NET_PATH))
- return 'n';
-
- if (strncmp(path, CLASS_PATH, strlen(CLASS_PATH)) == 0 &&
- strlen(path) > strlen(CLASS_PATH))
- return 'c';
-
- return '\0';
-}
void udev_set_values(struct udevice *udev, const char* devpath,
const char *subsystem, const char* action)
{
memset(udev, 0x00, sizeof(struct udevice));
- strfieldcpy(udev->devpath, devpath);
- strfieldcpy(udev->subsystem, subsystem);
- strfieldcpy(udev->action, action);
- udev->type = get_device_type(devpath, subsystem);
+ if (devpath)
+ strfieldcpy(udev->devpath, devpath);
+ if (subsystem)
+ strfieldcpy(udev->subsystem, subsystem);
+ if (action)
+ strfieldcpy(udev->action, action);
+
+ if (strcmp(udev->subsystem, "block") == 0)
+ udev->type = 'b';
+
+ if (strcmp(udev->subsystem, "net") == 0)
+ udev->type = 'n';
+
+ if (strncmp(udev->devpath, "/block/", 7) == 0)
+ udev->type = 'b';
+
+ if (strncmp(udev->devpath, "/class/net/", 11) == 0)
+ udev->type = 'n';
+
+ if (strncmp(udev->devpath, "/class/", 7) == 0)
+ udev->type = 'c';
}
int kernel_release_satisfactory(int version, int patchlevel, int sublevel)
===== udev_lib.h 1.16 vs edited =====
--- 1.16/udev_lib.h 2004-11-13 04:36:46 +01:00
+++ edited/udev_lib.h 2004-11-16 01:23:01 +01:00
@@ -76,7 +76,6 @@ do { \
# define asmlinkage /* nothing */
#endif
-extern char get_device_type(const char *path, const char *subsystem);
extern void udev_set_values(struct udevice *udev, const char* devpath,
const char *subsystem, const char* action);
extern int kernel_release_satisfactory(int version, int patchlevel, int sublevel);
===== udevd.c 1.47 vs edited =====
--- 1.47/udevd.c 2004-11-11 22:18:28 +01:00
+++ edited/udevd.c 2004-11-16 02:35:46 +01:00
@@ -153,9 +153,14 @@ static void udev_run(struct hotplug_msg
static struct hotplug_msg *running_with_devpath(struct hotplug_msg *msg)
{
struct hotplug_msg *loop_msg;
- list_for_each_entry(loop_msg, &running_list, list)
- if (strncmp(loop_msg->devpath, msg->devpath, sizeof(loop_msg->devpath)) == 0)
+ list_for_each_entry(loop_msg, &running_list, list) {
+ if (loop_msg->devpath == NULL || msg->devpath == NULL)
+ continue;
+
+ if (strcmp(loop_msg->devpath, msg->devpath) == 0)
return loop_msg;
+ }
+
return NULL;
}
===== udevinfo.c 1.32 vs edited =====
--- 1.32/udevinfo.c 2004-11-12 21:33:25 +01:00
+++ edited/udevinfo.c 2004-11-16 01:22:40 +01:00
@@ -125,10 +125,6 @@ static int print_device_chain(const char
struct sysfs_device *sysfs_dev;
struct sysfs_device *sysfs_dev_parent;
int retval = 0;
- char type;
-
- type = get_device_type(path, "");
- dbg("device type is %c", type);
/* get the class dev */
class_dev = sysfs_open_class_device_path(path);
@@ -144,16 +140,10 @@ static int print_device_chain(const char
"to match the device for which the node will be created.\n"
"\n");
- if (type == 'b' || type =='c') {
- /* read the 'dev' file for major/minor*/
- attr = sysfs_get_classdev_attr(class_dev, "dev");
- if (attr == NULL) {
- printf("couldn't get the \"dev\" file\n");
- retval = -1;
- goto exit;
- }
+ /* look for the 'dev' file */
+ attr = sysfs_get_classdev_attr(class_dev, "dev");
+ if (attr == NULL)
printf("device '%s' has major:minor %s", class_dev->path, attr->value);
- }
/* open sysfs class device directory and print all attributes */
printf(" looking at class device '%s':\n", class_dev->path);
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
@ 2004-11-18 1:25 ` Greg KH
2004-11-18 4:04 ` Kevin P. Fleming
` (7 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2004-11-18 1:25 UTC (permalink / raw)
To: linux-hotplug
On Thu, Nov 18, 2004 at 01:27:26AM +0100, Kay Sievers wrote:
> This patch applies on top of udev v045. /proc/sys/kernel/hotplug should be
> set to /sbin/udevsend.
No, it applies on top of the latest udev bk tree, not on top of the
recently released udev v045 that is on kernel.org.
That's my fault due to the way I've been releasing v044 and v045 without
your database changes. I'll fix this up tomorrow by putting out a v046
that has all of your recent changes in it, and then this patch will
apply on top of it.
Sorry for any confusion.
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
2004-11-18 1:25 ` Greg KH
@ 2004-11-18 4:04 ` Kevin P. Fleming
2004-11-18 6:40 ` Stefan Schweizer
` (6 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Kevin P. Fleming @ 2004-11-18 4:04 UTC (permalink / raw)
To: linux-hotplug
Kay Sievers wrote:
> This experimental patch changes udevd/udev to handle the _whole_ hotplug
> event from the kernel up to the multiplexing of /etc/hotplug.d/. It
> should solve most of the current shortcomings of the hotplug event handling:
> - sysfs if not fully populated at event time
> - at device disconnect/reconnect, the "remove" may beat the "add"
> - an event may already work on the same DEVPATH
> - the hotplug scripts don't know the device node name
> - the total count of event processes can't be controlled
This is very, very cool. What a major simplification of the whole
process, with the addition of interesting new features as well.
What is the likely timeframe for this to make it into udev proper?
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
2004-11-18 1:25 ` Greg KH
2004-11-18 4:04 ` Kevin P. Fleming
@ 2004-11-18 6:40 ` Stefan Schweizer
2004-11-18 23:47 ` Kay Sievers
` (5 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Stefan Schweizer @ 2004-11-18 6:40 UTC (permalink / raw)
To: linux-hotplug
This will also solve problems where the hottplug scripts cannot be
run, because the dev is not created. Hotplug scripts normallyy access
the dev, so this is imo very much needed.
Stefan
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
` (2 preceding siblings ...)
2004-11-18 6:40 ` Stefan Schweizer
@ 2004-11-18 23:47 ` Kay Sievers
2004-11-19 0:03 ` Kay Sievers
` (4 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Kay Sievers @ 2004-11-18 23:47 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1031 bytes --]
On Wed, Nov 17, 2004 at 05:25:01PM -0800, Greg KH wrote:
> On Thu, Nov 18, 2004 at 01:27:26AM +0100, Kay Sievers wrote:
> > This patch applies on top of udev v045. /proc/sys/kernel/hotplug should be
> > set to /sbin/udevsend.
>
> No, it applies on top of the latest udev bk tree, not on top of the
> recently released udev v045 that is on kernel.org.
>
> That's my fault due to the way I've been releasing v044 and v045 without
> your database changes. I'll fix this up tomorrow by putting out a v046
> that has all of your recent changes in it, and then this patch will
> apply on top of it.
Here is a new version on top of the released v046. It's a very small
patch now. To test it:
kill the current daemon:
[root@pim udev.kay]# killall udevd
disable the usual hotplug multiplexer and pass the event to the daemon only:
[root@pim udev.kay]# echo /sbin/udevsend > /proc/sys/kernel/hotplug
start the daemon, but let it fork the new udev:
[root@pim udev.kay]# UDEV_BIN=/home/kay/src/udev.kay/udev ./udevd
Thanks,
Kay
[-- Attachment #2: udev-as-hotplugd-03.patch --]
[-- Type: text/plain, Size: 7449 bytes --]
===== dev_d.c 1.20 vs edited =====
--- 1.20/dev_d.c 2004-11-11 22:32:18 +01:00
+++ edited/dev_d.c 2004-11-18 21:28:52 +01:00
@@ -37,6 +37,11 @@
int fd;
struct udevice *udev = data;
+ if (strstr(filename, "udev.hotplug") != NULL) {
+ dbg("prevent loop, don't call link pointing to ourself");
+ return 0;
+ }
+
dbg("running %s", filename);
pid = fork();
@@ -96,13 +101,17 @@
temp = strchr(temp, '/');
}
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
- dirname[PATH_MAX-1] = '\0';
- call_foreach_file(run_program, dirname, suffix, udev);
-
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
- dirname[PATH_MAX-1] = '\0';
- call_foreach_file(run_program, dirname, suffix, udev);
+ if (udev->name[0] != '\0') {
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
+ }
+
+ if (udev->subsystem[0] != '\0') {
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
+ }
snprintf(dirname, PATH_MAX, "%s/default", basedir);
dirname[PATH_MAX-1] = '\0';
===== udev.c 1.82 vs edited =====
--- 1.82/udev.c 2004-11-13 06:51:09 +01:00
+++ edited/udev.c 2004-11-18 21:28:53 +01:00
@@ -4,6 +4,7 @@
* Userspace devfs
*
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -68,66 +69,19 @@
{
struct sigaction act;
struct sysfs_class_device *class_dev;
+ struct sysfs_device *devices_dev;
struct udevice udev;
char path[SYSFS_PATH_MAX];
int retval = -EINVAL;
- enum {
- ADD,
- REMOVE,
- UDEVSTART,
- } act_type;
+ const char *error;
+ const char *action = getenv("ACTION");
+ const char *devpath = getenv("DEVPATH");
+ const char *subsystem = argv[1];
dbg("version %s", UDEV_VERSION);
logging_init("udev");
udev_init_config();
- if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
- act_type = UDEVSTART;
- } else {
- const char *action = getenv("ACTION");
- const char *devpath = getenv("DEVPATH");
- const char *subsystem = argv[1];
-
- if (!action) {
- dbg("no action?");
- goto exit;
- }
- if (strcmp(action, "add") == 0) {
- act_type = ADD;
- } else if (strcmp(action, "remove") == 0) {
- act_type = REMOVE;
- } else {
- dbg("no action '%s' for us", action);
- goto exit;
- }
-
- if (!devpath) {
- dbg("no devpath?");
- goto exit;
- }
- dbg("looking at '%s'", devpath);
-
- /* we only care about class devices and block stuff */
- if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
- dbg("not a block or class device");
- goto exit;
- }
-
- if (!subsystem) {
- dbg("no subsystem");
- goto exit;
- }
-
- udev_set_values(&udev, devpath, subsystem, action);
-
- /* skip blacklisted subsystems */
- if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) {
- dbg("don't care about '%s' devices", subsystem);
- goto exit;
- };
-
- }
-
/* set signal handlers */
act.sa_handler = (void (*) (int))sig_handler;
sigemptyset (&act.sa_mask);
@@ -137,51 +91,104 @@
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
- /* trigger timout to interrupt blocking syscalls */
+ /* trigger timeout to interrupt blocking syscalls */
alarm(ALARM_TIMEOUT);
- switch(act_type) {
- case UDEVSTART:
- dbg("udevstart");
+ udev_set_values(&udev, devpath, subsystem, action);
+
+ if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
+ dbg("event: udevstart");
udev_log = 0;
namedev_init();
retval = udev_start();
- break;
- case ADD:
- dbg("udev add");
-
- /* 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);
+ goto exit;
+ }
- /* init rules */
- namedev_init();
+ if (!action) {
+ dbg("no action");
+ goto hotplug;
+ }
+
+ if (!subsystem) {
+ dbg("no subsystem");
+ goto hotplug;
+ }
+
+ if (!devpath) {
+ dbg("no devpath");
+ goto hotplug;
+ }
+
+ if ((strncmp(devpath, "/block/", 7) == 0) || (strncmp(devpath, "/class/", 7) == 0)) {
+ if (strcmp(action, "add") == 0) {
+ /* wait for sysfs and possibly add node */
+ dbg("event: udev add");
+
+ /* skip blacklisted subsystems */
+ if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
+ dbg("don't care about '%s' devices", udev.subsystem);
+ goto hotplug;
+ };
+
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
+ class_dev = wait_class_device_open(path);
+ if (class_dev == NULL) {
+ dbg ("sysfs_open_class_device_path failed");
+ goto hotplug;
+ }
+ dbg("opened class_dev->name='%s'", class_dev->name);
+
+ wait_for_class_device(class_dev, &error);
+
+ /* init rules, permissions */
+ namedev_init();
+
+ /* name, create node, store in db */
+ retval = udev_add_device(&udev, class_dev);
+
+ /* run dev.d/ scripts if we created a node or changed a netif name */
+ if (udev.devname[0] != '\0') {
+ setenv("DEVNAME", udev.devname, 1);
+ dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ }
- /* name, create node, store in db */
- retval = udev_add_device(&udev, class_dev);
+ sysfs_close_class_device(class_dev);
+ } else if (strcmp(action, "remove") == 0) {
+ /* possibly remove a node */
+ dbg("event: udev remove");
- /* run dev.d/ scripts if we created a node or changed a netif name */
- if (udev.devname[0] != '\0') {
- setenv("DEVNAME", udev.devname, 1);
+ /* get node from db, delete it */
+ retval = udev_remove_device(&udev);
+
+ /* run scripts */
dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
}
+ } else if ((strncmp(devpath, "/devices/", 9) == 0)) {
+ if (strcmp(action, "add") == 0) {
+ /* wait for sysfs */
+ dbg("event: devices add");
- sysfs_close_class_device(class_dev);
- break;
- case REMOVE:
- dbg("udev remove");
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath);
+ devices_dev = wait_devices_device_open(path);
+ if (!devices_dev) {
+ dbg("error: devices device unavailable (probably remove has beaten us)");
+ goto hotplug;
+ }
+ dbg("devices device opened '%s'", path);
- /* get node from db, delete it*/
- retval = udev_remove_device(&udev);
+ wait_for_devices_device(devices_dev, &error);
- /* run scripts */
- dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ sysfs_close_device(devices_dev);
+ } else if (strcmp(action, "remove") == 0) {
+ dbg("event: devices remove");
+ }
+ } else {
+ dbg("event: unhandled");
}
+
+hotplug:
+ /* call the hotplug scripts */
+ dev_d_execute(&udev, HOTPLUGD_DIR, HOTPLUG_SUFFIX);
exit:
logging_close();
===== udev.h 1.72 vs edited =====
--- 1.72/udev.h 2004-11-13 06:43:23 +01:00
+++ edited/udev.h 2004-11-18 21:28:53 +01:00
@@ -44,6 +44,9 @@
#define DEVD_DIR "/etc/dev.d"
#define DEVD_SUFFIX ".dev"
+#define HOTPLUGD_DIR "/etc/hotplug.d"
+#define HOTPLUG_SUFFIX ".hotplug"
+
struct udevice {
char devpath[DEVPATH_SIZE];
char subsystem[SUBSYSTEM_SIZE];
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
` (3 preceding siblings ...)
2004-11-18 23:47 ` Kay Sievers
@ 2004-11-19 0:03 ` Kay Sievers
2004-11-19 0:55 ` Greg KH
` (3 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Kay Sievers @ 2004-11-19 0:03 UTC (permalink / raw)
To: linux-hotplug
On Wed, 2004-11-17 at 21:04 -0700, Kevin P. Fleming wrote:
> Kay Sievers wrote:
>
> > This experimental patch changes udevd/udev to handle the _whole_ hotplug
> > event from the kernel up to the multiplexing of /etc/hotplug.d/. It
> > should solve most of the current shortcomings of the hotplug event handling:
> > - sysfs if not fully populated at event time
> > - at device disconnect/reconnect, the "remove" may beat the "add"
> > - an event may already work on the same DEVPATH
> > - the hotplug scripts don't know the device node name
> > - the total count of event processes can't be controlled
>
> This is very, very cool. What a major simplification of the whole
> process, with the addition of interesting new features as well.
>
> What is the likely timeframe for this to make it into udev proper?
How can I know? :) I started this back in March this year and just give
it a second try now with this much improved version.
We are run into serious trouble with HAL(hal.freedesktop.org) managing
the unordered events from the programs in /etc/hotplug.d and /etc/dev.d/,
to match these two events together by SEQNUM and wait for sysfs to get
populated. This all should be pretty easy now with only one small
hal-notify program in the /etc/hotplug.d directory.
Let's see what other people think about it.
Thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
` (4 preceding siblings ...)
2004-11-19 0:03 ` Kay Sievers
@ 2004-11-19 0:55 ` Greg KH
2004-11-19 1:11 ` Kay Sievers
` (2 subsequent siblings)
8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2004-11-19 0:55 UTC (permalink / raw)
To: linux-hotplug
On Wed, Nov 17, 2004 at 09:04:55PM -0700, Kevin P. Fleming wrote:
> Kay Sievers wrote:
>
> >This experimental patch changes udevd/udev to handle the _whole_ hotplug
> >event from the kernel up to the multiplexing of /etc/hotplug.d/. It
> >should solve most of the current shortcomings of the hotplug event
> >handling:
> > - sysfs if not fully populated at event time
> > - at device disconnect/reconnect, the "remove" may beat the "add"
> > - an event may already work on the same DEVPATH
> > - the hotplug scripts don't know the device node name
> > - the total count of event processes can't be controlled
>
> This is very, very cool. What a major simplification of the whole
> process, with the addition of interesting new features as well.
>
> What is the likely timeframe for this to make it into udev proper?
The main "problem" with this is for people who don't want to run udev on
their machines. They are happy with their static dev, yet they want to
have the hotplug package manage their modules, and do the other fun
stuff (like HAL). If udev requires that it take over the hotplug
multiplexer, then anyone who doesn't use udev looses out from the good
things that HAL and anyone who relies on the functionality that this new
udevd provides can't ensure that all users will actually have it
running.
Did that make sense?
I don't know how to resolve this issue right now :(
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
` (5 preceding siblings ...)
2004-11-19 0:55 ` Greg KH
@ 2004-11-19 1:11 ` Kay Sievers
2004-11-19 7:27 ` Greg KH
2004-11-19 16:03 ` Kay Sievers
8 siblings, 0 replies; 10+ messages in thread
From: Kay Sievers @ 2004-11-19 1:11 UTC (permalink / raw)
To: linux-hotplug
On Thu, 2004-11-18 at 16:55 -0800, Greg KH wrote:
> On Wed, Nov 17, 2004 at 09:04:55PM -0700, Kevin P. Fleming wrote:
> > Kay Sievers wrote:
> >
> > >This experimental patch changes udevd/udev to handle the _whole_ hotplug
> > >event from the kernel up to the multiplexing of /etc/hotplug.d/. It
> > >should solve most of the current shortcomings of the hotplug event
> > >handling:
> > > - sysfs if not fully populated at event time
> > > - at device disconnect/reconnect, the "remove" may beat the "add"
> > > - an event may already work on the same DEVPATH
> > > - the hotplug scripts don't know the device node name
> > > - the total count of event processes can't be controlled
> >
> > This is very, very cool. What a major simplification of the whole
> > process, with the addition of interesting new features as well.
> >
> > What is the likely timeframe for this to make it into udev proper?
>
> The main "problem" with this is for people who don't want to run udev on
> their machines. They are happy with their static dev, yet they want to
> have the hotplug package manage their modules, and do the other fun
> stuff (like HAL). If udev requires that it take over the hotplug
> multiplexer, then anyone who doesn't use udev looses out from the good
> things that HAL and anyone who relies on the functionality that this new
> udevd provides can't ensure that all users will actually have it
> running.
HAL will not work without udev!
And take it the other way around: Which udev user really needs to
run /sbin/hotplug?
The question is not what we can do _with_ udev for people who don't want
udev, right? :)
Thanks,
Kay
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
` (6 preceding siblings ...)
2004-11-19 1:11 ` Kay Sievers
@ 2004-11-19 7:27 ` Greg KH
2004-11-19 16:03 ` Kay Sievers
8 siblings, 0 replies; 10+ messages in thread
From: Greg KH @ 2004-11-19 7:27 UTC (permalink / raw)
To: linux-hotplug
On Fri, Nov 19, 2004 at 02:11:40AM +0100, Kay Sievers wrote:
> On Thu, 2004-11-18 at 16:55 -0800, Greg KH wrote:
> > The main "problem" with this is for people who don't want to run udev on
> > their machines. They are happy with their static dev, yet they want to
> > have the hotplug package manage their modules, and do the other fun
> > stuff (like HAL). If udev requires that it take over the hotplug
> > multiplexer, then anyone who doesn't use udev looses out from the good
> > things that HAL and anyone who relies on the functionality that this new
> > udevd provides can't ensure that all users will actually have it
> > running.
>
> HAL will not work without udev!
Ah, I didn't realize this. So much for my "problem" then :)
> And take it the other way around: Which udev user really needs to
> run /sbin/hotplug?
Well, they need to run the files under /etc/hotplug.d/ but that's it.
> The question is not what we can do _with_ udev for people who don't want
> udev, right? :)
Heh, true.
Ok, I like the idea, it's just going to take a while for me to get used
to it. I also need to think about how everyone's going to convert over
to this new scheme (or not...)
thanks,
greg k-h
-------------------------------------------------------
This SF.Net email is sponsored by: InterSystems CACHE
FREE OODBMS DOWNLOAD - A multidimensional database that combines
robust object and relational technologies, making it a perfect match
for Java, C++,COM, XML, ODBC and JDBC. www.intersystems.com/match8
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [adventure] replace /sbin/hotplug by udevd
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
` (7 preceding siblings ...)
2004-11-19 7:27 ` Greg KH
@ 2004-11-19 16:03 ` Kay Sievers
8 siblings, 0 replies; 10+ messages in thread
From: Kay Sievers @ 2004-11-19 16:03 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 764 bytes --]
On Thu, Nov 18, 2004 at 11:27:55PM -0800, Greg KH wrote:
> On Fri, Nov 19, 2004 at 02:11:40AM +0100, Kay Sievers wrote:
> > The question is not what we can do _with_ udev for people who don't want
> > udev, right? :)
>
> Heh, true.
>
> Ok, I like the idea, it's just going to take a while for me to get used
> to it. I also need to think about how everyone's going to convert over
> to this new scheme (or not...)
Yeah, it's a good question, how to convert. We need to test it, then we will
get an idea, I expect.
To make the testing easier, here is a version which should by default
behave like the current udev.
Only if /proc/sys/kernel/hotplug is set to call udevsend we switch over to
the new scheme and /etc/hotplug.d is handled from udev.
Thanks,
Kay
[-- Attachment #2: udev-as-hotplugd-04.patch --]
[-- Type: text/plain, Size: 8093 bytes --]
===== dev_d.c 1.20 vs edited =====
--- 1.20/dev_d.c 2004-11-11 22:32:18 +01:00
+++ edited/dev_d.c 2004-11-19 16:00:50 +01:00
@@ -37,6 +37,12 @@ static int run_program(const char *filen
int fd;
struct udevice *udev = data;
+ /* prevent a loop if we handle /etc/hotplug.d */
+ if (strstr(filename, "udev.hotplug") != NULL) {
+ dbg("prevent loop, don't call link pointing to ourself");
+ return 0;
+ }
+
dbg("running %s", filename);
pid = fork();
@@ -96,13 +102,17 @@ void dev_d_execute(struct udevice *udev,
temp = strchr(temp, '/');
}
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
- dirname[PATH_MAX-1] = '\0';
- call_foreach_file(run_program, dirname, suffix, udev);
-
- snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
- dirname[PATH_MAX-1] = '\0';
- call_foreach_file(run_program, dirname, suffix, udev);
+ if (udev->name[0] != '\0') {
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->name);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
+ }
+
+ if (udev->subsystem[0] != '\0') {
+ snprintf(dirname, PATH_MAX, "%s/%s", basedir, udev->subsystem);
+ dirname[PATH_MAX-1] = '\0';
+ call_foreach_file(run_program, dirname, suffix, udev);
+ }
snprintf(dirname, PATH_MAX, "%s/default", basedir);
dirname[PATH_MAX-1] = '\0';
===== udev.c 1.82 vs edited =====
--- 1.82/udev.c 2004-11-13 06:51:09 +01:00
+++ edited/udev.c 2004-11-19 16:16:40 +01:00
@@ -4,6 +4,7 @@
* Userspace devfs
*
* Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -24,6 +25,7 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
@@ -68,66 +70,22 @@ int main(int argc, char *argv[], char *e
{
struct sigaction act;
struct sysfs_class_device *class_dev;
+ struct sysfs_device *devices_dev;
struct udevice udev;
char path[SYSFS_PATH_MAX];
+ char helper[256];
+ int fd;
+ int len;
int retval = -EINVAL;
- enum {
- ADD,
- REMOVE,
- UDEVSTART,
- } act_type;
+ const char *error;
+ const char *action = getenv("ACTION");
+ const char *devpath = getenv("DEVPATH");
+ const char *subsystem = argv[1];
dbg("version %s", UDEV_VERSION);
logging_init("udev");
udev_init_config();
- if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
- act_type = UDEVSTART;
- } else {
- const char *action = getenv("ACTION");
- const char *devpath = getenv("DEVPATH");
- const char *subsystem = argv[1];
-
- if (!action) {
- dbg("no action?");
- goto exit;
- }
- if (strcmp(action, "add") == 0) {
- act_type = ADD;
- } else if (strcmp(action, "remove") == 0) {
- act_type = REMOVE;
- } else {
- dbg("no action '%s' for us", action);
- goto exit;
- }
-
- if (!devpath) {
- dbg("no devpath?");
- goto exit;
- }
- dbg("looking at '%s'", devpath);
-
- /* we only care about class devices and block stuff */
- if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
- dbg("not a block or class device");
- goto exit;
- }
-
- if (!subsystem) {
- dbg("no subsystem");
- goto exit;
- }
-
- udev_set_values(&udev, devpath, subsystem, action);
-
- /* skip blacklisted subsystems */
- if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) {
- dbg("don't care about '%s' devices", subsystem);
- goto exit;
- };
-
- }
-
/* set signal handlers */
act.sa_handler = (void (*) (int))sig_handler;
sigemptyset (&act.sa_mask);
@@ -137,51 +95,114 @@ int main(int argc, char *argv[], char *e
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
- /* trigger timout to interrupt blocking syscalls */
+ /* trigger timeout to interrupt blocking syscalls */
alarm(ALARM_TIMEOUT);
- switch(act_type) {
- case UDEVSTART:
- dbg("udevstart");
+ udev_set_values(&udev, devpath, subsystem, action);
+
+ if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
+ dbg("event: udevstart");
udev_log = 0;
namedev_init();
retval = udev_start();
- break;
- case ADD:
- dbg("udev add");
-
- /* 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);
+ goto exit;
+ }
- /* init rules */
- namedev_init();
+ if (!action) {
+ dbg("no action");
+ goto hotplug;
+ }
+
+ if (!subsystem) {
+ dbg("no subsystem");
+ goto hotplug;
+ }
+
+ if (!devpath) {
+ dbg("no devpath");
+ goto hotplug;
+ }
+
+ if ((strncmp(devpath, "/block/", 7) == 0) || (strncmp(devpath, "/class/", 7) == 0)) {
+ if (strcmp(action, "add") == 0) {
+ /* wait for sysfs and possibly add node */
+ dbg("event: udev add");
- /* name, create node, store in db */
- retval = udev_add_device(&udev, class_dev);
+ /* skip blacklisted subsystems */
+ if (udev.type != 'n' && subsystem_expect_no_dev(udev.subsystem)) {
+ dbg("don't care about '%s' devices", udev.subsystem);
+ goto hotplug;
+ };
+
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
+ class_dev = wait_class_device_open(path);
+ if (class_dev == NULL) {
+ dbg ("sysfs_open_class_device_path failed");
+ goto hotplug;
+ }
+ dbg("opened class_dev->name='%s'", class_dev->name);
+
+ wait_for_class_device(class_dev, &error);
+
+ /* init rules, permissions */
+ namedev_init();
+
+ /* name, create node, store in db */
+ retval = udev_add_device(&udev, class_dev);
+
+ /* run dev.d/ scripts if we created a node or changed a netif name */
+ if (udev.devname[0] != '\0') {
+ setenv("DEVNAME", udev.devname, 1);
+ dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ }
- /* run dev.d/ scripts if we created a node or changed a netif name */
- if (udev.devname[0] != '\0') {
- setenv("DEVNAME", udev.devname, 1);
+ sysfs_close_class_device(class_dev);
+ } else if (strcmp(action, "remove") == 0) {
+ /* possibly remove a node */
+ dbg("event: udev remove");
+
+ /* get node from db, delete it */
+ retval = udev_remove_device(&udev);
+
+ /* run scripts */
dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
}
+ } else if ((strncmp(devpath, "/devices/", 9) == 0)) {
+ if (strcmp(action, "add") == 0) {
+ /* wait for sysfs */
+ dbg("event: devices add");
- sysfs_close_class_device(class_dev);
- break;
- case REMOVE:
- dbg("udev remove");
+ snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, devpath);
+ devices_dev = wait_devices_device_open(path);
+ if (!devices_dev) {
+ dbg("error: devices device unavailable (probably remove has beaten us)");
+ goto hotplug;
+ }
+ dbg("devices device opened '%s'", path);
- /* get node from db, delete it*/
- retval = udev_remove_device(&udev);
+ wait_for_devices_device(devices_dev, &error);
- /* run scripts */
- dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
+ sysfs_close_device(devices_dev);
+ } else if (strcmp(action, "remove") == 0) {
+ dbg("event: devices remove");
+ }
+ } else {
+ dbg("event: unhandled");
}
+
+hotplug:
+ /* call the hotplug scripts if udevsend is the helper */
+ fd = open("/proc/sys/kernel/hotplug", O_RDONLY);
+ if (fd < 0)
+ goto exit;
+
+ len = read(fd, helper, 256);
+ if (len < 0)
+ goto exit;
+ helper[len] = '\0';
+
+ if (strstr(helper, "udevsend"))
+ dev_d_execute(&udev, HOTPLUGD_DIR, HOTPLUG_SUFFIX);
exit:
logging_close();
===== udev.h 1.72 vs edited =====
--- 1.72/udev.h 2004-11-13 06:43:23 +01:00
+++ edited/udev.h 2004-11-19 15:57:18 +01:00
@@ -44,6 +44,9 @@
#define DEVD_DIR "/etc/dev.d"
#define DEVD_SUFFIX ".dev"
+#define HOTPLUGD_DIR "/etc/hotplug.d"
+#define HOTPLUG_SUFFIX ".hotplug"
+
struct udevice {
char devpath[DEVPATH_SIZE];
char subsystem[SUBSYSTEM_SIZE];
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2004-11-19 16:03 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-18 0:27 [adventure] replace /sbin/hotplug by udevd Kay Sievers
2004-11-18 1:25 ` Greg KH
2004-11-18 4:04 ` Kevin P. Fleming
2004-11-18 6:40 ` Stefan Schweizer
2004-11-18 23:47 ` Kay Sievers
2004-11-19 0:03 ` Kay Sievers
2004-11-19 0:55 ` Greg KH
2004-11-19 1:11 ` Kay Sievers
2004-11-19 7:27 ` Greg KH
2004-11-19 16:03 ` Kay Sievers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).