6 * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include "libsysfs/sysfs/libsysfs.h"
35 #include "udev_sysfs.h"
36 #include "udev_version.h"
42 unsigned char logname[LOGNAME_SIZE];
43 void log_message(int level, const char *format, ...)
50 va_start(args, format);
51 vsyslog(level, format, args);
56 static void asmlinkage sig_handler(int signum)
67 int main(int argc, char *argv[], char *envp[])
70 struct sysfs_class_device *class_dev;
72 char path[SYSFS_PATH_MAX];
80 dbg("version %s", UDEV_VERSION);
84 if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
87 const char *action = getenv("ACTION");
88 const char *devpath = getenv("DEVPATH");
89 const char *subsystem = argv[1];
95 if (strcmp(action, "add") == 0) {
97 } else if (strcmp(action, "remove") == 0) {
100 dbg("no action '%s' for us", action);
108 dbg("looking at '%s'", devpath);
110 /* we only care about class devices and block stuff */
111 if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
112 dbg("not a block or class device");
121 udev_set_values(&udev, devpath, subsystem, action);
123 /* skip blacklisted subsystems */
124 if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) {
125 dbg("don't care about '%s' devices", subsystem);
131 /* set signal handlers */
132 act.sa_handler = (void (*) (int))sig_handler;
133 sigemptyset (&act.sa_mask);
135 /* alarm must not restart syscalls*/
136 sigaction(SIGALRM, &act, NULL);
137 sigaction(SIGINT, &act, NULL);
138 sigaction(SIGTERM, &act, NULL);
140 /* trigger timout to interrupt blocking syscalls */
141 alarm(ALARM_TIMEOUT);
148 retval = udev_start();
153 /* open the device */
154 snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
155 class_dev = sysfs_open_class_device_path(path);
156 if (class_dev == NULL) {
157 dbg ("sysfs_open_class_device_path failed");
160 dbg("opened class_dev->name='%s'", class_dev->name);
165 /* name, create node, store in db */
166 retval = udev_add_device(&udev, class_dev);
168 /* run dev.d/ scripts if we created a node or changed a netif name */
169 if (udev.devname[0] != '\0') {
170 setenv("DEVNAME", udev.devname, 1);
171 dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);
174 sysfs_close_class_device(class_dev);
179 /* get node from db, delete it*/
180 retval = udev_remove_device(&udev);
183 dev_d_execute(&udev, DEVD_DIR, DEVD_SUFFIX);