udevadm-monitor.c revision e345e2670a8c17f5e1145cc554b7a7646e271032
/*
* Copyright (C) 2004-2008 Kay Sievers <kay.sievers@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <getopt.h>
#include "udev.h"
static int udev_exit;
{
udev_exit = 1;
}
{
int option;
int env = 0;
int print_kernel = 0;
int print_udev = 0;
int rc = 0;
{}
};
while (1) {
if (option == -1)
break;
switch (option) {
case 'e':
env = 1;
break;
case 'k':
print_kernel = 1;
break;
case 'u':
print_udev = 1;
break;
case 'h':
printf("Usage: udevadm monitor [--environment] [--kernel] [--udev] [--help]\n"
" --env print the whole event environment\n"
" --kernel print kernel uevents\n"
" --udev print udev events\n"
" --help print this help text\n\n");
default:
goto out;
}
}
if (!print_kernel && !print_udev) {
print_kernel = 1;
print_udev =1;
}
if (getuid() != 0 && print_kernel) {
goto out;
}
/* set signal handlers */
printf("monitor will print the received events for:\n");
if (print_udev) {
if (udev_monitor == NULL) {
rc = 1;
goto out;
}
if (udev_monitor_enable_receiving(udev_monitor) < 0) {
rc = 2;
goto out;
}
printf("UDEV the event which udev sends out after rule processing\n");
}
if (print_kernel) {
if (kernel_monitor == NULL) {
rc = 3;
goto out;
}
if (udev_monitor_enable_receiving(kernel_monitor) < 0) {
rc = 4;
goto out;
}
printf("UEVENT the kernel uevent\n");
}
printf("\n");
while (!udev_exit) {
int fdcount;
char timestr[64];
if (kernel_monitor != NULL)
if (udev_monitor != NULL)
fdcount = select(UDEV_MAX(udev_monitor_get_fd(kernel_monitor), udev_monitor_get_fd(udev_monitor))+1,
if (fdcount < 0) {
continue;
}
} else
timestr[0] = '\0';
continue;
if (env) {
}
printf("\n");
}
}
continue;
if (env) {
}
printf("\n");
}
}
}
out:
return rc;
}