From 74c73ef994f3ea8d013c33fe7be73e0c0c86977b Mon Sep 17 00:00:00 2001 From: "hannal@us.ibm.com" Date: Mon, 19 Jan 2004 19:42:42 -0800 Subject: [PATCH] [PATCH] set default owner/group in db. This patch fixes a bug where the udev database stored empty strings for Owner and Group if they were default. This patch stores the default value into the database if not set otherwise. See example output: crw------- 1 root root 4, 65 Jan 16 11:13 ttyS1 P: /class/tty/ttyS1 N: ttyS1 S: O: root G: root This is a bit of a hack. However, until udev supports setting the o/g values they will be root/root anyway so the database might as well reflect the truth instead of empty strings. --- namedev.c | 20 ++++++++++++++++++-- udev.h | 2 ++ udev_config.c | 4 ++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/namedev.c b/namedev.c index 137446e2..e39207e6 100644 --- a/namedev.c +++ b/namedev.c @@ -151,6 +151,22 @@ static mode_t get_default_mode(struct sysfs_class_device *class_dev) return mode; } +static char * get_default_owner(void) +{ + if (strlen(default_owner_str) == 0) { + strncpy(default_owner_str, "root", OWNER_SIZE); + } + return default_owner_str; +} + +static char * get_default_group(void) +{ + if (strlen(default_group_str) == 0) { + strncpy(default_group_str, "root", GROUP_SIZE); + } + return default_group_str; +} + static void apply_format(struct udevice *udev, unsigned char *string) { char temp[NAME_SIZE]; @@ -720,8 +736,8 @@ done: } else { /* no matching perms found :( */ udev->mode = get_default_mode(class_dev); - udev->owner[0] = 0x00; - udev->group[0] = 0x00; + strncpy(udev->owner, get_default_owner(), OWNER_SIZE); + strncpy(udev->group, get_default_group(), GROUP_SIZE); } dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o", udev->name, udev->owner, udev->group, udev->mode); diff --git a/udev.h b/udev.h index 90aa8239..963f8d25 100644 --- a/udev.h +++ b/udev.h @@ -68,5 +68,7 @@ extern char udev_permissions_filename[PATH_MAX+NAME_MAX]; extern char udev_config_filename[PATH_MAX+NAME_MAX]; extern char udev_rules_filename[PATH_MAX+NAME_MAX]; extern char default_mode_str[NAME_MAX]; +extern char default_owner_str[OWNER_SIZE]; +extern char default_group_str[GROUP_SIZE]; #endif diff --git a/udev_config.c b/udev_config.c index 44b5767b..d262f2af 100644 --- a/udev_config.c +++ b/udev_config.c @@ -46,6 +46,8 @@ char udev_permissions_filename[PATH_MAX+NAME_MAX]; char udev_rules_filename[PATH_MAX+NAME_MAX]; char udev_config_filename[PATH_MAX+NAME_MAX]; char default_mode_str[NAME_MAX]; +char default_owner_str[OWNER_SIZE]; +char default_group_str[GROUP_SIZE]; static void init_variables(void) @@ -117,6 +119,8 @@ static int parse_config_file(void) set_var("udev_rules", udev_rules_filename); set_var("udev_permissions", udev_permissions_filename); set_var("default_mode", default_mode_str); + set_var("default_owner", default_owner_str); + set_var("default_group", default_group_str); } dbg_parse("%s:%d:%Zd: error parsing '%s'", udev_config_filename, lineno, temp - line, temp); -- 2.39.5