2 * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #define PREALLOC_TOKEN 2048
32 #define PREALLOC_STRBUF 32 * 1024
35 unsigned int name_off
;
42 /* KEY=="", KEY!="", KEY+="", KEY="", KEY:="" */
47 /* every key in the rules file becomes a token */
49 unsigned int token_cur
;
50 unsigned int token_max
;
52 /* all key strings are copied to a single string buffer */
56 unsigned int buf_count
;
58 /* during rule parsing, we cache uid/gid lookup results */
60 unsigned int uids_cur
;
61 unsigned int uids_max
;
63 unsigned int gids_cur
;
64 unsigned int gids_max
;
79 enum string_glob_type
{
81 GL_PLAIN
, /* no special chars */
82 GL_GLOB
, /* shell globs ?,*,[] */
83 GL_SPLIT
, /* multi-value A|B */
84 GL_SPLIT_GLOB
, /* multi-value with glob A*|B* */
85 GL_SOMETHING
, /* commonly used "?*" */
89 /* tokens of a rule are sorted/handled in this order */
94 TK_M_ACTION
, /* val */
95 TK_M_DEVPATH
, /* val */
96 TK_M_KERNEL
, /* val */
97 TK_M_DEVLINK
, /* val */
99 TK_M_ENV
, /* val, attr */
100 TK_M_SUBSYSTEM
, /* val */
101 TK_M_DRIVER
, /* val */
102 TK_M_WAITFOR
, /* val */
103 TK_M_ATTR
, /* val, attr */
106 TK_M_KERNELS
, /* val */
107 TK_M_SUBSYSTEMS
, /* val */
108 TK_M_DRIVERS
, /* val */
109 TK_M_ATTRS
, /* val, attr */
112 TK_M_TEST
, /* val, mode_t */
113 TK_M_PROGRAM
, /* val */
114 TK_M_IMPORT_FILE
, /* val */
115 TK_M_IMPORT_PROG
, /* val */
116 TK_M_IMPORT_PARENT
, /* val */
117 TK_M_RESULT
, /* val */
121 TK_A_STRING_ESCAPE_NONE
,
122 TK_A_STRING_ESCAPE_REPLACE
,
123 TK_A_NUM_FAKE_PART
, /* int */
124 TK_A_DEVLINK_PRIO
, /* int */
125 TK_A_OWNER
, /* val */
126 TK_A_GROUP
, /* val */
128 TK_A_OWNER_ID
, /* uid_t */
129 TK_A_GROUP_ID
, /* gid_t */
130 TK_A_MODE_ID
, /* mode_t */
131 TK_A_ENV
, /* val, attr */
133 TK_A_DEVLINK
, /* val */
134 TK_A_EVENT_TIMEOUT
, /* int */
136 TK_A_ATTR
, /* val, attr */
137 TK_A_RUN
, /* val, bool */
138 TK_A_GOTO
, /* size_t */
144 /* we try to pack stuff in a way that we take only 16 bytes per token */
147 unsigned short type
; /* same as in rule and key */
150 unsigned short flags
;
151 unsigned int next_rule
;
152 unsigned int label_off
;
153 unsigned short filename_off
;
154 unsigned short filename_line
;
158 unsigned short flags
;
161 unsigned int value_off
;
163 unsigned int attr_off
;
166 unsigned int rule_goto
;
180 struct udev_rules
*rules
;
182 struct token token
[MAX_TK
];
183 unsigned int token_cur
;
187 static const char *operation_str
[] = {
188 [OP_UNSET
] = "UNSET",
189 [OP_MATCH
] = "match",
190 [OP_NOMATCH
] = "nomatch",
191 [OP_MATCH_MAX
] = "MATCH_MAX",
194 [OP_ASSIGN
] = "assign",
195 [OP_ASSIGN_FINAL
] = "assign-final",
198 static const char *string_glob_str
[] = {
199 [GL_UNSET
] = "UNSET",
200 [GL_PLAIN
] = "plain",
202 [GL_SPLIT
] = "split",
203 [GL_SPLIT_GLOB
] = "split-glob",
204 [GL_SOMETHING
] = "split-glob",
205 [GL_FORMAT
] = "format",
208 static const char *token_str
[] = {
209 [TK_UNSET
] = "UNSET",
212 [TK_M_ACTION
] = "M ACTION",
213 [TK_M_DEVPATH
] = "M DEVPATH",
214 [TK_M_KERNEL
] = "M KERNEL",
215 [TK_M_DEVLINK
] = "M DEVLINK",
216 [TK_M_NAME
] = "M NAME",
217 [TK_M_ENV
] = "M ENV",
218 [TK_M_SUBSYSTEM
] = "M SUBSYSTEM",
219 [TK_M_DRIVER
] = "M DRIVER",
220 [TK_M_WAITFOR
] = "M WAITFOR",
221 [TK_M_ATTR
] = "M ATTR",
223 [TK_M_PARENTS_MIN
] = "M PARENTS_MIN",
224 [TK_M_KERNELS
] = "M KERNELS",
225 [TK_M_SUBSYSTEMS
] = "M SUBSYSTEMS",
226 [TK_M_DRIVERS
] = "M DRIVERS",
227 [TK_M_ATTRS
] = "M ATTRS",
228 [TK_M_PARENTS_MAX
] = "M PARENTS_MAX",
230 [TK_M_TEST
] = "M TEST",
231 [TK_M_PROGRAM
] = "M PROGRAM",
232 [TK_M_IMPORT_FILE
] = "M IMPORT_FILE",
233 [TK_M_IMPORT_PROG
] = "M IMPORT_PROG",
234 [TK_M_IMPORT_PARENT
] = "M MPORT_PARENT",
235 [TK_M_RESULT
] = "M RESULT",
236 [TK_M_MAX
] = "M MAX",
238 [TK_A_IGNORE_DEVICE
] = "A IGNORE_DEVICE",
239 [TK_A_STRING_ESCAPE_NONE
] = "A STRING_ESCAPE_NONE",
240 [TK_A_STRING_ESCAPE_REPLACE
] = "A STRING_ESCAPE_REPLACE",
241 [TK_A_NUM_FAKE_PART
] = "A NUM_FAKE_PART",
242 [TK_A_DEVLINK_PRIO
] = "A DEVLINK_PRIO",
243 [TK_A_OWNER
] = "A OWNER",
244 [TK_A_GROUP
] = "A GROUP",
245 [TK_A_MODE
] = "A MODE",
246 [TK_A_OWNER_ID
] = "A OWNER_ID",
247 [TK_A_GROUP_ID
] = "A GROUP_ID",
248 [TK_A_MODE_ID
] = "A MODE_ID",
249 [TK_A_ENV
] = "A ENV",
250 [TK_A_NAME
] = "A NAME",
251 [TK_A_DEVLINK
] = "A DEVLINK",
252 [TK_A_EVENT_TIMEOUT
] = "A EVENT_TIMEOUT",
253 [TK_A_IGNORE_REMOVE
] = "A IGNORE_REMOVE",
254 [TK_A_ATTR
] = "A ATTR",
255 [TK_A_RUN
] = "A RUN",
256 [TK_A_GOTO
] = "A GOTO",
257 [TK_A_LAST_RULE
] = "A LAST_RULE",
262 static void dump_token(struct udev_rules
*rules
, struct token
*token
)
264 enum token_type type
= token
->type
;
265 enum operation_type op
= token
->key
.op
;
266 enum string_glob_type glob
= token
->key
.glob
;
267 const char *value
= &rules
->buf
[token
->key
.value_off
];
268 const char *attr
= &rules
->buf
[token
->key
.attr_off
];
273 const char *tks_ptr
= (char *)rules
->tokens
;
274 const char *tk_ptr
= (char *)token
;
275 unsigned int off
= tk_ptr
- tks_ptr
;
277 dbg(rules
->udev
, "* RULE %s:%u, off: %u(%u), next: %u, label: '%s', flags: 0x%02x\n",
278 &rules
->buf
[token
->rule
.filename_off
], token
->rule
.filename_line
,
279 off
/ (unsigned int) sizeof(struct token
), off
,
280 token
->rule
.next_rule
,
281 &rules
->buf
[token
->rule
.label_off
],
294 case TK_M_SUBSYSTEMS
:
297 case TK_M_IMPORT_FILE
:
298 case TK_M_IMPORT_PROG
:
299 case TK_M_IMPORT_PARENT
:
307 dbg(rules
->udev
, "%s %s '%s'(%s)\n",
308 token_str
[type
], operation_str
[op
], value
, string_glob_str
[glob
]);
315 dbg(rules
->udev
, "%s %s '%s' '%s'(%s)\n",
316 token_str
[type
], operation_str
[op
], attr
, value
, string_glob_str
[glob
]);
318 case TK_A_IGNORE_DEVICE
:
319 case TK_A_STRING_ESCAPE_NONE
:
320 case TK_A_STRING_ESCAPE_REPLACE
:
322 case TK_A_IGNORE_REMOVE
:
323 dbg(rules
->udev
, "%s\n", token_str
[type
]);
326 dbg(rules
->udev
, "%s %s '%s'(%s) %#o\n",
327 token_str
[type
], operation_str
[op
], value
, string_glob_str
[glob
], token
->key
.mode
);
329 case TK_A_NUM_FAKE_PART
:
330 dbg(rules
->udev
, "%s %u\n", token_str
[type
], token
->key
.num_fake_part
);
332 case TK_A_DEVLINK_PRIO
:
333 dbg(rules
->udev
, "%s %s %u\n", token_str
[type
], operation_str
[op
], token
->key
.devlink_prio
);
336 dbg(rules
->udev
, "%s %s %u\n", token_str
[type
], operation_str
[op
], token
->key
.uid
);
339 dbg(rules
->udev
, "%s %s %u\n", token_str
[type
], operation_str
[op
], token
->key
.gid
);
342 dbg(rules
->udev
, "%s %s %#o\n", token_str
[type
], operation_str
[op
], token
->key
.mode
);
344 case TK_A_EVENT_TIMEOUT
:
345 dbg(rules
->udev
, "%s %s %u\n", token_str
[type
], operation_str
[op
], token
->key
.event_timeout
);
348 dbg(rules
->udev
, "%s '%s' %u\n", token_str
[type
], value
, token
->key
.rule_goto
);
351 dbg(rules
->udev
, "* %s\n", token_str
[type
]);
353 case TK_M_PARENTS_MIN
:
354 case TK_M_PARENTS_MAX
:
357 dbg(rules
->udev
, "unknown type %u\n", type
);
362 static void dump_rules(struct udev_rules
*rules
)
366 dbg(rules
->udev
, "dumping %u (%zu bytes) tokens, %u (%zu bytes) strings\n",
368 rules
->token_cur
* sizeof(struct token
),
371 for(i
= 0; i
< rules
->token_cur
; i
++)
372 dump_token(rules
, &rules
->tokens
[i
]);
375 static const char **operation_str
;
376 static const char **token_str
;
377 static inline void dump_token(struct udev_rules
*rules
, struct token
*token
) {}
378 static inline void dump_rules(struct udev_rules
*rules
) {}
381 /* we could lookup and return existing strings, or tails of strings */
382 static int add_string(struct udev_rules
*rules
, const char *str
)
384 size_t len
= strlen(str
)+1;
387 /* offset 0 is always '\0' */
391 /* grow buffer if needed */
392 if (rules
->buf_cur
+ len
+1 >= rules
->buf_max
) {
396 /* double the buffer size */
397 add
= rules
->buf_max
;
401 buf
= realloc(rules
->buf
, rules
->buf_max
+ add
);
404 dbg(rules
->udev
, "extend buffer from %zu to %zu\n", rules
->buf_max
, rules
->buf_max
+ add
);
406 rules
->buf_max
+= add
;
408 off
= rules
->buf_cur
;
409 memcpy(&rules
->buf
[rules
->buf_cur
], str
, len
);
410 rules
->buf_cur
+= len
;
415 static int add_token(struct udev_rules
*rules
, struct token
*token
)
418 /* grow buffer if needed */
419 if (rules
->token_cur
+1 >= rules
->token_max
) {
420 struct token
*tokens
;
423 /* double the buffer size */
424 add
= rules
->token_max
;
428 tokens
= realloc(rules
->tokens
, (rules
->token_max
+ add
) * sizeof(struct token
));
431 dbg(rules
->udev
, "extend tokens from %u to %u\n", rules
->token_max
, rules
->token_max
+ add
);
432 rules
->tokens
= tokens
;
433 rules
->token_max
+= add
;
435 memcpy(&rules
->tokens
[rules
->token_cur
], token
, sizeof(struct token
));
440 static uid_t
add_uid(struct udev_rules
*rules
, const char *owner
)
446 /* lookup, if we know it already */
447 for (i
= 0; i
< rules
->uids_cur
; i
++) {
448 off
= rules
->uids
[i
].name_off
;
449 if (strcmp(&rules
->buf
[off
], owner
) == 0) {
450 uid
= rules
->uids
[i
].uid
;
451 dbg(rules
->udev
, "return existing %u for '%s'\n", uid
, owner
);
455 uid
= util_lookup_user(rules
->udev
, owner
);
457 /* grow buffer if needed */
458 if (rules
->uids_cur
+1 >= rules
->uids_max
) {
459 struct uid_gid
*uids
;
462 /* double the buffer size */
463 add
= rules
->uids_max
;
467 uids
= realloc(rules
->uids
, (rules
->uids_max
+ add
) * sizeof(struct uid_gid
));
470 dbg(rules
->udev
, "extend uids from %u to %u\n", rules
->uids_max
, rules
->uids_max
+ add
);
472 rules
->uids_max
+= add
;
474 rules
->uids
[rules
->uids_cur
].uid
= uid
;
475 off
= add_string(rules
, owner
);
478 rules
->uids
[rules
->uids_cur
].name_off
= off
;
483 static gid_t
add_gid(struct udev_rules
*rules
, const char *group
)
489 /* lookup, if we know it already */
490 for (i
= 0; i
< rules
->gids_cur
; i
++) {
491 off
= rules
->gids
[i
].name_off
;
492 if (strcmp(&rules
->buf
[off
], group
) == 0) {
493 gid
= rules
->gids
[i
].gid
;
494 dbg(rules
->udev
, "return existing %u for '%s'\n", gid
, group
);
498 gid
= util_lookup_group(rules
->udev
, group
);
500 /* grow buffer if needed */
501 if (rules
->gids_cur
+1 >= rules
->gids_max
) {
502 struct uid_gid
*gids
;
505 /* double the buffer size */
506 add
= rules
->gids_max
;
510 gids
= realloc(rules
->gids
, (rules
->gids_max
+ add
) * sizeof(struct uid_gid
));
513 dbg(rules
->udev
, "extend gids from %u to %u\n", rules
->gids_max
, rules
->gids_max
+ add
);
515 rules
->gids_max
+= add
;
517 rules
->gids
[rules
->gids_cur
].gid
= gid
;
518 off
= add_string(rules
, group
);
521 rules
->gids
[rules
->gids_cur
].name_off
= off
;
526 static int import_property_from_string(struct udev_device
*dev
, char *line
)
528 struct udev
*udev
= udev_device_get_udev(dev
);
535 while (isspace(key
[0]))
538 /* comment or empty line */
539 if (key
[0] == '#' || key
[0] == '\0')
542 /* split key/value */
543 val
= strchr(key
, '=');
550 while (isspace(val
[0]))
557 while (isspace(key
[len
-1]))
561 /* terminate value */
565 while (isspace(val
[len
-1]))
573 if (val
[0] == '"' || val
[0] == '\'') {
574 if (val
[len
-1] != val
[0]) {
575 info(udev
, "inconsistent quoting: '%s', skip\n", line
);
582 dbg(udev
, "adding '%s'='%s'\n", key
, val
);
584 /* handle device, renamed by external tool, returning new path */
585 if (strcmp(key
, "DEVPATH") == 0) {
586 char syspath
[UTIL_PATH_SIZE
];
588 info(udev
, "updating devpath from '%s' to '%s'\n",
589 udev_device_get_devpath(dev
), val
);
590 util_strlcpy(syspath
, udev_get_sys_path(udev
), sizeof(syspath
));
591 util_strlcat(syspath
, val
, sizeof(syspath
));
592 udev_device_set_syspath(dev
, syspath
);
594 struct udev_list_entry
*entry
;
596 entry
= udev_device_add_property(dev
, key
, val
);
598 udev_list_entry_set_flag(entry
, 1);
603 static int import_file_into_properties(struct udev_device
*dev
, const char *filename
)
606 char line
[UTIL_LINE_SIZE
];
608 f
= fopen(filename
, "r");
611 while (fgets(line
, sizeof(line
), f
) != NULL
)
612 import_property_from_string(dev
, line
);
617 static int import_program_into_properties(struct udev_device
*dev
, const char *program
)
619 struct udev
*udev
= udev_device_get_udev(dev
);
625 envp
= udev_device_get_properties_envp(dev
);
626 if (util_run_program(udev
, program
, envp
, result
, sizeof(result
), &reslen
) != 0)
630 while (line
!= NULL
) {
633 pos
= strchr(line
, '\n');
638 import_property_from_string(dev
, line
);
644 static int import_parent_into_properties(struct udev_device
*dev
, const char *filter
)
646 struct udev
*udev
= udev_device_get_udev(dev
);
647 struct udev_device
*dev_parent
;
648 struct udev_list_entry
*list_entry
;
650 dev_parent
= udev_device_get_parent(dev
);
651 if (dev_parent
== NULL
)
654 dbg(udev
, "found parent '%s', get the node name\n", udev_device_get_syspath(dev_parent
));
655 udev_list_entry_foreach(list_entry
, udev_device_get_properties_list_entry(dev_parent
)) {
656 const char *key
= udev_list_entry_get_name(list_entry
);
657 const char *val
= udev_list_entry_get_value(list_entry
);
659 if (fnmatch(filter
, key
, 0) == 0) {
660 struct udev_list_entry
*entry
;
662 dbg(udev
, "import key '%s=%s'\n", key
, val
);
663 entry
= udev_device_add_property(dev
, key
, val
);
665 udev_list_entry_set_flag(entry
, 1);
671 #define WAIT_LOOP_PER_SECOND 50
672 static int wait_for_file(struct udev_device
*dev
, const char *file
, int timeout
)
674 struct udev
*udev
= udev_device_get_udev(dev
);
675 char filepath
[UTIL_PATH_SIZE
];
676 char devicepath
[UTIL_PATH_SIZE
];
678 int loop
= timeout
* WAIT_LOOP_PER_SECOND
;
680 /* a relative path is a device attribute */
681 devicepath
[0] = '\0';
682 if (file
[0] != '/') {
683 util_strlcpy(devicepath
, udev_get_sys_path(udev
), sizeof(devicepath
));
684 util_strlcat(devicepath
, udev_device_get_devpath(dev
), sizeof(devicepath
));
686 util_strlcpy(filepath
, devicepath
, sizeof(filepath
));
687 util_strlcat(filepath
, "/", sizeof(filepath
));
688 util_strlcat(filepath
, file
, sizeof(filepath
));
692 dbg(udev
, "will wait %i sec for '%s'\n", timeout
, file
);
695 if (stat(file
, &stats
) == 0) {
696 info(udev
, "file '%s' appeared after %i loops\n", file
, (timeout
* WAIT_LOOP_PER_SECOND
) - loop
-1);
699 /* make sure, the device did not disappear in the meantime */
700 if (devicepath
[0] != '\0' && stat(devicepath
, &stats
) != 0) {
701 info(udev
, "device disappeared while waiting for '%s'\n", file
);
704 info(udev
, "wait for '%s' for %i mseconds\n", file
, 1000 / WAIT_LOOP_PER_SECOND
);
705 usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND
);
707 info(udev
, "waiting for '%s' failed\n", file
);
711 static int attr_subst_subdir(char *attr
, size_t len
)
716 pos
= strstr(attr
, "/*/");
718 char str
[UTIL_PATH_SIZE
];
722 util_strlcpy(str
, &pos
[2], sizeof(str
));
727 for (dent
= readdir(dir
); dent
!= NULL
; dent
= readdir(dir
)) {
730 if (dent
->d_name
[0] == '.')
732 util_strlcat(attr
, dent
->d_name
, len
);
733 util_strlcat(attr
, str
, len
);
734 if (stat(attr
, &stats
) == 0) {
743 util_strlcat(attr
, str
, len
);
749 static int get_key(struct udev
*udev
, char **line
, char **key
, enum operation_type
*op
, char **value
)
755 if (linepos
== NULL
&& linepos
[0] == '\0')
758 /* skip whitespace */
759 while (isspace(linepos
[0]) || linepos
[0] == ',')
763 if (linepos
[0] == '\0')
769 if (linepos
[0] == '\0')
771 if (isspace(linepos
[0]))
773 if (linepos
[0] == '=')
775 if ((linepos
[0] == '+') || (linepos
[0] == '!') || (linepos
[0] == ':'))
776 if (linepos
[1] == '=')
780 /* remember end of key */
783 /* skip whitespace after key */
784 while (isspace(linepos
[0]))
786 if (linepos
[0] == '\0')
789 /* get operation type */
790 if (linepos
[0] == '=' && linepos
[1] == '=') {
793 } else if (linepos
[0] == '!' && linepos
[1] == '=') {
796 } else if (linepos
[0] == '+' && linepos
[1] == '=') {
799 } else if (linepos
[0] == '=') {
802 } else if (linepos
[0] == ':' && linepos
[1] == '=') {
803 *op
= OP_ASSIGN_FINAL
;
811 /* skip whitespace after operator */
812 while (isspace(linepos
[0]))
814 if (linepos
[0] == '\0')
818 if (linepos
[0] == '"')
825 temp
= strchr(linepos
, '"');
830 dbg(udev
, "%s '%s'-'%s'\n", operation_str
[*op
], *key
, *value
);
832 /* move line to next key */
837 /* extract possible KEY{attr} */
838 static char *get_key_attribute(struct udev
*udev
, char *str
)
843 attr
= strchr(str
, '{');
846 pos
= strchr(attr
, '}');
848 err(udev
, "missing closing brace for format\n");
852 dbg(udev
, "attribute='%s'\n", attr
);
858 static int rule_add_key(struct rule_tmp
*rule_tmp
, enum token_type type
,
859 enum operation_type op
,
860 const char *value
, const void *data
)
862 struct token
*token
= &rule_tmp
->token
[rule_tmp
->token_cur
];
863 const char *attr
= data
;
864 enum string_glob_type glob
;
866 memset(token
, 0x00, sizeof(struct token
));
878 case TK_M_SUBSYSTEMS
:
881 case TK_M_IMPORT_FILE
:
882 case TK_M_IMPORT_PROG
:
883 case TK_M_IMPORT_PARENT
:
891 token
->key
.value_off
= add_string(rule_tmp
->rules
, value
);
898 token
->key
.value_off
= add_string(rule_tmp
->rules
, value
);
899 token
->key
.attr_off
= add_string(rule_tmp
->rules
, attr
);
902 token
->key
.value_off
= add_string(rule_tmp
->rules
, value
);
904 token
->key
.mode
= *(mode_t
*)data
;
906 case TK_A_IGNORE_DEVICE
:
907 case TK_A_STRING_ESCAPE_NONE
:
908 case TK_A_STRING_ESCAPE_REPLACE
:
909 case TK_A_IGNORE_REMOVE
:
913 token
->key
.value_off
= add_string(rule_tmp
->rules
, value
);
914 token
->key
.ignore_error
= *(int *)data
;
916 case TK_A_NUM_FAKE_PART
:
917 token
->key
.num_fake_part
= *(int *)data
;
919 case TK_A_DEVLINK_PRIO
:
920 token
->key
.devlink_prio
= *(int *)data
;
923 token
->key
.uid
= *(uid_t
*)data
;
926 token
->key
.gid
= *(gid_t
*)data
;
929 token
->key
.mode
= *(mode_t
*)data
;
931 case TK_A_EVENT_TIMEOUT
:
932 token
->key
.event_timeout
= *(int *)data
;
935 case TK_M_PARENTS_MIN
:
936 case TK_M_PARENTS_MAX
:
940 err(rule_tmp
->rules
->udev
, "wrong type %u\n", type
);
946 if (type
< TK_M_MAX
) {
947 /* check if we need to split or call fnmatch() while matching rules */
951 has_split
= (strchr(value
, '|') != NULL
);
952 has_glob
= (strchr(value
, '*') != NULL
|| strchr(value
, '?') != NULL
||
953 strchr(value
, '[') != NULL
|| strchr(value
, ']') != NULL
);
954 if (has_split
&& has_glob
) {
955 glob
= GL_SPLIT_GLOB
;
956 } else if (has_split
) {
958 } else if (has_glob
) {
959 if (strcmp(value
, "?*") == 0)
965 /* check if we need to substitute format strings for matching rules */
966 if (strchr(value
, '%') != NULL
|| strchr(value
, '$') != NULL
)
971 token
->key
.type
= type
;
973 token
->key
.glob
= glob
;
974 rule_tmp
->token_cur
++;
975 if (rule_tmp
->token_cur
>= ARRAY_SIZE(rule_tmp
->token
)) {
976 err(rule_tmp
->rules
->udev
, "temporary rule array too small\n");
982 static int sort_token(struct udev_rules
*rules
, struct rule_tmp
*rule_tmp
)
985 unsigned int start
= 0;
986 unsigned int end
= rule_tmp
->token_cur
;
988 for (i
= 0; i
< rule_tmp
->token_cur
; i
++) {
989 enum token_type next_val
= TK_UNSET
;
990 unsigned int next_idx
;
993 /* find smallest value */
994 for (j
= start
; j
< end
; j
++) {
995 if (rule_tmp
->token
[j
].type
== TK_UNSET
)
997 if (next_val
== TK_UNSET
|| rule_tmp
->token
[j
].type
< next_val
) {
998 next_val
= rule_tmp
->token
[j
].type
;
1003 /* add token and mark done */
1004 if (add_token(rules
, &rule_tmp
->token
[next_idx
]) != 0)
1006 rule_tmp
->token
[next_idx
].type
= TK_UNSET
;
1009 if (next_idx
== start
)
1011 if (next_idx
+1 == end
)
1017 static int add_rule(struct udev_rules
*rules
, char *line
,
1018 const char *filename
, unsigned int filename_off
, unsigned int lineno
)
1024 struct rule_tmp rule_tmp
;
1026 memset(&rule_tmp
, 0x00, sizeof(struct rule_tmp
));
1027 rule_tmp
.rules
= rules
;
1028 rule_tmp
.rule
.type
= TK_RULE
;
1029 rule_tmp
.rule
.rule
.filename_off
= filename_off
;
1030 rule_tmp
.rule
.rule
.filename_line
= lineno
;
1036 enum operation_type op
;
1038 if (get_key(rules
->udev
, &linepos
, &key
, &op
, &value
) != 0)
1041 if (strcasecmp(key
, "ACTION") == 0) {
1042 if (op
> OP_MATCH_MAX
) {
1043 err(rules
->udev
, "invalid ACTION operation\n");
1046 rule_add_key(&rule_tmp
, TK_M_ACTION
, op
, value
, NULL
);
1051 if (strcasecmp(key
, "DEVPATH") == 0) {
1052 if (op
> OP_MATCH_MAX
) {
1053 err(rules
->udev
, "invalid DEVPATH operation\n");
1056 rule_add_key(&rule_tmp
, TK_M_DEVPATH
, op
, value
, NULL
);
1061 if (strcasecmp(key
, "KERNEL") == 0) {
1062 if (op
> OP_MATCH_MAX
) {
1063 err(rules
->udev
, "invalid KERNEL operation\n");
1066 rule_add_key(&rule_tmp
, TK_M_KERNEL
, op
, value
, NULL
);
1071 if (strcasecmp(key
, "SUBSYSTEM") == 0) {
1072 if (op
> OP_MATCH_MAX
) {
1073 err(rules
->udev
, "invalid SUBSYSTEM operation\n");
1076 /* bus, class, subsystem events should all be the same */
1077 if (strcmp(value
, "subsystem") == 0 ||
1078 strcmp(value
, "bus") == 0 ||
1079 strcmp(value
, "class") == 0) {
1080 if (strcmp(value
, "bus") == 0 || strcmp(value
, "class") == 0)
1081 err(rules
->udev
, "'%s' must be specified as 'subsystem' \n"
1082 "please fix it in %s:%u", value
, filename
, lineno
);
1083 rule_add_key(&rule_tmp
, TK_M_SUBSYSTEM
, op
, "subsystem|class|bus", NULL
);
1085 rule_add_key(&rule_tmp
, TK_M_SUBSYSTEM
, op
, value
, NULL
);
1090 if (strcasecmp(key
, "DRIVER") == 0) {
1091 if (op
> OP_MATCH_MAX
) {
1092 err(rules
->udev
, "invalid DRIVER operation\n");
1095 rule_add_key(&rule_tmp
, TK_M_DRIVER
, op
, value
, NULL
);
1100 if (strncasecmp(key
, "ATTR{", sizeof("ATTR{")-1) == 0) {
1101 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("ATTR")-1);
1103 err(rules
->udev
, "error parsing ATTR attribute\n");
1106 if (op
< OP_MATCH_MAX
) {
1107 rule_add_key(&rule_tmp
, TK_M_ATTR
, op
, value
, attr
);
1109 rule_add_key(&rule_tmp
, TK_A_ATTR
, op
, value
, attr
);
1115 if (strcasecmp(key
, "KERNELS") == 0 ||
1116 strcasecmp(key
, "ID") == 0) {
1117 if (op
> OP_MATCH_MAX
) {
1118 err(rules
->udev
, "invalid KERNELS operation\n");
1121 rule_add_key(&rule_tmp
, TK_M_KERNELS
, op
, value
, NULL
);
1126 if (strcasecmp(key
, "SUBSYSTEMS") == 0 ||
1127 strcasecmp(key
, "BUS") == 0) {
1128 if (op
> OP_MATCH_MAX
) {
1129 err(rules
->udev
, "invalid SUBSYSTEMS operation\n");
1132 rule_add_key(&rule_tmp
, TK_M_SUBSYSTEMS
, op
, value
, NULL
);
1137 if (strcasecmp(key
, "DRIVERS") == 0) {
1138 if (op
> OP_MATCH_MAX
) {
1139 err(rules
->udev
, "invalid DRIVERS operation\n");
1142 rule_add_key(&rule_tmp
, TK_M_DRIVERS
, op
, value
, NULL
);
1147 if (strncasecmp(key
, "ATTRS{", sizeof("ATTRS{")-1) == 0 ||
1148 strncasecmp(key
, "SYSFS{", sizeof("SYSFS{")-1) == 0) {
1149 if (op
> OP_MATCH_MAX
) {
1150 err(rules
->udev
, "invalid ATTRS operation\n");
1153 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("ATTRS")-1);
1155 err(rules
->udev
, "error parsing ATTRS attribute\n");
1158 if (strncmp(attr
, "device/", 7) == 0)
1159 err(rules
->udev
, "the 'device' link may not be available in a future kernel, "
1160 "please fix it in %s:%u", filename
, lineno
);
1161 else if (strstr(attr
, "../") != NULL
)
1162 err(rules
->udev
, "do not reference parent sysfs directories directly, "
1163 "it may break with a future kernel, please fix it in %s:%u", filename
, lineno
);
1164 rule_add_key(&rule_tmp
, TK_M_ATTRS
, op
, value
, attr
);
1169 if (strncasecmp(key
, "ENV{", sizeof("ENV{")-1) == 0) {
1170 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("ENV")-1);
1172 err(rules
->udev
, "error parsing ENV attribute\n");
1175 if (strncmp(attr
, "PHYSDEV", 7) == 0)
1177 if (op
< OP_MATCH_MAX
) {
1178 if (rule_add_key(&rule_tmp
, TK_M_ENV
, op
, value
, attr
) != 0)
1181 if (rule_add_key(&rule_tmp
, TK_A_ENV
, op
, value
, attr
) != 0)
1188 if (strcasecmp(key
, "PROGRAM") == 0) {
1189 rule_add_key(&rule_tmp
, TK_M_PROGRAM
, op
, value
, NULL
);
1194 if (strcasecmp(key
, "RESULT") == 0) {
1195 if (op
> OP_MATCH_MAX
) {
1196 err(rules
->udev
, "invalid RESULT operation\n");
1199 rule_add_key(&rule_tmp
, TK_M_RESULT
, op
, value
, NULL
);
1204 if (strncasecmp(key
, "IMPORT", sizeof("IMPORT")-1) == 0) {
1205 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("IMPORT")-1);
1206 if (attr
!= NULL
&& strstr(attr
, "program")) {
1207 dbg(rules
->udev
, "IMPORT will be executed\n");
1208 rule_add_key(&rule_tmp
, TK_M_IMPORT_PROG
, op
, value
, NULL
);
1210 } else if (attr
!= NULL
&& strstr(attr
, "file")) {
1211 dbg(rules
->udev
, "IMPORT will be included as file\n");
1212 rule_add_key(&rule_tmp
, TK_M_IMPORT_FILE
, op
, value
, NULL
);
1214 } else if (attr
!= NULL
&& strstr(attr
, "parent")) {
1215 dbg(rules
->udev
, "IMPORT will include the parent values\n");
1216 rule_add_key(&rule_tmp
, TK_M_IMPORT_PARENT
, op
, value
, NULL
);
1219 /* figure it out if it is executable */
1220 char file
[UTIL_PATH_SIZE
];
1222 struct stat statbuf
;
1224 util_strlcpy(file
, value
, sizeof(file
));
1225 pos
= strchr(file
, ' ');
1229 /* allow programs in /lib/udev called without the path */
1230 if (strchr(file
, '/') == NULL
) {
1231 util_strlcpy(file
, UDEV_PREFIX
"/lib/udev/", sizeof(file
));
1232 util_strlcat(file
, value
, sizeof(file
));
1233 pos
= strchr(file
, ' ');
1238 dbg(rules
->udev
, "IMPORT auto mode for '%s'\n", file
);
1239 if (!lstat(file
, &statbuf
) && (statbuf
.st_mode
& S_IXUSR
)) {
1240 dbg(rules
->udev
, "IMPORT will be executed (autotype)\n");
1241 rule_add_key(&rule_tmp
, TK_M_IMPORT_PROG
, op
, value
, NULL
);
1244 dbg(rules
->udev
, "IMPORT will be included as file (autotype)\n");
1245 rule_add_key(&rule_tmp
, TK_M_IMPORT_FILE
, op
, value
, NULL
);
1252 if (strncasecmp(key
, "TEST", sizeof("TEST")-1) == 0) {
1255 if (op
> OP_MATCH_MAX
) {
1256 err(rules
->udev
, "invalid TEST operation\n");
1259 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("TEST")-1);
1261 mode
= strtol(attr
, NULL
, 8);
1262 rule_add_key(&rule_tmp
, TK_M_TEST
, op
, value
, &mode
);
1264 rule_add_key(&rule_tmp
, TK_M_TEST
, op
, value
, NULL
);
1270 if (strncasecmp(key
, "RUN", sizeof("RUN")-1) == 0) {
1273 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("RUN")-1);
1274 if (attr
!= NULL
&& strstr(attr
, "ignore_error"))
1276 rule_add_key(&rule_tmp
, TK_A_RUN
, op
, value
, &flag
);
1281 if (strcasecmp(key
, "WAIT_FOR") == 0 || strcasecmp(key
, "WAIT_FOR_SYSFS") == 0) {
1282 rule_add_key(&rule_tmp
, TK_M_WAITFOR
, 0, value
, NULL
);
1287 if (strcasecmp(key
, "LABEL") == 0) {
1288 rule_tmp
.rule
.rule
.label_off
= add_string(rules
, value
);
1293 if (strcasecmp(key
, "GOTO") == 0) {
1294 rule_add_key(&rule_tmp
, TK_A_GOTO
, 0, value
, NULL
);
1299 if (strncasecmp(key
, "NAME", sizeof("NAME")-1) == 0) {
1300 if (op
< OP_MATCH_MAX
) {
1301 rule_add_key(&rule_tmp
, TK_M_NAME
, op
, value
, NULL
);
1303 if (value
[0] == '\0')
1304 dbg(rules
->udev
, "name empty, node creation suppressed\n");
1305 rule_add_key(&rule_tmp
, TK_A_NAME
, op
, value
, NULL
);
1306 attr
= get_key_attribute(rules
->udev
, key
+ sizeof("NAME")-1);
1308 if (strstr(attr
, "all_partitions") != NULL
) {
1309 int num
= DEFAULT_FAKE_PARTITIONS_COUNT
;
1311 dbg(rules
->udev
, "creation of partition nodes requested\n");
1312 rule_add_key(&rule_tmp
, TK_A_NUM_FAKE_PART
, 0, NULL
, &num
);
1314 if (strstr(attr
, "ignore_remove") != NULL
) {
1315 dbg(rules
->udev
, "remove event should be ignored\n");
1316 rule_add_key(&rule_tmp
, TK_A_IGNORE_REMOVE
, 0, NULL
, NULL
);
1320 rule_tmp
.rule
.rule
.flags
= 1;
1324 if (strcasecmp(key
, "SYMLINK") == 0) {
1325 if (op
< OP_MATCH_MAX
)
1326 rule_add_key(&rule_tmp
, TK_M_DEVLINK
, op
, value
, NULL
);
1328 rule_add_key(&rule_tmp
, TK_A_DEVLINK
, op
, value
, NULL
);
1329 rule_tmp
.rule
.rule
.flags
= 1;
1334 if (strcasecmp(key
, "OWNER") == 0) {
1338 uid
= strtoul(value
, &endptr
, 10);
1339 if (endptr
[0] == '\0') {
1340 rule_add_key(&rule_tmp
, TK_A_OWNER_ID
, op
, NULL
, &uid
);
1341 } else if (rules
->resolve_names
&& strchr("$%", value
[0]) == NULL
) {
1342 uid
= add_uid(rules
, value
);
1343 rule_add_key(&rule_tmp
, TK_A_OWNER_ID
, op
, NULL
, &uid
);
1345 rule_add_key(&rule_tmp
, TK_A_OWNER
, op
, value
, NULL
);
1347 rule_tmp
.rule
.rule
.flags
= 1;
1352 if (strcasecmp(key
, "GROUP") == 0) {
1356 gid
= strtoul(value
, &endptr
, 10);
1357 if (endptr
[0] == '\0') {
1358 rule_add_key(&rule_tmp
, TK_A_GROUP_ID
, op
, NULL
, &gid
);
1359 } else if (rules
->resolve_names
&& strchr("$%", value
[0]) == NULL
) {
1360 gid
= add_gid(rules
, value
);
1361 rule_add_key(&rule_tmp
, TK_A_GROUP_ID
, op
, NULL
, &gid
);
1363 rule_add_key(&rule_tmp
, TK_A_GROUP
, op
, value
, NULL
);
1365 rule_tmp
.rule
.rule
.flags
= 1;
1370 if (strcasecmp(key
, "MODE") == 0) {
1374 mode
= strtol(value
, &endptr
, 8);
1375 if (endptr
[0] == '\0')
1376 rule_add_key(&rule_tmp
, TK_A_MODE_ID
, op
, NULL
, &mode
);
1378 rule_add_key(&rule_tmp
, TK_A_MODE
, op
, value
, NULL
);
1379 rule_tmp
.rule
.rule
.flags
= 1;
1384 if (strcasecmp(key
, "OPTIONS") == 0) {
1387 if (strstr(value
, "last_rule") != NULL
) {
1388 dbg(rules
->udev
, "last rule to be applied\n");
1389 rule_add_key(&rule_tmp
, TK_A_LAST_RULE
, 0, NULL
, NULL
);
1391 if (strstr(value
, "ignore_device") != NULL
) {
1392 dbg(rules
->udev
, "device should be ignored\n");
1393 rule_add_key(&rule_tmp
, TK_A_IGNORE_DEVICE
, 0, NULL
, NULL
);
1395 if (strstr(value
, "ignore_remove") != NULL
) {
1396 dbg(rules
->udev
, "remove event should be ignored\n");
1397 rule_add_key(&rule_tmp
, TK_A_IGNORE_REMOVE
, 0, NULL
, NULL
);
1399 pos
= strstr(value
, "link_priority=");
1401 int prio
= atoi(&pos
[strlen("link_priority=")]);
1403 rule_add_key(&rule_tmp
, TK_A_DEVLINK_PRIO
, 0, NULL
, &prio
);
1404 dbg(rules
->udev
, "link priority=%i\n", prio
);
1406 pos
= strstr(value
, "event_timeout=");
1408 int tout
= atoi(&pos
[strlen("event_timeout=")]);
1410 rule_add_key(&rule_tmp
, TK_A_EVENT_TIMEOUT
, 0, NULL
, &tout
);
1411 dbg(rules
->udev
, "event timout=%i\n", tout
);
1413 pos
= strstr(value
, "string_escape=");
1415 pos
= &pos
[strlen("string_escape=")];
1416 if (strncmp(pos
, "none", strlen("none")) == 0)
1417 rule_add_key(&rule_tmp
, TK_A_STRING_ESCAPE_NONE
, 0, NULL
, NULL
);
1418 else if (strncmp(pos
, "replace", strlen("replace")) == 0)
1419 rule_add_key(&rule_tmp
, TK_A_STRING_ESCAPE_REPLACE
, 0, NULL
, NULL
);
1421 if (strstr(value
, "all_partitions") != NULL
) {
1422 int num
= DEFAULT_FAKE_PARTITIONS_COUNT
;
1424 rule_add_key(&rule_tmp
, TK_A_NUM_FAKE_PART
, 0, NULL
, &num
);
1425 dbg(rules
->udev
, "creation of partition nodes requested\n");
1430 err(rules
->udev
, "unknown key '%s' in %s:%u\n", key
, filename
, lineno
);
1434 err(rules
->udev
, "PHYSDEV* values are deprecated and not available on recent kernels, \n"
1435 "please fix it in %s:%u", filename
, lineno
);
1437 /* skip line if not any valid key was found */
1441 /* add rule token */
1442 if (add_token(rules
, &rule_tmp
.rule
) != 0)
1445 /* add tokens to list, sorted by type */
1446 if (sort_token(rules
, &rule_tmp
) != 0)
1450 err(rules
->udev
, "invalid rule '%s:%u'\n", filename
, lineno
);
1454 static int parse_file(struct udev_rules
*rules
, const char *filename
, unsigned short filename_off
)
1457 unsigned int first_token
;
1458 char line
[UTIL_LINE_SIZE
];
1462 info(rules
->udev
, "reading '%s' as rules file\n", filename
);
1464 f
= fopen(filename
, "r");
1468 first_token
= rules
->token_cur
;
1470 while(fgets(line
, sizeof(line
), f
) != NULL
) {
1474 /* skip whitespace */
1477 while (isspace(key
[0]))
1488 /* continue reading if backslash+newline is found */
1489 while (line
[len
-2] == '\\') {
1490 if (fgets(&line
[len
-2], (sizeof(line
)-len
)+2, f
) == NULL
)
1496 if (len
+1 >= sizeof(line
)) {
1497 err(rules
->udev
, "line too long '%s':%u, ignored\n", filename
, line_nr
);
1500 add_rule(rules
, key
, filename
, filename_off
, line_nr
);
1504 /* link GOTOs to LABEL rules in this file to be able to fast-forward */
1505 for (i
= first_token
+1; i
< rules
->token_cur
; i
++) {
1506 if (rules
->tokens
[i
].type
== TK_A_GOTO
) {
1507 char *label
= &rules
->buf
[rules
->tokens
[i
].key
.value_off
];
1510 for (j
= i
+1; j
< rules
->token_cur
; j
++) {
1511 if (rules
->tokens
[j
].type
!= TK_RULE
)
1513 if (rules
->tokens
[j
].rule
.label_off
== 0)
1515 if (strcmp(label
, &rules
->buf
[rules
->tokens
[j
].rule
.label_off
]) != 0)
1517 rules
->tokens
[i
].key
.rule_goto
= j
;
1519 if (rules
->tokens
[i
].key
.rule_goto
== 0)
1520 err(rules
->udev
, "GOTO '%s' has no matching label in: '%s'\n", label
, filename
);
1526 static int add_matching_files(struct udev
*udev
, struct udev_list_node
*file_list
, const char *dirname
, const char *suffix
)
1530 char filename
[UTIL_PATH_SIZE
];
1532 dbg(udev
, "open directory '%s'\n", dirname
);
1533 dir
= opendir(dirname
);
1535 err(udev
, "unable to open '%s': %m\n", dirname
);
1541 if (ent
== NULL
|| ent
->d_name
[0] == '\0')
1544 if ((ent
->d_name
[0] == '.') || (ent
->d_name
[0] == '#'))
1547 /* look for file matching with specified suffix */
1548 if (suffix
!= NULL
) {
1551 ext
= strrchr(ent
->d_name
, '.');
1554 if (strcmp(ext
, suffix
) != 0)
1557 dbg(udev
, "put file '%s/%s' into list\n", dirname
, ent
->d_name
);
1559 snprintf(filename
, sizeof(filename
), "%s/%s", dirname
, ent
->d_name
);
1560 filename
[sizeof(filename
)-1] = '\0';
1561 udev_list_entry_add(udev
, file_list
, filename
, NULL
, 1, 1);
1568 struct udev_rules
*udev_rules_new(struct udev
*udev
, int resolve_names
)
1570 struct udev_rules
*rules
;
1571 struct stat statbuf
;
1572 struct udev_list_node file_list
;
1573 struct udev_list_entry
*file_loop
, *file_tmp
;
1574 unsigned int prev_rule
;
1575 struct token end_token
;
1578 rules
= malloc(sizeof(struct udev_rules
));
1581 memset(rules
, 0x00, sizeof(struct udev_rules
));
1583 rules
->resolve_names
= resolve_names
;
1584 udev_list_init(&file_list
);
1586 /* init token array and string buffer */
1587 rules
->tokens
= malloc(PREALLOC_TOKEN
* sizeof(struct token
));
1588 if (rules
->tokens
== NULL
)
1590 rules
->token_max
= PREALLOC_TOKEN
;
1591 rules
->buf
= malloc(PREALLOC_STRBUF
);
1592 if (rules
->buf
== NULL
)
1594 rules
->buf_max
= PREALLOC_STRBUF
;
1595 /* offset 0 is always '\0' */
1596 rules
->buf
[0] = '\0';
1598 dbg(udev
, "prealloc %zu bytes tokens (%u * %zu bytes), %zu bytes buffer\n",
1599 rules
->token_max
* sizeof(struct token
), rules
->token_max
, sizeof(struct token
), rules
->buf_max
);
1601 if (udev_get_rules_path(udev
) != NULL
) {
1602 /* custom rules location for testing */
1603 add_matching_files(udev
, &file_list
, udev_get_rules_path(udev
), ".rules");
1605 char filename
[PATH_MAX
];
1606 struct udev_list_node sort_list
;
1607 struct udev_list_entry
*sort_loop
, *sort_tmp
;
1609 /* read user/custom rules */
1610 add_matching_files(udev
, &file_list
, SYSCONFDIR
"/udev/rules.d", ".rules");
1612 /* read dynamic/temporary rules */
1613 util_strlcpy(filename
, udev_get_dev_path(udev
), sizeof(filename
));
1614 util_strlcat(filename
, "/.udev/rules.d", sizeof(filename
));
1615 if (stat(filename
, &statbuf
) != 0) {
1616 util_create_path(udev
, filename
);
1617 udev_selinux_setfscreatecon(udev
, filename
, S_IFDIR
|0755);
1618 mkdir(filename
, 0755);
1619 udev_selinux_resetfscreatecon(udev
);
1621 udev_list_init(&sort_list
);
1622 add_matching_files(udev
, &sort_list
, filename
, ".rules");
1624 /* read default rules */
1625 add_matching_files(udev
, &sort_list
, UDEV_PREFIX
"/lib/udev/rules.d", ".rules");
1627 /* sort all rules files by basename into list of files */
1628 udev_list_entry_foreach_safe(sort_loop
, sort_tmp
, udev_list_get_entry(&sort_list
)) {
1629 const char *sort_name
= udev_list_entry_get_name(sort_loop
);
1630 const char *sort_base
= strrchr(sort_name
, '/');
1632 if (sort_base
== NULL
)
1634 /* sort entry into existing list */
1635 udev_list_entry_foreach_safe(file_loop
, file_tmp
, udev_list_get_entry(&file_list
)) {
1636 const char *file_name
= udev_list_entry_get_name(file_loop
);
1637 const char *file_base
= strrchr(file_name
, '/');
1639 if (file_base
== NULL
)
1641 if (strcmp(file_base
, sort_base
) == 0) {
1642 info(udev
, "rule file basename '%s' already added, ignoring '%s'\n",
1643 file_name
, sort_name
);
1644 udev_list_entry_delete(sort_loop
);
1648 if (strcmp(file_base
, sort_base
) > 0) {
1649 /* found later file, insert before */
1650 udev_list_entry_remove(sort_loop
);
1651 udev_list_entry_insert_before(sort_loop
, file_loop
);
1656 /* current file already handled */
1657 if (sort_loop
== NULL
)
1659 /* no later file, append to end of list */
1660 udev_list_entry_remove(sort_loop
);
1661 udev_list_entry_append(sort_loop
, &file_list
);
1665 /* add all filenames to the string buffer */
1666 udev_list_entry_foreach(file_loop
, udev_list_get_entry(&file_list
)) {
1667 const char *filename
= udev_list_entry_get_name(file_loop
);
1668 unsigned int filename_off
;
1670 filename_off
= add_string(rules
, filename
);
1671 /* the offset in the rule is limited to unsigned short */
1672 if (filename_off
< USHRT_MAX
)
1673 udev_list_entry_set_flag(file_loop
, filename_off
);
1676 /* parse list of files */
1677 udev_list_entry_foreach_safe(file_loop
, file_tmp
, udev_list_get_entry(&file_list
)) {
1678 const char *filename
= udev_list_entry_get_name(file_loop
);
1679 unsigned int filename_off
= udev_list_entry_get_flag(file_loop
);
1681 if (stat(filename
, &statbuf
) == 0 && statbuf
.st_size
> 0)
1682 parse_file(rules
, filename
, filename_off
);
1684 info(udev
, "can not read '%s'\n", filename
);
1685 udev_list_entry_delete(file_loop
);
1688 memset(&end_token
, 0x00, sizeof(struct token
));
1689 end_token
.type
= TK_END
;
1690 add_token(rules
, &end_token
);
1692 /* link all TK_RULE tokens to be able to fast-forward to next TK_RULE */
1694 for (i
= 1; i
< rules
->token_cur
; i
++) {
1695 if (rules
->tokens
[i
].type
== TK_RULE
) {
1696 rules
->tokens
[prev_rule
].rule
.next_rule
= i
;
1701 /* shrink allocated token and string buffer */
1702 if (rules
->token_cur
< rules
->token_max
) {
1703 struct token
*tokens
;
1705 tokens
= realloc(rules
->tokens
, rules
->token_cur
* sizeof(struct token
));
1706 if (tokens
!= NULL
|| rules
->token_cur
== 0) {
1707 rules
->tokens
= tokens
;
1708 rules
->token_max
= rules
->token_cur
;
1711 if (rules
->buf_cur
< rules
->buf_max
) {
1714 buf
= realloc(rules
->buf
, rules
->buf_cur
);
1715 if (buf
!= NULL
|| rules
->buf_cur
== 0) {
1717 rules
->buf_max
= rules
->buf_cur
;
1720 info(udev
, "shrunk to %lu bytes tokens (%u * %zu bytes), %zu bytes buffer\n",
1721 rules
->token_max
* sizeof(struct token
), rules
->token_max
, sizeof(struct token
), rules
->buf_max
);
1723 /* cleanup uid/gid cache */
1726 rules
->uids_cur
= 0;
1727 rules
->uids_max
= 0;
1730 rules
->gids_cur
= 0;
1731 rules
->gids_max
= 0;
1737 void udev_rules_unref(struct udev_rules
*rules
)
1741 free(rules
->tokens
);
1748 static int match_key(struct udev_rules
*rules
, struct token
*token
, const char *val
)
1750 char *key_value
= &rules
->buf
[token
->key
.value_off
];
1757 switch (token
->key
.glob
) {
1759 match
= (strcmp(key_value
, val
) == 0);
1762 match
= (fnmatch(key_value
, val
, 0) == 0);
1769 split
= &rules
->buf
[token
->key
.value_off
];
1774 next
= strchr(split
, '|');
1776 size_t matchlen
= (size_t)(next
- split
);
1778 match
= (matchlen
== len
&& strncmp(split
, val
, matchlen
) == 0);
1782 match
= (strcmp(split
, val
) == 0);
1791 char value
[UTIL_PATH_SIZE
];
1793 util_strlcpy(value
, &rules
->buf
[token
->key
.value_off
], sizeof(value
));
1795 while (key_value
!= NULL
) {
1796 pos
= strchr(key_value
, '|');
1801 dbg(rules
->udev
, "match %s '%s' <-> '%s'\n", token_str
[token
->type
], key_value
, val
);
1802 match
= (fnmatch(key_value
, val
, 0) == 0);
1810 match
= (val
[0] != '\0');
1817 if (match
&& (token
->key
.op
== OP_MATCH
)) {
1818 dbg(rules
->udev
, "%s is true (matching value)\n", token_str
[token
->type
]);
1821 if (!match
&& (token
->key
.op
== OP_NOMATCH
)) {
1822 dbg(rules
->udev
, "%s is true (non-matching value)\n", token_str
[token
->type
]);
1825 dbg(rules
->udev
, "%s is not true\n", token_str
[token
->type
]);
1829 static int match_attr(struct udev_rules
*rules
, struct udev_device
*dev
, struct udev_event
*event
, struct token
*cur
)
1831 const char *key_name
= &rules
->buf
[cur
->key
.attr_off
];
1832 const char *key_value
= &rules
->buf
[cur
->key
.value_off
];
1833 char value
[UTIL_NAME_SIZE
];
1837 if (key_name
[0] == '[') {
1838 char attr
[UTIL_PATH_SIZE
];
1840 util_strlcpy(attr
, key_name
, sizeof(attr
));
1841 util_resolve_subsys_kernel(event
->udev
, attr
, value
, sizeof(value
), 1);
1843 if (value
[0] == '\0') {
1846 val
= udev_device_get_sysattr_value(dev
, key_name
);
1849 util_strlcpy(value
, val
, sizeof(value
));
1852 /* strip trailing whitespace of value, if not asked to match for it */
1853 len
= strlen(key_value
);
1854 if (len
> 0 && !isspace(key_value
[len
-1])) {
1855 len
= strlen(value
);
1856 while (len
> 0 && isspace(value
[--len
]))
1858 dbg(rules
->udev
, "removed trailing whitespace from '%s'\n", value
);
1860 return match_key(rules
, cur
, value
);
1869 int udev_rules_apply_to_event(struct udev_rules
*rules
, struct udev_event
*event
)
1873 enum escape_type esc
= ESCAPE_UNSET
;
1876 if (rules
->tokens
== NULL
)
1879 can_set_name
= ((strcmp(udev_device_get_action(event
->dev
), "add") == 0 ||
1880 strcmp(udev_device_get_action(event
->dev
), "change") == 0) &&
1881 (major(udev_device_get_devnum(event
->dev
)) > 0 ||
1882 strcmp(udev_device_get_subsystem(event
->dev
), "net") == 0));
1884 /* loop through token list, match, run actions or forward to next rule */
1885 cur
= &rules
->tokens
[0];
1890 dump_token(rules
, cur
);
1891 switch (cur
->type
) {
1895 /* possibly skip rules which want to set NAME, SYMLINK, OWNER, GROUP, MODE */
1896 if (!can_set_name
&& rule
->rule
.flags
)
1901 if (match_key(rules
, cur
, udev_device_get_action(event
->dev
)) != 0)
1905 if (match_key(rules
, cur
, udev_device_get_devpath(event
->dev
)) != 0)
1909 if (match_key(rules
, cur
, udev_device_get_sysname(event
->dev
)) != 0)
1914 size_t devlen
= strlen(udev_get_dev_path(event
->udev
))+1;
1915 struct udev_list_entry
*list_entry
;
1918 udev_list_entry_foreach(list_entry
, udev_device_get_devlinks_list_entry(event
->dev
)) {
1919 const char *devlink
;
1921 devlink
= &udev_list_entry_get_name(list_entry
)[devlen
];
1922 if (match_key(rules
, cur
, devlink
) == 0) {
1932 if (match_key(rules
, cur
, event
->name
) != 0)
1937 struct udev_list_entry
*list_entry
;
1938 const char *key_name
= &rules
->buf
[cur
->key
.attr_off
];
1941 list_entry
= udev_device_get_properties_list_entry(event
->dev
);
1942 list_entry
= udev_list_entry_get_by_name(list_entry
, key_name
);
1943 value
= udev_list_entry_get_value(list_entry
);
1944 if (value
== NULL
) {
1945 dbg(event
->udev
, "ENV{%s} is not set, treat as empty\n", key_name
);
1948 if (match_key(rules
, cur
, value
))
1952 case TK_M_SUBSYSTEM
:
1953 if (match_key(rules
, cur
, udev_device_get_subsystem(event
->dev
)) != 0)
1957 if (match_key(rules
, cur
, udev_device_get_driver(event
->dev
)) != 0)
1962 char filename
[UTIL_PATH_SIZE
];
1965 util_strlcpy(filename
, &rules
->buf
[cur
->key
.value_off
], sizeof(filename
));
1966 udev_event_apply_format(event
, filename
, sizeof(filename
));
1967 found
= (wait_for_file(event
->dev
, filename
, 10) == 0);
1968 if (!found
&& (cur
->key
.op
!= OP_NOMATCH
))
1973 if (match_attr(rules
, event
->dev
, event
, cur
) != 0)
1977 case TK_M_SUBSYSTEMS
:
1983 /* get whole sequence of parent matches */
1985 while (next
->type
> TK_M_PARENTS_MIN
&& next
->type
< TK_M_PARENTS_MAX
)
1988 /* loop over parents */
1989 event
->dev_parent
= event
->dev
;
1993 dbg(event
->udev
, "parent: '%s'\n", udev_device_get_syspath(event
->dev_parent
));
1994 /* loop over sequence of parent match keys */
1995 for (key
= cur
; key
< next
; key
++ ) {
1996 dump_token(rules
, key
);
1999 if (match_key(rules
, key
, udev_device_get_sysname(event
->dev_parent
)) != 0)
2002 case TK_M_SUBSYSTEMS
:
2003 if (match_key(rules
, key
, udev_device_get_subsystem(event
->dev_parent
)) != 0)
2007 if (match_key(rules
, key
, udev_device_get_driver(event
->dev_parent
)) != 0)
2011 if (match_attr(rules
, event
->dev_parent
, event
, key
) != 0)
2017 dbg(event
->udev
, "parent key matched\n");
2019 dbg(event
->udev
, "all parent keys matched\n");
2020 /* all keys matched */
2024 event
->dev_parent
= udev_device_get_parent(event
->dev_parent
);
2025 if (event
->dev_parent
== NULL
)
2028 /* move behind our sequence of parent match keys */
2034 char filename
[UTIL_PATH_SIZE
];
2035 struct stat statbuf
;
2038 util_strlcpy(filename
, &rules
->buf
[cur
->key
.value_off
], sizeof(filename
));
2039 udev_event_apply_format(event
, filename
, sizeof(filename
));
2040 if (util_resolve_subsys_kernel(event
->udev
, NULL
, filename
, sizeof(filename
), 0) != 0)
2041 if (filename
[0] != '/') {
2042 char tmp
[UTIL_PATH_SIZE
];
2044 util_strlcpy(tmp
, udev_device_get_syspath(event
->dev
), sizeof(tmp
));
2045 util_strlcat(tmp
, "/", sizeof(tmp
));
2046 util_strlcat(tmp
, filename
, sizeof(tmp
));
2047 util_strlcpy(filename
, tmp
, sizeof(filename
));
2050 attr_subst_subdir(filename
, sizeof(filename
));
2052 match
= (stat(filename
, &statbuf
) == 0);
2053 dbg(event
->udev
, "'%s' %s", filename
, match
? "exists\n" : "does not exist\n");
2054 if (match
&& cur
->key
.mode
> 0) {
2055 match
= ((statbuf
.st_mode
& cur
->key
.mode
) > 0);
2056 dbg(event
->udev
, "'%s' has mode=%#o and %s %#o\n", filename
, statbuf
.st_mode
,
2057 match
? "matches" : "does not match", cur
->key
.mode
);
2059 if (match
&& cur
->key
.op
== OP_NOMATCH
)
2061 if (!match
&& cur
->key
.op
== OP_MATCH
)
2067 char program
[UTIL_PATH_SIZE
];
2069 char result
[UTIL_PATH_SIZE
];
2071 free(event
->program_result
);
2072 event
->program_result
= NULL
;
2073 util_strlcpy(program
, &rules
->buf
[cur
->key
.value_off
], sizeof(program
));
2074 udev_event_apply_format(event
, program
, sizeof(program
));
2075 envp
= udev_device_get_properties_envp(event
->dev
);
2076 info(event
->udev
, "PROGRAM '%s' %s:%u\n",
2078 &rules
->buf
[rule
->rule
.filename_off
],
2079 rule
->rule
.filename_line
);
2080 if (util_run_program(event
->udev
, program
, envp
, result
, sizeof(result
), NULL
) != 0) {
2081 if (cur
->key
.op
!= OP_NOMATCH
)
2086 util_remove_trailing_chars(result
, '\n');
2087 if (esc
== ESCAPE_UNSET
|| esc
== ESCAPE_REPLACE
) {
2088 count
= util_replace_chars(result
, ALLOWED_CHARS_INPUT
);
2090 info(event
->udev
, "%i character(s) replaced\n" , count
);
2092 event
->program_result
= strdup(result
);
2093 dbg(event
->udev
, "storing result '%s'\n", event
->program_result
);
2094 if (cur
->key
.op
== OP_NOMATCH
)
2099 case TK_M_IMPORT_FILE
:
2101 char import
[UTIL_PATH_SIZE
];
2103 util_strlcpy(import
, &rules
->buf
[cur
->key
.value_off
], sizeof(import
));
2104 udev_event_apply_format(event
, import
, sizeof(import
));
2105 if (import_file_into_properties(event
->dev
, import
) != 0)
2106 if (cur
->key
.op
!= OP_NOMATCH
)
2110 case TK_M_IMPORT_PROG
:
2112 char import
[UTIL_PATH_SIZE
];
2114 util_strlcpy(import
, &rules
->buf
[cur
->key
.value_off
], sizeof(import
));
2115 udev_event_apply_format(event
, import
, sizeof(import
));
2116 info(event
->udev
, "IMPORT '%s' %s:%u\n",
2118 &rules
->buf
[rule
->rule
.filename_off
],
2119 rule
->rule
.filename_line
);
2120 if (import_program_into_properties(event
->dev
, import
) != 0)
2121 if (cur
->key
.op
!= OP_NOMATCH
)
2125 case TK_M_IMPORT_PARENT
:
2127 char import
[UTIL_PATH_SIZE
];
2129 util_strlcpy(import
, &rules
->buf
[cur
->key
.value_off
], sizeof(import
));
2130 udev_event_apply_format(event
, import
, sizeof(import
));
2131 if (import_parent_into_properties(event
->dev
, import
) != 0)
2132 if (cur
->key
.op
!= OP_NOMATCH
)
2137 if (match_key(rules
, cur
, event
->program_result
) != 0)
2141 case TK_A_IGNORE_DEVICE
:
2142 event
->ignore_device
= 1;
2145 case TK_A_STRING_ESCAPE_NONE
:
2148 case TK_A_STRING_ESCAPE_REPLACE
:
2149 esc
= ESCAPE_REPLACE
;
2151 case TK_A_NUM_FAKE_PART
:
2152 if (strcmp(udev_device_get_subsystem(event
->dev
), "block") != 0)
2154 if (udev_device_get_sysnum(event
->dev
) != NULL
)
2156 udev_device_set_num_fake_partitions(event
->dev
, cur
->key
.num_fake_part
);
2158 case TK_A_DEVLINK_PRIO
:
2159 udev_device_set_devlink_priority(event
->dev
, cur
->key
.devlink_prio
);
2163 char owner
[UTIL_NAME_SIZE
];
2165 if (event
->owner_final
)
2167 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2168 event
->owner_final
= 1;
2169 util_strlcpy(owner
, &rules
->buf
[cur
->key
.value_off
], sizeof(owner
));
2170 udev_event_apply_format(event
, owner
, sizeof(owner
));
2171 event
->uid
= util_lookup_user(event
->udev
, owner
);
2172 info(event
->udev
, "OWNER %u %s:%u\n",
2174 &rules
->buf
[rule
->rule
.filename_off
],
2175 rule
->rule
.filename_line
);
2180 char group
[UTIL_NAME_SIZE
];
2182 if (event
->group_final
)
2184 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2185 event
->group_final
= 1;
2186 util_strlcpy(group
, &rules
->buf
[cur
->key
.value_off
], sizeof(group
));
2187 udev_event_apply_format(event
, group
, sizeof(group
));
2188 event
->gid
= util_lookup_group(event
->udev
, group
);
2189 info(event
->udev
, "GROUP %u %s:%u\n",
2191 &rules
->buf
[rule
->rule
.filename_off
],
2192 rule
->rule
.filename_line
);
2197 char mode
[UTIL_NAME_SIZE
];
2200 if (event
->mode_final
)
2202 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2203 event
->mode_final
= 1;
2204 util_strlcpy(mode
, &rules
->buf
[cur
->key
.value_off
], sizeof(mode
));
2205 udev_event_apply_format(event
, mode
, sizeof(mode
));
2206 event
->mode
= strtol(mode
, &endptr
, 8);
2207 if (endptr
[0] != '\0') {
2208 err(event
->udev
, "invalide mode '%s' set default mode 0660\n", mode
);
2211 info(event
->udev
, "MODE %#o %s:%u\n",
2213 &rules
->buf
[rule
->rule
.filename_off
],
2214 rule
->rule
.filename_line
);
2218 if (event
->owner_final
)
2220 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2221 event
->owner_final
= 1;
2222 event
->uid
= cur
->key
.uid
;
2223 info(event
->udev
, "OWNER %u %s:%u\n",
2225 &rules
->buf
[rule
->rule
.filename_off
],
2226 rule
->rule
.filename_line
);
2229 if (event
->group_final
)
2231 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2232 event
->group_final
= 1;
2233 event
->gid
= cur
->key
.gid
;
2234 info(event
->udev
, "GROUP %u %s:%u\n",
2236 &rules
->buf
[rule
->rule
.filename_off
],
2237 rule
->rule
.filename_line
);
2240 if (event
->mode_final
)
2242 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2243 event
->mode_final
= 1;
2244 event
->mode
= cur
->key
.mode
;
2245 info(event
->udev
, "MODE %#o %s:%u\n",
2247 &rules
->buf
[rule
->rule
.filename_off
],
2248 rule
->rule
.filename_line
);
2252 const char *name
= &rules
->buf
[cur
->key
.attr_off
];
2253 char *value
= &rules
->buf
[cur
->key
.value_off
];
2255 if (value
[0] != '\0') {
2256 char temp_value
[UTIL_NAME_SIZE
];
2257 struct udev_list_entry
*entry
;
2259 util_strlcpy(temp_value
, value
, sizeof(temp_value
));
2260 udev_event_apply_format(event
, temp_value
, sizeof(temp_value
));
2261 entry
= udev_device_add_property(event
->dev
, name
, temp_value
);
2263 udev_list_entry_set_flag(entry
, 1);
2265 udev_device_add_property(event
->dev
, name
, NULL
);
2271 const char *name
= &rules
->buf
[cur
->key
.value_off
];
2272 char name_str
[UTIL_PATH_SIZE
];
2275 if (event
->name_final
)
2277 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2278 event
->name_final
= 1;
2279 if (name
[0] == '\0') {
2284 util_strlcpy(name_str
, name
, sizeof(name_str
));
2285 udev_event_apply_format(event
, name_str
, sizeof(name_str
));
2286 if (esc
== ESCAPE_UNSET
|| esc
== ESCAPE_REPLACE
) {
2287 count
= util_replace_chars(name_str
, ALLOWED_CHARS_FILE
);
2289 info(event
->udev
, "%i character(s) replaced\n", count
);
2291 event
->name
= strdup(name_str
);
2292 info(event
->udev
, "NAME '%s' %s:%u\n",
2294 &rules
->buf
[rule
->rule
.filename_off
],
2295 rule
->rule
.filename_line
);
2301 char temp
[UTIL_PATH_SIZE
];
2302 char filename
[UTIL_PATH_SIZE
];
2306 if (event
->devlink_final
)
2308 if (major(udev_device_get_devnum(event
->dev
)) == 0)
2310 if (cur
->key
.op
== OP_ASSIGN_FINAL
)
2311 event
->devlink_final
= 1;
2312 if (cur
->key
.op
== OP_ASSIGN
|| cur
->key
.op
== OP_ASSIGN_FINAL
)
2313 udev_device_cleanup_devlinks_list(event
->dev
);
2315 /* allow multiple symlinks separated by spaces */
2316 util_strlcpy(temp
, &rules
->buf
[cur
->key
.value_off
], sizeof(temp
));
2317 udev_event_apply_format(event
, temp
, sizeof(temp
));
2318 if (esc
== ESCAPE_UNSET
)
2319 count
= util_replace_chars(temp
, ALLOWED_CHARS_FILE
" ");
2320 else if (esc
== ESCAPE_REPLACE
)
2321 count
= util_replace_chars(temp
, ALLOWED_CHARS_FILE
);
2323 info(event
->udev
, "%i character(s) replaced\n" , count
);
2324 dbg(event
->udev
, "rule applied, added symlink(s) '%s'\n", temp
);
2326 while (isspace(pos
[0]))
2328 next
= strchr(pos
, ' ');
2331 info(event
->udev
, "LINK '%s' %s:%u\n",
2333 &rules
->buf
[rule
->rule
.filename_off
],
2334 rule
->rule
.filename_line
);
2335 util_strlcpy(filename
, udev_get_dev_path(event
->udev
), sizeof(filename
));
2336 util_strlcat(filename
, "/", sizeof(filename
));
2337 util_strlcat(filename
, pos
, sizeof(filename
));
2338 udev_device_add_devlink(event
->dev
, filename
);
2339 while (isspace(next
[1]))
2342 next
= strchr(pos
, ' ');
2344 if (pos
[0] != '\0') {
2345 info(event
->udev
, "LINK '%s' %s:%u\n",
2347 &rules
->buf
[rule
->rule
.filename_off
],
2348 rule
->rule
.filename_line
);
2349 util_strlcpy(filename
, udev_get_dev_path(event
->udev
), sizeof(filename
));
2350 util_strlcat(filename
, "/", sizeof(filename
));
2351 util_strlcat(filename
, pos
, sizeof(filename
));
2352 udev_device_add_devlink(event
->dev
, filename
);
2356 case TK_A_EVENT_TIMEOUT
:
2357 udev_device_set_event_timeout(event
->dev
, cur
->key
.event_timeout
);
2359 case TK_A_IGNORE_REMOVE
:
2360 udev_device_set_ignore_remove(event
->dev
, 1);
2364 const char *key_name
= &rules
->buf
[cur
->key
.attr_off
];
2365 char attr
[UTIL_PATH_SIZE
];
2366 char value
[UTIL_NAME_SIZE
];
2369 util_strlcpy(attr
, key_name
, sizeof(attr
));
2370 if (util_resolve_subsys_kernel(event
->udev
, key_name
, attr
, sizeof(attr
), 0) != 0) {
2371 util_strlcpy(attr
, udev_device_get_syspath(event
->dev
), sizeof(attr
));
2372 util_strlcat(attr
, "/", sizeof(attr
));
2373 util_strlcat(attr
, key_name
, sizeof(attr
));
2376 attr_subst_subdir(attr
, sizeof(attr
));
2378 util_strlcpy(value
, &rules
->buf
[cur
->key
.value_off
], sizeof(value
));
2379 udev_event_apply_format(event
, value
, sizeof(value
));
2380 info(event
->udev
, "ATTR '%s' writing '%s' %s:%u\n", attr
, value
,
2381 &rules
->buf
[rule
->rule
.filename_off
],
2382 rule
->rule
.filename_line
);
2383 f
= fopen(attr
, "w");
2386 if (fprintf(f
, "%s", value
) <= 0)
2387 err(event
->udev
, "error writing ATTR{%s}: %m\n", attr
);
2390 err(event
->udev
, "error opening ATTR{%s} for writing: %m\n", attr
);
2396 struct udev_list_entry
*list_entry
;
2398 if (cur
->key
.op
== OP_ASSIGN
|| cur
->key
.op
== OP_ASSIGN_FINAL
)
2399 udev_list_cleanup_entries(event
->udev
, &event
->run_list
);
2400 info(event
->udev
, "RUN '%s' %s:%u\n",
2401 &rules
->buf
[cur
->key
.value_off
],
2402 &rules
->buf
[rule
->rule
.filename_off
],
2403 rule
->rule
.filename_line
);
2404 list_entry
= udev_list_entry_add(event
->udev
, &event
->run_list
,
2405 &rules
->buf
[cur
->key
.value_off
], NULL
, 1, 0);
2406 if (cur
->key
.ignore_error
)
2407 udev_list_entry_set_flag(list_entry
, 1);
2411 cur
= &rules
->tokens
[cur
->key
.rule_goto
];
2413 case TK_A_LAST_RULE
:
2417 case TK_M_PARENTS_MIN
:
2418 case TK_M_PARENTS_MAX
:
2421 err(rules
->udev
, "wrong type %u\n", cur
->type
);
2428 /* fast-forward to next rule */
2429 idx
= rule
->rule
.next_rule
;
2432 dbg(rules
->udev
, "forward to rule: %u\n", idx
);
2433 cur
= &rules
->tokens
[idx
];