chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
udev: don't close std{in,out,err}
[elogind.git]
/
src
/
udev
/
udev-rules.c
diff --git
a/src/udev/udev-rules.c
b/src/udev/udev-rules.c
index 855a4e4060f4d8ff24889253be341e2e95ac71b2..db95442fda916730f1fb392ded5cecf64629e336 100644
(file)
--- a/
src/udev/udev-rules.c
+++ b/
src/udev/udev-rules.c
@@
-82,7
+82,7
@@
static unsigned int rules_add_string(struct udev_rules *rules, const char *s) {
return strbuf_add_string(rules->strbuf, s, strlen(s));
}
return strbuf_add_string(rules->strbuf, s, strlen(s));
}
-/* KEY=="", KEY!="", KEY+="", KEY="", KEY:="" */
+/* KEY=="", KEY!="", KEY+="", KEY
-="", KEY
="", KEY:="" */
enum operation_type {
OP_UNSET,
enum operation_type {
OP_UNSET,
@@
-91,6
+91,7
@@
enum operation_type {
OP_MATCH_MAX,
OP_ADD,
OP_MATCH_MAX,
OP_ADD,
+ OP_REMOVE,
OP_ASSIGN,
OP_ASSIGN_FINAL,
};
OP_ASSIGN,
OP_ASSIGN_FINAL,
};
@@
-137,7
+138,6
@@
enum token_type {
TK_M_PARENTS_MAX,
TK_M_TEST, /* val, mode_t */
TK_M_PARENTS_MAX,
TK_M_TEST, /* val, mode_t */
- TK_M_EVENT_TIMEOUT, /* int */
TK_M_PROGRAM, /* val */
TK_M_IMPORT_FILE, /* val */
TK_M_IMPORT_PROG, /* val */
TK_M_PROGRAM, /* val */
TK_M_IMPORT_FILE, /* val */
TK_M_IMPORT_PROG, /* val */
@@
-201,7
+201,6
@@
struct token {
uid_t uid;
gid_t gid;
int devlink_prio;
uid_t uid;
gid_t gid;
int devlink_prio;
- int event_timeout;
int watch;
enum udev_builtin_cmd builtin_cmd;
};
int watch;
enum udev_builtin_cmd builtin_cmd;
};
@@
-218,8
+217,7
@@
struct rule_tmp {
};
#ifdef DEBUG
};
#ifdef DEBUG
-static const char *operation_str(enum operation_type type)
-{
+static const char *operation_str(enum operation_type type) {
static const char *operation_strs[] = {
[OP_UNSET] = "UNSET",
[OP_MATCH] = "match",
static const char *operation_strs[] = {
[OP_UNSET] = "UNSET",
[OP_MATCH] = "match",
@@
-227,6
+225,7
@@
static const char *operation_str(enum operation_type type)
[OP_MATCH_MAX] = "MATCH_MAX",
[OP_ADD] = "add",
[OP_MATCH_MAX] = "MATCH_MAX",
[OP_ADD] = "add",
+ [OP_REMOVE] = "remove",
[OP_ASSIGN] = "assign",
[OP_ASSIGN_FINAL] = "assign-final",
} ;
[OP_ASSIGN] = "assign",
[OP_ASSIGN_FINAL] = "assign-final",
} ;
@@
-234,8
+233,7
@@
static const char *operation_str(enum operation_type type)
return operation_strs[type];
}
return operation_strs[type];
}
-static const char *string_glob_str(enum string_glob_type type)
-{
+static const char *string_glob_str(enum string_glob_type type) {
static const char *string_glob_strs[] = {
[GL_UNSET] = "UNSET",
[GL_PLAIN] = "plain",
static const char *string_glob_strs[] = {
[GL_UNSET] = "UNSET",
[GL_PLAIN] = "plain",
@@
-248,8
+246,7
@@
static const char *string_glob_str(enum string_glob_type type)
return string_glob_strs[type];
}
return string_glob_strs[type];
}
-static const char *token_str(enum token_type type)
-{
+static const char *token_str(enum token_type type) {
static const char *token_strs[] = {
[TK_UNSET] = "UNSET",
[TK_RULE] = "RULE",
static const char *token_strs[] = {
[TK_UNSET] = "UNSET",
[TK_RULE] = "RULE",
@@
-275,7
+272,6
@@
static const char *token_str(enum token_type type)
[TK_M_PARENTS_MAX] = "M PARENTS_MAX",
[TK_M_TEST] = "M TEST",
[TK_M_PARENTS_MAX] = "M PARENTS_MAX",
[TK_M_TEST] = "M TEST",
- [TK_M_EVENT_TIMEOUT] = "M EVENT_TIMEOUT",
[TK_M_PROGRAM] = "M PROGRAM",
[TK_M_IMPORT_FILE] = "M IMPORT_FILE",
[TK_M_IMPORT_PROG] = "M IMPORT_PROG",
[TK_M_PROGRAM] = "M PROGRAM",
[TK_M_IMPORT_FILE] = "M IMPORT_FILE",
[TK_M_IMPORT_PROG] = "M IMPORT_PROG",
@@
-314,8
+310,7
@@
static const char *token_str(enum token_type type)
return token_strs[type];
}
return token_strs[type];
}
-static void dump_token(struct udev_rules *rules, struct token *token)
-{
+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;
enum token_type type = token->type;
enum operation_type op = token->key.op;
enum string_glob_type glob = token->key.glob;
@@
-409,9
+404,6
@@
static void dump_token(struct udev_rules *rules, struct token *token)
case TK_A_SECLABEL:
log_debug("%s %s '%s' '%s'", token_str(type), operation_str(op), attr, value);
break;
case TK_A_SECLABEL:
log_debug("%s %s '%s' '%s'", token_str(type), operation_str(op), attr, value);
break;
- case TK_M_EVENT_TIMEOUT:
- log_debug("%s %u", token_str(type), token->key.event_timeout);
- break;
case TK_A_GOTO:
log_debug("%s '%s' %u", token_str(type), value, token->key.rule_goto);
break;
case TK_A_GOTO:
log_debug("%s '%s' %u", token_str(type), value, token->key.rule_goto);
break;
@@
-427,8
+419,7
@@
static void dump_token(struct udev_rules *rules, struct token *token)
}
}
}
}
-static void dump_rules(struct udev_rules *rules)
-{
+static void dump_rules(struct udev_rules *rules) {
unsigned int i;
log_debug("dumping %u (%zu bytes) tokens, %u (%zu bytes) strings",
unsigned int i;
log_debug("dumping %u (%zu bytes) tokens, %u (%zu bytes) strings",
@@
-440,14
+431,11
@@
static void dump_rules(struct udev_rules *rules)
dump_token(rules, &rules->tokens[i]);
}
#else
dump_token(rules, &rules->tokens[i]);
}
#else
-static inline const char *operation_str(enum operation_type type) { return NULL; }
-static inline const char *token_str(enum token_type type) { return NULL; }
static inline void dump_token(struct udev_rules *rules, struct token *token) {}
static inline void dump_rules(struct udev_rules *rules) {}
#endif /* DEBUG */
static inline void dump_token(struct udev_rules *rules, struct token *token) {}
static inline void dump_rules(struct udev_rules *rules) {}
#endif /* DEBUG */
-static int add_token(struct udev_rules *rules, struct token *token)
-{
+static int add_token(struct udev_rules *rules, struct token *token) {
/* grow buffer if needed */
if (rules->token_cur+1 >= rules->token_max) {
struct token *tokens;
/* grow buffer if needed */
if (rules->token_cur+1 >= rules->token_max) {
struct token *tokens;
@@
-469,8
+457,7
@@
static int add_token(struct udev_rules *rules, struct token *token)
return 0;
}
return 0;
}
-static uid_t add_uid(struct udev_rules *rules, const char *owner)
-{
+static uid_t add_uid(struct udev_rules *rules, const char *owner) {
unsigned int i;
uid_t uid;
unsigned int off;
unsigned int i;
uid_t uid;
unsigned int off;
@@
-510,8
+497,7
@@
static uid_t add_uid(struct udev_rules *rules, const char *owner)
return uid;
}
return uid;
}
-static gid_t add_gid(struct udev_rules *rules, const char *group)
-{
+static gid_t add_gid(struct udev_rules *rules, const char *group) {
unsigned int i;
gid_t gid;
unsigned int off;
unsigned int i;
gid_t gid;
unsigned int off;
@@
-551,8
+537,7
@@
static gid_t add_gid(struct udev_rules *rules, const char *group)
return gid;
}
return gid;
}
-static int import_property_from_string(struct udev_device *dev, char *line)
-{
+static int import_property_from_string(struct udev_device *dev, char *line) {
char *key;
char *val;
size_t len;
char *key;
char *val;
size_t len;
@@
-615,8
+600,7
@@
static int import_property_from_string(struct udev_device *dev, char *line)
return 0;
}
return 0;
}
-static int import_file_into_properties(struct udev_device *dev, const char *filename)
-{
+static int import_file_into_properties(struct udev_device *dev, const char *filename) {
FILE *f;
char line[UTIL_LINE_SIZE];
FILE *f;
char line[UTIL_LINE_SIZE];
@@
-629,8
+613,10
@@
static int import_file_into_properties(struct udev_device *dev, const char *file
return 0;
}
return 0;
}
-static int import_program_into_properties(struct udev_event *event, const char *program, const sigset_t *sigmask)
-{
+static int import_program_into_properties(struct udev_event *event,
+ usec_t timeout_usec,
+ usec_t timeout_warn_usec,
+ const char *program, const sigset_t *sigmask) {
struct udev_device *dev = event->dev;
char **envp;
char result[UTIL_LINE_SIZE];
struct udev_device *dev = event->dev;
char **envp;
char result[UTIL_LINE_SIZE];
@@
-638,7
+624,7
@@
static int import_program_into_properties(struct udev_event *event, const char *
int err;
envp = udev_device_get_properties_envp(dev);
int err;
envp = udev_device_get_properties_envp(dev);
- err = udev_event_spawn(event, program, envp, sigmask, result, sizeof(result));
+ err = udev_event_spawn(event,
timeout_usec, timeout_warn_usec,
program, envp, sigmask, result, sizeof(result));
if (err < 0)
return err;
if (err < 0)
return err;
@@
-657,8
+643,7
@@
static int import_program_into_properties(struct udev_event *event, const char *
return 0;
}
return 0;
}
-static int import_parent_into_properties(struct udev_device *dev, const char *filter)
-{
+static int import_parent_into_properties(struct udev_device *dev, const char *filter) {
struct udev_device *dev_parent;
struct udev_list_entry *list_entry;
struct udev_device *dev_parent;
struct udev_list_entry *list_entry;
@@
-683,8
+668,7
@@
static int import_parent_into_properties(struct udev_device *dev, const char *fi
}
#define WAIT_LOOP_PER_SECOND 50
}
#define WAIT_LOOP_PER_SECOND 50
-static int wait_for_file(struct udev_device *dev, const char *file, int timeout)
-{
+static int wait_for_file(struct udev_device *dev, const char *file, int timeout) {
char filepath[UTIL_PATH_SIZE];
char devicepath[UTIL_PATH_SIZE];
struct stat stats;
char filepath[UTIL_PATH_SIZE];
char devicepath[UTIL_PATH_SIZE];
struct stat stats;
@@
-718,8
+702,7
@@
static int wait_for_file(struct udev_device *dev, const char *file, int timeout)
return -1;
}
return -1;
}
-static int attr_subst_subdir(char *attr, size_t len)
-{
+static int attr_subst_subdir(char *attr, size_t len) {
bool found = false;
if (strstr(attr, "/*/")) {
bool found = false;
if (strstr(attr, "/*/")) {
@@
-756,8
+739,7
@@
static int attr_subst_subdir(char *attr, size_t len)
return found;
}
return found;
}
-static int get_key(struct udev *udev, char **line, char **key, enum operation_type *op, char **value)
-{
+static int get_key(struct udev *udev, char **line, char **key, enum operation_type *op, char **value) {
char *linepos;
char *temp;
char *linepos;
char *temp;
@@
-782,7
+764,7
@@
static int get_key(struct udev *udev, char **line, char **key, enum operation_ty
break;
if (linepos[0] == '=')
break;
break;
if (linepos[0] == '=')
break;
- if ((linepos[0] == '+') || (linepos[0] == '!') || (linepos[0] == ':'))
+ if ((linepos[0] == '+') || (linepos[0] == '
-') || (linepos[0] == '
!') || (linepos[0] == ':'))
if (linepos[1] == '=')
break;
}
if (linepos[1] == '=')
break;
}
@@
-806,6
+788,9
@@
static int get_key(struct udev *udev, char **line, char **key, enum operation_ty
} else if (linepos[0] == '+' && linepos[1] == '=') {
*op = OP_ADD;
linepos += 2;
} else if (linepos[0] == '+' && linepos[1] == '=') {
*op = OP_ADD;
linepos += 2;
+ } else if (linepos[0] == '-' && linepos[1] == '=') {
+ *op = OP_REMOVE;
+ linepos += 2;
} else if (linepos[0] == '=') {
*op = OP_ASSIGN;
linepos++;
} else if (linepos[0] == '=') {
*op = OP_ASSIGN;
linepos++;
@@
-844,8
+829,7
@@
static int get_key(struct udev *udev, char **line, char **key, enum operation_ty
}
/* extract possible KEY{attr} */
}
/* extract possible KEY{attr} */
-static const char *get_key_attribute(struct udev *udev, char *str)
-{
+static const char *get_key_attribute(struct udev *udev, char *str) {
char *pos;
char *attr;
char *pos;
char *attr;
@@
-865,12
+849,11
@@
static const char *get_key_attribute(struct udev *udev, char *str)
static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
enum operation_type op,
static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
enum operation_type op,
- const char *value, const void *data)
-{
+ const char *value, const void *data) {
struct token *token = &rule_tmp->token[rule_tmp->token_cur];
const char *attr = NULL;
struct token *token = &rule_tmp->token[rule_tmp->token_cur];
const char *attr = NULL;
- mem
set(token, 0x00
, sizeof(struct token));
+ mem
zero(token
, sizeof(struct token));
switch (type) {
case TK_M_ACTION:
switch (type) {
case TK_M_ACTION:
@@
-944,9
+927,6
@@
static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
case TK_A_MODE_ID:
token->key.mode = *(mode_t *)data;
break;
case TK_A_MODE_ID:
token->key.mode = *(mode_t *)data;
break;
- case TK_M_EVENT_TIMEOUT:
- token->key.event_timeout = *(int *)data;
- break;
case TK_RULE:
case TK_M_PARENTS_MIN:
case TK_M_PARENTS_MAX:
case TK_RULE:
case TK_M_PARENTS_MIN:
case TK_M_PARENTS_MAX:
@@
-1010,8
+990,7
@@
static int rule_add_key(struct rule_tmp *rule_tmp, enum token_type type,
return 0;
}
return 0;
}
-static int sort_token(struct udev_rules *rules, struct rule_tmp *rule_tmp)
-{
+static int sort_token(struct udev_rules *rules, struct rule_tmp *rule_tmp) {
unsigned int i;
unsigned int start = 0;
unsigned int end = rule_tmp->token_cur;
unsigned int i;
unsigned int start = 0;
unsigned int end = rule_tmp->token_cur;
@@
-1046,13
+1025,12
@@
static int sort_token(struct udev_rules *rules, struct rule_tmp *rule_tmp)
}
static int add_rule(struct udev_rules *rules, char *line,
}
static int add_rule(struct udev_rules *rules, char *line,
- const char *filename, unsigned int filename_off, unsigned int lineno)
-{
+ const char *filename, unsigned int filename_off, unsigned int lineno) {
char *linepos;
const char *attr;
struct rule_tmp rule_tmp;
char *linepos;
const char *attr;
struct rule_tmp rule_tmp;
- mem
set(&rule_tmp, 0x00
, sizeof(struct rule_tmp));
+ mem
zero(&rule_tmp
, sizeof(struct rule_tmp));
rule_tmp.rules = rules;
rule_tmp.rule.type = TK_RULE;
/* the offset in the rule is limited to unsigned short */
rule_tmp.rules = rules;
rule_tmp.rule.type = TK_RULE;
/* the offset in the rule is limited to unsigned short */
@@
-1144,11
+1122,15
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "ATTR{")) {
}
if (startswith(key, "ATTR{")) {
- attr = get_key_attribute(rules->udev, key + s
izeof("ATTR")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("ATTR")
);
if (attr == NULL) {
log_error("error parsing ATTR attribute");
goto invalid;
}
if (attr == NULL) {
log_error("error parsing ATTR attribute");
goto invalid;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid ATTR operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX) {
rule_add_key(&rule_tmp, TK_M_ATTR, op, value, attr);
} else {
if (op < OP_MATCH_MAX) {
rule_add_key(&rule_tmp, TK_M_ATTR, op, value, attr);
} else {
@@
-1158,11
+1140,15
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "SECLABEL{")) {
}
if (startswith(key, "SECLABEL{")) {
- attr = get_key_attribute(rules->udev, key + s
izeof("SECLABEL")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("SECLABEL")
);
if (!attr) {
log_error("error parsing SECLABEL attribute");
goto invalid;
}
if (!attr) {
log_error("error parsing SECLABEL attribute");
goto invalid;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid SECLABEL operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_A_SECLABEL, op, value, attr);
continue;
rule_add_key(&rule_tmp, TK_A_SECLABEL, op, value, attr);
continue;
@@
-1200,7
+1186,7
@@
static int add_rule(struct udev_rules *rules, char *line,
log_error("invalid ATTRS operation");
goto invalid;
}
log_error("invalid ATTRS operation");
goto invalid;
}
- attr = get_key_attribute(rules->udev, key + s
izeof("ATTRS")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("ATTRS")
);
if (attr == NULL) {
log_error("error parsing ATTRS attribute");
goto invalid;
if (attr == NULL) {
log_error("error parsing ATTRS attribute");
goto invalid;
@@
-1225,11
+1211,15
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "ENV{")) {
}
if (startswith(key, "ENV{")) {
- attr = get_key_attribute(rules->udev, key + s
izeof("ENV")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("ENV")
);
if (attr == NULL) {
log_error("error parsing ENV attribute");
goto invalid;
}
if (attr == NULL) {
log_error("error parsing ENV attribute");
goto invalid;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid ENV operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX) {
if (rule_add_key(&rule_tmp, TK_M_ENV, op, value, attr) != 0)
goto invalid;
if (op < OP_MATCH_MAX) {
if (rule_add_key(&rule_tmp, TK_M_ENV, op, value, attr) != 0)
goto invalid;
@@
-1270,6
+1260,10
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (streq(key, "PROGRAM")) {
}
if (streq(key, "PROGRAM")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid PROGRAM operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_M_PROGRAM, op, value, NULL);
continue;
}
rule_add_key(&rule_tmp, TK_M_PROGRAM, op, value, NULL);
continue;
}
@@
-1284,11
+1278,15
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "IMPORT")) {
}
if (startswith(key, "IMPORT")) {
- attr = get_key_attribute(rules->udev, key + s
izeof("IMPORT")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("IMPORT")
);
if (attr == NULL) {
log_error("IMPORT{} type missing, ignoring IMPORT %s:%u", filename, lineno);
continue;
}
if (attr == NULL) {
log_error("IMPORT{} type missing, ignoring IMPORT %s:%u", filename, lineno);
continue;
}
+ if (op == OP_REMOVE) {
+ log_error("invalid IMPORT operation");
+ goto invalid;
+ }
if (streq(attr, "program")) {
/* find known built-in command */
if (value[0] != '/') {
if (streq(attr, "program")) {
/* find known built-in command */
if (value[0] != '/') {
@@
-1330,7
+1328,7
@@
static int add_rule(struct udev_rules *rules, char *line,
log_error("invalid TEST operation");
goto invalid;
}
log_error("invalid TEST operation");
goto invalid;
}
- attr = get_key_attribute(rules->udev, key + s
izeof("TEST")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("TEST")
);
if (attr != NULL) {
mode = strtol(attr, NULL, 8);
rule_add_key(&rule_tmp, TK_M_TEST, op, value, &mode);
if (attr != NULL) {
mode = strtol(attr, NULL, 8);
rule_add_key(&rule_tmp, TK_M_TEST, op, value, &mode);
@@
-1341,9
+1339,13
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (startswith(key, "RUN")) {
}
if (startswith(key, "RUN")) {
- attr = get_key_attribute(rules->udev, key + s
izeof("RUN")-1
);
+ attr = get_key_attribute(rules->udev, key + s
trlen("RUN")
);
if (attr == NULL)
attr = "program";
if (attr == NULL)
attr = "program";
+ if (op == OP_REMOVE) {
+ log_error("invalid RUN operation");
+ goto invalid;
+ }
if (streq(attr, "builtin")) {
enum udev_builtin_cmd cmd = udev_builtin_lookup(value);
if (streq(attr, "builtin")) {
enum udev_builtin_cmd cmd = udev_builtin_lookup(value);
@@
-1351,7
+1353,7
@@
static int add_rule(struct udev_rules *rules, char *line,
if (cmd < UDEV_BUILTIN_MAX)
rule_add_key(&rule_tmp, TK_A_RUN_BUILTIN, op, value, &cmd);
else
if (cmd < UDEV_BUILTIN_MAX)
rule_add_key(&rule_tmp, TK_A_RUN_BUILTIN, op, value, &cmd);
else
- log_error("
IMPORT
{builtin}: '%s' unknown %s:%u", value, filename, lineno);
+ log_error("
RUN
{builtin}: '%s' unknown %s:%u", value, filename, lineno);
} else if (streq(attr, "program")) {
enum udev_builtin_cmd cmd = UDEV_BUILTIN_MAX;
} else if (streq(attr, "program")) {
enum udev_builtin_cmd cmd = UDEV_BUILTIN_MAX;
@@
-1364,21
+1366,37
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (streq(key, "WAIT_FOR") || streq(key, "WAIT_FOR_SYSFS")) {
}
if (streq(key, "WAIT_FOR") || streq(key, "WAIT_FOR_SYSFS")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid WAIT_FOR/WAIT_FOR_SYSFS operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_M_WAITFOR, 0, value, NULL);
continue;
}
if (streq(key, "LABEL")) {
rule_add_key(&rule_tmp, TK_M_WAITFOR, 0, value, NULL);
continue;
}
if (streq(key, "LABEL")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid LABEL operation");
+ goto invalid;
+ }
rule_tmp.rule.rule.label_off = rules_add_string(rules, value);
continue;
}
if (streq(key, "GOTO")) {
rule_tmp.rule.rule.label_off = rules_add_string(rules, value);
continue;
}
if (streq(key, "GOTO")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid GOTO operation");
+ goto invalid;
+ }
rule_add_key(&rule_tmp, TK_A_GOTO, 0, value, NULL);
continue;
}
if (startswith(key, "NAME")) {
rule_add_key(&rule_tmp, TK_A_GOTO, 0, value, NULL);
continue;
}
if (startswith(key, "NAME")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid NAME operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX) {
rule_add_key(&rule_tmp, TK_M_NAME, op, value, NULL);
} else {
if (op < OP_MATCH_MAX) {
rule_add_key(&rule_tmp, TK_M_NAME, op, value, NULL);
} else {
@@
-1399,6
+1417,10
@@
static int add_rule(struct udev_rules *rules, char *line,
}
if (streq(key, "SYMLINK")) {
}
if (streq(key, "SYMLINK")) {
+ if (op == OP_REMOVE) {
+ log_error("invalid SYMLINK operation");
+ goto invalid;
+ }
if (op < OP_MATCH_MAX)
rule_add_key(&rule_tmp, TK_M_DEVLINK, op, value, NULL);
else
if (op < OP_MATCH_MAX)
rule_add_key(&rule_tmp, TK_M_DEVLINK, op, value, NULL);
else
@@
-1411,6
+1433,11
@@
static int add_rule(struct udev_rules *rules, char *line,
uid_t uid;
char *endptr;
uid_t uid;
char *endptr;
+ if (op == OP_REMOVE) {
+ log_error("invalid OWNER operation");
+ goto invalid;
+ }
+
uid = strtoul(value, &endptr, 10);
if (endptr[0] == '\0') {
rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid);
uid = strtoul(value, &endptr, 10);
if (endptr[0] == '\0') {
rule_add_key(&rule_tmp, TK_A_OWNER_ID, op, NULL, &uid);
@@
-1428,6
+1455,11
@@
static int add_rule(struct udev_rules *rules, char *line,
gid_t gid;
char *endptr;
gid_t gid;
char *endptr;
+ if (op == OP_REMOVE) {
+ log_error("invalid GROUP operation");
+ goto invalid;
+ }
+
gid = strtoul(value, &endptr, 10);
if (endptr[0] == '\0') {
rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid);
gid = strtoul(value, &endptr, 10);
if (endptr[0] == '\0') {
rule_add_key(&rule_tmp, TK_A_GROUP_ID, op, NULL, &gid);
@@
-1445,6
+1477,11
@@
static int add_rule(struct udev_rules *rules, char *line,
mode_t mode;
char *endptr;
mode_t mode;
char *endptr;
+ if (op == OP_REMOVE) {
+ log_error("invalid MODE operation");
+ goto invalid;
+ }
+
mode = strtol(value, &endptr, 8);
if (endptr[0] == '\0')
rule_add_key(&rule_tmp, TK_A_MODE_ID, op, NULL, &mode);
mode = strtol(value, &endptr, 8);
if (endptr[0] == '\0')
rule_add_key(&rule_tmp, TK_A_MODE_ID, op, NULL, &mode);
@@
-1457,6
+1494,11
@@
static int add_rule(struct udev_rules *rules, char *line,
if (streq(key, "OPTIONS")) {
const char *pos;
if (streq(key, "OPTIONS")) {
const char *pos;
+ if (op == OP_REMOVE) {
+ log_error("invalid OPTIONS operation");
+ goto invalid;
+ }
+
pos = strstr(value, "link_priority=");
if (pos != NULL) {
int prio = atoi(&pos[strlen("link_priority=")]);
pos = strstr(value, "link_priority=");
if (pos != NULL) {
int prio = atoi(&pos[strlen("link_priority=")]);
@@
-1464,13
+1506,6
@@
static int add_rule(struct udev_rules *rules, char *line,
rule_add_key(&rule_tmp, TK_A_DEVLINK_PRIO, op, NULL, &prio);
}
rule_add_key(&rule_tmp, TK_A_DEVLINK_PRIO, op, NULL, &prio);
}
- pos = strstr(value, "event_timeout=");
- if (pos != NULL) {
- int tout = atoi(&pos[strlen("event_timeout=")]);
-
- rule_add_key(&rule_tmp, TK_M_EVENT_TIMEOUT, op, NULL, &tout);
- }
-
pos = strstr(value, "string_escape=");
if (pos != NULL) {
pos = &pos[strlen("string_escape=")];
pos = strstr(value, "string_escape=");
if (pos != NULL) {
pos = &pos[strlen("string_escape=")];
@@
-1526,8
+1561,7
@@
invalid:
return -1;
}
return -1;
}
-static int parse_file(struct udev_rules *rules, const char *filename)
-{
+static int parse_file(struct udev_rules *rules, const char *filename) {
FILE *f;
unsigned int first_token;
unsigned int filename_off;
FILE *f;
unsigned int first_token;
unsigned int filename_off;
@@
-1535,15
+1569,19
@@
static int parse_file(struct udev_rules *rules, const char *filename)
int line_nr = 0;
unsigned int i;
int line_nr = 0;
unsigned int i;
- if (null_or_empty_path(filename)) {
- log_debug("skip empty file: %s", filename);
- return 0;
+ f = fopen(filename, "re");
+ if (!f) {
+ if (errno == ENOENT)
+ return 0;
+ else
+ return -errno;
}
}
- log_debug("read rules file: %s", filename);
- f = fopen(filename, "re");
- if (f == NULL)
- return -1;
+ if (null_or_empty_fd(fileno(f))) {
+ log_debug("Skipping empty file: %s", filename);
+ return 0;
+ } else
+ log_debug("Reading rules file: %s", filename);
first_token = rules->token_cur;
filename_off = rules_add_string(rules, filename);
first_token = rules->token_cur;
filename_off = rules_add_string(rules, filename);
@@
-1607,15
+1645,14
@@
static int parse_file(struct udev_rules *rules, const char *filename)
return 0;
}
return 0;
}
-struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
-{
+struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names) {
struct udev_rules *rules;
struct udev_list file_list;
struct token end_token;
char **files, **f;
int r;
struct udev_rules *rules;
struct udev_list file_list;
struct token end_token;
char **files, **f;
int r;
- rules =
calloc(1, sizeof(struct udev_rules)
);
+ rules =
new0(struct udev_rules, 1
);
if (rules == NULL)
return NULL;
rules->udev = udev;
if (rules == NULL)
return NULL;
rules->udev = udev;
@@
-1652,7
+1689,7
@@
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
strv_free(files);
strv_free(files);
- mem
set(&end_token, 0x00
, sizeof(struct token));
+ mem
zero(&end_token
, sizeof(struct token));
end_token.type = TK_END;
add_token(rules, &end_token);
log_debug("rules contain %zu bytes tokens (%u * %zu bytes), %zu bytes strings",
end_token.type = TK_END;
add_token(rules, &end_token);
log_debug("rules contain %zu bytes tokens (%u * %zu bytes), %zu bytes strings",
@@
-1678,8
+1715,7
@@
struct udev_rules *udev_rules_new(struct udev *udev, int resolve_names)
return rules;
}
return rules;
}
-struct udev_rules *udev_rules_unref(struct udev_rules *rules)
-{
+struct udev_rules *udev_rules_unref(struct udev_rules *rules) {
if (rules == NULL)
return NULL;
free(rules->tokens);
if (rules == NULL)
return NULL;
free(rules->tokens);
@@
-1690,16
+1726,14
@@
struct udev_rules *udev_rules_unref(struct udev_rules *rules)
return NULL;
}
return NULL;
}
-bool udev_rules_check_timestamp(struct udev_rules *rules)
-{
+bool udev_rules_check_timestamp(struct udev_rules *rules) {
if (!rules)
return false;
return paths_check_timestamp(rules_dirs, &rules->dirs_ts_usec, true);
}
if (!rules)
return false;
return paths_check_timestamp(rules_dirs, &rules->dirs_ts_usec, true);
}
-static int match_key(struct udev_rules *rules, struct token *token, const char *val)
-{
+static int match_key(struct udev_rules *rules, struct token *token, const char *val) {
char *key_value = rules_str(rules, token->key.value_off);
char *pos;
bool match = false;
char *key_value = rules_str(rules, token->key.value_off);
char *pos;
bool match = false;
@@
-1772,8
+1806,7
@@
static int match_key(struct udev_rules *rules, struct token *token, const char *
return -1;
}
return -1;
}
-static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct udev_event *event, struct token *cur)
-{
+static int match_attr(struct udev_rules *rules, struct udev_device *dev, struct udev_event *event, struct token *cur) {
const char *name;
char nbuf[UTIL_NAME_SIZE];
const char *value;
const char *name;
char nbuf[UTIL_NAME_SIZE];
const char *value;
@@
-1827,8
+1860,11
@@
enum escape_type {
ESCAPE_REPLACE,
};
ESCAPE_REPLACE,
};
-int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event, const sigset_t *sigmask)
-{
+int udev_rules_apply_to_event(struct udev_rules *rules,
+ struct udev_event *event,
+ usec_t timeout_usec,
+ usec_t timeout_warn_usec,
+ const sigset_t *sigmask) {
struct token *cur;
struct token *rule;
enum escape_type esc = ESCAPE_UNSET;
struct token *cur;
struct token *rule;
enum escape_type esc = ESCAPE_UNSET;
@@
-2022,14
+2058,10
@@
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
goto nomatch;
break;
}
goto nomatch;
break;
}
- case TK_M_EVENT_TIMEOUT:
- log_debug("OPTIONS event_timeout=%u", cur->key.event_timeout);
- event->timeout_usec = cur->key.event_timeout * 1000 * 1000;
- break;
case TK_M_PROGRAM: {
char program[UTIL_PATH_SIZE];
char **envp;
case TK_M_PROGRAM: {
char program[UTIL_PATH_SIZE];
char **envp;
- char result[UTIL_
PATH
_SIZE];
+ char result[UTIL_
LINE
_SIZE];
free(event->program_result);
event->program_result = NULL;
free(event->program_result);
event->program_result = NULL;
@@
-2040,7
+2072,7
@@
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
rules_str(rules, rule->rule.filename_off),
rule->rule.filename_line);
rules_str(rules, rule->rule.filename_off),
rule->rule.filename_line);
- if (udev_event_spawn(event, program, envp, sigmask, result, sizeof(result)) < 0) {
+ if (udev_event_spawn(event,
timeout_usec, timeout_warn_usec,
program, envp, sigmask, result, sizeof(result)) < 0) {
if (cur->key.op != OP_NOMATCH)
goto nomatch;
} else {
if (cur->key.op != OP_NOMATCH)
goto nomatch;
} else {
@@
-2076,7
+2108,7
@@
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
rules_str(rules, rule->rule.filename_off),
rule->rule.filename_line);
rules_str(rules, rule->rule.filename_off),
rule->rule.filename_line);
- if (import_program_into_properties(event, import, sigmask) != 0)
+ if (import_program_into_properties(event,
timeout_usec, timeout_warn_usec,
import, sigmask) != 0)
if (cur->key.op != OP_NOMATCH)
goto nomatch;
break;
if (cur->key.op != OP_NOMATCH)
goto nomatch;
break;
@@
-2359,7
+2391,10
@@
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
log_error("ignoring invalid tag name '%s'", tag);
break;
}
log_error("ignoring invalid tag name '%s'", tag);
break;
}
- udev_device_add_tag(event->dev, tag);
+ if (cur->key.op == OP_REMOVE)
+ udev_device_remove_tag(event->dev, tag);
+ else
+ udev_device_add_tag(event->dev, tag);
break;
}
case TK_A_NAME: {
break;
}
case TK_A_NAME: {
@@
-2501,8
+2536,7
@@
int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
}
}
}
}
-int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
-{
+int udev_rules_apply_static_dev_perms(struct udev_rules *rules) {
struct token *cur;
struct token *rule;
uid_t uid = 0;
struct token *cur;
struct token *rule;
uid_t uid = 0;
@@
-2557,10
+2591,15
@@
int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
struct stat stats;
/* we assure, that the permissions tokens are sorted before the static token */
struct stat stats;
/* we assure, that the permissions tokens are sorted before the static token */
+
if (mode == 0 && uid == 0 && gid == 0 && tags == NULL)
goto next;
strscpyl(device_node, sizeof(device_node), "/dev/", rules_str(rules, cur->key.value_off), NULL);
if (mode == 0 && uid == 0 && gid == 0 && tags == NULL)
goto next;
strscpyl(device_node, sizeof(device_node), "/dev/", rules_str(rules, cur->key.value_off), NULL);
+ if (stat(device_node, &stats) != 0)
+ break;
+ if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode))
+ break;
/* export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
if (tags) {
/* export the tags to a directory as symlinks, allowing otherwise dead nodes to be tagged */
if (tags) {
@@
-2590,11
+2629,6
@@
int udev_rules_apply_static_dev_perms(struct udev_rules *rules)
if (mode == 0 && uid == 0 && gid == 0)
break;
if (mode == 0 && uid == 0 && gid == 0)
break;
- if (stat(device_node, &stats) != 0)
- break;
- if (!S_ISBLK(stats.st_mode) && !S_ISCHR(stats.st_mode))
- break;
-
if (mode == 0) {
if (gid > 0)
mode = 0660;
if (mode == 0) {
if (gid > 0)
mode = 0660;