]> git.ipfire.org Git - thirdparty/systemd.git/blame - udevtest.c
[PATCH] overall trivial trivial cleanup
[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
GKH
31#include "udev.h"
32#include "udev_version.h"
bb051f66
GKH
33#include "logging.h"
34#include "namedev.h"
bb051f66
GKH
35
36/* global variables */
37char **main_argv;
38char **main_envp;
39
40#ifdef LOG
d00bd172 41unsigned char logname[LOGNAME_SIZE];
bb051f66
GKH
42void log_message (int level, const char *format, ...)
43{
d00bd172 44 va_list args;
bb051f66 45
bb051f66 46 va_start(args, format);
eb10f97f 47 vprintf(format, args);
bb051f66 48 va_end(args);
eb10f97f
GKH
49 if (format[strlen(format)-1] != '\n')
50 printf("\n");
bb051f66
GKH
51}
52#endif
53
bb051f66
GKH
54static char *subsystem_blacklist[] = {
55 "net",
56 "scsi_host",
57 "scsi_device",
58 "usb_host",
59 "pci_bus",
d00bd172
KS
60 "pcmcia_socket",
61 ""
bb051f66
GKH
62};
63
d00bd172 64static int udev_hotplug(void)
bb051f66 65{
bb051f66
GKH
66 char *devpath;
67 char *subsystem;
68 int retval = -EINVAL;
69 int i;
bb051f66 70
d00bd172 71 devpath = main_argv[1];
bb051f66 72 if (!devpath) {
eb10f97f 73 dbg("no devpath?");
bb051f66
GKH
74 goto exit;
75 }
76 dbg("looking at '%s'", devpath);
77
78 /* we only care about class devices and block stuff */
79 if (!strstr(devpath, "class") &&
80 !strstr(devpath, "block")) {
81 dbg("not a block or class device");
82 goto exit;
83 }
84
85 /* skip blacklisted subsystems */
d00bd172 86 subsystem = main_argv[1];
bb051f66
GKH
87 i = 0;
88 while (subsystem_blacklist[i][0] != '\0') {
89 if (strcmp(subsystem, subsystem_blacklist[i]) == 0) {
90 dbg("don't care about '%s' devices", subsystem);
91 goto exit;
92 }
93 i++;
94 }
95
bb051f66
GKH
96 /* initialize our configuration */
97 udev_init_config();
98
bb051f66
GKH
99 /* initialize the naming deamon */
100 namedev_init();
101
d00bd172 102 /* simulate node creation with fake flag */
eb10f97f 103 retval = udev_add_device(devpath, subsystem, 1);
bb051f66
GKH
104
105exit:
106 if (retval > 0)
107 retval = 0;
108
109 return -retval;
110}
111
d00bd172 112int main(int argc, char *argv[], char *envp[])
bb051f66
GKH
113{
114 main_argv = argv;
115 main_envp = envp;
116
bb051f66
GKH
117 dbg("version %s", UDEV_VERSION);
118
d00bd172 119 return udev_hotplug();
bb051f66
GKH
120}
121
122