- token->key.gid = *(gid_t *)data;
- break;
- case TK_A_MODE_ID:
- token->key.mode = *(mode_t *)data;
- break;
- case TK_A_EVENT_TIMEOUT:
- token->key.event_timeout = *(int *)data;
- break;
- case TK_RULE:
- case TK_M_PARENTS_MAX:
- case TK_M_MAX:
- case TK_END:
- case TK_UNSET:
- err(rule_tmp->rules->udev, "wrong type %u\n", type);
- return -1;
- }
-
- glob = GL_PLAIN;
- if (value != NULL) {
- if (type < TK_M_MAX) {
- /* check if we need to split or call fnmatch() while matching rules */
- int has_split;
- int has_glob;
-
- has_split = (strchr(value, '|') != NULL);
- has_glob = (strchr(value, '*') != NULL || strchr(value, '?') != NULL ||
- strchr(value, '[') != NULL || strchr(value, ']') != NULL);
- if (has_split && has_glob) {
- glob = GL_SPLIT_GLOB;
- } else if (has_split) {
- glob = GL_SPLIT;
- } else if (has_glob) {
- if (strcmp(value, "?*") == 0)
- glob = GL_SOMETHING;
- else
- glob = GL_GLOB;
- }
- } else {
- /* check if we need to substitute format strings for matching rules */
- if (strchr(value, '%') != NULL || strchr(value, '$') != NULL)
- glob = GL_FORMAT;
- }
- }
-
- token->type = type;
- token->key.op = op;
- token->key.glob = glob;
- rule_tmp->token_cur++;
- if (rule_tmp->token_cur >= ARRAY_SIZE(rule_tmp->token)) {
- err(rule_tmp->rules->udev, "temporary rule array too small\n");
- return -1;
- }
- return 0;
-}
-
-#ifdef DEBUG
-static void dump_token(struct udev_rules *rules, struct token *token)
-{
- enum token_type type = token->type;
- enum operation_type op = token->key.op;
- enum string_glob_type glob = token->key.glob;
- const char *value = &rules->buf[token->key.value_off];
- const char *attr = &rules->buf[token->key.attr_off];
-
- switch (type) {
- case TK_RULE:
- {
- const char *tks_ptr = (char *)rules->tokens;
- const char *tk_ptr = (char *)token;
- unsigned int off = tk_ptr - tks_ptr;
-
- dbg(rules->udev, "* RULE '%s', off: %u(%u), next: %u, label: '%s'\n",
- &rules->buf[token->rule.filename_off],
- off / (unsigned int) sizeof(struct token), off,
- token->rule.next_rule,
- &rules->buf[token->rule.label_off]);
- break;
- }
- case TK_M_ACTION:
- case TK_M_DEVPATH:
- case TK_M_KERNEL:
- case TK_M_SUBSYSTEM:
- case TK_M_DRIVER:
- case TK_M_WAITFOR:
- case TK_M_DEVLINK:
- case TK_M_NAME:
- case TK_M_KERNELS:
- case TK_M_SUBSYSTEMS:
- case TK_M_DRIVERS:
- case TK_M_PROGRAM:
- case TK_M_IMPORT_FILE:
- case TK_M_IMPORT_PROG:
- case TK_M_IMPORT_PARENT:
- case TK_M_RESULT:
- case TK_A_NAME:
- case TK_A_DEVLINK:
- case TK_A_OWNER:
- case TK_A_GROUP:
- case TK_A_MODE:
- case TK_A_RUN:
- dbg(rules->udev, "%s %s '%s'(%s)\n",
- token_str[type], operation_str[op], value, string_glob_str[glob]);
- break;
- case TK_M_ATTR:
- case TK_M_ATTRS:
- case TK_M_ENV:
- case TK_A_ATTR:
- case TK_A_ENV:
- dbg(rules->udev, "%s %s '%s' '%s'(%s)\n",
- token_str[type], operation_str[op], attr, value, string_glob_str[glob]);
- break;
- case TK_A_IGNORE_DEVICE:
- case TK_A_STRING_ESCAPE_NONE:
- case TK_A_STRING_ESCAPE_REPLACE:
- case TK_A_LAST_RULE:
- case TK_A_IGNORE_REMOVE:
- dbg(rules->udev, "%s\n", token_str[type]);
- break;
- case TK_M_TEST:
- dbg(rules->udev, "%s %s '%s'(%s) %#o\n",
- token_str[type], operation_str[op], value, string_glob_str[glob], token->key.mode);
- break;
- case TK_A_NUM_FAKE_PART:
- dbg(rules->udev, "%s %u\n", token_str[type], token->key.num_fake_part);
- break;
- case TK_A_DEVLINK_PRIO:
- dbg(rules->udev, "%s %s %u\n", token_str[type], operation_str[op], token->key.devlink_prio);
- break;
- case TK_A_OWNER_ID:
- dbg(rules->udev, "%s %s %u\n", token_str[type], operation_str[op], token->key.uid);
- break;
- case TK_A_GROUP_ID:
- dbg(rules->udev, "%s %s %u\n", token_str[type], operation_str[op], token->key.gid);