X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=udev%2Fudev_rules.c;h=d06f536d1e0e24aa518ffe656d5d23289cacca4e;hp=3b9631b883c67e98b07676dc3575f54d42dae2b8;hb=ee173c5927649e8f2e6f42046315e84eb8e55e1b;hpb=9d7e1b3fdd3c2bd064f33a29ea5241fdefb718ee diff --git a/udev/udev_rules.c b/udev/udev_rules.c index 3b9631b88..d06f536d1 100644 --- a/udev/udev_rules.c +++ b/udev/udev_rules.c @@ -1,20 +1,19 @@ /* * Copyright (C) 2003 Greg Kroah-Hartman - * Copyright (C) 2003-2006 Kay Sievers + * Copyright (C) 2003-2008 Kay Sievers * - * 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 . */ #include @@ -35,7 +34,6 @@ #include "udev.h" #include "udev_rules.h" -#include "udev_selinux.h" extern char **environ; @@ -125,15 +123,15 @@ static int run_program(struct udev *udev, const char *command, const char *subsy 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; @@ -161,21 +159,21 @@ static int run_program(struct udev *udev, const char *command, const char *subsy /* prepare pipes from child to parent */ if (result != NULL || udev_get_log_priority(udev) >= LOG_INFO) { if (pipe(outpipe) != 0) { - err(udev, "pipe failed: %s\n", strerror(errno)); + err(udev, "pipe failed: %m\n"); return -1; } } if (udev_get_log_priority(udev) >= LOG_INFO) { if (pipe(errpipe) != 0) { - err(udev, "pipe failed: %s\n", strerror(errno)); + err(udev, "pipe failed: %m\n"); return -1; } } /* 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; } @@ -198,7 +196,7 @@ static int run_program(struct udev *udev, const char *command, const char *subsy dup2(devnull, STDERR_FILENO); close(devnull); } else - err(udev, "open /dev/null failed: %s\n", strerror(errno)); + err(udev, "open /dev/null failed: %m\n"); if (outpipe[WRITE_END] > 0) { dup2(outpipe[WRITE_END], STDOUT_FILENO); close(outpipe[WRITE_END]); @@ -217,7 +215,7 @@ static int run_program(struct udev *udev, const char *command, const char *subsy } _exit(1); case -1: - err(udev, "fork of '%s' failed: %s\n", argv[0], strerror(errno)); + err(udev, "fork of '%s' failed: %m\n", argv[0]); return -1; default: /* read from child if requested */ @@ -260,7 +258,7 @@ static int run_program(struct udev *udev, const char *command, const char *subsy close(outpipe[READ_END]); outpipe[READ_END] = -1; if (count < 0) { - err(udev, "stdin read failed: %s\n", strerror(errno)); + err(udev, "stdin read failed: %m\n"); retval = -1; } continue; @@ -294,7 +292,7 @@ static int run_program(struct udev *udev, const char *command, const char *subsy close(errpipe[READ_END]); errpipe[READ_END] = -1; if (count < 0) - err(udev, "stderr read failed: %s\n", strerror(errno)); + err(udev, "stderr read failed: %m\n"); continue; } errbuf[count] = '\0'; @@ -333,7 +331,7 @@ static int run_program(struct udev *udev, const char *command, const char *subsy 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; @@ -360,7 +358,7 @@ static int import_keys_into_env(struct udevice *udevice, const char *buf, size_t continue; /* see if this is a comment */ - if (bufline[0] == COMMENT_CHARACTER) + if (bufline[0] == '#') continue; if (count >= sizeof(line)) { @@ -394,7 +392,7 @@ static int import_file_into_env(struct udevice *udevice, const char *filename) size_t bufsize; if (file_map(filename, &buf, &bufsize) != 0) { - err(udevice->udev, "can't open '%s': %s\n", filename, strerror(errno)); + err(udevice->udev, "can't open '%s': %m\n", filename); return -1; } import_keys_into_env(udevice, buf, bufsize); @@ -431,10 +429,10 @@ static int import_parent_into_env(struct udevice *udevice, const char *filter) 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'; @@ -474,22 +472,22 @@ static int pass_env_to_socket(struct udev *udev, const char *sockpath, const cha 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), "%s@%s", action, devpath); bufpos++; for (i = 0; environ[i] != NULL && bufpos < (sizeof(buf)); i++) { - bufpos += strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos); + bufpos += util_strlcpy(&buf[bufpos], environ[i], sizeof(buf) - bufpos); bufpos++; } if (bufpos > sizeof(buf)) @@ -514,9 +512,9 @@ int udev_rules_run(struct udevice *udevice) 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) @@ -530,19 +528,19 @@ int udev_rules_run(struct udevice *udevice) #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; } @@ -568,7 +566,7 @@ static int wait_for_file(struct udevice *udevice, const char *file, int timeout) /* handle "[$SUBSYSTEM/$KERNEL]" 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; @@ -582,7 +580,7 @@ static int attr_get_by_subsys_id(struct udev *udev, const char *attrstr, char *d 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; @@ -612,11 +610,11 @@ static int attr_subst_subdir(char *attr, size_t len) 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; @@ -626,8 +624,8 @@ static int attr_subst_subdir(char *attr, size_t len) 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; @@ -637,7 +635,7 @@ static int attr_subst_subdir(char *attr, size_t len) closedir(dir); } if (!found) - strlcat(attr, str, len); + util_strlcat(attr, str, len); } return found; @@ -645,8 +643,8 @@ static int attr_subst_subdir(char *attr, size_t len) 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; @@ -706,8 +704,8 @@ void udev_rules_apply_format(struct udevice *udevice, char *string, size_t maxsi 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; } @@ -727,8 +725,8 @@ void udev_rules_apply_format(struct udevice *udevice, char *string, size_t maxsi 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; } @@ -751,42 +749,42 @@ void udev_rules_apply_format(struct udevice *udevice, char *string, size_t maxsi 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: @@ -809,17 +807,17 @@ found: 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; @@ -827,7 +825,7 @@ found: 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; @@ -860,15 +858,15 @@ found: 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; @@ -885,7 +883,7 @@ found: 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"); @@ -902,37 +900,37 @@ found: 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: @@ -946,7 +944,7 @@ found: 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); @@ -957,7 +955,7 @@ found: 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); } } @@ -973,7 +971,7 @@ static char *key_pair_name(struct udev_rule *rule, struct key_pair *pair) 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; @@ -983,7 +981,7 @@ static int match_key(struct udev *udev, const char *key_name, struct udev_rule * 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) { @@ -1072,30 +1070,30 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) 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)); @@ -1116,10 +1114,10 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) } 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)) @@ -1134,10 +1132,10 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) 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)) { @@ -1150,7 +1148,7 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) 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); @@ -1190,7 +1188,7 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) 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); @@ -1198,7 +1196,7 @@ static int match_rule(struct udevice *udevice, struct udev_rule *rule) 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); @@ -1228,10 +1226,10 @@ try_parent: /* 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"); @@ -1242,15 +1240,15 @@ try_parent: 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; @@ -1264,10 +1262,10 @@ try_parent: /* 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) { @@ -1293,13 +1291,13 @@ try_parent: 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); @@ -1323,41 +1321,41 @@ try_parent: 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"); if (f != NULL) { if (!udevice->test_run) if (fprintf(f, "%s", value) <= 0) - err(udevice->udev, "error writing ATTR{%s}: %s\n", attr, strerror(errno)); + err(udevice->udev, "error writing ATTR{%s}: %m\n", attr); fclose(f); } else - err(udevice->udev, "error opening ATTR{%s} for writing: %s\n", attr, strerror(errno)); + err(udevice->udev, "error opening ATTR{%s} for writing: %m\n", attr); } } return 0; @@ -1422,7 +1420,7 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) 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); @@ -1430,14 +1428,14 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) 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); } @@ -1447,9 +1445,9 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) (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; + int count = 0; if (rule->symlink.operation == KEY_OP_ASSIGN_FINAL) udevice->symlink_final = 1; @@ -1459,14 +1457,14 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) 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 " "); - if (count > 0) - info(udevice->udev, "%i character(s) replaced\n" , count); - } + if (rule->string_escape == ESCAPE_UNSET) + count = util_replace_chars(temp, ALLOWED_CHARS_FILE " "); + else if (rule->string_escape == ESCAPE_REPLACE) + count = util_replace_chars(temp, ALLOWED_CHARS_FILE); + if (count > 0) + info(udevice->udev, "%i character(s) replaced\n" , count); dbg(udevice->udev, "rule applied, added symlink(s) '%s'\n", temp); pos = temp; while (isspace(pos[0])) @@ -1494,11 +1492,11 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) 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); } @@ -1531,14 +1529,14 @@ int udev_rules_get_name(struct udev_rules *rules, struct udevice *udevice) 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(&iter, key_val(rule, &rule->goto_label)); + udev_rules_iter_goto(&iter, rule->goto_rule_off); } } } 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') { @@ -1611,7 +1609,7 @@ int udev_rules_get_run(struct udev_rules *rules, struct udevice *udevice) 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(&iter, key_val(rule, &rule->goto_label)); + udev_rules_iter_goto(&iter, rule->goto_rule_off); } } }