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.
30 #include "libsysfs/sysfs/libsysfs.h"
32 #include "udev_version.h"
33 #include "udev_dbus.h"
38 /* global variables */
43 unsigned char logname[42];
44 void log_message(int level, const char *format, ...)
51 va_start(args, format);
52 vsyslog(level, format, args);
57 static void sig_handler(int signum)
66 dbg("unhandled signal");
70 static char *subsystem_blacklist[] = {
80 static int udev_hotplug(void)
89 action = get_action();
95 devpath = get_devpath();
100 dbg("looking at '%s'", devpath);
102 /* we only care about class devices and block stuff */
103 if (!strstr(devpath, "class") &&
104 !strstr(devpath, "block")) {
105 dbg("not a block or class device");
109 /* skip blacklisted subsystems */
110 subsystem = get_subsystem(main_argv[1]);
112 dbg("no subsystem?");
116 while (subsystem_blacklist[i][0] != '\0') {
117 if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
118 dbg("don't care about '%s' devices", subsystem);
124 /* connect to the system message bus */
127 /* initialize udev database */
128 retval = udevdb_init(UDEVDB_DEFAULT);
130 dbg("unable to initialize database");
134 /* set up a default signal handler for now */
135 act.sa_handler = sig_handler;
136 sigemptyset (&act.sa_mask);
137 act.sa_flags = SA_RESTART;
138 sigaction(SIGINT, &act, NULL);
139 sigaction(SIGTERM, &act, NULL);
141 /* initialize the naming deamon */
144 if (strcmp(action, "add") == 0)
145 retval = udev_add_device(devpath, subsystem, 0);
147 else if (strcmp(action, "remove") == 0)
148 retval = udev_remove_device(devpath, subsystem);
151 dbg("unknown action '%s'", action);
157 /* disconnect from the system message bus */
167 int main(int argc, char **argv, char **envp)
172 init_logging("udev");
174 /* initialize our configuration */
177 dbg("version %s", UDEV_VERSION);
179 return udev_hotplug();