2 * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
35 #include "udev_rules.h"
37 static void asmlinkage sig_handler(int signum)
48 int main(int argc, char *argv[])
51 struct sysfs_device *dev;
52 struct udevice *udevice;
53 const char *maj, *min;
54 struct udev_rules rules;
57 const char *subsystem;
64 dbg(udev, "version %s\n", VERSION);
66 /* set signal handlers */
67 memset(&act, 0x00, sizeof(act));
68 act.sa_handler = (void (*)(int)) sig_handler;
69 sigemptyset (&act.sa_mask);
71 sigaction(SIGALRM, &act, NULL);
72 sigaction(SIGINT, &act, NULL);
73 sigaction(SIGTERM, &act, NULL);
75 /* trigger timeout to prevent hanging processes */
76 alarm(UDEV_EVENT_TIMEOUT);
78 action = getenv("ACTION");
79 devpath = getenv("DEVPATH");
80 subsystem = getenv("SUBSYSTEM");
81 /* older kernels passed the SUBSYSTEM only as argument */
82 if (subsystem == NULL && argc == 2)
85 if (action == NULL || subsystem == NULL || devpath == NULL) {
86 err(udev, "action, subsystem or devpath missing\n");
90 /* export log_priority , as called programs may want to do the same as udev */
91 if (udev_get_log_priority(udev) > 0) {
94 sprintf(priority, "%i", udev_get_log_priority(udev));
95 setenv("UDEV_LOG", priority, 1);
99 udev_rules_init(udev, &rules, 0);
101 dev = sysfs_device_get(udev, devpath);
103 info(udev, "unable to open '%s'\n", devpath);
107 udevice = udev_device_init(udev);
111 /* override built-in sysfs device */
113 strlcpy(udevice->action, action, sizeof(udevice->action));
115 /* get dev_t from environment, which is needed for "remove" to work, "add" works also from sysfs */
116 maj = getenv("MAJOR");
117 min = getenv("MINOR");
118 if (maj != NULL && min != NULL)
119 udevice->devt = makedev(atoi(maj), atoi(min));
121 udevice->devt = udev_device_get_devt(udevice);
123 retval = udev_device_event(&rules, udevice);
125 /* rules may change/disable the timeout */
126 if (udevice->event_timeout >= 0)
127 alarm(udevice->event_timeout);
129 if (retval == 0 && !udevice->ignore_device && udev_get_run(udev))
130 udev_rules_run(udevice);
132 udev_device_cleanup(udevice);
134 udev_rules_cleanup(&rules);