X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev%2Flib%2Ftest-libudev.c;h=db08d4845f31572bc078624c10201465855ca907;hp=fd12bd9344ccbc9c0b576452aa4b0e1250a8a86b;hb=dacea9ff6be55f1b115c13b1ab530812d0d66879;hpb=bf8b2ae177fd016d03349b3aa881b72afd7d037d diff --git a/udev/lib/test-libudev.c b/udev/lib/test-libudev.c index fd12bd934..db08d4845 100644 --- a/udev/lib/test-libudev.c +++ b/udev/lib/test-libudev.c @@ -3,18 +3,10 @@ * * Copyright (C) 2008 Kay Sievers * - * 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 - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. */ #include @@ -101,6 +93,10 @@ static void print_device(struct udev_device *device) if (count > 0) printf("found %i properties\n", count); + str = udev_device_get_property_value(device, "MAJOR"); + if (str != NULL) + printf("MAJOR: '%s'\n", str); + str = udev_device_get_sysattr_value(device, "dev"); if (str != NULL) printf("attr{dev}: '%s'\n", str); @@ -221,17 +217,23 @@ static int test_enumerate_print_list(struct udev_enumerate *enumerate) return count; } -static int test_monitor(struct udev *udev, const char *socket_path) +static int test_monitor(struct udev *udev) { struct udev_monitor *udev_monitor; fd_set readfds; int fd; - udev_monitor = udev_monitor_new_from_socket(udev, socket_path); + udev_monitor = udev_monitor_new_from_netlink(udev, "udev"); if (udev_monitor == NULL) { printf("no socket\n"); return -1; } + if (udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "block", NULL) < 0 || + udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "tty", NULL) < 0 || + udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device") < 0) { + printf("filter failed\n"); + return -1; + } if (udev_monitor_enable_receiving(udev_monitor) < 0) { printf("bind failed\n"); return -1; @@ -247,7 +249,7 @@ static int test_monitor(struct udev *udev, const char *socket_path) FD_SET(STDIN_FILENO, &readfds); FD_SET(fd, &readfds); - printf("waiting for events on %s, press ENTER to exit\n", socket_path); + printf("waiting for events from udev, press ENTER to exit\n"); fdcount = select(fd+1, &readfds, NULL, NULL, NULL); printf("select fd count: %i\n", fdcount); @@ -381,7 +383,6 @@ int main(int argc, char *argv[]) static const struct option options[] = { { "syspath", required_argument, NULL, 'p' }, { "subsystem", required_argument, NULL, 's' }, - { "socket", required_argument, NULL, 'S' }, { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -389,7 +390,6 @@ int main(int argc, char *argv[]) }; const char *syspath = "/devices/virtual/mem/null"; const char *subsystem = NULL; - const char *socket = "@/org/kernel/udev/monitor"; char path[1024]; const char *str; @@ -416,15 +416,12 @@ int main(int argc, char *argv[]) case 's': subsystem = optarg; break; - case 'S': - socket = optarg; - break; case 'd': if (udev_get_log_priority(udev) < LOG_INFO) udev_set_log_priority(udev, LOG_INFO); break; case 'h': - printf("--debug --syspath= --subsystem= --socket= --help\n"); + printf("--debug --syspath= --subsystem= --help\n"); goto out; case 'V': printf("%s\n", VERSION); @@ -454,7 +451,7 @@ int main(int argc, char *argv[]) test_queue(udev); - test_monitor(udev, socket); + test_monitor(udev); out: udev_unref(udev); return 0;