udevtrigger.c revision 225cb03bd851adc6d269b13bdf2b1bfded2b96b9
/*
* 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"
static int verbose;
static int dry_run;
/* devices that should run last cause of their dependencies */
static int delay_device(const char *devpath)
{
static const char *delay_device_list[] = {
"*/md*",
"*/dm-*",
};
int i;
for (i = 0; delay_device_list[i] != NULL; i++)
return 1;
return 0;
}
static int device_list_insert(const char *path)
{
/* we only have a device, if we have an uevent file */
return -1;
return -1;
/* resolve possible link to real target */
return -1;
return -1;
return 0;
}
{
int fd;
if (verbose)
if (dry_run)
return;
if (fd < 0) {
return;
}
}
{
struct name_entry *loop_device;
struct name_entry *tmp_device;
continue;
}
/* trigger remaining delayed devices */
}
}
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_subsystem_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;
}
enum scan_type {
};
{
const char *subdir;
if (scan == SCAN_DEVICES)
subdir = "/devices";
else if (scan == SCAN_SUBSYSTEM)
subdir = "/drivers";
else
return;
continue;
if (scan == SCAN_DEVICES)
continue;
if (scan == SCAN_SUBSYSTEM) {
if (!subsystem_filtered("subsystem"))
if (subsystem_filtered("drivers"))
continue;
}
continue;
if (attr_filtered(dirname2))
continue;
}
}
}
}
}
static void scan_block(void)
{
if (subsystem_filtered("block"))
return;
continue;
if (attr_filtered(dirname))
continue;
if (device_list_insert(dirname) != 0)
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;
}
}
}
{
int failed = 0;
int option;
const char *action = "add";
{}
};
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 'c':
break;
case 's':
break;
case 'S':
break;
case 'a':
break;
case 'A':
break;
case 'h':
printf("Usage: udevadm trigger OPTIONS\n"
" --verbose print the list of devices while running\n"
" --dry-run do not actually trigger the events\n"
" --retry-failed trigger only the events which have been\n"
" marked as failed during a previous run\n"
" --subsystem-match=<subsystem> trigger devices from a matching subystem\n"
" --subsystem-nomatch=<subsystem> exclude devices from a matching subystem\n"
" --attr-match=<file[=<value>]> trigger devices with a matching sysfs\n"
" attribute\n"
" --attr-nomatch=<file[=<value>]> exclude devices with a matching sysfs\n"
" attribute\n"
" --help print this text\n"
"\n");
goto exit;
default:
goto exit;
}
}
if (failed) {
scan_failed();
} else {
} else {
scan_class();
/* scan "block" if it isn't a "class" */
scan_block();
}
}
exit:
return 0;
}