chiark / gitweb /
Docs: udev.xml: Clarify through a change in word ordering
[elogind.git] / udev / udevadm-monitor.c
index 4063c48303c08544a579ab07fa94d50acfd2a34c..85252bb7d98e1bd61f10b4e6809d47053688d127 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2009 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2010 Kay Sievers <kay.sievers@vrfy.org>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -73,6 +73,7 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[])
        int print_kernel = 0;
        int print_udev = 0;
        struct udev_list_node subsystem_match_list;
+       struct udev_list_node tag_match_list;
        struct udev_monitor *udev_monitor = NULL;
        struct udev_monitor *kernel_monitor = NULL;
        fd_set readfds;
@@ -84,13 +85,15 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[])
                { "kernel", no_argument, NULL, 'k' },
                { "udev", no_argument, NULL, 'u' },
                { "subsystem-match", required_argument, NULL, 's' },
+               { "tag-match", required_argument, NULL, 't' },
                { "help", no_argument, NULL, 'h' },
                {}
        };
 
        udev_list_init(&subsystem_match_list);
-       while (1) {
-               option = getopt_long(argc, argv, "epkus:h", options, NULL);
+       udev_list_init(&tag_match_list);
+       for (;;) {
+               option = getopt_long(argc, argv, "pekus:t:h", options, NULL);
                if (option == -1)
                        break;
 
@@ -111,7 +114,7 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[])
                                char *devtype;
 
                                util_strscpy(subsys, sizeof(subsys), optarg);
-                               devtype = strchr(subsys, ':');
+                               devtype = strchr(subsys, '/');
                                if (devtype != NULL) {
                                        devtype[0] = '\0';
                                        devtype++;
@@ -119,12 +122,16 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[])
                                udev_list_entry_add(udev, &subsystem_match_list, subsys, devtype, 0, 0);
                                break;
                        }
+               case 't':
+                       udev_list_entry_add(udev, &tag_match_list, optarg, NULL, 0, 0);
+                       break;
                case 'h':
                        printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
-                              "  --property                    print the event properties\n"
-                              "  --kernel                      print kernel uevents\n"
-                              "  --udev                        print udev events\n"
-                              "  --subsystem-match=<subsystem> filter events\n"
+                              "  --property                              print the event properties\n"
+                              "  --kernel                                print kernel uevents\n"
+                              "  --udev                                  print udev events\n"
+                              "  --subsystem-match=<subsystem[/devtype]> filter events by subsystem\n"
+                              "  --tag-match=<tag>                       filter events by tag\n"
                               "  --help\n\n");
                default:
                        goto out;
@@ -168,6 +175,13 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[])
                                fprintf(stderr, "error: unable to apply subsystem filter '%s'\n", subsys);
                }
 
+               udev_list_entry_foreach(entry, udev_list_get_entry(&tag_match_list)) {
+                       const char *tag = udev_list_entry_get_name(entry);
+
+                       if (udev_monitor_filter_add_match_tag(udev_monitor, tag) < 0)
+                               fprintf(stderr, "error: unable to apply tag filter '%s'\n", tag);
+               }
+
                if (udev_monitor_enable_receiving(udev_monitor) < 0) {
                        fprintf(stderr, "error: unable to subscribe to udev events\n");
                        rc = 2;
@@ -244,5 +258,6 @@ out:
        udev_monitor_unref(udev_monitor);
        udev_monitor_unref(kernel_monitor);
        udev_list_cleanup_entries(udev, &subsystem_match_list);
+       udev_list_cleanup_entries(udev, &tag_match_list);
        return rc;
 }