mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-27 13:57:26 +03:00
add TEST=="<file>" key
This commit is contained in:
parent
5e9eb88f2f
commit
953249a3a0
5
udev.7
5
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.
|
||||
|
1
udev.h
1
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);
|
||||
|
8
udev.xml
8
udev.xml
@ -224,6 +224,14 @@
|
||||
</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>
|
||||
|
@ -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;
|
||||
|
29
udev_rules.c
29
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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user