1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-11 09:18:07 +03:00

allow final assignment for OPTIONS:="nowatch"

A final assignemnt operator will disable any device watching by
inotify, and any possible later rules setting "watch" again will
be ignored.
This commit is contained in:
Kay Sievers 2010-07-07 11:35:40 +02:00
parent 847b4f84c6
commit 3b529da425
3 changed files with 19 additions and 8 deletions

View File

@ -1569,42 +1569,42 @@ static int add_rule(struct udev_rules *rules, char *line,
if (pos != NULL) { if (pos != NULL) {
int prio = atoi(&pos[strlen("link_priority=")]); int prio = atoi(&pos[strlen("link_priority=")]);
rule_add_key(&rule_tmp, TK_A_DEVLINK_PRIO, 0, NULL, &prio); rule_add_key(&rule_tmp, TK_A_DEVLINK_PRIO, op, NULL, &prio);
dbg(rules->udev, "link priority=%i\n", prio); dbg(rules->udev, "link priority=%i\n", prio);
} }
pos = strstr(value, "event_timeout="); pos = strstr(value, "event_timeout=");
if (pos != NULL) { if (pos != NULL) {
int tout = atoi(&pos[strlen("event_timeout=")]); int tout = atoi(&pos[strlen("event_timeout=")]);
rule_add_key(&rule_tmp, TK_A_EVENT_TIMEOUT, 0, NULL, &tout); rule_add_key(&rule_tmp, TK_A_EVENT_TIMEOUT, op, NULL, &tout);
dbg(rules->udev, "event timeout=%i\n", tout); dbg(rules->udev, "event timeout=%i\n", tout);
} }
pos = strstr(value, "string_escape="); pos = strstr(value, "string_escape=");
if (pos != NULL) { if (pos != NULL) {
pos = &pos[strlen("string_escape=")]; pos = &pos[strlen("string_escape=")];
if (strncmp(pos, "none", strlen("none")) == 0) if (strncmp(pos, "none", strlen("none")) == 0)
rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_NONE, 0, NULL, NULL); rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_NONE, op, NULL, NULL);
else if (strncmp(pos, "replace", strlen("replace")) == 0) else if (strncmp(pos, "replace", strlen("replace")) == 0)
rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_REPLACE, 0, NULL, NULL); rule_add_key(&rule_tmp, TK_A_STRING_ESCAPE_REPLACE, op, NULL, NULL);
} }
pos = strstr(value, "nowatch"); pos = strstr(value, "nowatch");
if (pos != NULL) { if (pos != NULL) {
const int off = 0; const int off = 0;
rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, 0, NULL, &off); rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, op, NULL, &off);
dbg(rules->udev, "inotify watch of device disabled\n"); dbg(rules->udev, "inotify watch of device disabled\n");
} else { } else {
pos = strstr(value, "watch"); pos = strstr(value, "watch");
if (pos != NULL) { if (pos != NULL) {
const int on = 1; const int on = 1;
rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, 0, NULL, &on); rule_add_key(&rule_tmp, TK_A_INOTIFY_WATCH, op, NULL, &on);
dbg(rules->udev, "inotify watch of device requested\n"); dbg(rules->udev, "inotify watch of device requested\n");
} }
} }
pos = strstr(value, "static_node="); pos = strstr(value, "static_node=");
if (pos != NULL) { if (pos != NULL) {
rule_add_key(&rule_tmp, TK_A_STATIC_NODE, 0, &pos[strlen("static_node=")], NULL); rule_add_key(&rule_tmp, TK_A_STATIC_NODE, op, &pos[strlen("static_node=")], NULL);
rule_tmp.rule.rule.has_static_node = true; rule_tmp.rule.rule.has_static_node = true;
} }
continue; continue;
@ -2400,6 +2400,10 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
esc = ESCAPE_REPLACE; esc = ESCAPE_REPLACE;
break; break;
case TK_A_INOTIFY_WATCH: case TK_A_INOTIFY_WATCH:
if (event->inotify_watch_final)
break;
if (cur->key.op == OP_ASSIGN_FINAL)
event->inotify_watch_final = true;
event->inotify_watch = cur->key.watch; event->inotify_watch = cur->key.watch;
break; break;
case TK_A_DEVLINK_PRIO: case TK_A_DEVLINK_PRIO:

View File

@ -44,13 +44,14 @@ struct udev_event {
gid_t gid; gid_t gid;
struct udev_list_node run_list; struct udev_list_node run_list;
int exec_delay; int exec_delay;
bool inotify_watch;
bool inotify_watch_final;
bool group_final; bool group_final;
bool owner_final; bool owner_final;
bool mode_final; bool mode_final;
bool name_final; bool name_final;
bool devlink_final; bool devlink_final;
bool run_final; bool run_final;
bool inotify_watch;
}; };
struct udev_watch { struct udev_watch {

View File

@ -513,6 +513,12 @@
writing, a change uevent will be synthesised.</para> writing, a change uevent will be synthesised.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>nowatch</option></term>
<listitem>
<para>Disable the watching of a device node with inotify.</para>
</listitem>
</varlistentry>
</variablelist> </variablelist>
</listitem> </listitem>
</varlistentry> </varlistentry>