chiark / gitweb /
[PATCH] udev - program to query all device attributes to build a rule
[elogind.git] / namedev.c
index b3b23521d6cf154f1554921546171ddb480809ce..7fd69f7778954332ab2075232fa98b7297b58001 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -36,6 +36,7 @@
 #include "list.h"
 #include "udev.h"
 #include "udev_version.h"
+#include "logging.h"
 #include "namedev.h"
 #include "libsysfs/libsysfs.h"
 #include "klibc_fixups.h"
@@ -140,7 +141,7 @@ static struct perm_device *find_perm(char *name)
        return NULL;
 }
 
-static mode_t get_default_mode(struct sysfs_class_device *class_dev)
+static mode_t get_default_mode(void)
 {
        mode_t mode = 0600;     /* default to owner rw only */
 
@@ -150,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];
@@ -285,12 +302,12 @@ static void wait_for_device_to_initialize(struct sysfs_device *sysfs_device)
                                /* sleep to give the kernel a chance to create the file */
                                sleep(1);
                        }
-                       dbg("Timed out waiting for '%s' file, continuing on anyway...", b->file);
+                       dbg("timed out waiting for '%s' file, continuing on anyway...", b->file);
                        goto exit;
                }
                b++;
        }
-       dbg("Did not find bus type '%s' on list of bus_id_files, contact greg@kroah.com", sysfs_device->bus);
+       dbg("did not find bus type '%s' on list of bus_id_files, contact greg@kroah.com", sysfs_device->bus);
 exit:
        return; /* here to prevent compiler warning... */
 }
@@ -534,7 +551,7 @@ static struct sysfs_device *get_sysfs_device(struct sysfs_class_device *class_de
                if (sysfs_device != NULL)
                        goto device_found;
        }
-       dbg("Timed out waiting for device symlink, continuing on anyway...");
+       dbg("timed out waiting for device symlink, continuing on anyway...");
        
 device_found:
         /* We have another issue with just the wait above - the sysfs part of
@@ -559,10 +576,10 @@ device_found:
                        if (sysfs_device->bus[0] != '\0')
                                goto bus_found;
                }
-               dbg("Timed out waiting to find the device bus, continuing on anyway\n");
+               dbg("timed out waiting to find the device bus, continuing on anyway");
                goto exit;
 bus_found:
-               dbg("Device %s is registered with bus %s\n",
+               dbg("device %s is registered with bus '%s'",
                                sysfs_device->name, sysfs_device->bus);
        }
 exit:
@@ -694,7 +711,8 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud
                }
 
                /* Yup, this rule belongs to us! */
-               dbg("found matching rule, '%s' becomes '%s'", dev->kernel, dev->name);
+               info("configured rule in '%s' at line %i applied, '%s' becomes '%s'",
+                   udev_rules_filename, dev->config_line, udev->kernel_name, dev->name);
                strfieldcpy(udev->name, dev->name);
                strfieldcpy(udev->symlink, dev->symlink);
                goto found;
@@ -717,9 +735,9 @@ done:
                strfieldcpy(udev->group, perm->group);
        } else {
                /* no matching perms found :( */
-               udev->mode = get_default_mode(class_dev);
-               udev->owner[0] = 0x00;
-               udev->group[0] = 0x00;
+               udev->mode = get_default_mode();
+               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);