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[] = {
79 static int udev_hotplug(int argc, char **argv)
88 action = get_action();
94 devpath = get_devpath();
99 dbg("looking at '%s'", devpath);
101 /* we only care about class devices and block stuff */
102 if (!strstr(devpath, "class") &&
103 !strstr(devpath, "block")) {
104 dbg("not a block or class device");
108 /* skip blacklisted subsystems */
109 subsystem = get_subsystem(argv[1]);
111 dbg("no subsystem?");
115 while (subsystem_blacklist[i][0] != '\0') {
116 if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
117 dbg("don't care about '%s' devices", subsystem);
123 /* connect to the system message bus */
126 /* initialize our configuration */
129 /* initialize udev database */
130 retval = udevdb_init(UDEVDB_DEFAULT);
132 dbg("unable to initialize database");
136 /* set up a default signal handler for now */
137 act.sa_handler = sig_handler;
138 sigemptyset (&act.sa_mask);
139 act.sa_flags = SA_RESTART;
140 sigaction(SIGINT, &act, NULL);
141 sigaction(SIGTERM, &act, NULL);
143 /* initialize the naming deamon */
146 if (strcmp(action, "add") == 0)
147 retval = udev_add_device(devpath, subsystem, 0);
149 else if (strcmp(action, "remove") == 0)
150 retval = udev_remove_device(devpath, subsystem);
153 dbg("unknown action '%s'", action);
159 /* disconnect from the system message bus */
169 int main(int argc, char **argv, char **envp)
174 init_logging("udev");
175 dbg("version %s", UDEV_VERSION);
177 return udev_hotplug(argc, argv);