udevtrigger.c revision 051445e078ab1a6d0cbbc1bd7f1a6fbd80e8bed1
/*
* Copyright (C) 2004-2006 Kay Sievers <kay@vrfy.org>
* Copyright (C) 2006 Hannes Reinecke <hare@suse.de>
*
* 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 <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <syslog.h>
#include <fnmatch.h>
#include "udev.h"
#include "udevd.h"
#ifdef USE_LOG
{
if (priority > udev_log_priority)
return;
}
#endif
static int verbose;
static int dry_run;
/* list of devices that we should run last due to any one of a number of reasons */
static char *last_list[] = {
};
/* list of devices that we should run first due to any one of a number of reasons */
static char *first_list[] = {
};
static int device_list_insert(const char *path)
{
int i;
for (i = 0; first_list[i] != NULL; i++) {
break;
}
}
break;
}
}
/* double entries will be ignored */
return 0;
}
static void trigger_uevent(const char *path)
{
int fd;
if (verbose)
if (dry_run)
return;
if (fd < 0) {
return;
}
}
static void exec_lists(void)
{
struct name_entry *loop_device;
struct name_entry *tmp_device;
/* handle the devices on the "first" list first */
}
/* handle the devices on the "default" list next */
}
/* handle devices on the "last" list, if any */
}
}
{
/* look for the uevent file of the kobject */
return 0;
return 0;
return 1;
}
static int subsystem_filtered(const char *subsystem)
{
struct name_entry *loop_name;
/* skip devices matching the listed subsystems */
return 1;
/* skip devices not matching the listed subsystems */
if (!list_empty(&filter_subsytem_match_list)) {
return 0;
return 1;
}
return 0;
}
{
char *match_value;
/* separate attr and match value */
if (match_value != NULL) {
match_value[0] = '\0';
}
if (match_value != NULL) {
/* match file content */
int fd;
if (fd < 0)
return 0;
if (size < 0)
return 0;
/* match if attribute value matches */
return 1;
} else {
/* match if attribute exists */
return 1;
}
return 0;
}
static int attr_filtered(const char *path)
{
struct name_entry *loop_name;
/* skip devices matching the listed sysfs attributes */
return 1;
/* skip devices not matching the listed sysfs attributes */
if (!list_empty(&filter_attr_match_list)) {
return 0;
return 1;
}
return 0;
}
static void scan_bus(void)
{
continue;
continue;
/* look for devices */
continue;
if (attr_filtered(dirname2))
continue;
}
}
}
}
}
static void scan_block(void)
{
/* skip if "block" is already a "class" */
return;
if (subsystem_filtered("block"))
return;
continue;
if (attr_filtered(dirname))
continue;
else
continue;
/* look for partitions */
continue;
continue;
if (attr_filtered(dirname2))
continue;
}
}
}
}
}
static void scan_class(void)
{
continue;
continue;
continue;
continue;
if (attr_filtered(dirname2))
continue;
}
}
}
}
}
static void scan_failed(void)
{
continue;
/* replace PATH_TO_NAME_CHAR with '/' */
if (device[i] == PATH_TO_NAME_CHAR)
device[i] = '/';
else
continue;
}
}
}
{
int failed = 0;
int option;
{}
};
logging_init("udevtrigger");
sysfs_init();
while (1) {
if (option == -1)
break;
switch (option) {
case 'v':
verbose = 1;
break;
case 'n':
dry_run = 1;
break;
case 'F':
failed = 1;
break;
case 's':
break;
case 'S':
break;
case 'a':
break;
case 'A':
break;
case 'h':
printf("Usage: udevtrigger OPTIONS\n"
" --verbose print the list of devices which will be triggered\n"
" --dry-run do not actually trigger the event\n"
" --retry-failed trigger only the events which are failed during a previous run\n"
" --subsystem-match=<subsystem> select only devices from the specified subystem\n"
" --subsystem-nomatch=<subsystem> exclude devices from the specified subystem\n"
" --attr-match=<file[=<value>]> select only devices with a matching sysfs attribute\n"
" --attr-nomatch=<file[=<value>]> exclude devices with a matching sysfs attribute\n"
" --help print this text\n"
"\n");
goto exit;
default:
goto exit;
}
}
if (failed)
scan_failed();
else {
scan_bus();
scan_class();
scan_block();
}
exec_lists();
exit:
return 0;
}