#include <errno.h>
#include <sys/wait.h>
#include <sys/stat.h>
-#include <sys/sysinfo.h>
#include "libsysfs/sysfs/libsysfs.h"
#include "list.h"
static struct sysfs_attribute *find_sysfs_attribute(struct sysfs_class_device *class_dev, struct sysfs_device *sysfs_device, char *attr);
-LIST_HEAD(config_device_list);
-LIST_HEAD(perm_device_list);
-
-
/* compare string with pattern (supports * ? [0-9] [!A-Z]) */
static int strcmp_pattern(const char *p, const char *s)
{
return 1;
}
-static struct perm_device *find_perm_entry(const char *name)
-{
- struct perm_device *perm;
-
- list_for_each_entry(perm, &perm_device_list, node) {
- if (strcmp_pattern(perm->name, name))
- continue;
- return perm;
- }
- return NULL;
-}
-
/* extract possible {attr} and move str behind it */
static char *get_format_attribute(char **str)
{
/* check for matching result of external program */
if (dev->result[0] != '\0') {
- dbg("check for " FIELD_RESULT
- " dev->result='%s', udev->program_result='%s'",
+ dbg("check for " FIELD_RESULT " dev->result='%s', udev->program_result='%s'",
dev->result, udev->program_result);
if (strcmp_pattern(dev->result, udev->program_result) != 0) {
dbg(FIELD_RESULT " is not matching");
struct sysfs_class_device *class_dev_parent;
struct sysfs_device *sysfs_device = NULL;
struct config_device *dev;
- struct perm_device *perm;
- struct sysinfo info;
char *pos;
- udev->mode = 0;
dbg("class_dev->name='%s'", class_dev->name);
/* Figure out where the "device"-symlink is at. For char devices this will
udev->ignore_remove = dev->ignore_remove;
if (udev->type == 'n')
- goto done;
+ goto exit;
udev->partitions = dev->partitions;
- udev->mode = dev->mode;
- strfieldcpy(udev->owner, dev->owner);
- strfieldcpy(udev->group, dev->group);
+ if (dev->mode != 0000)
+ udev->mode = dev->mode;
+ if (dev->owner[0] != '\0') {
+ strfieldcpy(udev->owner, dev->owner);
+ apply_format(udev, udev->owner, sizeof(udev->owner), class_dev, sysfs_device);
+ }
+ if (dev->group[0] != '\0') {
+ strfieldcpy(udev->group, dev->group);
+ apply_format(udev, udev->group, sizeof(udev->group), class_dev, sysfs_device);
+ }
+
+ dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o",
+ udev->name, udev->owner, udev->group, udev->mode);
- goto perms;
+ goto exit;
}
}
}
/* no rule matched, so we use the kernel name */
strfieldcpy(udev->name, udev->kernel_name);
+ dbg("no rule found, use kernel name '%s'", udev->name);
- if (udev->type == 'n')
- goto done;
-
-perms:
- /* apply permissions from permissions file to empty fields */
- perm = find_perm_entry(udev->name);
- if (perm != NULL) {
- if (udev->mode == 0000)
- udev->mode = perm->mode;
- if (udev->owner[0] == '\0')
- strfieldcpy(udev->owner, perm->owner);
- if (udev->group[0] == '\0')
- strfieldcpy(udev->group, perm->group);
- }
-
- /* apply permissions from config to empty fields */
- if (udev->mode == 0000)
- udev->mode = default_mode;
- if (udev->owner[0] == '\0')
- strfieldcpy(udev->owner, default_owner);
- if (udev->group[0] == '\0')
- strfieldcpy(udev->group, default_group);
-
- dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o",
- udev->name, udev->owner, udev->group, udev->mode);
-
-done:
- /* store time of action */
- sysinfo(&info);
- udev->config_uptime = info.uptime;
-
+exit:
return 0;
}
-
-int namedev_init(void)
-{
- int retval;
-
- retval = namedev_init_rules();
- if (retval)
- return retval;
-
- retval = namedev_init_permissions();
- if (retval)
- return retval;
-
- dump_config_dev_list();
- dump_perm_dev_list();
- return retval;
-}