chiark / gitweb /
udevadm: test - print list of properties
[elogind.git] / udev / udevadm-test.c
index 2c8e0bf..6c57103 100644 (file)
 int udevadm_test(struct udev *udev, int argc, char *argv[])
 {
        char filename[UTIL_PATH_SIZE];
-       int force = 0;
        const char *action = "add";
        const char *syspath = NULL;
        struct udev_event *event;
        struct udev_device *dev;
        struct udev_rules *rules = NULL;
+       struct udev_list_entry *entry;
        int err;
        int rc = 0;
 
        static const struct option options[] = {
                { "action", required_argument, NULL, 'a' },
-               { "force", no_argument, NULL, 'f' },
                { "help", no_argument, NULL, 'h' },
                {}
        };
@@ -63,14 +62,10 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
                case 'a':
                        action = optarg;
                        break;
-               case 'f':
-                       force = 1;
-                       break;
                case 'h':
                        printf("Usage: udevadm test OPTIONS <syspath>\n"
                               "  --action=<string>     set action string\n"
-                              "  --force               don't skip node/link creation\n"
-                              "  --help                print this help text\n\n");
+                              "  --help\n\n");
                        exit(0);
                default:
                        exit(1);
@@ -97,15 +92,15 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
        }
 
        /* add /sys if needed */
-       if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
-               util_strlcpy(filename, udev_get_sys_path(udev), sizeof(filename));
-               util_strlcat(filename, syspath, sizeof(filename));
-               syspath = filename;
-       }
+       if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0)
+               util_strscpyl(filename, sizeof(filename), udev_get_sys_path(udev), syspath, NULL);
+       else
+               util_strscpy(filename, sizeof(filename), syspath);
+       util_remove_trailing_chars(filename, '/');
 
-       dev = udev_device_new_from_syspath(udev, syspath);
+       dev = udev_device_new_from_syspath(udev, filename);
        if (dev == NULL) {
-               fprintf(stderr, "unable to open device '%s'\n", syspath);
+               fprintf(stderr, "unable to open device '%s'\n", filename);
                rc = 2;
                goto exit;
        }
@@ -116,24 +111,19 @@ int udevadm_test(struct udev *udev, int argc, char *argv[])
 
        udev_device_set_action(dev, action);
        event = udev_event_new(dev);
-
-       /* simulate node creation with test flag */
-       if (!force)
-               event->test = 1;
-
        err = udev_event_execute_rules(event, rules);
 
        if (udev_device_get_event_timeout(dev) >= 0)
                info(udev, "custom event timeout: %i\n", udev_device_get_event_timeout(dev));
 
-       if (err == 0 && !event->ignore_device && udev_get_run(udev)) {
-               struct udev_list_entry *entry;
+       udev_list_entry_foreach(entry, udev_device_get_properties_list_entry(dev))
+               info(udev, "%s=%s\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
 
+       if (err == 0 && !event->ignore_device && udev_get_run(udev)) {
                udev_list_entry_foreach(entry, udev_list_get_entry(&event->run_list)) {
                        char program[UTIL_PATH_SIZE];
 
-                       util_strlcpy(program, udev_list_entry_get_name(entry), sizeof(program));
-                       udev_event_apply_format(event, program, sizeof(program));
+                       udev_event_apply_format(event, udev_list_entry_get_name(entry), program, sizeof(program));
                        info(udev, "run: '%s'\n", program);
                }
        }