4 * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation version 2 of the License.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include "udev_rules.h"
37 void log_message (int priority, const char *format, ...)
41 if (priority > udev_log_priority)
44 va_start(args, format);
45 vprintf(format, args);
47 if (format[strlen(format)-1] != '\n')
52 int main(int argc, char *argv[], char *envp[])
54 struct udev_rules rules = {};
57 struct sysfs_device *dev;
62 info("version %s", UDEV_VERSION);
64 if (udev_log_priority < LOG_INFO)
65 udev_log_priority = LOG_INFO;
67 for (i = 1 ; i < argc; i++) {
70 if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) {
71 printf("Usage: udevtest [--help] <devpath>\n");
77 if (devpath == NULL) {
78 fprintf(stderr, "devpath parameter missing\n");
84 udev_rules_init(&rules, 0);
86 /* remove /sys if given */
87 if (strncmp(devpath, sysfs_path, strlen(sysfs_path)) == 0)
88 devpath = &devpath[strlen(sysfs_path)];
90 dev = sysfs_device_get(devpath);
92 fprintf(stderr, "unable to open device '%s'\n", devpath);
97 udev = udev_device_init();
99 fprintf(stderr, "error initializing device\n");
104 /* override built-in sysfs device */
106 strcpy(udev->action, "add");
107 udev->devt = udev_device_get_devt(udev);
109 /* simulate node creation with test flag */
112 setenv("DEVPATH", udev->dev->devpath, 1);
113 setenv("SUBSYSTEM", udev->dev->subsystem, 1);
114 setenv("ACTION", "add", 1);
116 info("looking at device '%s' from subsystem '%s'", udev->dev->devpath, udev->dev->subsystem);
117 retval = udev_device_event(&rules, udev);
118 if (retval == 0 && !udev->ignore_device && udev_run) {
119 struct name_entry *name_loop;
121 list_for_each_entry(name_loop, &udev->run_list, node) {
122 char program[PATH_SIZE];
124 strlcpy(program, name_loop->name, sizeof(program));
125 udev_rules_apply_format(udev, program, sizeof(program));
126 info("run: '%s'", program);
131 udev_rules_cleanup(&rules);