4 * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include "udev_rules.h"
36 void log_message (int priority, const char *format, ...)
40 if (priority > udev_log_priority)
43 va_start(args, format);
44 vprintf(format, args);
46 if (format[strlen(format)-1] != '\n')
51 int main(int argc, char *argv[], char *envp[])
53 struct udev_rules rules;
57 struct sysfs_device *dev;
61 info("version %s", UDEV_VERSION);
63 /* initialize our configuration */
65 if (udev_log_priority < LOG_INFO)
66 udev_log_priority = LOG_INFO;
69 info("Usage: udevtest <devpath>");
73 /* remove sysfs_path if given */
74 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
75 devpath = &argv[1][strlen(sysfs_path)];
77 if (argv[1][0] != '/') {
78 /* prepend '/' if missing */
79 snprintf(temp, sizeof(temp), "/%s", argv[1]);
80 temp[sizeof(temp)-1] = '\0';
86 udev_rules_init(&rules, 0);
88 dev = sysfs_device_get(devpath);
90 info("unable to open '%s'", devpath);
95 udev = udev_device_init();
97 info("can't open device");
102 /* override built-in sysfs device */
104 strcpy(udev->action, "add");
105 udev->devt = udev_device_get_devt(udev);
107 /* simulate node creation with test flag */
110 setenv("DEVPATH", udev->dev->devpath, 1);
111 setenv("SUBSYSTEM", udev->dev->subsystem, 1);
112 setenv("ACTION", "add", 1);
114 info("looking at device '%s' from subsystem '%s'", udev->dev->devpath, udev->dev->subsystem);
115 retval = udev_device_event(&rules, udev);
116 if (retval == 0 && !udev->ignore_device && udev_run) {
117 struct name_entry *name_loop;
119 list_for_each_entry(name_loop, &udev->run_list, node) {
120 char program[PATH_SIZE];
122 strlcpy(program, name_loop->name, sizeof(program));
123 udev_rules_apply_format(udev, program, sizeof(program));
124 info("run: '%s'", program);
129 udev_rules_cleanup(&rules);