/*
* Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
- * Copyright (C) 2003-2006 Kay Sievers <kay.sievers@vrfy.org>
+ * Copyright (C) 2003-2008 Kay Sievers <kay.sievers@vrfy.org>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2 of the License.
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stddef.h>
#include "udev.h"
#include "udev_rules.h"
-#include "udev_selinux.h"
extern char **environ;
int outpipe[2] = {-1, -1};
int errpipe[2] = {-1, -1};
pid_t pid;
- char arg[PATH_SIZE];
- char program[PATH_SIZE];
+ char arg[UTIL_PATH_SIZE];
+ char program[UTIL_PATH_SIZE];
char *argv[(sizeof(arg) / 2) + 1];
int devnull;
int i;
int retval = 0;
/* build argv from comand */
- strlcpy(arg, command, sizeof(arg));
+ util_strlcpy(arg, command, sizeof(arg));
i = 0;
if (strchr(arg, ' ') != NULL) {
char *pos = arg;
/* allow programs in /lib/udev called without the path */
if (strchr(argv[0], '/') == NULL) {
- strlcpy(program, UDEV_PREFIX "/lib/udev/", sizeof(program));
- strlcat(program, argv[0], sizeof(program));
+ util_strlcpy(program, UDEV_PREFIX "/lib/udev/", sizeof(program));
+ util_strlcat(program, argv[0], sizeof(program));
argv[0] = program;
}
static int import_keys_into_env(struct udevice *udevice, const char *buf, size_t bufsize)
{
- char line[LINE_SIZE];
+ char line[UTIL_LINE_SIZE];
const char *bufline;
char *linepos;
char *variable;
continue;
/* see if this is a comment */
- if (bufline[0] == COMMENT_CHARACTER)
+ if (bufline[0] == '#')
continue;
if (count >= sizeof(line)) {
if (udev_db_get_device(udev_parent, dev_parent->devpath) == 0) {
dbg(udevice->udev, "import stored parent env '%s'\n", udev_parent->name);
list_for_each_entry(name_loop, &udev_parent->env_list, node) {
- char name[NAME_SIZE];
+ char name[UTIL_NAME_SIZE];
char *pos;
- strlcpy(name, name_loop->name, sizeof(name));
+ util_strlcpy(name, name_loop->name, sizeof(name));
pos = strchr(name, '=');
if (pos) {
pos[0] = '\0';
saddr.sun_family = AF_LOCAL;
if (sockpath[0] == '@') {
/* abstract namespace socket requested */
- strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1);
+ util_strlcpy(&saddr.sun_path[1], &sockpath[1], sizeof(saddr.sun_path)-1);
saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
} else if (stat(sockpath, &stats) == 0 && S_ISSOCK(stats.st_mode)) {
/* existing socket file */
- strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path));
+ util_strlcpy(saddr.sun_path, sockpath, sizeof(saddr.sun_path));
saddrlen = offsetof(struct sockaddr_un, sun_path) + strlen(saddr.sun_path);
} else {
/* no socket file, assume abstract namespace socket */
- strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
+ util_strlcpy(&saddr.sun_path[1], sockpath, sizeof(saddr.sun_path)-1);
saddrlen = offsetof(struct sockaddr_un, sun_path) + 1 + strlen(&saddr.sun_path[1]);
}
- bufpos = snprintf(buf, sizeof(buf)-1, "%s@%s", action, devpath);
+ bufpos = snprintf(buf, sizeof(buf), "%s@%s", action, devpath);
bufpos++;
- for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)-1); i++) {
- bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos-1);
+ for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)); i++) {
+ bufpos += util_strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos);
bufpos++;
}
if (bufpos > sizeof(buf))
if (strncmp(name_loop->name, "socket:", strlen("socket:")) == 0) {
pass_env_to_socket(udevice->udev, &name_loop->name[strlen("socket:")], udevice->dev->devpath, udevice->action);
} else {
- char program[PATH_SIZE];
+ char program[UTIL_PATH_SIZE];
- strlcpy(program, name_loop->name, sizeof(program));
+ util_strlcpy(program, name_loop->name, sizeof(program));
udev_rules_apply_format(udevice, program, sizeof(program));
if (run_program(udevice->udev, program, udevice->dev->subsystem, NULL, 0, NULL) != 0)
if (!name_loop->ignore_error)
#define WAIT_LOOP_PER_SECOND 50
static int wait_for_file(struct udevice *udevice, const char *file, int timeout)
{
- char filepath[PATH_SIZE];
- char devicepath[PATH_SIZE] = "";
+ char filepath[UTIL_PATH_SIZE];
+ char devicepath[UTIL_PATH_SIZE] = "";
struct stat stats;
int loop = timeout * WAIT_LOOP_PER_SECOND;
/* a relative path is a device attribute */
if (file[0] != '/') {
- strlcpy(devicepath, udev_get_sys_path(udevice->udev), sizeof(devicepath));
- strlcat(devicepath, udevice->dev->devpath, sizeof(devicepath));
+ util_strlcpy(devicepath, udev_get_sys_path(udevice->udev), sizeof(devicepath));
+ util_strlcat(devicepath, udevice->dev->devpath, sizeof(devicepath));
- strlcpy(filepath, devicepath, sizeof(filepath));
- strlcat(filepath, "/", sizeof(filepath));
- strlcat(filepath, file, sizeof(filepath));
+ util_strlcpy(filepath, devicepath, sizeof(filepath));
+ util_strlcat(filepath, "/", sizeof(filepath));
+ util_strlcat(filepath, file, sizeof(filepath));
file = filepath;
}
/* handle "[$SUBSYSTEM/$KERNEL]<attribute>" lookup */
static int attr_get_by_subsys_id(struct udev *udev, const char *attrstr, char *devpath, size_t len, char **attr)
{
- char subsys[NAME_SIZE];
+ char subsys[UTIL_NAME_SIZE];
char *pos;
char *id;
char *attrib;
goto out;
attrib = &attrib[1];
- strlcpy(subsys, &attrstr[1], sizeof(subsys));
+ util_strlcpy(subsys, &attrstr[1], sizeof(subsys));
pos = strchr(subsys, ']');
if (pos == NULL)
goto out;
pos = strstr(attr, "/*/");
if (pos != NULL) {
- char str[PATH_SIZE];
+ char str[UTIL_PATH_SIZE];
DIR *dir;
pos[1] = '\0';
- strlcpy(str, &pos[2], sizeof(str));
+ util_strlcpy(str, &pos[2], sizeof(str));
dir = opendir(attr);
if (dir != NULL) {
struct dirent *dent;
if (dent->d_name[0] == '.')
continue;
- strlcat(attr, dent->d_name, len);
- strlcat(attr, str, len);
+ util_strlcat(attr, dent->d_name, len);
+ util_strlcat(attr, str, len);
if (stat(attr, &stats) == 0) {
found = 1;
break;
closedir(dir);
}
if (!found)
- strlcat(attr, str, len);
+ util_strlcat(attr, str, len);
}
return found;
void udev_rules_apply_format(struct udevice *udevice, char *string, size_t maxsize)
{
- char temp[PATH_SIZE];
- char temp2[PATH_SIZE];
+ char temp[UTIL_PATH_SIZE];
+ char temp2[UTIL_PATH_SIZE];
char *head, *tail, *pos, *cpos, *attr, *rest;
int len;
int i;
if (head[1] == '\0')
break;
if (head[1] == '$') {
- strlcpy(temp, head+2, sizeof(temp));
- strlcpy(head+1, temp, maxsize);
+ util_strlcpy(temp, head+2, sizeof(temp));
+ util_strlcpy(head+1, temp, maxsize);
head++;
continue;
}
if (head[1] == '\0')
break;
if (head[1] == '%') {
- strlcpy(temp, head+2, sizeof(temp));
- strlcpy(head+1, temp, maxsize);
+ util_strlcpy(temp, head+2, sizeof(temp));
+ util_strlcpy(head+1, temp, maxsize);
head++;
continue;
}
break;
found:
attr = get_format_attribute(udevice->udev, &tail);
- strlcpy(temp, tail, sizeof(temp));
+ util_strlcpy(temp, tail, sizeof(temp));
dbg(udevice->udev, "format=%i, string='%s', tail='%s'\n", type ,string, tail);
switch (type) {
case SUBST_DEVPATH:
- strlcat(string, udevice->dev->devpath, maxsize);
+ util_strlcat(string, udevice->dev->devpath, maxsize);
dbg(udevice->udev, "substitute devpath '%s'\n", udevice->dev->devpath);
break;
case SUBST_KERNEL:
- strlcat(string, udevice->dev->kernel, maxsize);
+ util_strlcat(string, udevice->dev->kernel, maxsize);
dbg(udevice->udev, "substitute kernel name '%s'\n", udevice->dev->kernel);
break;
case SUBST_KERNEL_NUMBER:
- strlcat(string, udevice->dev->kernel_number, maxsize);
+ util_strlcat(string, udevice->dev->kernel_number, maxsize);
dbg(udevice->udev, "substitute kernel number '%s'\n", udevice->dev->kernel_number);
break;
case SUBST_ID:
if (udevice->dev_parent != NULL) {
- strlcat(string, udevice->dev_parent->kernel, maxsize);
+ util_strlcat(string, udevice->dev_parent->kernel, maxsize);
dbg(udevice->udev, "substitute id '%s'\n", udevice->dev_parent->kernel);
}
break;
case SUBST_DRIVER:
if (udevice->dev_parent != NULL) {
- strlcat(string, udevice->dev_parent->driver, maxsize);
+ util_strlcat(string, udevice->dev_parent->driver, maxsize);
dbg(udevice->udev, "substitute driver '%s'\n", udevice->dev_parent->driver);
}
break;
case SUBST_MAJOR:
sprintf(temp2, "%d", major(udevice->devt));
- strlcat(string, temp2, maxsize);
+ util_strlcat(string, temp2, maxsize);
dbg(udevice->udev, "substitute major number '%s'\n", temp2);
break;
case SUBST_MINOR:
sprintf(temp2, "%d", minor(udevice->devt));
- strlcat(string, temp2, maxsize);
+ util_strlcat(string, temp2, maxsize);
dbg(udevice->udev, "substitute minor number '%s'\n", temp2);
break;
case SUBST_RESULT:
err(udevice->udev, "requested part of result string not found\n");
break;
}
- strlcpy(temp2, cpos, sizeof(temp2));
+ util_strlcpy(temp2, cpos, sizeof(temp2));
/* %{2+}c copies the whole string from the second part on */
if (rest[0] != '+') {
cpos = strchr(temp2, ' ');
if (cpos)
cpos[0] = '\0';
}
- strlcat(string, temp2, maxsize);
+ util_strlcat(string, temp2, maxsize);
dbg(udevice->udev, "substitute part of result string '%s'\n", temp2);
} else {
- strlcat(string, udevice->program_result, maxsize);
+ util_strlcat(string, udevice->program_result, maxsize);
dbg(udevice->udev, "substitute result string '%s'\n", udevice->program_result);
}
break;
if (attr == NULL)
err(udevice->udev, "missing file parameter for attr\n");
else {
- char devpath[PATH_SIZE];
+ char devpath[UTIL_PATH_SIZE];
char *attrib;
const char *value = NULL;
size_t size;
break;
/* strip trailing whitespace, and replace unwanted characters */
- size = strlcpy(temp2, value, sizeof(temp2));
+ size = util_strlcpy(temp2, value, sizeof(temp2));
if (size >= sizeof(temp2))
size = sizeof(temp2)-1;
while (size > 0 && isspace(temp2[size-1]))
temp2[--size] = '\0';
- count = replace_chars(temp2, ALLOWED_CHARS_INPUT);
+ count = util_replace_chars(temp2, ALLOWED_CHARS_INPUT);
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n" , count);
- strlcat(string, temp2, maxsize);
+ util_strlcat(string, temp2, maxsize);
dbg(udevice->udev, "substitute sysfs value '%s'\n", temp2);
}
break;
if (udev_parent != NULL) {
/* lookup the name in the udev_db with the DEVPATH of the parent */
if (udev_db_get_device(udev_parent, dev_parent->devpath) == 0) {
- strlcat(string, udev_parent->name, maxsize);
+ util_strlcat(string, udev_parent->name, maxsize);
dbg(udevice->udev, "substitute parent node name'%s'\n", udev_parent->name);
} else
dbg(udevice->udev, "parent not found in database\n");
udevice->tmp_node[sizeof(udevice->tmp_node)-1] = '\0';
udev_node_mknod(udevice, udevice->tmp_node, udevice->devt, 0600, 0, 0);
}
- strlcat(string, udevice->tmp_node, maxsize);
+ util_strlcat(string, udevice->tmp_node, maxsize);
dbg(udevice->udev, "substitute temporary device node name '%s'\n", udevice->tmp_node);
break;
case SUBST_NAME:
if (udevice->name[0] == '\0') {
- strlcat(string, udevice->dev->kernel, maxsize);
+ util_strlcat(string, udevice->dev->kernel, maxsize);
dbg(udevice->udev, "substitute udevice->kernel '%s'\n", udevice->name);
} else {
- strlcat(string, udevice->name, maxsize);
+ util_strlcat(string, udevice->name, maxsize);
dbg(udevice->udev, "substitute udevice->name '%s'\n", udevice->name);
}
break;
case SUBST_LINKS:
if (!list_empty(&udevice->symlink_list)) {
struct name_entry *name_loop;
- char symlinks[PATH_SIZE] = "";
+ char symlinks[UTIL_PATH_SIZE] = "";
list_for_each_entry(name_loop, &udevice->symlink_list, node) {
- strlcat(symlinks, name_loop->name, sizeof(symlinks));
- strlcat(symlinks, " ", sizeof(symlinks));
+ util_strlcat(symlinks, name_loop->name, sizeof(symlinks));
+ util_strlcat(symlinks, " ", sizeof(symlinks));
}
- remove_trailing_chars(symlinks, ' ');
- strlcat(string, symlinks, maxsize);
+ util_remove_trailing_chars(symlinks, ' ');
+ util_strlcat(string, symlinks, maxsize);
}
break;
case SUBST_ROOT:
- strlcat(string, udev_get_dev_path(udevice->udev), maxsize);
+ util_strlcat(string, udev_get_dev_path(udevice->udev), maxsize);
dbg(udevice->udev, "substitute udev_root '%s'\n", udev_get_dev_path(udevice->udev));
break;
case SUBST_SYS:
- strlcat(string, udev_get_sys_path(udevice->udev), maxsize);
+ util_strlcat(string, udev_get_sys_path(udevice->udev), maxsize);
dbg(udevice->udev, "substitute sys_path '%s'\n", udev_get_sys_path(udevice->udev));
break;
case SUBST_ENV:
break;
}
dbg(udevice->udev, "substitute env '%s=%s'\n", attr, pos);
- strlcat(string, pos, maxsize);
+ util_strlcat(string, pos, maxsize);
break;
default:
err(udevice->udev, "unknown substitution type=%i\n", type);
head[len] = '\0';
dbg(udevice->udev, "truncate to %i chars, subtitution string becomes '%s'\n", len, head);
}
- strlcat(string, temp, maxsize);
+ util_strlcat(string, temp, maxsize);
}
}
static int match_key(struct udev *udev, const char *key_name, struct udev_rule *rule, struct key *key, const char *val)
{
- char value[PATH_SIZE];
+ char value[UTIL_PATH_SIZE];
char *key_value;
char *pos;
int match = 0;
return 0;
/* look for a matching string, parts are separated by '|' */
- strlcpy(value, rule->buf + key->val_off, sizeof(value));
+ util_strlcpy(value, rule->buf + key->val_off, sizeof(value));
key_value = value;
dbg(udev, "key %s value='%s'\n", key_name, key_value);
while (key_value) {
if (rule->test.operation == KEY_OP_MATCH ||
rule->test.operation == KEY_OP_NOMATCH) {
- char filename[PATH_SIZE];
- char devpath[PATH_SIZE];
+ char filename[UTIL_PATH_SIZE];
+ char devpath[UTIL_PATH_SIZE];
char *attr;
struct stat statbuf;
int match;
- strlcpy(filename, key_val(rule, &rule->test), sizeof(filename));
+ util_strlcpy(filename, key_val(rule, &rule->test), sizeof(filename));
udev_rules_apply_format(udevice, filename, sizeof(filename));
if (attr_get_by_subsys_id(udevice->udev, filename, devpath, sizeof(devpath), &attr)) {
- strlcpy(filename, udev_get_sys_path(udevice->udev), sizeof(filename));
- strlcat(filename, devpath, sizeof(filename));
+ util_strlcpy(filename, udev_get_sys_path(udevice->udev), sizeof(filename));
+ util_strlcat(filename, devpath, sizeof(filename));
if (attr != NULL) {
- strlcat(filename, "/", sizeof(filename));
- strlcat(filename, attr, sizeof(filename));
+ util_strlcat(filename, "/", sizeof(filename));
+ util_strlcat(filename, attr, sizeof(filename));
}
} else if (filename[0] != '/') {
- char tmp[PATH_SIZE];
+ char tmp[UTIL_PATH_SIZE];
- strlcpy(tmp, udev_get_sys_path(udevice->udev), sizeof(tmp));
- strlcat(tmp, udevice->dev->devpath, sizeof(tmp));
- strlcat(tmp, "/", sizeof(tmp));
- strlcat(tmp, filename, sizeof(tmp));
- strlcpy(filename, tmp, sizeof(filename));
+ util_strlcpy(tmp, udev_get_sys_path(udevice->udev), sizeof(tmp));
+ util_strlcat(tmp, udevice->dev->devpath, sizeof(tmp));
+ util_strlcat(tmp, "/", sizeof(tmp));
+ util_strlcat(tmp, filename, sizeof(tmp));
+ util_strlcpy(filename, tmp, sizeof(filename));
}
attr_subst_subdir(filename, sizeof(filename));
}
if (rule->wait_for.operation != KEY_OP_UNSET) {
- char filename[PATH_SIZE];
+ char filename[UTIL_PATH_SIZE];
int found;
- strlcpy(filename, key_val(rule, &rule->wait_for), sizeof(filename));
+ util_strlcpy(filename, key_val(rule, &rule->wait_for), sizeof(filename));
udev_rules_apply_format(udevice, filename, sizeof(filename));
found = (wait_for_file(udevice, filename, 10) == 0);
if (!found && (rule->wait_for.operation != KEY_OP_NOMATCH))
pair->key.operation == KEY_OP_NOMATCH) {
const char *key_name = key_pair_name(rule, pair);
const char *key_value = key_val(rule, &pair->key);
- char devpath[PATH_SIZE];
+ char devpath[UTIL_PATH_SIZE];
char *attrib;
const char *value = NULL;
- char val[VALUE_SIZE];
+ char val[UTIL_NAME_SIZE];
size_t len;
if (attr_get_by_subsys_id(udevice->udev, key_name, devpath, sizeof(devpath), &attrib)) {
value = sysfs_attr_get_value(udevice->udev, udevice->dev->devpath, key_name);
if (value == NULL)
goto nomatch;
- strlcpy(val, value, sizeof(val));
+ util_strlcpy(val, value, sizeof(val));
/* strip trailing whitespace of value, if not asked to match for it */
len = strlen(key_value);
const char *key_name = key_pair_name(rule, pair);
const char *key_value = key_val(rule, &pair->key);
const char *value;
- char val[VALUE_SIZE];
+ char val[UTIL_NAME_SIZE];
size_t len;
value = sysfs_attr_get_value(udevice->udev, udevice->dev_parent->devpath, key_name);
value = sysfs_attr_get_value(udevice->udev, udevice->dev->devpath, key_name);
if (value == NULL)
goto try_parent;
- strlcpy(val, value, sizeof(val));
+ util_strlcpy(val, value, sizeof(val));
/* strip trailing whitespace of value, if not asked to match for it */
len = strlen(key_value);
/* execute external program */
if (rule->program.operation != KEY_OP_UNSET) {
- char program[PATH_SIZE];
- char result[PATH_SIZE];
+ char program[UTIL_PATH_SIZE];
+ char result[UTIL_PATH_SIZE];
- strlcpy(program, key_val(rule, &rule->program), sizeof(program));
+ util_strlcpy(program, key_val(rule, &rule->program), sizeof(program));
udev_rules_apply_format(udevice, program, sizeof(program));
if (run_program(udevice->udev, program, udevice->dev->subsystem, result, sizeof(result), NULL) != 0) {
dbg(udevice->udev, "PROGRAM is false\n");
int count;
dbg(udevice->udev, "PROGRAM matches\n");
- remove_trailing_chars(result, '\n');
+ util_remove_trailing_chars(result, '\n');
if (rule->string_escape == ESCAPE_UNSET ||
rule->string_escape == ESCAPE_REPLACE) {
- count = replace_chars(result, ALLOWED_CHARS_INPUT);
+ count = util_replace_chars(result, ALLOWED_CHARS_INPUT);
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n" , count);
}
dbg(udevice->udev, "result is '%s'\n", result);
- strlcpy(udevice->program_result, result, sizeof(udevice->program_result));
+ util_strlcpy(udevice->program_result, result, sizeof(udevice->program_result));
dbg(udevice->udev, "PROGRAM returned successful\n");
if (rule->program.operation == KEY_OP_NOMATCH)
goto nomatch;
/* import variables returned from program or or file into environment */
if (rule->import.operation != KEY_OP_UNSET) {
- char import[PATH_SIZE];
+ char import[UTIL_PATH_SIZE];
int rc = -1;
- strlcpy(import, key_val(rule, &rule->import), sizeof(import));
+ util_strlcpy(import, key_val(rule, &rule->import), sizeof(import));
udev_rules_apply_format(udevice, import, sizeof(import));
dbg(udevice->udev, "check for IMPORT import='%s'\n", import);
if (rule->import_type == IMPORT_PROGRAM) {
struct key_pair *pair = &rule->env.keys[i];
if (pair->key.operation == KEY_OP_ASSIGN) {
- char temp_value[NAME_SIZE];
+ char temp_value[UTIL_NAME_SIZE];
const char *key_name = key_pair_name(rule, pair);
const char *value = key_val(rule, &pair->key);
/* make sure we don't write to the same string we possibly read from */
- strlcpy(temp_value, value, sizeof(temp_value));
- udev_rules_apply_format(udevice, temp_value, NAME_SIZE);
+ util_strlcpy(temp_value, value, sizeof(temp_value));
+ udev_rules_apply_format(udevice, temp_value, sizeof(temp_value));
if (temp_value[0] == '\0') {
name_list_key_remove(udevice->udev, &udevice->env_list, key_name);
if (pair->key.operation == KEY_OP_ASSIGN) {
const char *key_name = key_pair_name(rule, pair);
- char devpath[PATH_SIZE];
+ char devpath[UTIL_PATH_SIZE];
char *attrib;
- char attr[PATH_SIZE] = "";
- char value[NAME_SIZE];
+ char attr[UTIL_PATH_SIZE] = "";
+ char value[UTIL_NAME_SIZE];
FILE *f;
if (attr_get_by_subsys_id(udevice->udev, key_name, devpath, sizeof(devpath), &attrib)) {
if (attrib != NULL) {
- strlcpy(attr, udev_get_sys_path(udevice->udev), sizeof(attr));
- strlcat(attr, devpath, sizeof(attr));
- strlcat(attr, "/", sizeof(attr));
- strlcat(attr, attrib, sizeof(attr));
+ util_strlcpy(attr, udev_get_sys_path(udevice->udev), sizeof(attr));
+ util_strlcat(attr, devpath, sizeof(attr));
+ util_strlcat(attr, "/", sizeof(attr));
+ util_strlcat(attr, attrib, sizeof(attr));
}
}
if (attr[0] == '\0') {
- strlcpy(attr, udev_get_sys_path(udevice->udev), sizeof(attr));
- strlcat(attr, udevice->dev->devpath, sizeof(attr));
- strlcat(attr, "/", sizeof(attr));
- strlcat(attr, key_name, sizeof(attr));
+ util_strlcpy(attr, udev_get_sys_path(udevice->udev), sizeof(attr));
+ util_strlcat(attr, udevice->dev->devpath, sizeof(attr));
+ util_strlcat(attr, "/", sizeof(attr));
+ util_strlcat(attr, key_name, sizeof(attr));
}
attr_subst_subdir(attr, sizeof(attr));
- strlcpy(value, key_val(rule, &pair->key), sizeof(value));
+ util_strlcpy(value, key_val(rule, &pair->key), sizeof(value));
udev_rules_apply_format(udevice, value, sizeof(value));
info(udevice->udev, "writing '%s' to sysfs file '%s'\n", value, attr);
f = fopen(attr, "w");
int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice)
{
+ struct udev_rules_iter iter;
struct udev_rule *rule;
int name_set = 0;
dbg(udevice->udev, "udevice->dev->kernel='%s'\n", udevice->dev->kernel);
/* look for a matching rule to apply */
- udev_rules_iter_init(rules);
+ udev_rules_iter_init(&iter, rules);
while (1) {
- rule = udev_rules_iter_next(rules);
+ rule = udev_rules_iter_next(&iter);
if (rule == NULL)
break;
if (rule->mode.operation == KEY_OP_ASSIGN_FINAL)
udevice->mode_final = 1;
char buf[20];
- strlcpy(buf, key_val(rule, &rule->mode), sizeof(buf));
+ util_strlcpy(buf, key_val(rule, &rule->mode), sizeof(buf));
udev_rules_apply_format(udevice, buf, sizeof(buf));
udevice->mode = strtol(buf, NULL, 8);
dbg(udevice->udev, "applied mode=%#o to '%s'\n", udevice->mode, udevice->dev->kernel);
if (!udevice->owner_final && rule->owner.operation != KEY_OP_UNSET) {
if (rule->owner.operation == KEY_OP_ASSIGN_FINAL)
udevice->owner_final = 1;
- strlcpy(udevice->owner, key_val(rule, &rule->owner), sizeof(udevice->owner));
+ util_strlcpy(udevice->owner, key_val(rule, &rule->owner), sizeof(udevice->owner));
udev_rules_apply_format(udevice, udevice->owner, sizeof(udevice->owner));
dbg(udevice->udev, "applied owner='%s' to '%s'\n", udevice->owner, udevice->dev->kernel);
}
if (!udevice->group_final && rule->group.operation != KEY_OP_UNSET) {
if (rule->group.operation == KEY_OP_ASSIGN_FINAL)
udevice->group_final = 1;
- strlcpy(udevice->group, key_val(rule, &rule->group), sizeof(udevice->group));
+ util_strlcpy(udevice->group, key_val(rule, &rule->group), sizeof(udevice->group));
udev_rules_apply_format(udevice, udevice->group, sizeof(udevice->group));
dbg(udevice->udev, "applied group='%s' to '%s'\n", udevice->group, udevice->dev->kernel);
}
(rule->symlink.operation == KEY_OP_ASSIGN ||
rule->symlink.operation == KEY_OP_ASSIGN_FINAL ||
rule->symlink.operation == KEY_OP_ADD)) {
- char temp[PATH_SIZE];
+ char temp[UTIL_PATH_SIZE];
char *pos, *next;
int count;
name_list_cleanup(udevice->udev, &udevice->symlink_list);
}
/* allow multiple symlinks separated by spaces */
- strlcpy(temp, key_val(rule, &rule->symlink), sizeof(temp));
+ util_strlcpy(temp, key_val(rule, &rule->symlink), sizeof(temp));
udev_rules_apply_format(udevice, temp, sizeof(temp));
if (rule->string_escape == ESCAPE_UNSET ||
rule->string_escape == ESCAPE_REPLACE) {
- count = replace_chars(temp, ALLOWED_CHARS_FILE " ");
+ count = util_replace_chars(temp, ALLOWED_CHARS_FILE " ");
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n" , count);
}
int count;
name_set = 1;
- strlcpy(udevice->name, key_val(rule, &rule->name), sizeof(udevice->name));
+ util_strlcpy(udevice->name, key_val(rule, &rule->name), sizeof(udevice->name));
udev_rules_apply_format(udevice, udevice->name, sizeof(udevice->name));
if (rule->string_escape == ESCAPE_UNSET ||
rule->string_escape == ESCAPE_REPLACE) {
- count = replace_chars(udevice->name, ALLOWED_CHARS_FILE);
+ count = util_replace_chars(udevice->name, ALLOWED_CHARS_FILE);
if (count > 0)
info(udevice->udev, "%i character(s) replaced\n", count);
}
if (rule->goto_label.operation != KEY_OP_UNSET) {
dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
- udev_rules_iter_label(rules, key_val(rule, &rule->goto_label));
+ udev_rules_iter_label(&iter, key_val(rule, &rule->goto_label));
}
}
}
if (!name_set) {
info(udevice->udev, "no node name set, will use kernel name '%s'\n", udevice->dev->kernel);
- strlcpy(udevice->name, udevice->dev->kernel, sizeof(udevice->name));
+ util_strlcpy(udevice->name, udevice->dev->kernel, sizeof(udevice->name));
}
if (udevice->tmp_node[0] != '\0') {
int udev_rules_get_run(struct udev_rules *rules, struct udevice *udevice)
{
+ struct udev_rules_iter iter;
struct udev_rule *rule;
dbg(udevice->udev, "udevice->kernel='%s'\n", udevice->dev->kernel);
/* look for a matching rule to apply */
- udev_rules_iter_init(rules);
+ udev_rules_iter_init(&iter, rules);
while (1) {
- rule = udev_rules_iter_next(rules);
+ rule = udev_rules_iter_next(&iter);
if (rule == NULL)
break;
if (rule->goto_label.operation != KEY_OP_UNSET) {
dbg(udevice->udev, "moving forward to label '%s'\n", key_val(rule, &rule->goto_label));
- udev_rules_iter_label(rules, key_val(rule, &rule->goto_label));
+ udev_rules_iter_label(&iter, key_val(rule, &rule->goto_label));
}
}
}