udevmonitor.c revision 225cb03bd851adc6d269b13bdf2b1bfded2b96b9
/*
* Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License.
*
* 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#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"
#include "udevd.h"
static int uevent_netlink_sock = -1;
static int udev_monitor_sock = -1;
static volatile int udev_exit;
static int init_udev_monitor_socket(void)
{
struct sockaddr_un saddr;
int retval;
/* use abstract namespace for socket path */
if (udev_monitor_sock == -1) {
return -1;
}
/* the bind takes care of ensuring only one copy running */
if (retval < 0) {
udev_monitor_sock = -1;
return -1;
}
return 0;
}
static int init_uevent_netlink_sock(void)
{
struct sockaddr_nl snl;
int retval;
if (uevent_netlink_sock == -1) {
return -1;
}
sizeof(struct sockaddr_nl));
if (retval < 0) {
uevent_netlink_sock = -1;
return -1;
}
return 0;
}
{
udev_exit = 1;
}
{
const char *key;
int keylen;
if (keylen == 0)
break;
}
return NULL;
}
{
int option;
int env = 0;
int kernel = 0;
int udev = 0;
int retval = 0;
{}
};
while (1) {
if (option == -1)
break;
switch (option) {
case 'e':
env = 1;
break;
case 'k':
kernel = 1;
break;
case 'u':
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;
}
}
kernel = 1;
udev =1;
}
goto out;
}
/* set signal handlers */
printf("udevmonitor will print the received events for:\n");
if (udev) {
if (retval)
goto out;
printf("UDEV the event which udev sends out after rule processing\n");
}
if (kernel) {
if (retval)
goto out;
printf("UEVENT the kernel uevent\n");
}
printf("\n");
while (!udev_exit) {
int fdcount;
char timestr[64];
buflen = 0;
if (uevent_netlink_sock >= 0)
if (udev_monitor_sock >= 0)
if (fdcount < 0) {
continue;
}
} else
timestr[0] = '\0';
if (buflen <= 0) {
continue;
}
source = "UEVENT";
}
if (buflen <= 0) {
continue;
}
source = "UDEV ";
}
if (buflen == 0)
continue;
/* print environment */
if (env) {
int keylen;
char *key;
if (keylen == 0)
break;
}
printf("\n");
}
}
out:
if (uevent_netlink_sock >= 0)
if (udev_monitor_sock >= 0)
if (retval)
return 1;
return 0;
}