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;
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)
79 udev_test = getenv("UDEV_TEST");
80 if (udev_test == NULL) {
81 /* normal operation, use the compiled in defaults */
82 udev_config_dir = UDEV_CONFIG_DIR;
83 udev_root = UDEV_ROOT;
84 retval = sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX);
85 dbg("sysfs_path = %s", sysfs_path);
87 dbg("sysfs_get_mnt_path failed");
90 /* hm testing is happening, use the specified values */
91 temp = getenv("UDEV_SYSFS_PATH");
92 strncpy(sysfs_path, temp, sizeof(sysfs_path));
93 udev_config_dir = getenv("UDEV_CONFIG_DIR");
94 udev_root = getenv("UDEV_ROOT");
97 strncpy(udev_db_filename, udev_config_dir, sizeof(udev_db_filename));
98 strncat(udev_db_filename, UDEV_DB, sizeof(udev_db_filename));
100 strncpy(udev_config_filename, udev_config_dir, sizeof(udev_config_filename));
101 strncat(udev_config_filename, NAMEDEV_CONFIG_FILE, sizeof(udev_config_filename));
103 strncpy(udev_config_permission_filename, udev_config_dir, sizeof(udev_config_permission_filename));
104 strncat(udev_config_permission_filename, NAMEDEV_CONFIG_PERMISSION_FILE, sizeof(udev_config_permission_filename));
107 int main(int argc, char **argv, char **envp)
112 int retval = -EINVAL;
117 dbg("version %s", UDEV_VERSION);
120 dbg ("unknown number of arguments");
126 devpath = get_devpath();
131 dbg("looking at %s", devpath);
133 /* we only care about class devices and block stuff */
134 if (!strstr(devpath, "class") &&
135 !strstr(devpath, "block")) {
136 dbg("not block or class");
140 /* but we don't care about net class devices */
141 if (strcmp(subsystem, "net") == 0) {
142 dbg("don't care about net devices");
146 action = get_action();
152 /* initialize udev database */
154 retval = udevdb_init(UDEVDB_DEFAULT);
156 dbg("Unable to initialize database.");
160 /* initialize the naming deamon */
163 if (strcmp(action, "add") == 0)
164 retval = udev_add_device(devpath, subsystem);
166 else if (strcmp(action, "remove") == 0)
167 retval = udev_remove_device(devpath, subsystem);
170 dbg("Unknown action: %s", action);