udevadm-monitor.c revision 116254097ad3c07d9f7ed06042dbec7ba4f0f4fd
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * This program is free software: you can redistribute it and/or modify
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sievers * it under the terms of the GNU General Public License as published by
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * the Free Software Foundation, either version 2 of the License, or
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * (at your option) any later version.
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * This program is distributed in the hope that it will be useful,
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * but WITHOUT ANY WARRANTY; without even the implied warranty of
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * GNU General Public License for more details.
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering * You should have received a copy of the GNU General Public License
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering * along with this program. If not, see <http://www.gnu.org/licenses/>.
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poetteringstatic void asmlinkage sig_handler(int signum)
3e2147858f21943d5f4a781c60f33ac22c6096edKay Sieversstatic void print_device(struct udev_device *device, const char *source, int env)
1c7dde3e475978c569a982d65fd86d4b4e3caad8Bastien Nocera (unsigned long long) tv.tv_sec, (unsigned int) tv.tv_usec,
47be870bd83fb3719dffc3ee9348a409ab762a14Lennart Poettering udev_list_entry_foreach(list_entry, udev_device_get_properties_list_entry(device))
86b2e20a5e5abf222fb81edcb5d58d012e35cbaaLennart Poetteringint udevadm_monitor(struct udev *udev, int argc, char *argv[])
fe1fed02c7637a2c18cd575f78be7fda27972148Zbigniew Jędrzejewski-Szmek static const struct option options[] = {
fe1fed02c7637a2c18cd575f78be7fda27972148Zbigniew Jędrzejewski-Szmek { "environment", no_argument, NULL, 'e' },
fe1fed02c7637a2c18cd575f78be7fda27972148Zbigniew Jędrzejewski-Szmek { "kernel", no_argument, NULL, 'k' },
fe1fed02c7637a2c18cd575f78be7fda27972148Zbigniew Jędrzejewski-Szmek { "udev", no_argument, NULL, 'u' },
8d7e170a5230753d8406276f8b5598e5bb6766e6Lennart Poettering option = getopt_long(argc, argv, "ekuh", options, NULL);
568c7e02372ff7b8eb41172ad7c3a426723512f8Zbigniew Jędrzejewski-Szmek printf("Usage: udevadm monitor [--environment] [--kernel] [--udev] [--help]\n"
78fbaacac004f912ec84b6f57d0bc656c3c95439Wulf C. Krueger " --env print the whole event environment\n"
8d7e170a5230753d8406276f8b5598e5bb6766e6Lennart Poettering " --kernel print kernel uevents\n"
568c7e02372ff7b8eb41172ad7c3a426723512f8Zbigniew Jędrzejewski-Szmek " --udev print udev events\n"
568c7e02372ff7b8eb41172ad7c3a426723512f8Zbigniew Jędrzejewski-Szmek if (!print_kernel && !print_udev) {
9c4fa6ed1069e98db5f01a5d1056b443a04cc7d9Lennart Poettering /* set signal handlers */
eb2e280f9c59b66965c9316eadc4c113a13ca744Lucas De Marchi memset(&act, 0x00, sizeof(struct sigaction));
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poettering act.sa_handler = (void (*)(int)) sig_handler;
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering printf("monitor will print the received events for:\n");
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering udev_monitor = udev_monitor_new_from_netlink(udev, UDEV_MONITOR_UDEV);
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering if (udev_monitor_enable_receiving(udev_monitor) < 0) {
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering printf("UDEV - the event which udev sends out after rule processing\n");
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering kernel_monitor = udev_monitor_new_from_netlink(udev, UDEV_MONITOR_KERNEL);
d1ab0ca07372649dad70a0348d75e394f254e1b6Lennart Poettering fprintf(stderr, "unable to subscribe to kernel events\n");
be1a67d9d63bfdd4a5f8ba9cfc804030f10f5833Lennart Poettering if (udev_monitor_enable_receiving(kernel_monitor) < 0) {
c1663b9daf5a43425e54bbe3daf6b10e64578f80Lennart Poettering FD_SET(udev_monitor_get_fd(kernel_monitor), &readfds);
5a45a93627609451784a04366cfa1150d32611d1Lennart Poettering FD_SET(udev_monitor_get_fd(udev_monitor), &readfds);
5a45a93627609451784a04366cfa1150d32611d1Lennart Poettering fdcount = select(UDEV_MAX(udev_monitor_get_fd(kernel_monitor), udev_monitor_get_fd(udev_monitor))+1,
9e7adc3ae1133fa08a468768a490812299fad030Lucas De Marchi fprintf(stderr, "error receiving uevent message: %m\n");
5a45a93627609451784a04366cfa1150d32611d1Lennart Poettering if ((kernel_monitor != NULL) && FD_ISSET(udev_monitor_get_fd(kernel_monitor), &readfds)) {
e17187091d463ad008c0b74eb04de5078b2abb96Michal Schmidt device = udev_monitor_receive_device(kernel_monitor);
85f19d825e7504676f3a80c78c1d9a7ec35a3b3fMichael Biebl if ((udev_monitor != NULL) && FD_ISSET(udev_monitor_get_fd(udev_monitor), &readfds)) {