summaryrefslogtreecommitdiff
path: root/udev
diff options
context:
space:
mode:
Diffstat (limited to 'udev')
-rw-r--r--udev/udev-event.c16
-rw-r--r--udev/udev-rules.c18
-rw-r--r--udev/udev.h1
3 files changed, 24 insertions, 11 deletions
diff --git a/udev/udev-event.c b/udev/udev-event.c
index 4c51ed58e5..832abbbfce 100644
--- a/udev/udev-event.c
+++ b/udev/udev-event.c
@@ -43,7 +43,6 @@ struct udev_event *udev_event_new(struct udev_device *dev)
event = calloc(1, sizeof(struct udev_event));
if (event == NULL)
return NULL;
- event->mode = 0600;
event->dev = dev;
event->udev = udev_device_get_udev(dev);
udev_list_init(&event->run_list);
@@ -1021,9 +1020,18 @@ int udev_event_execute_rules(struct udev_event *event, struct udev_rules *rules,
if (event->dev_db != NULL)
udev_node_update_old_links(dev, event->dev_db);
- /* change default 0600 to 0660 if a group is assigned */
- if (event->mode == 0600 && event->gid > 0)
- event->mode = 0660;
+ if (!event->mode_set) {
+ if (udev_device_get_devnode_mode(dev) > 0) {
+ /* kernel supplied value */
+ event->mode = udev_device_get_devnode_mode(dev);
+ } else if (event->gid > 0) {
+ /* default 0660 if a group is assigned */
+ event->mode = 0660;
+ } else {
+ /* default 0600 */
+ event->mode = 0600;
+ }
+ }
err = udev_node_add(dev, event->mode, event->uid, event->gid);
}
diff --git a/udev/udev-rules.c b/udev/udev-rules.c
index 892d8f27a7..63123e083a 100644
--- a/udev/udev-rules.c
+++ b/udev/udev-rules.c
@@ -2443,19 +2443,22 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
}
case TK_A_MODE:
{
- char mode[UTIL_NAME_SIZE];
+ char mode_str[UTIL_NAME_SIZE];
+ mode_t mode;
char *endptr;
if (event->mode_final)
break;
- if (cur->key.op == OP_ASSIGN_FINAL)
- event->mode_final = true;
- udev_event_apply_format(event, &rules->buf[cur->key.value_off], mode, sizeof(mode));
- event->mode = strtol(mode, &endptr, 8);
+ udev_event_apply_format(event, &rules->buf[cur->key.value_off], mode_str, sizeof(mode_str));
+ mode = strtol(mode_str, &endptr, 8);
if (endptr[0] != '\0') {
- err(event->udev, "invalide mode '%s' set default mode 0600\n", mode);
- event->mode = 0600;
+ err(event->udev, "ignoring invalid mode '%s'\n", mode_str);
+ break;
}
+ if (cur->key.op == OP_ASSIGN_FINAL)
+ event->mode_final = true;
+ event->mode_set = true;
+ event->mode = mode;
info(event->udev, "MODE %#o %s:%u\n",
event->mode,
&rules->buf[rule->rule.filename_off],
@@ -2489,6 +2492,7 @@ int udev_rules_apply_to_event(struct udev_rules *rules, struct udev_event *event
break;
if (cur->key.op == OP_ASSIGN_FINAL)
event->mode_final = true;
+ event->mode_set = true;
event->mode = cur->key.mode;
info(event->udev, "MODE %#o %s:%u\n",
event->mode,
diff --git a/udev/udev.h b/udev/udev.h
index 16a029e486..88c32ec203 100644
--- a/udev/udev.h
+++ b/udev/udev.h
@@ -49,6 +49,7 @@ struct udev_event {
bool inotify_watch_final;
bool group_final;
bool owner_final;
+ bool mode_set;
bool mode_final;
bool name_final;
bool devlink_final;