]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udev.c
0ef4cf8657f17d79e0bf3628fb7a5ec15e7ff8c6
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 /* global variables */
44 static int is_udevstart
;
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 asmlinkage
static void sig_handler(int signum
)
69 dbg("unhandled signal %d", signum
);
73 static char *subsystem_blacklist
[] = {
82 int __udev_hotplug(char *action
, const char *devpath
, const char *subsystem
)
89 dbg("looking at '%s'", devpath
);
91 /* we only care about class devices and block stuff */
92 if (!strstr(devpath
, "class") &&
93 !strstr(devpath
, "block")) {
94 dbg("not a block or class device");
99 while (subsystem_blacklist
[i
][0] != '\0') {
100 if (strcmp(subsystem
, subsystem_blacklist
[i
]) == 0) {
101 dbg("don't care about '%s' devices", subsystem
);
107 /* initialize udev database */
108 retval
= udevdb_init(UDEVDB_DEFAULT
);
110 dbg("unable to initialize database");
114 /* set signal handlers */
115 act
.sa_handler
= sig_handler
;
116 sigemptyset (&act
.sa_mask
);
117 act
.sa_flags
= SA_RESTART
;
118 sigaction(SIGINT
, &act
, NULL
);
119 sigaction(SIGTERM
, &act
, NULL
);
121 if (strcmp(action
, "add") == 0) {
125 retval
= udev_add_device(devpath
, subsystem
, nofake
);
129 if (strcmp(action
, "remove") == 0) {
130 retval
= udev_remove_device(devpath
, subsystem
);
134 dbg("unknown action '%s'", action
);
144 static int udev_hotplug(void)
150 action
= get_action();
156 devpath
= get_devpath();
162 /* skip blacklisted subsystems */
163 subsystem
= get_subsystem(main_argv
[1]);
165 dbg("no subsystem?");
169 return __udev_hotplug(action
, devpath
, subsystem
);
172 int main(int argc
, char *argv
[], char *envp
[])
177 if (strstr(argv
[0], "udevstart"))
180 /* initialize our configuration */
183 dbg("version %s", UDEV_VERSION
);
189 return udev_hotplug();