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 inline char *get_action(void)
74 action = getenv("ACTION");
78 static inline char *get_devpath(void)
82 devpath = getenv("DEVPATH");
86 static inline char *get_seqnum(void)
90 seqnum = getenv("SEQNUM");
94 static char *subsystem_blacklist[] = {
103 static int udev_hotplug(int argc, char **argv)
108 int retval = -EINVAL;
110 struct sigaction act;
112 action = get_action();
118 devpath = get_devpath();
123 dbg("looking at '%s'", devpath);
125 /* we only care about class devices and block stuff */
126 if (!strstr(devpath, "class") &&
127 !strstr(devpath, "block")) {
128 dbg("not a block or class device");
132 /* skip blacklisted subsystems */
135 dbg("no subsystem?");
139 while (subsystem_blacklist[i][0] != '\0') {
140 if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
141 dbg("don't care about '%s' devices", subsystem);
147 /* connect to the system message bus */
150 /* initialize our configuration */
153 /* initialize udev database */
154 retval = udevdb_init(UDEVDB_DEFAULT);
156 dbg("unable to initialize database");
160 /* set up a default signal handler for now */
161 act.sa_handler = sig_handler;
162 sigemptyset (&act.sa_mask);
163 act.sa_flags = SA_RESTART;
164 sigaction(SIGINT, &act, NULL);
165 sigaction(SIGTERM, &act, NULL);
167 /* initialize the naming deamon */
170 if (strcmp(action, "add") == 0)
171 retval = udev_add_device(devpath, subsystem, 0);
173 else if (strcmp(action, "remove") == 0)
174 retval = udev_remove_device(devpath, subsystem);
177 dbg("unknown action '%s'", action);
183 /* disconnect from the system message bus */
193 int main(int argc, char **argv, char **envp)
198 init_logging("udev");
199 dbg("version %s", UDEV_VERSION);
201 return udev_hotplug(argc, argv);