2004-02-13 10:48:07 +07:00
|
|
|
/*
|
2005-03-07 10:29:43 +07:00
|
|
|
* udevtest.c
|
2004-02-13 10:48:07 +07:00
|
|
|
*
|
2005-07-22 23:35:58 +07:00
|
|
|
* Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
|
2004-02-13 10:48:07 +07:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.,
|
|
|
|
* 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
2005-03-27 06:11:03 +07:00
|
|
|
#include <syslog.h>
|
2004-02-13 10:48:07 +07:00
|
|
|
|
2004-02-24 10:07:25 +07:00
|
|
|
#include "libsysfs/sysfs/libsysfs.h"
|
2004-02-13 10:48:07 +07:00
|
|
|
#include "udev.h"
|
2004-12-12 08:32:25 +07:00
|
|
|
#include "udev_sysfs.h"
|
2004-11-25 08:44:38 +07:00
|
|
|
#include "udev_utils.h"
|
2004-02-13 10:48:07 +07:00
|
|
|
#include "udev_version.h"
|
2005-03-13 04:36:32 +07:00
|
|
|
#include "udev_rules.h"
|
2004-11-12 12:32:19 +07:00
|
|
|
#include "logging.h"
|
2004-02-13 10:48:07 +07:00
|
|
|
|
2004-03-23 13:18:34 +07:00
|
|
|
|
2005-03-06 16:15:51 +07:00
|
|
|
#ifdef USE_LOG
|
2005-03-27 06:11:03 +07:00
|
|
|
void log_message (int priority, const char *format, ...)
|
2004-02-13 10:48:07 +07:00
|
|
|
{
|
2004-03-04 15:57:29 +07:00
|
|
|
va_list args;
|
2004-02-13 10:48:07 +07:00
|
|
|
|
2005-03-27 06:11:03 +07:00
|
|
|
if (priority > udev_log_priority)
|
|
|
|
return;
|
|
|
|
|
2004-02-13 10:48:07 +07:00
|
|
|
va_start(args, format);
|
2004-02-13 11:19:21 +07:00
|
|
|
vprintf(format, args);
|
2004-02-13 10:48:07 +07:00
|
|
|
va_end(args);
|
2004-02-13 11:19:21 +07:00
|
|
|
if (format[strlen(format)-1] != '\n')
|
|
|
|
printf("\n");
|
2004-02-13 10:48:07 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-23 13:18:34 +07:00
|
|
|
int main(int argc, char *argv[], char *envp[])
|
2004-02-13 10:48:07 +07:00
|
|
|
{
|
2005-07-05 20:24:41 +07:00
|
|
|
struct udev_rules rules;
|
2004-10-19 09:11:51 +07:00
|
|
|
struct sysfs_class_device *class_dev;
|
2004-02-13 10:48:07 +07:00
|
|
|
char *devpath;
|
2005-03-07 10:29:43 +07:00
|
|
|
char path[PATH_SIZE];
|
|
|
|
char temp[PATH_SIZE];
|
2004-10-19 09:11:51 +07:00
|
|
|
struct udevice udev;
|
2004-11-28 19:41:15 +07:00
|
|
|
char *subsystem = NULL;
|
2004-03-23 13:18:34 +07:00
|
|
|
|
|
|
|
info("version %s", UDEV_VERSION);
|
2004-02-13 10:48:07 +07:00
|
|
|
|
2004-11-28 19:41:15 +07:00
|
|
|
/* initialize our configuration */
|
|
|
|
udev_init_config();
|
2005-03-27 06:11:03 +07:00
|
|
|
if (udev_log_priority < LOG_INFO)
|
|
|
|
udev_log_priority = LOG_INFO;
|
2004-11-28 19:41:15 +07:00
|
|
|
|
2005-03-29 16:30:51 +07:00
|
|
|
if (argc != 3) {
|
|
|
|
info("Usage: udevtest <devpath> <subsystem>");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-03-23 13:18:34 +07:00
|
|
|
/* remove sysfs_path if given */
|
2005-03-07 10:29:43 +07:00
|
|
|
if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
|
2004-11-28 19:41:15 +07:00
|
|
|
devpath = &argv[1][strlen(sysfs_path)] ;
|
2004-03-23 13:18:34 +07:00
|
|
|
else
|
|
|
|
if (argv[1][0] != '/') {
|
|
|
|
/* prepend '/' if missing */
|
2005-03-07 10:29:43 +07:00
|
|
|
snprintf(temp, sizeof(temp), "/%s", argv[1]);
|
|
|
|
temp[sizeof(temp)-1] = '\0';
|
2004-03-23 13:18:34 +07:00
|
|
|
devpath = temp;
|
2005-03-07 10:29:43 +07:00
|
|
|
} else
|
2004-03-23 13:18:34 +07:00
|
|
|
devpath = argv[1];
|
|
|
|
|
2005-03-29 16:25:52 +07:00
|
|
|
subsystem = argv[2];
|
|
|
|
setenv("DEVPATH", devpath, 1);
|
|
|
|
setenv("SUBSYSTEM", subsystem, 1);
|
|
|
|
setenv("ACTION", "add", 1);
|
|
|
|
info("looking at device '%s' from subsystem '%s'", devpath, subsystem);
|
2004-02-13 10:48:07 +07:00
|
|
|
|
|
|
|
/* initialize the naming deamon */
|
2005-08-08 22:43:42 +07:00
|
|
|
udev_rules_init(&rules, 0, 0);
|
2004-02-13 10:48:07 +07:00
|
|
|
|
2004-10-19 09:11:51 +07:00
|
|
|
/* fill in values and test_run flag*/
|
2005-03-29 16:25:52 +07:00
|
|
|
udev_init_device(&udev, devpath, subsystem, "add");
|
2004-10-19 09:11:51 +07:00
|
|
|
|
|
|
|
/* open the device */
|
2005-03-07 10:29:43 +07:00
|
|
|
snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
|
|
|
|
path[sizeof(path)-1] = '\0';
|
2004-10-19 09:11:51 +07:00
|
|
|
class_dev = sysfs_open_class_device_path(path);
|
2004-10-30 18:44:46 +07:00
|
|
|
if (class_dev == NULL) {
|
|
|
|
info("sysfs_open_class_device_path failed");
|
|
|
|
return 1;
|
|
|
|
}
|
2004-12-12 08:03:14 +07:00
|
|
|
info("opened class_dev->name='%s'", class_dev->name);
|
2004-10-19 09:11:51 +07:00
|
|
|
|
2005-06-22 06:31:24 +07:00
|
|
|
if (udev.type == DEV_BLOCK || udev.type == DEV_CLASS)
|
|
|
|
udev.devt = get_devt(class_dev);
|
|
|
|
|
2004-10-19 09:28:39 +07:00
|
|
|
/* simulate node creation with test flag */
|
|
|
|
udev.test_run = 1;
|
2005-06-22 06:31:24 +07:00
|
|
|
if (udev.type == DEV_NET || udev.devt) {
|
2005-07-05 20:24:41 +07:00
|
|
|
udev_rules_get_name(&rules, &udev, class_dev);
|
2005-06-22 06:31:24 +07:00
|
|
|
udev_add_device(&udev, class_dev);
|
|
|
|
} else
|
|
|
|
info("only char and block devices with a dev-file are supported by this test program");
|
2004-10-19 09:28:39 +07:00
|
|
|
sysfs_close_class_device(class_dev);
|
|
|
|
|
2004-03-23 13:18:34 +07:00
|
|
|
return 0;
|
2004-02-13 10:48:07 +07:00
|
|
|
}
|