chiark / gitweb /
[PATCH] first cut at standalone udev_selinux program.
[elogind.git] / namedev.c
index a9142374f4c1400e6737974795b083fe99633ec9..b9d8a3db2c2dec9fc9e8c7b2157b77e0e16b6173 100644 (file)
--- a/namedev.c
+++ b/namedev.c
@@ -36,6 +36,7 @@
 #include "libsysfs/sysfs/libsysfs.h"
 #include "list.h"
 #include "udev.h"
+#include "udev_lib.h"
 #include "udev_version.h"
 #include "logging.h"
 #include "namedev.h"
@@ -190,6 +191,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
        int i;
        char c;
        char *spos;
+       char *rest;
        int slen;
        struct sysfs_attribute *tmpattr;
 
@@ -244,7 +246,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
                        /* get part part of the result string */
                        i = 0;
                        if (attr != NULL)
-                               i = atoi(attr);
+                               i = strtoul(attr, &rest, 10);
                        if (i > 0) {
                                foreach_strpart(udev->program_result, " \n\r", spos, slen) {
                                        i--;
@@ -255,7 +257,10 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
                                        dbg("requested part of result string not found");
                                        break;
                                }
-                               strfieldcpymax(temp2, spos, slen+1);
+                               if (rest[0] == '+')
+                                       strfieldcpy(temp2, spos);
+                               else
+                                       strfieldcpymax(temp2, spos, slen+1);
                                strfieldcatmax(string, temp2, maxsize);
                                dbg("substitute part of result string '%s'", temp2);
                        } else {
@@ -811,16 +816,15 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud
                        }
 
                        if (dev->symlink[0] != '\0') {
-                               char temp[NAME_MAX];
+                               char temp[NAME_SIZE];
 
                                info("configured rule in '%s' at line %i applied, added symlink '%s'",
                                     dev->config_file, dev->config_line, dev->symlink);
-                               /* do not clobber dev */
                                strfieldcpy(temp, dev->symlink);
-                               apply_format(udev, temp, sizeof(temp),
-                                            class_dev, sysfs_device);
+                               apply_format(udev, temp, sizeof(temp), class_dev, sysfs_device);
+                               if (udev->symlink[0] != '\0')
+                                       strfieldcat(udev->symlink, " ");
                                strfieldcat(udev->symlink, temp);
-                               strfieldcat(udev->symlink, " ");
                        }
 
                        if (dev->name[0] != '\0') {
@@ -837,16 +841,17 @@ int namedev_name_device(struct sysfs_class_device *class_dev, struct udevice *ud
        goto done;
 
 found:
-       apply_format(udev, udev->name, sizeof(udev->name),
-                    class_dev, sysfs_device);
+       apply_format(udev, udev->name, sizeof(udev->name), class_dev, sysfs_device);
        udev->partitions = dev->partitions;
+       strfieldcpy(udev->config_file, dev->config_file);
+       udev->config_line = dev->config_line;
 
-done:
        /* get permissions given in rule */
        set_empty_perms(udev, dev->mode,
                              dev->owner,
                              dev->group);
 
+done:
        /* get permissions given in config file or set defaults */
        perm = find_perm(udev->name);
        if (perm != NULL) {
@@ -862,6 +867,9 @@ done:
        dbg("name, '%s' is going to have owner='%s', group='%s', mode = %#o",
            udev->name, udev->owner, udev->group, udev->mode);
 
+       /* store time of action */
+       udev->config_time = time(NULL);
+
        return 0;
 }