test-libudev.c revision c0c6a4fc1c843fc61d44dc9f0a2b14c01201db12
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering/***
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering This file is part of systemd.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering Copyright 2008-2012 Kay Sievers <kay@vrfy.org>
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering systemd is free software; you can redistribute it and/or modify it
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering under the terms of the GNU Lesser General Public License as published by
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering (at your option) any later version.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering systemd is distributed in the hope that it will be useful, but
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering Lesser General Public License for more details.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering You should have received a copy of the GNU Lesser General Public License
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering***/
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include <stdio.h>
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include <unistd.h>
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include <getopt.h>
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include <sys/epoll.h>
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include "libudev.h"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include "udev-util.h"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#include "util.h"
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poetteringstatic void print_device(struct udev_device *device) {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering const char *str;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering dev_t devnum;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering int count;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering struct udev_list_entry *list_entry;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("*** device: %p ***\n", device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_action(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (str != NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("action: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_syspath(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("syspath: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_sysname(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("sysname: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_sysnum(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (str != NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("sysnum: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_devpath(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("devpath: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_subsystem(device);
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering if (str != NULL)
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering printf("subsystem: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering str = udev_device_get_devtype(device);
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering if (str != NULL)
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering printf("devtype: '%s'\n", str);
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering str = udev_device_get_driver(device);
875c6e1b48f37a07dfbb80d6653c73f205e94260Lennart Poettering if (str != NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("driver: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_devnode(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (str != NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("devname: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering devnum = udev_device_get_devnum(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (major(devnum) > 0)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("devnum: %u:%u\n", major(devnum), minor(devnum));
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering count = 0;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(device)) {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("link: '%s'\n", udev_list_entry_get_name(list_entry));
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering count++;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering }
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (count > 0)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("found %i links\n", count);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering count = 0;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device)) {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("property: '%s=%s'\n",
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering udev_list_entry_get_name(list_entry),
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering udev_list_entry_get_value(list_entry));
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering count++;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering }
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (count > 0)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("found %i properties\n", count);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_property_value(device, "MAJOR");
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (str != NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("MAJOR: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering str = udev_device_get_sysattr_value(device, "dev");
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (str != NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("attr{dev}: '%s'\n", str);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("\n");
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering}
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poetteringstatic int test_device(struct udev *udev, const char *syspath) {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering _cleanup_udev_device_unref_ struct udev_device *device;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("looking at device: %s\n", syspath);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering device = udev_device_new_from_syspath(udev, syspath);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (device == NULL) {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("no device found\n");
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering return -1;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering }
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering print_device(device);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering return 0;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering}
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poetteringstatic int test_device_parents(struct udev *udev, const char *syspath) {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering _cleanup_udev_device_unref_ struct udev_device *device;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering struct udev_device *device_parent;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("looking at device: %s\n", syspath);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering device = udev_device_new_from_syspath(udev, syspath);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering if (device == NULL)
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering return -1;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering printf("looking at parents\n");
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering device_parent = device;
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering do {
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering print_device(device_parent);
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering device_parent = udev_device_get_parent(device_parent);
} while (device_parent != NULL);
printf("looking at parents again\n");
device_parent = device;
do {
print_device(device_parent);
device_parent = udev_device_get_parent(device_parent);
} while (device_parent != NULL);
return 0;
}
static int test_device_devnum(struct udev *udev) {
dev_t devnum = makedev(1, 3);
struct udev_device *device;
printf("looking up device: %u:%u\n", major(devnum), minor(devnum));
device = udev_device_new_from_devnum(udev, 'c', devnum);
if (device == NULL)
return -1;
print_device(device);
udev_device_unref(device);
return 0;
}
static int test_device_subsys_name(struct udev *udev) {
struct udev_device *device;
printf("looking up device: 'block':'sda'\n");
device = udev_device_new_from_subsystem_sysname(udev, "block", "sda");
if (device == NULL)
return -1;
print_device(device);
udev_device_unref(device);
printf("looking up device: 'subsystem':'pci'\n");
device = udev_device_new_from_subsystem_sysname(udev, "subsystem", "pci");
if (device == NULL)
return -1;
print_device(device);
udev_device_unref(device);
printf("looking up device: 'drivers':'scsi:sd'\n");
device = udev_device_new_from_subsystem_sysname(udev, "drivers", "scsi:sd");
if (device == NULL)
return -1;
print_device(device);
udev_device_unref(device);
printf("looking up device: 'module':'printk'\n");
device = udev_device_new_from_subsystem_sysname(udev, "module", "printk");
if (device == NULL)
return -1;
print_device(device);
udev_device_unref(device);
return 0;
}
static int test_enumerate_print_list(struct udev_enumerate *enumerate) {
struct udev_list_entry *list_entry;
int count = 0;
udev_list_entry_foreach(list_entry, udev_enumerate_get_list_entry(enumerate)) {
struct udev_device *device;
device = udev_device_new_from_syspath(udev_enumerate_get_udev(enumerate),
udev_list_entry_get_name(list_entry));
if (device != NULL) {
printf("device: '%s' (%s)\n",
udev_device_get_syspath(device),
udev_device_get_subsystem(device));
udev_device_unref(device);
count++;
}
}
printf("found %i devices\n\n", count);
return count;
}
static int test_monitor(struct udev *udev) {
struct udev_monitor *udev_monitor = NULL;
int fd_ep;
int fd_udev = -1;
struct epoll_event ep_udev, ep_stdin;
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
printf("error creating epoll fd: %m\n");
goto out;
}
udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
if (udev_monitor == NULL) {
printf("no socket\n");
goto out;
}
fd_udev = udev_monitor_get_fd(udev_monitor);
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");
goto out;
}
if (udev_monitor_enable_receiving(udev_monitor) < 0) {
printf("bind failed\n");
goto out;
}
memzero(&ep_udev, sizeof(struct epoll_event));
ep_udev.events = EPOLLIN;
ep_udev.data.fd = fd_udev;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) {
printf("fail to add fd to epoll: %m\n");
goto out;
}
memzero(&ep_stdin, sizeof(struct epoll_event));
ep_stdin.events = EPOLLIN;
ep_stdin.data.fd = STDIN_FILENO;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, STDIN_FILENO, &ep_stdin) < 0) {
printf("fail to add fd to epoll: %m\n");
goto out;
}
for (;;) {
int fdcount;
struct epoll_event ev[4];
struct udev_device *device;
int i;
printf("waiting for events from udev, press ENTER to exit\n");
fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1);
printf("epoll fd count: %i\n", fdcount);
for (i = 0; i < fdcount; i++) {
if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
device = udev_monitor_receive_device(udev_monitor);
if (device == NULL) {
printf("no device from socket\n");
continue;
}
print_device(device);
udev_device_unref(device);
} else if (ev[i].data.fd == STDIN_FILENO && ev[i].events & EPOLLIN) {
printf("exiting loop\n");
goto out;
}
}
}
out:
if (fd_ep >= 0)
close(fd_ep);
udev_monitor_unref(udev_monitor);
return 0;
}
static int test_queue(struct udev *udev) {
struct udev_queue *udev_queue;
udev_queue = udev_queue_new(udev);
if (udev_queue == NULL)
return -1;
if (udev_queue_get_queue_is_empty(udev_queue))
printf("queue is empty\n");
udev_queue_unref(udev_queue);
return 0;
}
static int test_enumerate(struct udev *udev, const char *subsystem) {
struct udev_enumerate *udev_enumerate;
int r;
printf("enumerate '%s'\n", subsystem == NULL ? "<all>" : subsystem);
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_add_match_subsystem(udev_enumerate, subsystem);
udev_enumerate_scan_devices(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
printf("enumerate 'net' + duplicated scan + null + zero\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_add_match_subsystem(udev_enumerate, "net");
udev_enumerate_scan_devices(udev_enumerate);
udev_enumerate_scan_devices(udev_enumerate);
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/null");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
udev_enumerate_add_syspath(udev_enumerate, "/sys/class/mem/zero");
udev_enumerate_scan_devices(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
printf("enumerate 'block'\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_add_match_subsystem(udev_enumerate,"block");
r = udev_enumerate_add_match_is_initialized(udev_enumerate);
if (r < 0)
return r;
udev_enumerate_scan_devices(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
printf("enumerate 'not block'\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_add_nomatch_subsystem(udev_enumerate, "block");
udev_enumerate_scan_devices(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
printf("enumerate 'pci, mem, vc'\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_add_match_subsystem(udev_enumerate, "pci");
udev_enumerate_add_match_subsystem(udev_enumerate, "mem");
udev_enumerate_add_match_subsystem(udev_enumerate, "vc");
udev_enumerate_scan_devices(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
printf("enumerate 'subsystem'\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_scan_subsystems(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
printf("enumerate 'property IF_FS_*=filesystem'\n");
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL)
return -1;
udev_enumerate_add_match_property(udev_enumerate, "ID_FS*", "filesystem");
udev_enumerate_scan_devices(udev_enumerate);
test_enumerate_print_list(udev_enumerate);
udev_enumerate_unref(udev_enumerate);
return 0;
}
static void test_hwdb(struct udev *udev, const char *modalias) {
struct udev_hwdb *hwdb;
struct udev_list_entry *entry;
hwdb = udev_hwdb_new(udev);
udev_list_entry_foreach(entry, udev_hwdb_get_properties_list_entry(hwdb, modalias, 0))
printf("'%s'='%s'\n", udev_list_entry_get_name(entry), udev_list_entry_get_value(entry));
printf("\n");
hwdb = udev_hwdb_unref(hwdb);
assert_se(hwdb == NULL);
}
int main(int argc, char *argv[]) {
struct udev *udev = NULL;
static const struct option options[] = {
{ "syspath", required_argument, NULL, 'p' },
{ "subsystem", required_argument, NULL, 's' },
{ "debug", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{}
};
const char *syspath = "/devices/virtual/mem/null";
const char *subsystem = NULL;
char path[1024];
int c;
udev = udev_new();
printf("context: %p\n", udev);
if (udev == NULL) {
printf("no context\n");
return 1;
}
while ((c = getopt_long(argc, argv, "p:s:dhV", options, NULL)) >= 0)
switch (c) {
case 'p':
syspath = optarg;
break;
case 's':
subsystem = optarg;
break;
case 'd':
if (log_get_max_level() < LOG_INFO)
log_set_max_level(LOG_INFO);
break;
case 'h':
printf("--debug --syspath= --subsystem= --help\n");
goto out;
case 'V':
printf("%s\n", VERSION);
goto out;
case '?':
goto out;
default:
assert_not_reached("Unhandled option code.");
}
/* add sys path if needed */
if (!startswith(syspath, "/sys")) {
snprintf(path, sizeof(path), "/sys/%s", syspath);
syspath = path;
}
test_device(udev, syspath);
test_device_devnum(udev);
test_device_subsys_name(udev);
test_device_parents(udev, syspath);
test_enumerate(udev, subsystem);
test_queue(udev);
test_hwdb(udev, "usb:v0D50p0011*");
test_monitor(udev);
out:
udev_unref(udev);
return 0;
}