]> git.ipfire.org Git - thirdparty/systemd.git/blob - udev.c
[PATCH] got REPLACE to work properly.
[thirdparty/systemd.git] / udev.c
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>
26 #include <stdio.h>
27 #include <fcntl.h>
28 #include <unistd.h>
29 #include <errno.h>
30
31 #include "udev.h"
32 #include "udev_version.h"
33 #include "namedev.h"
34 #include "libsysfs/libsysfs.h"
35
36
37 static char *get_action(void)
38 {
39 char *action;
40
41 action = getenv("ACTION");
42 return action;
43 }
44
45
46 static char *get_device(void)
47 {
48 char *device;
49
50 device = getenv("DEVPATH");
51 return device;
52 }
53
54 int main(int argc, char *argv[])
55 {
56 char *action;
57 char *device;
58 char *subsystem;
59 int retval = -EINVAL;
60
61 if (argc != 2) {
62 dbg ("unknown number of arguments");
63 goto exit;
64 }
65
66 subsystem = argv[1];
67
68 device = get_device();
69 if (!device) {
70 dbg ("no device?");
71 goto exit;
72 }
73 dbg("looking at %s", device);
74
75 /* we only care about class devices and block stuff */
76 if (!strstr(device, "class") &&
77 !strstr(device, "block")) {
78 dbg("not block or class");
79 goto exit;
80 }
81
82 /* but we don't care about net class devices */
83 if (strcmp(subsystem, "net") == 0) {
84 dbg("don't care about net devices");
85 goto exit;
86 }
87
88 action = get_action();
89 if (!action) {
90 dbg ("no action?");
91 goto exit;
92 }
93
94 /* initialize the naming deamon */
95 namedev_init();
96
97 if (strcmp(action, "add") == 0)
98 return udev_add_device(device, argv[1]);
99
100 if (strcmp(action, "remove") == 0)
101 return udev_remove_device(device, argv[1]);
102
103 dbg("Unknown action: %s", action);
104 retval = -EINVAL;
105
106 exit:
107 return retval;
108 }
109