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;
56 struct sysfs_device *dev;
60 info("version %s", UDEV_VERSION);
62 /* initialize our configuration */
64 if (udev_log_priority < LOG_INFO)
65 udev_log_priority = LOG_INFO;
68 info("Usage: udevtest <devpath>");
74 /* remove /sys if given */
75 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
76 devpath = &argv[1][strlen(sysfs_path)];
80 udev_rules_init(&rules, 0);
82 dev = sysfs_device_get(devpath);
84 info("unable to open '%s'", devpath);
89 udev = udev_device_init();
91 info("can't open device");
96 /* override built-in sysfs device */
98 strcpy(udev->action, "add");
99 udev->devt = udev_device_get_devt(udev);
101 /* simulate node creation with test flag */
104 setenv("DEVPATH", udev->dev->devpath, 1);
105 setenv("SUBSYSTEM", udev->dev->subsystem, 1);
106 setenv("ACTION", "add", 1);
108 info("looking at device '%s' from subsystem '%s'", udev->dev->devpath, udev->dev->subsystem);
109 retval = udev_device_event(&rules, udev);
110 if (retval == 0 && !udev->ignore_device && udev_run) {
111 struct name_entry *name_loop;
113 list_for_each_entry(name_loop, &udev->run_list, node) {
114 char program[PATH_SIZE];
116 strlcpy(program, name_loop->name, sizeof(program));
117 udev_rules_apply_format(udev, program, sizeof(program));
118 info("run: '%s'", program);
123 udev_rules_cleanup(&rules);