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.
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);
</listitem>
</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>
/* 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;
}
}
+ 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;
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;
}
}
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);
}
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;
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;