]>
git.ipfire.org Git - thirdparty/systemd.git/blob - udevtest.c
6 * Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
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.
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.
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.
30 #include "libsysfs/sysfs/libsysfs.h"
33 #include "udev_version.h"
37 /* global variables */
43 unsigned char logname
[LOGNAME_SIZE
];
44 void log_message (int level
, const char *format
, ...)
48 va_start(args
, format
);
49 vprintf(format
, args
);
51 if (format
[strlen(format
)-1] != '\n')
56 int main(int argc
, char *argv
[], char *envp
[])
58 struct sysfs_class_device
*class_dev
;
60 char path
[SYSFS_PATH_MAX
];
68 info("version %s", UDEV_VERSION
);
70 if (argv
[1] == NULL
) {
71 info("udevinfo expects the DEVPATH of the sysfs device as a argument");
75 /* remove sysfs_path if given */
76 if (strncmp(argv
[1], sysfs_path
, strlen(sysfs_path
)) == 0)
77 devpath
= argv
[1] + strlen(sysfs_path
);
79 if (argv
[1][0] != '/') {
80 /* prepend '/' if missing */
81 strfieldcpy(temp
, "/");
82 strfieldcat(temp
, argv
[1]);
88 info("looking at '%s'", devpath
);
90 /* we only care about class devices and block stuff */
91 if (!strstr(devpath
, "class") && !strstr(devpath
, "block")) {
92 dbg("not a block or class device");
96 /* initialize our configuration */
99 /* initialize the naming deamon */
105 /* fill in values and test_run flag*/
106 udev_set_values(&udev
, devpath
, subsystem
);
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 info("sysfs_open_class_device_path failed");
116 dbg("opened class_dev->name='%s'", class_dev
->name
);
118 /* simulate node creation with test flag */
120 udev_add_device(&udev
, class_dev
);
122 sysfs_close_class_device(class_dev
);