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.
23 #define _KLIBC_HAS_ARCH_SIG_ATOMIC_T
33 #include "libsysfs/sysfs/libsysfs.h"
36 #include "udev_sysfs.h"
37 #include "udev_version.h"
42 /* timeout flag for udevdb */
43 extern sig_atomic_t gotalarm;
45 /* global variables */
50 unsigned char logname[LOGNAME_SIZE];
51 void log_message(int level, const char *format, ...)
58 va_start(args, format);
59 vsyslog(level, format, args);
64 static void asmlinkage sig_handler(int signum)
69 info("error: timeout reached, event probably not handled correctly");
76 dbg("unhandled signal %d", signum);
80 int main(int argc, char *argv[], char *envp[])
83 struct sysfs_class_device *class_dev;
85 char path[SYSFS_PATH_MAX];
93 dbg("version %s", UDEV_VERSION);
102 if (strstr(argv[0], "udevstart")) {
103 act_type = UDEVSTART;
105 const char *action = get_action();
106 const char *devpath = get_devpath();
107 const char *subsystem = get_subsystem(main_argv[1]);
113 if (strcmp(action, "add") == 0) {
115 } else if (strcmp(action, "remove") == 0) {
118 dbg("no action '%s' for us", action);
126 dbg("looking at '%s'", devpath);
128 /* we only care about class devices and block stuff */
129 if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
130 dbg("not a block or class device");
139 udev_set_values(&udev, devpath, subsystem);
141 /* skip blacklisted subsystems */
142 if (udev.type != 'n' && subsystem_expect_no_dev(subsystem)) {
143 dbg("don't care about '%s' devices", subsystem);
149 /* set signal handlers */
150 act.sa_handler = (void (*) (int))sig_handler;
151 sigemptyset (&act.sa_mask);
152 /* alarm must not restart syscalls*/
153 sigaction(SIGALRM, &act, NULL);
154 sigaction(SIGINT, &act, NULL);
155 sigaction(SIGTERM, &act, NULL);
157 /* trigger timout to interrupt blocking syscalls */
158 alarm(ALARM_TIMEOUT);
160 /* initialize udev database */
161 if (udevdb_init(UDEVDB_DEFAULT) != 0)
162 info("error: unable to initialize database, continuing without database");
168 retval = udev_start();
173 /* open the device */
174 snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
175 class_dev = sysfs_open_class_device_path(path);
176 if (class_dev == NULL) {
177 dbg ("sysfs_open_class_device_path failed");
180 dbg("opened class_dev->name='%s'", class_dev->name);
185 /* name, create node, store in db */
186 retval = udev_add_device(&udev, class_dev);
189 dev_d_execute(&udev);
191 sysfs_close_class_device(class_dev);
196 /* get node from db, delete it*/
197 retval = udev_remove_device(&udev);
200 dev_d_execute(&udev);