#include <unistd.h>
#include <errno.h>
#include <syslog.h>
+#include <dirent.h>
#include <fnmatch.h>
#include <sys/socket.h>
#include <sys/un.h>
cur += count+1;
lineno++;
- if (count >= sizeof(line)) {
- err("line too long, conf line skipped %s, line %d", udev_config_filename, lineno);
- continue;
- }
-
/* eat the whitespace */
while ((count > 0) && isspace(bufline[0])) {
bufline++;
if (bufline[0] == COMMENT_CHARACTER)
continue;
+ if (count >= sizeof(line)) {
+ err("line too long, conf line skipped %s, line %d", udev_config_filename, lineno);
+ continue;
+ }
+
memcpy(line, bufline, count);
line[count] = '\0';
return found;
}
+static int attr_subst_subdir(char *attr, size_t len)
+{
+ char *pos;
+ int found = 0;
+
+ pos = strstr(attr, "/*/");
+ if (pos != NULL) {
+ char str[PATH_SIZE];
+ DIR *dir;
+
+ pos[1] = '\0';
+ strlcpy(str, &pos[2], sizeof(str));
+ dir = opendir(attr);
+ if (dir != NULL) {
+ struct dirent *dent;
+
+ for (dent = readdir(dir); dent != NULL; dent = readdir(dir)) {
+ struct stat stats;
+
+ if (dent->d_name[0] == '.')
+ continue;
+ strlcat(attr, dent->d_name, len);
+ strlcat(attr, str, len);
+ if (stat(attr, &stats) == 0) {
+ found = 1;
+ break;
+ }
+ pos[1] = '\0';
+ }
+ closedir(dir);
+ }
+ if (!found)
+ strlcat(attr, str, len);
+ }
+
+ return found;
+}
+
void udev_rules_apply_format(struct udevice *udev, char *string, size_t maxsize)
{
char temp[PATH_SIZE];
strlcpy(filename, tmp, sizeof(filename));
}
+ attr_subst_subdir(filename, sizeof(filename));
+
match = (stat(filename, &statbuf) == 0);
info("'%s' %s", filename, match ? "exists" : "does not exist");
if (match && rule->test_mode_mask > 0) {
if (rule->wait_for_sysfs.operation != KEY_OP_UNSET) {
int found;
- found = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 3) == 0);
+ found = (wait_for_sysfs(udev, key_val(rule, &rule->wait_for_sysfs), 10) == 0);
if (!found && (rule->wait_for_sysfs.operation != KEY_OP_NOMATCH))
goto nomatch;
}
strlcat(attr, key_name, sizeof(attr));
}
+ attr_subst_subdir(attr, sizeof(attr));
+
strlcpy(value, key_val(rule, &pair->key), sizeof(value));
udev_rules_apply_format(udev, value, sizeof(value));
info("writing '%s' to sysfs file '%s'", value, attr);
}
if (!name_set) {
- info("no node name set, will use kernel name '%s'", udev->name);
+ info("no node name set, will use kernel name '%s'", udev->dev->kernel);
strlcpy(udev->name, udev->dev->kernel, sizeof(udev->name));
}