]> git.ipfire.org Git - thirdparty/systemd.git/blame - udevtest.c
Added symlinks thanks to Kay's script and git hacking.
[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>
6b493a20 29#include <syslog.h>
bb051f66 30
c80da508 31#include "libsysfs/sysfs/libsysfs.h"
bb051f66 32#include "udev.h"
d7190b05 33#include "udev_sysfs.h"
9af5bb2f 34#include "udev_utils.h"
bb051f66 35#include "udev_version.h"
e5e322bc 36#include "udev_rules.h"
02fa9ae5 37#include "logging.h"
bb051f66 38
8a0acf85 39
6c18b1fb 40#ifdef USE_LOG
6b493a20 41void log_message (int priority, const char *format, ...)
bb051f66 42{
d00bd172 43 va_list args;
bb051f66 44
6b493a20
KS
45 if (priority > udev_log_priority)
46 return;
47
bb051f66 48 va_start(args, format);
eb10f97f 49 vprintf(format, args);
bb051f66 50 va_end(args);
eb10f97f
GKH
51 if (format[strlen(format)-1] != '\n')
52 printf("\n");
bb051f66
GKH
53}
54#endif
55
8a0acf85 56int main(int argc, char *argv[], char *envp[])
bb051f66 57{
7a947ce5 58 struct sysfs_class_device *class_dev;
bb051f66 59 char *devpath;
63f61c5c
KS
60 char path[PATH_SIZE];
61 char temp[PATH_SIZE];
7a947ce5 62 struct udevice udev;
a0294b76 63 char *subsystem = NULL;
8a0acf85 64
8a0acf85 65 info("version %s", UDEV_VERSION);
bb051f66 66
a0294b76
KS
67 /* initialize our configuration */
68 udev_init_config();
6b493a20
KS
69 if (udev_log_priority < LOG_INFO)
70 udev_log_priority = LOG_INFO;
a0294b76 71
e03a196a
KS
72 if (argc != 3) {
73 info("Usage: udevtest <devpath> <subsystem>");
74 return 1;
75 }
76
8a0acf85 77 /* remove sysfs_path if given */
63f61c5c 78 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
a0294b76 79 devpath = &argv[1][strlen(sysfs_path)] ;
8a0acf85
KS
80 else
81 if (argv[1][0] != '/') {
82 /* prepend '/' if missing */
63f61c5c
KS
83 snprintf(temp, sizeof(temp), "/%s", argv[1]);
84 temp[sizeof(temp)-1] = '\0';
8a0acf85 85 devpath = temp;
63f61c5c 86 } else
8a0acf85 87 devpath = argv[1];
8a0acf85 88
fb39f056
KS
89 subsystem = argv[2];
90 setenv("DEVPATH", devpath, 1);
91 setenv("SUBSYSTEM", subsystem, 1);
92 setenv("ACTION", "add", 1);
93 info("looking at device '%s' from subsystem '%s'", devpath, subsystem);
bb051f66 94
bb051f66 95 /* initialize the naming deamon */
e5e322bc 96 udev_rules_init();
bb051f66 97
7a947ce5 98 /* fill in values and test_run flag*/
fb39f056 99 udev_init_device(&udev, devpath, subsystem, "add");
7a947ce5 100
5ce120d3 101 /* skip subsystems without "dev", but handle net devices */
e6764498 102 if (udev.type != DEV_NET && subsystem_expect_no_dev(udev.subsystem)) {
5ce120d3
KS
103 info("don't care about '%s' devices", udev.subsystem);
104 return 2;
105 }
106
7a947ce5 107 /* open the device */
63f61c5c
KS
108 snprintf(path, sizeof(path), "%s%s", sysfs_path, udev.devpath);
109 path[sizeof(path)-1] = '\0';
7a947ce5 110 class_dev = sysfs_open_class_device_path(path);
e5e2ea95
KS
111 if (class_dev == NULL) {
112 info("sysfs_open_class_device_path failed");
113 return 1;
114 }
115
5ce120d3 116 info("opened class_dev->name='%s'", class_dev->name);
7a947ce5 117
5d24c6ca
KS
118 /* simulate node creation with test flag */
119 udev.test_run = 1;
7a947ce5 120 udev_add_device(&udev, class_dev);
bb051f66 121
5d24c6ca
KS
122 sysfs_close_class_device(class_dev);
123
8a0acf85 124 return 0;
bb051f66 125}