]>
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 | ||
30 | #include "udev.h" | |
31 | #include "udev_version.h" | |
bb051f66 GKH |
32 | #include "logging.h" |
33 | #include "namedev.h" | |
bb051f66 GKH |
34 | #include "libsysfs/libsysfs.h" |
35 | ||
36 | /* global variables */ | |
37 | char **main_argv; | |
38 | char **main_envp; | |
39 | ||
40 | #ifdef LOG | |
41 | unsigned char logname[42]; | |
42 | void log_message (int level, const char *format, ...) | |
43 | { | |
44 | va_list args; | |
45 | ||
eb10f97f GKH |
46 | // if (!udev_log) |
47 | // return; | |
bb051f66 | 48 | |
eb10f97f | 49 | /* FIXME use level... */ |
bb051f66 | 50 | va_start(args, format); |
eb10f97f | 51 | vprintf(format, args); |
bb051f66 | 52 | va_end(args); |
eb10f97f GKH |
53 | if (format[strlen(format)-1] != '\n') |
54 | printf("\n"); | |
bb051f66 GKH |
55 | } |
56 | #endif | |
57 | ||
58 | static void sig_handler(int signum) | |
59 | { | |
60 | switch (signum) { | |
61 | case SIGINT: | |
62 | case SIGTERM: | |
bb051f66 GKH |
63 | exit(20 + signum); |
64 | default: | |
65 | dbg("unhandled signal"); | |
66 | } | |
67 | } | |
68 | ||
69 | static inline char *get_action(void) | |
70 | { | |
71 | char *action; | |
72 | ||
73 | action = getenv("ACTION"); | |
74 | return action; | |
75 | } | |
76 | ||
77 | static inline char *get_devpath(void) | |
78 | { | |
79 | char *devpath; | |
80 | ||
81 | devpath = getenv("DEVPATH"); | |
82 | return devpath; | |
83 | } | |
84 | ||
85 | static inline char *get_seqnum(void) | |
86 | { | |
87 | char *seqnum; | |
88 | ||
89 | seqnum = getenv("SEQNUM"); | |
90 | return seqnum; | |
91 | } | |
92 | ||
93 | static char *subsystem_blacklist[] = { | |
94 | "net", | |
95 | "scsi_host", | |
96 | "scsi_device", | |
97 | "usb_host", | |
98 | "pci_bus", | |
99 | "", | |
100 | }; | |
101 | ||
102 | static int udev_hotplug(int argc, char **argv) | |
103 | { | |
bb051f66 GKH |
104 | char *devpath; |
105 | char *subsystem; | |
106 | int retval = -EINVAL; | |
107 | int i; | |
108 | struct sigaction act; | |
109 | ||
eb10f97f | 110 | devpath = argv[1]; |
bb051f66 | 111 | if (!devpath) { |
eb10f97f | 112 | dbg("no devpath?"); |
bb051f66 GKH |
113 | goto exit; |
114 | } | |
115 | dbg("looking at '%s'", devpath); | |
116 | ||
117 | /* we only care about class devices and block stuff */ | |
118 | if (!strstr(devpath, "class") && | |
119 | !strstr(devpath, "block")) { | |
120 | dbg("not a block or class device"); | |
121 | goto exit; | |
122 | } | |
123 | ||
124 | /* skip blacklisted subsystems */ | |
125 | subsystem = argv[1]; | |
126 | i = 0; | |
127 | while (subsystem_blacklist[i][0] != '\0') { | |
128 | if (strcmp(subsystem, subsystem_blacklist[i]) == 0) { | |
129 | dbg("don't care about '%s' devices", subsystem); | |
130 | goto exit; | |
131 | } | |
132 | i++; | |
133 | } | |
134 | ||
bb051f66 GKH |
135 | /* initialize our configuration */ |
136 | udev_init_config(); | |
137 | ||
bb051f66 GKH |
138 | /* set up a default signal handler for now */ |
139 | act.sa_handler = sig_handler; | |
140 | sigemptyset (&act.sa_mask); | |
141 | act.sa_flags = SA_RESTART; | |
142 | sigaction(SIGINT, &act, NULL); | |
143 | sigaction(SIGTERM, &act, NULL); | |
144 | ||
145 | /* initialize the naming deamon */ | |
146 | namedev_init(); | |
147 | ||
eb10f97f | 148 | retval = udev_add_device(devpath, subsystem, 1); |
bb051f66 GKH |
149 | |
150 | exit: | |
151 | if (retval > 0) | |
152 | retval = 0; | |
153 | ||
154 | return -retval; | |
155 | } | |
156 | ||
157 | int main(int argc, char **argv, char **envp) | |
158 | { | |
159 | main_argv = argv; | |
160 | main_envp = envp; | |
161 | ||
bb051f66 GKH |
162 | dbg("version %s", UDEV_VERSION); |
163 | ||
164 | return udev_hotplug(argc, argv); | |
165 | } | |
166 | ||
167 |