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/>.
29 #include <sys/signalfd.h>
33 void udev_main_log(struct udev *udev, int priority,
34 const char *file, int line, const char *fn,
35 const char *format, va_list args) {}
37 int main(int argc, char *argv[])
40 struct udev_event *event = NULL;
41 struct udev_device *dev = NULL;
42 struct udev_rules *rules = NULL;
43 char syspath[UTIL_PATH_SIZE];
46 const char *subsystem;
47 sigset_t mask, sigmask_orig;
53 info(udev, "version %s\n", VERSION);
54 udev_selinux_init(udev);
56 sigprocmask(SIG_SETMASK, NULL, &sigmask_orig);
58 action = getenv("ACTION");
59 devpath = getenv("DEVPATH");
60 subsystem = getenv("SUBSYSTEM");
62 if (action == NULL || subsystem == NULL || devpath == NULL) {
63 err(udev, "action, subsystem or devpath missing\n");
67 rules = udev_rules_new(udev, 1);
69 util_strscpyl(syspath, sizeof(syspath), udev_get_sys_path(udev), devpath, NULL);
70 dev = udev_device_new_from_syspath(udev, syspath);
72 info(udev, "unknown device '%s'\n", devpath);
76 /* skip reading of db, but read kernel parameters */
77 udev_device_set_info_loaded(dev);
78 udev_device_read_uevent_file(dev);
80 udev_device_set_action(dev, action);
81 event = udev_event_new(dev);
84 sigprocmask(SIG_SETMASK, &mask, &sigmask_orig);
85 event->fd_signal = signalfd(-1, &mask, SFD_NONBLOCK|SFD_CLOEXEC);
86 if (event->fd_signal < 0) {
87 fprintf(stderr, "error creating signalfd\n");
91 err = udev_event_execute_rules(event, rules, &sigmask_orig);
93 udev_event_execute_run(event, NULL);
95 if (event != NULL && event->fd_signal >= 0)
96 close(event->fd_signal);
97 udev_event_unref(event);
98 udev_device_unref(dev);
99 udev_rules_unref(rules);
100 udev_selinux_exit(udev);