From: Kay Sievers Date: Wed, 22 Apr 2009 03:00:15 +0000 (+0200) Subject: udevadm monitor - add --subsystem-match= X-Git-Tag: 174~1083 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9550eb11fba3c0ae5f71e0f0780bd100ecc742d;p=systemd udevadm monitor - add --subsystem-match= --- diff --git a/udev/udevadm-monitor.c b/udev/udevadm-monitor.c index b5897b9f..92215b67 100644 --- a/udev/udevadm-monitor.c +++ b/udev/udevadm-monitor.c @@ -71,6 +71,7 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[]) int env = 0; int print_kernel = 0; int print_udev = 0; + struct udev_list_node subsystem_match_list; struct udev_monitor *udev_monitor = NULL; struct udev_monitor *kernel_monitor = NULL; fd_set readfds; @@ -80,12 +81,14 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[]) { "environment", no_argument, NULL, 'e' }, { "kernel", no_argument, NULL, 'k' }, { "udev", no_argument, NULL, 'u' }, + { "subsystem-match", required_argument, NULL, 's' }, { "help", no_argument, NULL, 'h' }, {} }; + udev_list_init(&subsystem_match_list); while (1) { - option = getopt_long(argc, argv, "ekuh", options, NULL); + option = getopt_long(argc, argv, "ekus:h", options, NULL); if (option == -1) break; @@ -99,6 +102,9 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[]) case 'u': print_udev = 1; break; + case 's': + udev_list_entry_add(udev, &subsystem_match_list, optarg, NULL, 1, 0); + break; case 'h': printf("Usage: udevadm monitor [--environment] [--kernel] [--udev] [--help]\n" " --env print the whole event environment\n" @@ -125,12 +131,22 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[]) printf("monitor will print the received events for:\n"); if (print_udev) { + struct udev_list_entry *entry; + udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); if (udev_monitor == NULL) { fprintf(stderr, "error: unable to create netlink socket\n"); rc = 1; goto out; } + + udev_list_entry_foreach(entry, udev_list_get_entry(&subsystem_match_list)) { + const char *subsys = udev_list_entry_get_name(entry); + + if (udev_monitor_filter_add_match_subsystem(udev_monitor, subsys) < 0) + fprintf(stderr, "error: unable to apply subsystem filter '%s'\n", subsys); + } + if (udev_monitor_enable_receiving(udev_monitor) < 0) { fprintf(stderr, "error: unable to subscribe to udev events\n"); rc = 2; @@ -195,5 +211,6 @@ int udevadm_monitor(struct udev *udev, int argc, char *argv[]) out: udev_monitor_unref(udev_monitor); udev_monitor_unref(kernel_monitor); + udev_list_cleanup_entries(udev, &subsystem_match_list); return rc; }