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.
32 #include "udev_version.h"
35 #include "libsysfs/libsysfs.h"
37 /* global variables */
41 char sysfs_path[SYSFS_PATH_MAX];
42 char *udev_config_dir = UDEV_CONFIG_DIR;
43 char *udev_root = UDEV_ROOT;
44 char udev_db_filename[PATH_MAX+NAME_MAX];
45 char udev_config_permission_filename[PATH_MAX+NAME_MAX];
46 char udev_config_filename[PATH_MAX+NAME_MAX];
49 static inline char *get_action(void)
53 action = getenv("ACTION");
57 static inline char *get_devpath(void)
61 devpath = getenv("DEVPATH");
65 static inline char *get_seqnum(void)
69 seqnum = getenv("SEQNUM");
73 static void get_dirs(void)
76 char *udev_db = UDEV_DB;
77 char *udev_config = UDEV_CONFIG_FILE;
78 char *udev_permission = UDEV_CONFIG_PERMISSION_FILE;
81 retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
83 dbg("sysfs_get_mnt_path failed");
85 /* see if we should try to override any of the default values */
86 temp = getenv("UDEV_TEST");
88 /* hm testing is happening, use the specified values, if they are present */
89 temp = getenv("UDEV_SYSFS_PATH");
91 strncpy(sysfs_path, temp, sizeof(sysfs_path));
92 temp = getenv("UDEV_CONFIG_DIR");
94 udev_config_dir = temp;
95 temp = getenv("UDEV_ROOT");
98 temp = getenv("UDEV_DB");
101 temp = getenv("UDEV_CONFIG_FILE");
104 temp = getenv("UDEV_PERMISSION_FILE");
106 udev_permission = temp;
108 dbg("sysfs_path = %s", sysfs_path);
110 strncpy(udev_db_filename, udev_config_dir, sizeof(udev_db_filename));
111 strncat(udev_db_filename, udev_db, sizeof(udev_db_filename));
113 strncpy(udev_config_filename, udev_config_dir, sizeof(udev_config_filename));
114 strncat(udev_config_filename, udev_config, sizeof(udev_config_filename));
116 strncpy(udev_config_permission_filename, udev_config_dir, sizeof(udev_config_permission_filename));
117 strncat(udev_config_permission_filename, udev_permission, sizeof(udev_config_permission_filename));
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 block or class");
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 udev database */
167 retval = udevdb_init(UDEVDB_DEFAULT);
169 dbg("Unable to initialize database.");
173 /* initialize the naming deamon */
176 if (strcmp(action, "add") == 0)
177 retval = udev_add_device(devpath, subsystem);
179 else if (strcmp(action, "remove") == 0)
180 retval = udev_remove_device(devpath, subsystem);
183 dbg("Unknown action: %s", action);