]>
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.
32 #include "libsysfs/sysfs/libsysfs.h"
35 #include "udev_sysfs.h"
36 #include "udev_version.h"
41 /* timeout flag for udevdb */
42 extern sig_atomic_t gotalarm
;
44 /* global variables */
49 unsigned char logname
[LOGNAME_SIZE
];
50 void log_message(int level
, const char *format
, ...)
57 va_start(args
, format
);
58 vsyslog(level
, format
, args
);
63 static void asmlinkage
sig_handler(int signum
)
75 int main(int argc
, char *argv
[], char *envp
[])
78 struct sysfs_class_device
*class_dev
;
80 char path
[SYSFS_PATH_MAX
];
88 dbg("version %s", UDEV_VERSION
);
97 if (strstr(argv
[0], "udevstart")) {
100 const char *action
= get_action();
101 const char *devpath
= get_devpath();
102 const char *subsystem
= get_subsystem(main_argv
[1]);
108 if (strcmp(action
, "add") == 0) {
110 } else if (strcmp(action
, "remove") == 0) {
113 dbg("no action '%s' for us", action
);
121 dbg("looking at '%s'", devpath
);
123 /* we only care about class devices and block stuff */
124 if (!strstr(devpath
, "class") && !strstr(devpath
, "block")) {
125 dbg("not a block or class device");
134 udev_set_values(&udev
, devpath
, subsystem
);
136 /* skip blacklisted subsystems */
137 if (udev
.type
!= 'n' && subsystem_expect_no_dev(subsystem
)) {
138 dbg("don't care about '%s' devices", subsystem
);
144 /* set signal handlers */
145 act
.sa_handler
= (void (*) (int))sig_handler
;
146 sigemptyset (&act
.sa_mask
);
148 /* alarm must not restart syscalls*/
149 sigaction(SIGALRM
, &act
, NULL
);
150 sigaction(SIGINT
, &act
, NULL
);
151 sigaction(SIGTERM
, &act
, NULL
);
153 /* trigger timout to interrupt blocking syscalls */
154 alarm(ALARM_TIMEOUT
);
156 /* initialize udev database */
157 if (udevdb_init(UDEVDB_DEFAULT
) != 0)
158 info("error: unable to initialize database, continuing without database");
164 retval
= udev_start();
169 /* open the device */
170 snprintf(path
, SYSFS_PATH_MAX
, "%s%s", sysfs_path
, udev
.devpath
);
171 class_dev
= sysfs_open_class_device_path(path
);
172 if (class_dev
== NULL
) {
173 dbg ("sysfs_open_class_device_path failed");
176 dbg("opened class_dev->name='%s'", class_dev
->name
);
181 /* name, create node, store in db */
182 retval
= udev_add_device(&udev
, class_dev
);
185 dev_d_execute(&udev
);
187 sysfs_close_class_device(class_dev
);
192 /* get node from db, delete it*/
193 retval
= udev_remove_device(&udev
);
196 dev_d_execute(&udev
);