]> git.ipfire.org Git - thirdparty/systemd.git/blame - udevtest.c
[PATCH] cleanup netif handling and netif-dev.d/ events
[thirdparty/systemd.git] / udevtest.c
CommitLineData
bb051f66
GKH
1/*
2 * udev.c
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"
30ccd6a3 32#include "udev_lib.h"
bb051f66 33#include "udev_version.h"
bb051f66
GKH
34#include "logging.h"
35#include "namedev.h"
bb051f66
GKH
36
37/* global variables */
38char **main_argv;
39char **main_envp;
40
8a0acf85 41
bb051f66 42#ifdef LOG
d00bd172 43unsigned char logname[LOGNAME_SIZE];
bb051f66
GKH
44void log_message (int level, const char *format, ...)
45{
d00bd172 46 va_list args;
bb051f66 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;
7a947ce5 60 char path[SYSFS_PATH_MAX];
8a0acf85 61 char temp[NAME_SIZE];
ce4256bd 62 char *subsystem = "";
7a947ce5 63 struct udevice udev;
8a0acf85
KS
64
65 main_argv = argv;
66 main_envp = envp;
67
68 info("version %s", UDEV_VERSION);
bb051f66 69
8a0acf85
KS
70 if (argv[1] == NULL) {
71 info("udevinfo expects the DEVPATH of the sysfs device as a argument");
5d24c6ca 72 return 1;
bb051f66 73 }
8a0acf85 74
8a0acf85
KS
75 /* remove sysfs_path if given */
76 if (strncmp(argv[1], sysfs_path, strlen(sysfs_path)) == 0)
77 devpath = argv[1] + strlen(sysfs_path);
78 else
79 if (argv[1][0] != '/') {
80 /* prepend '/' if missing */
81 strfieldcpy(temp, "/");
82 strfieldcat(temp, argv[1]);
83 devpath = temp;
84 } else {
85 devpath = argv[1];
86 }
87
88 info("looking at '%s'", devpath);
bb051f66
GKH
89
90 /* we only care about class devices and block stuff */
7a947ce5
KS
91 if (!strstr(devpath, "class") && !strstr(devpath, "block")) {
92 dbg("not a block or class device");
5d24c6ca 93 return 2;
bb051f66
GKH
94 }
95
5d24c6ca
KS
96 /* initialize our configuration */
97 udev_init_config();
98
bb051f66
GKH
99 /* initialize the naming deamon */
100 namedev_init();
101
ce4256bd
GKH
102 if (argv[2] != NULL)
103 subsystem = argv[2];
104
7a947ce5
KS
105 /* fill in values and test_run flag*/
106 udev_set_values(&udev, devpath, subsystem);
7a947ce5
KS
107
108 /* open the device */
109 snprintf(path, SYSFS_PATH_MAX, "%s%s", sysfs_path, udev.devpath);
110 class_dev = sysfs_open_class_device_path(path);
111 if (class_dev == NULL)
112 dbg ("sysfs_open_class_device_path failed");
113 else
114 dbg("opened class_dev->name='%s'", class_dev->name);
115
5d24c6ca
KS
116 /* simulate node creation with test flag */
117 udev.test_run = 1;
7a947ce5 118 udev_add_device(&udev, class_dev);
bb051f66 119
5d24c6ca
KS
120 sysfs_close_class_device(class_dev);
121
8a0acf85 122 return 0;
bb051f66 123}