]>
Commit | Line | Data |
---|---|---|
f0083e3d GKH |
1 | /* |
2 | * udev.c | |
3 | * | |
4 | * Userspace devfs | |
5 | * | |
6 | * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> | |
7 | * | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation version 2 of the License. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License along | |
19 | * with this program; if not, write to the Free Software Foundation, Inc., | |
20 | * 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | * | |
22 | */ | |
23 | ||
24 | #include <stdlib.h> | |
25 | #include <string.h> | |
85511f02 GKH |
26 | #include <stdio.h> |
27 | #include <fcntl.h> | |
28 | #include <unistd.h> | |
29 | #include <errno.h> | |
e8baccca | 30 | #include <ctype.h> |
85511f02 | 31 | |
f0083e3d GKH |
32 | #include "udev.h" |
33 | #include "udev_version.h" | |
7ac0feeb | 34 | #include "udev_dbus.h" |
2232cac8 | 35 | #include "namedev.h" |
dbfc520c | 36 | #include "udevdb.h" |
19dc5d4c | 37 | #include "libsysfs/libsysfs.h" |
f0083e3d | 38 | |
c056c514 GKH |
39 | /* global variables */ |
40 | char **main_argv; | |
41 | char **main_envp; | |
42 | ||
c056c514 | 43 | static inline char *get_action(void) |
f0083e3d GKH |
44 | { |
45 | char *action; | |
46 | ||
47 | action = getenv("ACTION"); | |
48 | return action; | |
49 | } | |
50 | ||
c056c514 GKH |
51 | static inline char *get_devpath(void) |
52 | { | |
53 | char *devpath; | |
54 | ||
55 | devpath = getenv("DEVPATH"); | |
56 | return devpath; | |
57 | } | |
f0083e3d | 58 | |
c056c514 | 59 | static inline char *get_seqnum(void) |
f0083e3d | 60 | { |
c056c514 | 61 | char *seqnum; |
f0083e3d | 62 | |
c056c514 GKH |
63 | seqnum = getenv("SEQNUM"); |
64 | return seqnum; | |
f0083e3d GKH |
65 | } |
66 | ||
c27e6911 | 67 | int main(int argc, char **argv, char **envp) |
f0083e3d | 68 | { |
f0083e3d | 69 | char *action; |
c056c514 | 70 | char *devpath; |
ea733a2f | 71 | char *subsystem; |
85511f02 | 72 | int retval = -EINVAL; |
f0083e3d | 73 | |
c27e6911 PM |
74 | main_argv = argv; |
75 | main_envp = envp; | |
76 | ||
2e5a8b99 GKH |
77 | dbg("version %s", UDEV_VERSION); |
78 | ||
f0083e3d GKH |
79 | if (argc != 2) { |
80 | dbg ("unknown number of arguments"); | |
85511f02 | 81 | goto exit; |
f0083e3d GKH |
82 | } |
83 | ||
ea733a2f GKH |
84 | subsystem = argv[1]; |
85 | ||
c056c514 GKH |
86 | devpath = get_devpath(); |
87 | if (!devpath) { | |
88 | dbg ("no devpath?"); | |
19dc5d4c GKH |
89 | goto exit; |
90 | } | |
f7b4eca4 | 91 | dbg("looking at '%s'", devpath); |
2232cac8 | 92 | |
19dc5d4c | 93 | /* we only care about class devices and block stuff */ |
c056c514 GKH |
94 | if (!strstr(devpath, "class") && |
95 | !strstr(devpath, "block")) { | |
f7b4eca4 | 96 | dbg("not a block or class device"); |
19dc5d4c GKH |
97 | goto exit; |
98 | } | |
af815f88 | 99 | |
ea733a2f GKH |
100 | /* but we don't care about net class devices */ |
101 | if (strcmp(subsystem, "net") == 0) { | |
102 | dbg("don't care about net devices"); | |
103 | goto exit; | |
104 | } | |
f0083e3d GKH |
105 | |
106 | action = get_action(); | |
107 | if (!action) { | |
108 | dbg ("no action?"); | |
85511f02 | 109 | goto exit; |
f0083e3d GKH |
110 | } |
111 | ||
e8baccca GKH |
112 | /* initialize our configuration */ |
113 | udev_init_config(); | |
114 | ||
7ac0feeb GKH |
115 | /* connect to the system message bus */ |
116 | sysbus_connect(); | |
5aebfbcb | 117 | |
dbfc520c DS |
118 | /* initialize udev database */ |
119 | retval = udevdb_init(UDEVDB_DEFAULT); | |
120 | if (retval != 0) { | |
f7b4eca4 | 121 | dbg("unable to initialize database"); |
dbfc520c DS |
122 | goto exit; |
123 | } | |
124 | ||
ea733a2f GKH |
125 | /* initialize the naming deamon */ |
126 | namedev_init(); | |
127 | ||
3f4967a1 | 128 | if (strcmp(action, "add") == 0) |
c056c514 | 129 | retval = udev_add_device(devpath, subsystem); |
85511f02 | 130 | |
dbfc520c | 131 | else if (strcmp(action, "remove") == 0) |
c056c514 | 132 | retval = udev_remove_device(devpath, subsystem); |
85511f02 | 133 | |
dbfc520c | 134 | else { |
f7b4eca4 | 135 | dbg("unknown action '%s'", action); |
dbfc520c DS |
136 | retval = -EINVAL; |
137 | } | |
138 | udevdb_exit(); | |
85511f02 | 139 | |
7ac0feeb GKH |
140 | /* disconnect from the system message bus */ |
141 | sysbus_disconnect(); | |
5aebfbcb | 142 | |
7ac0feeb | 143 | exit: |
85511f02 | 144 | return retval; |
f0083e3d | 145 | } |