- if (gettimeofday(&tv, &tz) == 0) {
- snprintf(timestr, sizeof(timestr), "%llu.%06u",
- (unsigned long long) tv.tv_sec, (unsigned int) tv.tv_usec);
- } else
- timestr[0] = '\0';
-
- if ((uevent_netlink_sock >= 0) && FD_ISSET(uevent_netlink_sock, &readfds)) {
- buflen = recv(uevent_netlink_sock, &buf, sizeof(buf), 0);
- if (buflen <= 0) {
- fprintf(stderr, "error receiving uevent message: %s\n", strerror(errno));
- continue;
- }
- source = "UEVENT";
- }
-
- if ((udev_monitor != NULL) && FD_ISSET(udev_monitor_get_fd(udev_monitor), &readfds)) {
- buflen = recv(udev_monitor_get_fd(udev_monitor), &buf, sizeof(buf), 0);
- if (buflen <= 0) {
- fprintf(stderr, "error receiving udev message: %s\n", strerror(errno));
- continue;
- }
- source = "UDEV ";
- }
-
- if (buflen == 0)
- continue;
-
- keys = strlen(buf) + 1; /* start of payload */
- devpath = search_key("DEVPATH", &buf[keys], buflen);
- action = search_key("ACTION", &buf[keys], buflen);
- subsys = search_key("SUBSYSTEM", &buf[keys], buflen);
- printf("%s[%s] %-8s %s (%s)\n", source, timestr, action, devpath, subsys);
-
- /* print environment */
- bufpos = keys;
- if (env) {
- while (bufpos < buflen) {
- int keylen;
- char *key;
-
- key = &buf[bufpos];
- keylen = strlen(key);
- if (keylen == 0)
- break;
- printf("%s\n", key);
- bufpos += keylen + 1;
+ for (i = 0; i < fdcount; i++) {
+ if (ev[i].data.fd == fd_kernel && ev[i].events & EPOLLIN) {
+ struct udev_device *device;
+
+ device = udev_monitor_receive_device(kernel_monitor);
+ if (device == NULL)
+ continue;
+ print_device(device, "KERNEL", prop);
+ udev_device_unref(device);
+ } else if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
+ struct udev_device *device;
+
+ device = udev_monitor_receive_device(udev_monitor);
+ if (device == NULL)
+ continue;
+ print_device(device, "UDEV", prop);
+ udev_device_unref(device);