]> git.ipfire.org Git - thirdparty/systemd.git/blame - udevtest.c
[PATCH] klibc: remove SCCS directories from the temporary klibc install
[thirdparty/systemd.git] / udevtest.c
CommitLineData
bb051f66 1/*
63f61c5c 2 * udevtest.c
bb051f66
GKH
3 *
4 * Userspace devfs
5 *
6 * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 */
22
23#include <stdlib.h>
24#include <string.h>
25#include <stdio.h>
26#include <errno.h>
27#include <ctype.h>
28#include <signal.h>
29
c80da508 30#include "libsysfs/sysfs/libsysfs.h"
bb051f66 31#include "udev.h"
d7190b05 32#include "udev_sysfs.h"
9af5bb2f 33#include "udev_utils.h"
bb051f66 34#include "udev_version.h"
e5e322bc 35#include "udev_rules.h"
02fa9ae5 36#include "logging.h"
bb051f66 37
8a0acf85 38
6c18b1fb 39#ifdef USE_LOG
bb051f66
GKH
40void log_message (int level, const char *format, ...)
41{
d00bd172 42 va_list args;
bb051f66 43
bb051f66 44 va_start(args, format);
eb10f97f 45 vprintf(format, args);
bb051f66 46 va_end(args);
eb10f97f
GKH
47 if (format[strlen(format)-1] != '\n')
48 printf("\n");
bb051f66
GKH
49}
50#endif
51
8a0acf85 52int main(int argc, char *argv[], char *envp[])
bb051f66 53{
7a947ce5 54 struct sysfs_class_device *class_dev;
bb051f66 55 char *devpath;
63f61c5c
KS
56 char path[PATH_SIZE];
57 char temp[PATH_SIZE];
7a947ce5 58 struct udevice udev;
a0294b76 59 char *subsystem = NULL;
8a0acf85 60
8a0acf85 61 info("version %s", UDEV_VERSION);
bb051f66 62
a0294b76
KS
63 if (argc < 2 || argc > 3) {
64 info("Usage: udevtest <devpath> [subsystem]");
5d24c6ca 65 return 1;
bb051f66 66 }
8a0acf85 67
a0294b76
KS
68 /* initialize our configuration */
69 udev_init_config();
70
8a0acf85 71 /* remove sysfs_path if given */
63f61c5c 72 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
a0294b76 73 devpath = &argv[1][strlen(sysfs_path)] ;
8a0acf85
KS
74 else
75 if (argv[1][0] != '/') {
76 /* prepend '/' if missing */
63f61c5c
KS
77 snprintf(temp, sizeof(temp), "/%s", argv[1]);
78 temp[sizeof(temp)-1] = '\0';
8a0acf85 79 devpath = temp;
63f61c5c 80 } else
8a0acf85 81 devpath = argv[1];
8a0acf85
KS
82
83 info("looking at '%s'", devpath);
bb051f66 84
bb051f66 85 /* initialize the naming deamon */
e5e322bc 86 udev_rules_init();
bb051f66 87
a0294b76 88 if (argc == 3)
ce4256bd
GKH
89 subsystem = argv[2];
90
7a947ce5 91 /* fill in values and test_run flag*/
45a7b668 92 udev_init_device(&udev, devpath, subsystem);
7a947ce5 93
5ce120d3 94 /* skip subsystems without "dev", but handle net devices */
e6764498 95 if (udev.type != DEV_NET && subsystem_expect_no_dev(udev.subsystem)) {
5ce120d3
KS
96 info("don't care about '%s' devices", udev.subsystem);
97 return 2;
98 }
99
7a947ce5 100 /* open the device */
63f61c5c
KS
101 snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
102 path[sizeof(path)-1] = '\0';
7a947ce5 103 class_dev = sysfs_open_class_device_path(path);
e5e2ea95
KS
104 if (class_dev == NULL) {
105 info("sysfs_open_class_device_path failed");
106 return 1;
107 }
108
5ce120d3 109 info("opened class_dev->name='%s'", class_dev->name);
7a947ce5 110
5d24c6ca
KS
111 /* simulate node creation with test flag */
112 udev.test_run = 1;
7a947ce5 113 udev_add_device(&udev, class_dev);
bb051f66 114
5d24c6ca
KS
115 sysfs_close_class_device(class_dev);
116
8a0acf85 117 return 0;
bb051f66 118}