+ count = udev_enumerate_devices(udev, subsystem, devices_enum_cb, NULL);
+ printf("found %i devices\n\n", count);
+ return count;
+}
+
+static int test_monitor(struct udev *udev, const char *socket_path)
+{
+ struct udev_monitor *udev_monitor;
+ fd_set readfds;
+ int fd;
+
+ udev_monitor = udev_monitor_new_from_socket(udev, socket_path);
+ if (udev_monitor == NULL) {
+ printf("no socket\n");
+ return -1;
+ }
+ if (udev_monitor_enable_receiving(udev_monitor) < 0) {
+ printf("bind failed\n");
+ return -1;
+ }
+
+ fd = udev_monitor_get_fd(udev_monitor);
+ FD_ZERO(&readfds);
+
+ while (1) {
+ struct udev_device *device;
+ int fdcount;
+
+ FD_SET(STDIN_FILENO, &readfds);
+ FD_SET(fd, &readfds);
+
+ printf("waiting for events on %s, press ENTER to exit\n", socket_path);
+ fdcount = select(fd+1, &readfds, NULL, NULL, NULL);
+ printf("select fd count: %i\n", fdcount);
+
+ if (FD_ISSET(fd, &readfds)) {
+ device = udev_monitor_receive_device(udev_monitor);
+ if (device == NULL) {
+ printf("no device from socket\n");
+ continue;
+ }
+ print_device(device);
+ udev_device_unref(device);
+ }
+
+ if (FD_ISSET(STDIN_FILENO, &readfds)) {
+ printf("exiting loop\n");
+ break;
+ }