]>
Commit | Line | Data |
---|---|---|
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 */ | |
37 | char **main_argv; | |
38 | char **main_envp; | |
39 | ||
8a0acf85 | 40 | |
bb051f66 | 41 | #ifdef LOG |
d00bd172 | 42 | unsigned char logname[LOGNAME_SIZE]; |
bb051f66 GKH |
43 | void log_message (int level, const char *format, ...) |
44 | { | |
d00bd172 | 45 | va_list args; |
bb051f66 | 46 | |
bb051f66 | 47 | va_start(args, format); |
eb10f97f | 48 | vprintf(format, args); |
bb051f66 | 49 | va_end(args); |
eb10f97f GKH |
50 | if (format[strlen(format)-1] != '\n') |
51 | printf("\n"); | |
bb051f66 GKH |
52 | } |
53 | #endif | |
54 | ||
8a0acf85 | 55 | int main(int argc, char *argv[], char *envp[]) |
bb051f66 | 56 | { |
bb051f66 | 57 | char *devpath; |
8a0acf85 KS |
58 | char temp[NAME_SIZE]; |
59 | char subsystem[] = ""; | |
60 | const int fake = 1; | |
61 | ||
62 | main_argv = argv; | |
63 | main_envp = envp; | |
64 | ||
65 | info("version %s", UDEV_VERSION); | |
bb051f66 | 66 | |
8a0acf85 KS |
67 | if (argv[1] == NULL) { |
68 | info("udevinfo expects the DEVPATH of the sysfs device as a argument"); | |
bb051f66 GKH |
69 | goto exit; |
70 | } | |
8a0acf85 KS |
71 | |
72 | /* initialize our configuration */ | |
73 | udev_init_config(); | |
74 | ||
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 */ | |
91 | if (!strstr(devpath, "class") && | |
92 | !strstr(devpath, "block")) { | |
8a0acf85 | 93 | info("not a block or class device"); |
bb051f66 GKH |
94 | goto exit; |
95 | } | |
96 | ||
bb051f66 GKH |
97 | /* initialize the naming deamon */ |
98 | namedev_init(); | |
99 | ||
d00bd172 | 100 | /* simulate node creation with fake flag */ |
8a0acf85 | 101 | udev_add_device(devpath, subsystem, fake); |
bb051f66 GKH |
102 | |
103 | exit: | |
8a0acf85 | 104 | return 0; |
bb051f66 | 105 | } |