summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-06-03 00:01:46 +0200
committerKay Sievers <kay.sievers@vrfy.org>2007-06-03 00:01:46 +0200
commit953249a3a01cbd442b42558168da6c76a92a0e40 (patch)
tree1b7c3d8c91da6cc04eec719badc9d099d2c3fa9e
parent5e9eb88f2f6d99eaee16aeeb76ac08a1bf98a668 (diff)
add TEST=="<file>" key
-rw-r--r--udev.75
-rw-r--r--udev.h1
-rw-r--r--udev.xml8
-rw-r--r--udev_node.c2
-rw-r--r--udev_rules.c29
-rw-r--r--udev_rules.h2
-rw-r--r--udev_rules_parse.c9
7 files changed, 53 insertions, 3 deletions
diff --git a/udev.7 b/udev.7
index 4fbaf92432..a253581581 100644
--- a/udev.7
+++ b/udev.7
@@ -151,6 +151,11 @@ Match against the value of an environment variable. Up to five
keys can be specified per rule. Depending on the type of operator, this key is also used to export a variable to the environment.
.RE
.PP
+\fBTEST{\fR\fB\fIoctal mode mask\fR\fR\fB}\fR
+.RS 4
+Test the existence of a file. An octal mode mask can be specified if needed.
+.RE
+.PP
\fBPROGRAM\fR
.RS 4
Execute external program. The key is true, if the program returns with exit code zero. The whole event environment is available to the executed program. The program's output printed to stdout, is available in the RESULT key.
diff --git a/udev.h b/udev.h
index 94d054f760..64510ed35f 100644
--- a/udev.h
+++ b/udev.h
@@ -119,6 +119,7 @@ extern struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev);
extern struct sysfs_device *sysfs_device_get_parent_with_subsystem(struct sysfs_device *dev, const char *subsystem);
extern char *sysfs_attr_get_value(const char *devpath, const char *attr_name);
extern int sysfs_resolve_link(char *path, size_t size);
+extern int sysfs_lookup_devpath_by_subsys_id(char *devpath, size_t len, const char *subsystem, const char *id);
/* udev_node.c */
extern int udev_node_mknod(struct udevice *udev, const char *file, dev_t devt, mode_t mode, uid_t uid, gid_t gid);
diff --git a/udev.xml b/udev.xml
index 1f9e6d9197..a3658bd548 100644
--- a/udev.xml
+++ b/udev.xml
@@ -225,6 +225,14 @@
</varlistentry>
<varlistentry>
+ <term><option>TEST{<replaceable>octal mode mask</replaceable>}</option></term>
+ <listitem>
+ <para>Test the existence of a file. An octal mode mask can be specified
+ if needed.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><option>PROGRAM</option></term>
<listitem>
<para>Execute external program. The key is true, if the program returns
diff --git a/udev_node.c b/udev_node.c
index b1bbda8369..338948fc54 100644
--- a/udev_node.c
+++ b/udev_node.c
@@ -322,7 +322,7 @@ int udev_node_add(struct udevice *udev)
/* take the maximum registered minor range */
attr = sysfs_attr_get_value(udev->dev->devpath, "range");
- if (attr) {
+ if (attr != NULL) {
range = atoi(attr);
if (range > 1)
udev->partitions = range-1;
diff --git a/udev_rules.c b/udev_rules.c
index e61c9a69b0..5ded26d049 100644
--- a/udev_rules.c
+++ b/udev_rules.c
@@ -641,6 +641,29 @@ static int match_rule(struct udevice *udev, struct udev_rule *rule)
}
}
+ if (rule->test.operation != KEY_OP_UNSET) {
+ char filename[PATH_SIZE];
+ struct stat statbuf;
+ int match;
+
+ strlcpy(filename, key_val(rule, &rule->test), sizeof(filename));
+ udev_rules_apply_format(udev, filename, sizeof(filename));
+
+ match = (stat(filename, &statbuf) == 0);
+ info("'%s' %s", filename, match ? "exists" : "does not exist");
+ if (match && rule->test_mode_mask > 0) {
+ match = ((statbuf.st_mode & rule->test_mode_mask) > 0);
+ info("'%s' has mode=%#o and %s %#o", filename, statbuf.st_mode,
+ match ? "matches" : "does not match",
+ rule->test_mode_mask);
+ }
+ if (match && rule->test.operation == KEY_OP_NOMATCH)
+ goto nomatch;
+ if (!match && rule->test.operation == KEY_OP_MATCH)
+ goto nomatch;
+ dbg("TEST key is true");
+ }
+
if (rule->wait_for_sysfs.operation != KEY_OP_UNSET) {
int found;
@@ -1037,7 +1060,8 @@ int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev)
dbg("process rule");
if (rule->name.operation != KEY_OP_UNSET || rule->symlink.operation != KEY_OP_UNSET ||
- rule->mode_operation != KEY_OP_UNSET || rule->owner.operation != KEY_OP_UNSET || rule->group.operation != KEY_OP_UNSET) {
+ rule->mode_operation != KEY_OP_UNSET || rule->owner.operation != KEY_OP_UNSET ||
+ rule->group.operation != KEY_OP_UNSET) {
dbg("skip rule that names a device");
continue;
}
@@ -1050,7 +1074,8 @@ int udev_rules_get_run(struct udev_rules *rules, struct udevice *udev)
}
if (!udev->run_final && rule->run.operation != KEY_OP_UNSET) {
- if (rule->run.operation == KEY_OP_ASSIGN || rule->run.operation == KEY_OP_ASSIGN_FINAL) {
+ if (rule->run.operation == KEY_OP_ASSIGN ||
+ rule->run.operation == KEY_OP_ASSIGN_FINAL) {
info("reset run list");
name_list_cleanup(&udev->run_list);
}
diff --git a/udev_rules.h b/udev_rules.h
index 7fbf88ba57..0e1ff76b42 100644
--- a/udev_rules.h
+++ b/udev_rules.h
@@ -75,6 +75,8 @@ struct udev_rule {
struct key result;
struct key import;
enum import_type import_type;
+ struct key test;
+ mode_t test_mode_mask;
struct key run;
struct key wait_for_sysfs;
struct key label;
diff --git a/udev_rules_parse.c b/udev_rules_parse.c
index 9166980488..4420616903 100644
--- a/udev_rules_parse.c
+++ b/udev_rules_parse.c
@@ -470,6 +470,15 @@ static int add_to_rules(struct udev_rules *rules, char *line, const char *filena
continue;
}
+ if (strncasecmp(key, "TEST", sizeof("TEST")-1) == 0) {
+ attr = get_key_attribute(key + sizeof("TEST")-1);
+ if (attr != NULL)
+ rule->test_mode_mask = strtol(attr, NULL, 8);
+ add_rule_key(rule, &rule->test, operation, value);
+ valid = 1;
+ continue;
+ }
+
if (strcasecmp(key, "RUN") == 0) {
add_rule_key(rule, &rule->run, operation, value);
valid = 1;