/*
- * Copyright (C) 2004-2010 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2004-2010 Kay Sievers <kay@vrfy.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
}
}
+static void help(void) {
+ printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
+ " -p,--property print the event properties\n"
+ " -k,--kernel print kernel uevents\n"
+ " -u,--udev print udev events\n"
+ " -s,--subsystem-match=SUBSYSTEM[/DEVTYPE] filter events by subsystem\n"
+ " -t,--tag-match=TAG filter events by tag\n"
+ " -h,--help\n\n");
+}
+
static int adm_monitor(struct udev *udev, int argc, char *argv[])
{
- struct sigaction act;
+ struct sigaction act = {};
sigset_t mask;
int option;
bool prop = false;
int fd_ep = -1;
int fd_kernel = -1, fd_udev = -1;
struct epoll_event ep_kernel, ep_udev;
- int rc = 0;
+ int rc = 0, c;
static const struct option options[] = {
- { "property", no_argument, NULL, 'p' },
- { "environment", no_argument, NULL, 'e' },
- { "kernel", no_argument, NULL, 'k' },
- { "udev", no_argument, NULL, 'u' },
+ { "property", no_argument, NULL, 'p' },
+ { "environment", no_argument, NULL, 'e' }, /* alias for -p */
+ { "kernel", no_argument, NULL, 'k' },
+ { "udev", no_argument, NULL, 'u' },
{ "subsystem-match", required_argument, NULL, 's' },
- { "tag-match", required_argument, NULL, 't' },
- { "help", no_argument, NULL, 'h' },
+ { "tag-match", required_argument, NULL, 't' },
+ { "help", no_argument, NULL, 'h' },
{}
};
udev_list_init(udev, &subsystem_match_list, true);
udev_list_init(udev, &tag_match_list, true);
- for (;;) {
- option = getopt_long(argc, argv, "pekus:t:h", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while((c = getopt_long(argc, argv, "pekus:t:h", options, NULL)) >= 0)
+ switch (c) {
case 'p':
case 'e':
prop = true;
char subsys[UTIL_NAME_SIZE];
char *devtype;
- util_strscpy(subsys, sizeof(subsys), optarg);
+ strscpy(subsys, sizeof(subsys), optarg);
devtype = strchr(subsys, '/');
if (devtype != NULL) {
devtype[0] = '\0';
udev_list_entry_add(&tag_match_list, optarg, NULL);
break;
case 'h':
- printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
- " --property print the event properties\n"
- " --kernel print kernel uevents\n"
- " --udev print udev events\n"
- " --subsystem-match=<subsystem[/devtype]> filter events by subsystem\n"
- " --tag-match=<tag> filter events by tag\n"
- " --help\n\n");
+ help();
goto out;
default:
rc = 1;
goto out;
}
- }
if (!print_kernel && !print_udev) {
print_kernel = true;
}
/* set signal handlers */
- memset(&act, 0x00, sizeof(struct sigaction));
act.sa_handler = sig_handler;
- sigemptyset(&act.sa_mask);
act.sa_flags = SA_RESTART;
sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL);
fd_ep = epoll_create1(EPOLL_CLOEXEC);
if (fd_ep < 0) {
- err(udev, "error creating epoll fd: %m\n");
+ log_error("error creating epoll fd: %m\n");
goto out;
}
ep_udev.events = EPOLLIN;
ep_udev.data.fd = fd_udev;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_udev, &ep_udev) < 0) {
- err(udev, "fail to add fd to epoll: %m\n");
+ log_error("fail to add fd to epoll: %m\n");
goto out;
}
ep_kernel.events = EPOLLIN;
ep_kernel.data.fd = fd_kernel;
if (epoll_ctl(fd_ep, EPOLL_CTL_ADD, fd_kernel, &ep_kernel) < 0) {
- err(udev, "fail to add fd to epoll: %m\n");
+ log_error("fail to add fd to epoll: %m\n");
goto out;
}
struct epoll_event ev[4];
int i;
- fdcount = epoll_wait(fd_ep, ev, ARRAY_SIZE(ev), -1);
+ fdcount = epoll_wait(fd_ep, ev, ELEMENTSOF(ev), -1);
if (fdcount < 0) {
if (errno != EINTR)
fprintf(stderr, "error receiving uevent message: %m\n");