TK_M_ATTR, /* string, takes filename through attribute, sd_device_get_sysattr_value(), util_resolve_subsys_kernel(), etc. */
TK_M_SYSCTL, /* string, takes kernel parameter through attribute */
- /* matches parent paramters */
+ /* matches parent parameters */
TK_M_PARENTS_KERNEL, /* string */
TK_M_PARENTS_SUBSYSTEM, /* string */
TK_M_PARENTS_DRIVER, /* string */
if (op == OP_REMOVE)
return log_token_invalid_op(rules, key);
if (!is_match) {
- if (op == OP_ASSIGN)
- log_token_debug(rules, "Operator '=' is specified to %s key, assuming '=='.", key);
- else
- log_token_warning(rules, "%s key takes '==' or '!=' operator, assuming '==', but please fix it.", key);
+ log_token_debug(rules, "%s key takes '==' or '!=' operator, assuming '=='.", key);
op = OP_MATCH;
}
if (op == OP_REMOVE)
return log_token_invalid_op(rules, key);
if (!is_match) {
- if (op == OP_ASSIGN)
- log_token_debug(rules, "Operator '=' is specified to %s key, assuming '=='.", key);
- else
- log_token_warning(rules, "%s key takes '==' or '!=' operator, assuming '==', but please fix it.", key);
+ log_token_debug(rules, "%s key takes '==' or '!=' operator, assuming '=='.", key);
op = OP_MATCH;
}
op = OP_ASSIGN;
}
- r = rule_line_add_token(rule_line, TK_A_SECLABEL, op, value, NULL);
+ r = rule_line_add_token(rule_line, TK_A_SECLABEL, op, value, attr);
} else if (streq(key, "RUN")) {
if (is_match || op == OP_REMOVE)
return log_token_invalid_op(rules, key);
if (isempty(line_str))
return 0;
- line = strdup(line_str);
+ /* We use memdup_suffix0() here, since we want to add a second NUL byte to the end, since possibly
+ * some parsers might turn this into a "nulstr", which requires an extra NUL at the end. */
+ line = memdup_suffix0(line_str, strlen(line_str) + 1);
if (!line)
return log_oom();
match = isempty(str);
break;
case MATCH_TYPE_SUBSYSTEM:
- NULSTR_FOREACH(i, "subsystem\0class\0bus\0")
- if (streq(i, str)) {
- match = true;
- break;
- }
+ match = STR_IN_SET(str, "subsystem", "class", "bus");
break;
case MATCH_TYPE_PLAIN_WITH_EMPTY:
if (isempty(str)) {
if (mode == MODE_INVALID)
return token->op == OP_MATCH;
- match = (((statbuf.st_mode ^ mode) & 07777) == 0);
+ match = (statbuf.st_mode & mode) > 0;
return token->op == (match ? OP_MATCH : OP_NOMATCH);
}
case TK_M_PROGRAM: {
log_rule_debug(dev, rules, "Running PROGRAM '%s'", buf);
r = udev_event_spawn(event, timeout_usec, true, buf, result, sizeof(result));
- if (r < 0)
- return log_rule_error_errno(dev, rules, r, "Failed to execute '%s': %m", buf);
- if (r > 0)
+ if (r != 0) {
+ if (r < 0)
+ log_rule_warning_errno(dev, rules, r, "Failed to execute '%s', ignoring: %m", buf);
+ else /* returned value is positive when program fails */
+ log_rule_debug(dev, rules, "Command \"%s\" returned %d (error), ignoring", buf, r);
return token->op == OP_NOMATCH;
+ }
delete_trailing_chars(result, "\n");
count = util_replace_chars(result, UDEV_ALLOWED_CHARS_INPUT);
log_rule_debug(dev, rules, "Importing properties from results of '%s'", buf);
r = udev_event_spawn(event, timeout_usec, true, buf, result, sizeof result);
- if (r < 0)
- return log_rule_error_errno(dev, rules, r, "Failed to execute '%s': %m", buf);
- if (r > 0) {
- log_rule_debug(dev, rules, "Command \"%s\" returned %d (error), ignoring", buf, r);
+ if (r != 0) {
+ if (r < 0)
+ log_rule_warning_errno(dev, rules, r, "Failed to execute '%s', ignoring: %m", buf);
+ else /* returned value is positive when program fails */
+ log_rule_debug(dev, rules, "Command \"%s\" returned %d (error), ignoring", buf, r);
return token->op == OP_NOMATCH;
}