]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udev.c
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.
23 #define _KLIBC_HAS_ARCH_SIG_ATOMIC_T
32 #include "libsysfs/sysfs/libsysfs.h"
35 #include "udev_version.h"
40 /* timeout flag for udevdb */
41 extern sig_atomic_t gotalarm
;
43 /* global variables */
48 unsigned char logname
[LOGNAME_SIZE
];
49 void log_message(int level
, const char *format
, ...)
56 va_start(args
, format
);
57 vsyslog(level
, format
, args
);
62 static void asmlinkage
sig_handler(int signum
)
67 info("error: timeout reached, event probably not handled correctly");
74 dbg("unhandled signal %d", signum
);
78 /* list of subsystems we don't care about. not listing such systems here
79 * is not critical, but it makes it faster as we don't look for the "dev" file
81 static int subsystem_without_dev(const char *subsystem
)
83 char *subsystem_blacklist
[] = {
99 for (subsys
= subsystem_blacklist
; *subsys
!= NULL
; subsys
++) {
100 if (strcmp(subsystem
, *subsys
) == 0)
107 int main(int argc
, char *argv
[], char *envp
[])
109 struct sigaction act
;
112 char *subsystem
= "";
113 int retval
= -EINVAL
;
120 dbg("version %s", UDEV_VERSION
);
125 init_logging("udev");
129 if (strstr(argv
[0], "udevstart")) {
130 act_type
= UDEVSTART
;
132 action
= get_action();
137 if (strcmp(action
, "add") == 0) {
139 } else if (strcmp(action
, "remove") == 0) {
142 dbg("unknown action '%s'", action
);
146 devpath
= get_devpath();
151 dbg("looking at '%s'", devpath
);
153 /* we only care about class devices and block stuff */
154 if (!strstr(devpath
, "class") && !strstr(devpath
, "block")) {
155 dbg("not a block or class device");
159 subsystem
= get_subsystem(main_argv
[1]);
161 dbg("no subsystem?");
165 /* skip blacklisted subsystems */
166 if (subsystem_without_dev(subsystem
)) {
167 dbg("don't care about '%s' devices", subsystem
);
172 /* set signal handlers */
173 act
.sa_handler
= (void (*) (int))sig_handler
;
174 sigemptyset (&act
.sa_mask
);
175 /* alarm must not restart syscalls*/
176 sigaction(SIGALRM
, &act
, NULL
);
177 sigaction(SIGINT
, &act
, NULL
);
178 sigaction(SIGTERM
, &act
, NULL
);
180 /* trigger timout to interrupt blocking syscalls */
181 alarm(ALARM_TIMEOUT
);
183 /* initialize udev database */
184 if (udevdb_init(UDEVDB_DEFAULT
) != 0)
185 info("error: unable to initialize database, continuing without database");
191 retval
= udev_start();
196 retval
= udev_add_device(devpath
, subsystem
, NOFAKE
);
200 retval
= udev_remove_device(devpath
, subsystem
);