#include <errno.h>
#include <signal.h>
#include <getopt.h>
+#include <time.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/un.h>
static void print_device(struct udev_device *device, const char *source, int prop)
{
- struct timeval tv;
- struct timezone tz;
+ struct timespec ts;
- gettimeofday(&tv, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &ts);
printf("%-6s[%llu.%06u] %-8s %s (%s)\n",
source,
- (unsigned long long) tv.tv_sec, (unsigned int) tv.tv_usec,
+ (unsigned long long) ts.tv_sec, (unsigned int) ts.tv_nsec/1000,
udev_device_get_action(device),
udev_device_get_devpath(device),
udev_device_get_subsystem(device));
}
}
-int udevadm_monitor(struct udev *udev, int argc, char *argv[])
+static int adm_monitor(struct udev *udev, int argc, char *argv[])
{
struct sigaction act;
sigset_t mask;
devtype[0] = '\0';
devtype++;
}
- udev_list_entry_add(udev, &subsystem_match_list, subsys, devtype, 0, 0);
+ udev_list_entry_add(udev, &subsystem_match_list, subsys, devtype, 0);
break;
}
case 't':
- udev_list_entry_add(udev, &tag_match_list, optarg, NULL, 0, 0);
+ udev_list_entry_add(udev, &tag_match_list, optarg, NULL, 0);
break;
case 'h':
printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
" --tag-match=<tag> filter events by tag\n"
" --help\n\n");
goto out;
+ default:
+ rc = 1;
+ goto out;
}
}
continue;
print_device(device, "KERNEL", prop);
udev_device_unref(device);
- }
-
- if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
+ } else if (ev[i].data.fd == fd_udev && ev[i].events & EPOLLIN) {
struct udev_device *device;
device = udev_monitor_receive_device(udev_monitor);
udev_list_cleanup_entries(udev, &tag_match_list);
return rc;
}
+
+const struct udevadm_cmd udevadm_monitor = {
+ .name = "monitor",
+ .cmd = adm_monitor,
+ .help = "listen to kernel and udev events",
+};