2 * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
3 * Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
31 /* global variables */
32 char udev_root[PATH_SIZE];
33 char udev_config_filename[PATH_SIZE];
34 char udev_rules_dir[PATH_SIZE];
35 int udev_log_priority;
38 static int get_key(char **line, char **key, char **value)
48 while (isspace(linepos[0]))
55 if (linepos[0] == '\0')
57 if (isspace(linepos[0]))
59 if (linepos[0] == '=')
68 while (isspace(linepos[0]))
72 if (linepos[0] == '"')
78 temp = strchr(linepos, '"');
86 static int parse_config_file(void)
100 if (file_map(udev_config_filename, &buf, &bufsize) != 0) {
101 err("can't open '%s' as config file: %s", udev_config_filename, strerror(errno));
105 /* loop through the whole file */
108 while (cur < bufsize) {
109 count = buf_get_line(buf, bufsize, cur);
114 if (count >= sizeof(line)) {
115 err("line too long, conf line skipped %s, line %d", udev_config_filename, lineno);
119 /* eat the whitespace */
120 while ((count > 0) && isspace(bufline[0])) {
127 /* see if this is a comment */
128 if (bufline[0] == COMMENT_CHARACTER)
131 memcpy(line, bufline, count);
135 retval = get_key(&linepos, &variable, &value);
137 err("error parsing %s, line %d:%d", udev_config_filename, lineno, (int)(linepos-line));
141 if (strcasecmp(variable, "udev_root") == 0) {
142 strlcpy(udev_root, value, sizeof(udev_root));
143 remove_trailing_chars(udev_root, '/');
147 if (strcasecmp(variable, "udev_rules") == 0) {
148 strlcpy(udev_rules_dir, value, sizeof(udev_rules_dir));
149 remove_trailing_chars(udev_rules_dir, '/');
153 if (strcasecmp(variable, "udev_log") == 0) {
154 udev_log_priority = log_priority(value);
159 file_unmap(buf, bufsize);
163 void udev_config_init(void)
167 strcpy(udev_root, UDEV_ROOT);
168 strcpy(udev_config_filename, UDEV_CONFIG_FILE);
169 strcpy(udev_rules_dir, UDEV_RULES_DIR);
170 udev_log_priority = LOG_ERR;
173 /* disable RUN key execution */
174 env = getenv("UDEV_RUN");
175 if (env && !string_is_true(env))
178 env = getenv("UDEV_CONFIG_FILE");
180 strlcpy(udev_config_filename, env, sizeof(udev_config_filename));
181 remove_trailing_chars(udev_config_filename, '/');
186 env = getenv("UDEV_ROOT");
188 strlcpy(udev_root, env, sizeof(udev_root));
189 remove_trailing_chars(udev_root, '/');
192 env = getenv("UDEV_LOG");
194 udev_log_priority = log_priority(env);
196 dbg("UDEV_CONFIG_FILE='%s'", udev_config_filename);
197 dbg("udev_root='%s'", udev_root);
198 dbg("udev_rules='%s'", udev_rules_dir);
199 dbg("udev_log=%d", udev_log_priority);