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.
31 #include "libsysfs/sysfs/libsysfs.h"
34 #include "udev_version.h"
39 /* timeout flag for udevdb */
40 extern sig_atomic_t gotalarm;
42 /* global variables */
47 unsigned char logname[LOGNAME_SIZE];
48 void log_message(int level, const char *format, ...)
55 va_start(args, format);
56 vsyslog(level, format, args);
61 static void asmlinkage sig_handler(int signum)
66 info("error: timeout reached, event probably not handled correctly");
73 dbg("unhandled signal %d", signum);
77 static char *subsystem_blacklist[] = {
86 int main(int argc, char *argv[], char *envp[])
102 dbg("version %s", UDEV_VERSION);
104 init_logging("udev");
108 if (strstr(argv[0], "udevstart")) {
109 act_type = UDEVSTART;
111 action = get_action();
116 if (strcmp(action, "add") == 0) {
118 } else if (strcmp(action, "remove") == 0) {
121 dbg("unknown action '%s'", action);
125 devpath = get_devpath();
130 dbg("looking at '%s'", devpath);
132 /* we only care about class devices and block stuff */
133 if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
134 dbg("not a block or class device");
138 subsystem = get_subsystem(main_argv[1]);
140 dbg("no subsystem?");
144 /* skip blacklisted subsystems */
146 while (subsystem_blacklist[i][0] != '\0') {
147 if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
148 dbg("don't care about '%s' devices", subsystem);
155 /* set signal handlers */
156 act.sa_handler = (void (*) (int))sig_handler;
157 sigemptyset (&act.sa_mask);
158 /* alarm must interrupt syscalls*/
159 sigaction(SIGALRM, &act, NULL);
160 sigaction(SIGINT, &act, NULL);
161 sigaction(SIGTERM, &act, NULL);
163 /* trigger timout to interrupt blocking syscalls */
164 alarm(ALARM_TIMEOUT);
166 /* initialize udev database */
167 if (udevdb_init(UDEVDB_DEFAULT) != 0)
168 info("error: unable to initialize database, continuing without database");
175 retval = udev_start();
180 retval = udev_add_device(devpath, subsystem, NOFAKE);
184 retval = udev_remove_device(devpath, subsystem);