X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;ds=sidebyside;f=udev%2Flib%2Ftest-libudev.c;h=39330a74c6cbbe036370008b01db80ec598556c3;hb=38f27948cdafd8a4b90a6b4f1f54b89891983506;hp=7795f5f0fba2a165fa5659fb76ca8b85ecdbba45;hpb=4ad3a37f50ed3af4158cd0d0badbd146eb8e3500;p=elogind.git
diff --git a/udev/lib/test-libudev.c b/udev/lib/test-libudev.c
index 7795f5f0f..39330a74c 100644
--- a/udev/lib/test-libudev.c
+++ b/udev/lib/test-libudev.c
@@ -17,13 +17,13 @@
* along with this program. If not, see .
*/
-#include "config.h"
-
#include
#include
#include
#include
#include
+#include
+#include
#include
#include "libudev.h"
@@ -54,14 +54,16 @@ static void print_device(struct udev_device *device)
int count;
printf("*** device: %p ***\n", device);
+ str = udev_device_get_action(device);
+ printf("action: '%s'\n", str);
+ str = udev_device_get_syspath(device);
+ printf("syspath: '%s'\n", str);
str = udev_device_get_devpath(device);
printf("devpath: '%s'\n", str);
str = udev_device_get_subsystem(device);
printf("subsystem: '%s'\n", str);
str = udev_device_get_driver(device);
printf("driver: '%s'\n", str);
- str = udev_device_get_syspath(device);
- printf("syspath: '%s'\n", str);
str = udev_device_get_devname(device);
printf("devname: '%s'\n", str);
count = udev_device_get_devlinks(device, print_devlinks_cb, NULL);
@@ -71,12 +73,12 @@ static void print_device(struct udev_device *device)
printf("\n");
}
-static int test_device(struct udev *udev, const char *devpath)
+static int test_device(struct udev *udev, const char *syspath)
{
struct udev_device *device;
- printf("looking at device: %s\n", devpath);
- device = udev_device_new_from_devpath(udev, devpath);
+ printf("looking at device: %s\n", syspath);
+ device = udev_device_new_from_syspath(udev, syspath);
if (device == NULL) {
printf("no device\n");
return -1;
@@ -86,28 +88,38 @@ static int test_device(struct udev *udev, const char *devpath)
return 0;
}
-static int test_device_parents(struct udev *udev, const char *devpath)
+static int test_device_parents(struct udev *udev, const char *syspath)
{
struct udev_device *device;
+ struct udev_device *device_parent;
- printf("looking at device: %s\n", devpath);
- device = udev_device_new_from_devpath(udev, devpath);
- while (device != NULL) {
- struct udev_device *device_parent;
+ printf("looking at device: %s\n", syspath);
+ device = udev_device_new_from_syspath(udev, syspath);
+ if (device == NULL)
+ return -1;
+
+ device_parent = device;
+ do {
+ print_device(device_parent);
+ device_parent = udev_device_get_parent(device_parent);
+ } while (device_parent != NULL);
+
+ device_parent = device;
+ do {
+ print_device(device_parent);
+ device_parent = udev_device_get_parent(device_parent);
+ } while (device_parent != NULL);
+ udev_device_unref(device);
- print_device(device);
- device_parent = udev_device_new_from_parent(device);
- udev_device_unref(device);
- device = device_parent;
- }
return 0;
}
-static int devices_enum_cb(struct udev *udev,
- const char *devpath, const char *subsystem, const char *name,
- void *data)
+static int devices_enum_cb(struct udev_device *device, void *data)
{
- printf("device: '%s' (%s) '%s'\n", devpath, subsystem, name);
+ printf("device: '%s' (%s) '%s'\n",
+ udev_device_get_syspath(device),
+ udev_device_get_subsystem(device),
+ udev_device_get_sysname(device));
return 0;
}
@@ -172,20 +184,22 @@ static int test_monitor(struct udev *udev, const char *socket_path)
int main(int argc, char *argv[], char *envp[])
{
- struct udev *udev;
- const char *devpath = "/devices/virtual/mem/null";
+ struct udev *udev = NULL;
+ static const struct option options[] = {
+ { "syspath", 1, NULL, 'p' },
+ { "subsystem", 1, NULL, 's' },
+ { "socket", 1, NULL, 'S' },
+ { "debug", 0, NULL, 'd' },
+ { "help", 0, NULL, 'h' },
+ { "version", 0, NULL, 'V' },
+ {}
+ };
+ const char *syspath = "/devices/virtual/mem/null";
const char *subsystem = NULL;
const char *socket = "@/org/kernel/udev/monitor";
+ char path[1024];
const char *str;
- if (argv[1] != NULL) {
- devpath = argv[1];
- if (argv[2] != NULL)
- subsystem = argv[2];
- if (argv[3] != NULL)
- socket = argv[3];
- }
-
udev = udev_new();
printf("context: %p\n", udev);
if (udev == NULL) {
@@ -195,16 +209,54 @@ int main(int argc, char *argv[], char *envp[])
udev_set_log_fn(udev, log_fn);
printf("set log: %p\n", log_fn);
+ while (1) {
+ int option;
+
+ option = getopt_long(argc, argv, "+dhV", options, NULL);
+ if (option == -1)
+ break;
+
+ switch (option) {
+ case 'p':
+ syspath = optarg;
+ break;
+ 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");
+ goto out;
+ case 'V':
+ printf("%s\n", VERSION);
+ goto out;
+ default:
+ goto out;
+ }
+ }
+
str = udev_get_sys_path(udev);
printf("sys_path: '%s'\n", str);
str = udev_get_dev_path(udev);
printf("dev_path: '%s'\n", str);
- test_device(udev, devpath);
- test_device_parents(udev, devpath);
+ /* add sys path if needed */
+ if (strncmp(syspath, udev_get_sys_path(udev), strlen(udev_get_sys_path(udev))) != 0) {
+ snprintf(path, sizeof(path), "%s%s", udev_get_sys_path(udev), syspath);
+ syspath = path;
+ }
+
+ test_device(udev, syspath);
+ test_device_parents(udev, syspath);
test_enumerate(udev, subsystem);
test_monitor(udev, socket);
-
+out:
udev_unref(udev);
return 0;
}