chiark / gitweb /
libudev: also import "uevent" file when reading udev database
[elogind.git] / udev / lib / test-libudev.c
index 4dcc80a141c666c2e446f44cb451c44840eab7be..8afd294a2fb33873ce4ae55dcfcf8eeb30be1992 100644 (file)
@@ -17,8 +17,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
-
 #include <stdio.h>
 #include <stdarg.h>
 #include <unistd.h>
@@ -26,6 +24,7 @@
 #include <string.h>
 #include <getopt.h>
 #include <syslog.h>
+#include <fcntl.h>
 #include <sys/select.h>
 
 #include "libudev.h"
@@ -56,6 +55,8 @@ 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);
@@ -64,7 +65,7 @@ static void print_device(struct udev_device *device)
        printf("subsystem: '%s'\n", str);
        str = udev_device_get_driver(device);
        printf("driver:    '%s'\n", str);
-       str = udev_device_get_devname(device);
+       str = udev_device_get_devnode(device);
        printf("devname:   '%s'\n", str);
        count = udev_device_get_devlinks(device, print_devlinks_cb, NULL);
        printf("found %i links\n", count);
@@ -114,11 +115,26 @@ static int test_device_parents(struct udev *udev, const char *syspath)
        return 0;
 }
 
-static int devices_enum_cb(struct udev *udev,
-                          const char *devpath, const char *subsystem, const char *name,
-                          void *data)
+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 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;
 }
 
@@ -252,6 +268,7 @@ int main(int argc, char *argv[], char *envp[])
        }
 
        test_device(udev, syspath);
+       test_device_devnum(udev);
        test_device_parents(udev, syspath);
        test_enumerate(udev, subsystem);
        test_monitor(udev, socket);