6 * Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
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.
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.
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.
33 #include "udev_version.h"
36 #include "libsysfs/libsysfs.h"
38 /* global variables */
42 static inline char *get_action(void)
46 action = getenv("ACTION");
50 static inline char *get_devpath(void)
54 devpath = getenv("DEVPATH");
58 static inline char *get_seqnum(void)
62 seqnum = getenv("SEQNUM");
68 /** Global variable for the connection the to system message bus or #NULL
69 * if we cannot connect or acquire the org.kernel.udev service
71 DBusConnection* sysbus_connection;
73 /** Disconnect from the system message bus */
74 static void sysbus_disconnect()
76 if (sysbus_connection == NULL)
79 dbus_connection_disconnect(sysbus_connection);
80 sysbus_connection = NULL;
83 /** Connect to the system message bus */
84 static void sysbus_connect()
88 /* Connect to a well-known bus instance, the system bus */
89 dbus_error_init(&error);
90 sysbus_connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
91 if (sysbus_connection == NULL) {
92 dbg("cannot connect to system message bus, error %s: %s",
93 error.name, error.message);
94 dbus_error_free(&error);
98 /* Acquire the org.kernel.udev service such that listeners
99 * know that the message is really from us and not from a
100 * random attacker. See the file udev_sysbus_policy.conf for
103 * Note that a service can have multiple owners (though there
104 * is a concept of a primary owner for reception of messages)
105 * so no race is introduced if two copies of udev is running
108 dbus_bus_acquire_service(sysbus_connection, "org.kernel.udev", 0,
110 if (dbus_error_is_set(&error)) {
111 printf("cannot acquire org.kernel.udev service, error %s: %s'",
112 error.name, error.message);
118 #endif /* USE_DBUS */
120 int main(int argc, char **argv, char **envp)
125 int retval = -EINVAL;
130 dbg("version %s", UDEV_VERSION);
133 dbg ("unknown number of arguments");
139 devpath = get_devpath();
144 dbg("looking at '%s'", devpath);
146 /* we only care about class devices and block stuff */
147 if (!strstr(devpath, "class") &&
148 !strstr(devpath, "block")) {
149 dbg("not a block or class device");
153 /* but we don't care about net class devices */
154 if (strcmp(subsystem, "net") == 0) {
155 dbg("don't care about net devices");
159 action = get_action();
165 /* initialize our configuration */
169 /* connect to the system message bus */
171 #endif /* USE_DBUS */
173 /* initialize udev database */
174 retval = udevdb_init(UDEVDB_DEFAULT);
176 dbg("unable to initialize database");
180 /* initialize the naming deamon */
183 if (strcmp(action, "add") == 0)
184 retval = udev_add_device(devpath, subsystem);
186 else if (strcmp(action, "remove") == 0)
187 retval = udev_remove_device(devpath, subsystem);
190 dbg("unknown action '%s'", action);
196 /* disconnect from the system message bus */
198 #endif /* USE_DBUS */