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"
43 unsigned char logname[LOGNAME_SIZE];
44 void log_message(int level, const char *format, ...)
51 va_start(args, format);
52 vsyslog(level, format, args);
57 static void asmlinkage sig_handler(int signum)
68 int main(int argc, char *argv[], char *envp[])
71 struct sysfs_class_device *class_dev;
73 char path[SYSFS_PATH_MAX];
81 dbg("version %s", UDEV_VERSION);
85 if (strstr(argv[0], "udevstart") || (argv[1] != NULL && strstr(argv[1], "udevstart"))) {
88 const char *action = getenv("ACTION");
89 const char *devpath = getenv("DEVPATH");
90 const char *subsystem = argv[1];
96 if (strcmp(action, "add") == 0) {
98 } else if (strcmp(action, "remove") == 0) {
101 dbg("no action '%s' for us", action);
109 dbg("looking at '%s'", devpath);
111 /* we only care about class devices and block stuff */
112 if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
113 dbg("not a block or class device");
122 udev_set_values(&udev, devpath, subsystem, action);
124 /* skip blacklisted subsystems */
125 if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) {
126 dbg("don't care about '%s' devices", subsystem);
132 /* set signal handlers */
133 act.sa_handler = (void (*) (int))sig_handler;
134 sigemptyset (&act.sa_mask);
136 /* alarm must not restart syscalls*/
137 sigaction(SIGALRM, &act, NULL);
138 sigaction(SIGINT, &act, NULL);
139 sigaction(SIGTERM, &act, NULL);
141 /* trigger timout to interrupt blocking syscalls */
142 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);
169 dev_d_execute(&udev);
171 sysfs_close_class_device(class_dev);
176 /* get node from db, delete it*/
177 retval = udev_remove_device(&udev);
180 dev_d_execute(&udev);