2 * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 static void asmlinkage sig_handler(int signum)
44 int main(int argc, char *argv[])
47 struct udev_event *event;
48 struct udev_device *dev;
49 struct udev_rules *rules;
50 char syspath[UTIL_PATH_SIZE];
53 const char *subsystem;
60 info(udev, "version %s\n", VERSION);
61 udev_selinux_init(udev);
63 /* set signal handlers */
64 memset(&act, 0x00, sizeof(act));
65 act.sa_handler = (void (*)(int)) sig_handler;
66 sigemptyset (&act.sa_mask);
68 sigaction(SIGALRM, &act, NULL);
69 sigaction(SIGINT, &act, NULL);
70 sigaction(SIGTERM, &act, NULL);
72 /* trigger timeout to prevent hanging processes */
73 alarm(UDEV_EVENT_TIMEOUT);
75 action = getenv("ACTION");
76 devpath = getenv("DEVPATH");
77 subsystem = getenv("SUBSYSTEM");
79 if (action == NULL || subsystem == NULL || devpath == NULL) {
80 err(udev, "action, subsystem or devpath missing\n");
84 rules = udev_rules_new(udev, 1);
86 util_strlcpy(syspath, udev_get_sys_path(udev), sizeof(syspath));
87 util_strlcat(syspath, devpath, sizeof(syspath));
88 dev = udev_device_new_from_syspath(udev, syspath);
90 info(udev, "unknown device '%s'\n", devpath);
94 /* skip reading of db, but read kernel parameters */
95 udev_device_set_info_loaded(dev);
96 udev_device_read_uevent_file(dev);
98 udev_device_set_action(dev, action);
99 event = udev_event_new(dev);
100 err = udev_event_execute_rules(event, rules);
102 /* rules may change/disable the timeout */
103 if (udev_device_get_event_timeout(dev) >= 0)
104 alarm(udev_device_get_event_timeout(dev));
106 if (err == 0 && !event->ignore_device && udev_get_run(udev))
107 udev_event_execute_run(event);
109 udev_event_unref(event);
110 udev_device_unref(dev);
112 udev_rules_unref(rules);
114 udev_selinux_exit(udev);