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 "udev_version.h"
32 #include "udev_dbus.h"
36 #include "libsysfs/libsysfs.h"
38 /* global variables */
41 unsigned char logname[42];
48 static void sig_handler(int signum)
50 dbg("caught signal %d", signum);
59 dbg("unhandled signal");
63 static inline char *get_action(void)
67 action = getenv("ACTION");
71 static inline char *get_devpath(void)
75 devpath = getenv("DEVPATH");
79 static inline char *get_seqnum(void)
83 seqnum = getenv("SEQNUM");
87 static char *subsystem_blacklist[] = {
96 static int udev_hotplug(int argc, char **argv)
101 int retval = -EINVAL;
104 action = get_action();
110 devpath = get_devpath();
115 dbg("looking at '%s'", devpath);
117 /* we only care about class devices and block stuff */
118 if (!strstr(devpath, "class") &&
119 !strstr(devpath, "block")) {
120 dbg("not a block or class device");
124 /* skip blacklisted subsystems */
127 while (subsystem_blacklist[i][0] != '\0') {
128 if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
129 dbg("don't care about '%s' devices", subsystem);
135 /* connect to the system message bus */
138 /* initialize our configuration */
141 /* initialize udev database */
142 retval = udevdb_init(UDEVDB_DEFAULT);
144 dbg("unable to initialize database");
148 /* set up a default signal handler for now */
149 signal(SIGINT, sig_handler);
150 signal(SIGTERM, sig_handler);
152 /* initialize the naming deamon */
155 if (strcmp(action, "add") == 0)
156 retval = udev_add_device(devpath, subsystem);
158 else if (strcmp(action, "remove") == 0)
159 retval = udev_remove_device(devpath, subsystem);
162 dbg("unknown action '%s'", action);
168 /* disconnect from the system message bus */
178 int main(int argc, char **argv, char **envp)
183 init_logging("udev");
184 dbg("version %s", UDEV_VERSION);
186 return udev_hotplug(argc, argv);