2 * udev_event.c - udev event process
4 * Copyright (C) 2004, 2005 Kay Sievers <kay.sievers@vrfy.org>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <sys/utsname.h>
36 #include "udev_libc_wrapper.h"
39 #include "udev_rules.h"
40 #include "udev_utils.h"
41 #include "udev_sysfs.h"
45 int udev_process_event(struct udev_rules *rules, struct udevice *udev)
51 if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS || udev->type == DEV_NET) {
52 /* handle device node */
53 if (strcmp(udev->action, "add") == 0) {
54 struct sysfs_class_device *class_dev;
56 /* wait for sysfs of /sys/class /sys/block */
58 snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath);
59 path[sizeof(path)-1] = '\0';
60 class_dev = wait_class_device_open(path);
61 if (class_dev == NULL) {
62 dbg("open class device failed");
65 dbg("opened class_dev->name='%s'", class_dev->name);
66 wait_for_class_device(class_dev, &error);
69 if (udev->type == DEV_BLOCK || udev->type == DEV_CLASS)
70 udev->devt = get_devt(class_dev);
72 if (udev->type == DEV_NET || udev->devt) {
74 udev_rules_get_name(rules, udev, class_dev);
75 if (udev->ignore_device) {
76 info("device event will be ignored");
77 sysfs_close_class_device(class_dev);
80 if (udev->name[0] == '\0') {
81 info("device node creation supressed");
82 sysfs_close_class_device(class_dev);
85 /* create node, store in db */
86 retval = udev_add_device(udev, class_dev);
88 dbg("no dev-file found");
89 udev_rules_get_run(rules, udev, class_dev, NULL);
90 if (udev->ignore_device) {
91 info("device event will be ignored");
92 sysfs_close_class_device(class_dev);
96 sysfs_close_class_device(class_dev);
97 } else if (strcmp(udev->action, "remove") == 0) {
99 udev_rules_get_run(rules, udev, NULL, NULL);
100 if (udev->ignore_device) {
101 dbg("device event will be ignored");
105 /* get name from db, remove db-entry, delete node */
106 retval = udev_remove_device(udev);
109 /* export name of device node or netif */
110 if (udev->devname[0] != '\0')
111 setenv("DEVNAME", udev->devname, 1);
112 } else if (udev->type == DEV_DEVICE && strcmp(udev->action, "add") == 0) {
113 struct sysfs_device *devices_dev;
115 /* wait for sysfs of /sys/devices/ */
117 snprintf(path, sizeof(path), "%s%s", sysfs_path, udev->devpath);
118 path[sizeof(path)-1] = '\0';
119 devices_dev = wait_devices_device_open(path);
121 dbg("devices device unavailable (probably remove has beaten us)");
124 dbg("devices device opened '%s'", path);
125 wait_for_devices_device(devices_dev, &error);
126 udev_rules_get_run(rules, udev, NULL, devices_dev);
127 sysfs_close_device(devices_dev);
128 if (udev->ignore_device) {
129 info("device event will be ignored");
133 dbg("default handling");
134 udev_rules_get_run(rules, udev, NULL, NULL);
135 if (udev->ignore_device) {
136 info("device event will be ignored");