summaryrefslogtreecommitdiff
path: root/namedev.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2003-11-23 21:14:33 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:02 -0700
commitc124eafa238b34a2e79100d3eb1fb143b7e8cb8b (patch)
tree27c73ba42de9958da6125a9c24b6a41ac0e0402f /namedev.c
parent53dc383ee90b6699b85f2843247389f5adeb8d50 (diff)
downloadsystemd-c124eafa238b34a2e79100d3eb1fb143b7e8cb8b.tar.gz
[PATCH] - format char for CALLOUT output
here is a patch for inserting the callout output into NAME=. ID= supports the usual wildcard to compare with the output. I've moved all wildcard matching to a function cause this was the third occurrence. Also attached is the last whitespace cleanup and debug text corrections. The callout patch depends on the whitespace patch. CALLOUT, BUS="usb", PROGRAM="/bin/echo -n return", ID="ret*", NAME="webcam-%c-" results in: Nov 21 17:33:51 pim udev[20399]: get_major_minor: found major = 81, minor = 0 Nov 21 17:33:51 pim udev[20399]: exec_callout: callout to '/bin/echo -n return' Nov 21 17:33:51 pim udev[20399]: exec_callout: callout returned 'return' Nov 21 17:33:51 pim udev[20399]: get_attr: substitute callout output 'return' Nov 21 17:33:51 pim udev[20399]: udev_add_device: name = webcam-return- Nov 21 17:33:51 pim udev[20399]: create_node: mknod(/udev/webcam-return-, 020660, 81, 0)
Diffstat (limited to 'namedev.c')
-rw-r--r--namedev.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/namedev.c b/namedev.c
index a010979052..cf9e92635e 100644
--- a/namedev.c
+++ b/namedev.c
@@ -50,6 +50,19 @@
static LIST_HEAD(config_device_list);
+/* s2 may end with '*' to match everything */
+static int strncmp_wildcard(char *s1, char *s2, int max)
+{
+ int len = strlen(s2);
+ if (len > max)
+ len = max;
+ if (s2[len-1] == '*')
+ len--;
+ else
+ len = max;
+ return strncmp(s1, s2, len);
+}
+
static void dump_dev(struct config_device *dev)
{
switch (dev->type) {
@@ -109,16 +122,8 @@ static int add_dev(struct config_device *new_dev)
/* update the values if we already have the device */
list_for_each(tmp, &config_device_list) {
struct config_device *dev = list_entry(tmp, struct config_device, node);
- int len = strlen(new_dev->name);
- if (new_dev->name[len-1] == '*') {
- len--;
- if (strncmp(dev->name, new_dev->name, len))
- continue;
- } else {
- if (strcmp(dev->name, new_dev->name))
- continue;
- }
- /* the same, copy the new info into this structure */
+ if (strncmp_wildcard(dev->name, new_dev->name, sizeof(dev->name)))
+ continue;
copy_var(dev, new_dev, type);
copy_var(dev, new_dev, mode);
copy_string(dev, new_dev, bus);
@@ -572,20 +577,18 @@ static int exec_callout(struct config_device *dev, char *value, int len)
return retval;
}
-static int do_callout(struct sysfs_class_device *class_dev, struct udevice *udev)
+static int do_callout(struct sysfs_class_device *class_dev, struct udevice *udev, char *value, int len)
{
struct config_device *dev;
struct list_head *tmp;
- char value[ID_SIZE];
list_for_each(tmp, &config_device_list) {
dev = list_entry(tmp, struct config_device, node);
if (dev->type != CALLOUT)
continue;
-
- if (exec_callout(dev, value, sizeof(value)))
+ if (exec_callout(dev, value, len))
continue;
- if (strncmp(value, dev->id, sizeof(value)) != 0)
+ if (strncmp_wildcard(value, dev->id, len) != 0)
continue;
strfieldcpy(udev->name, dev->name);
if (dev->mode != 0) {
@@ -784,17 +787,12 @@ static void do_kernelname(struct sysfs_class_device *class_dev, struct udevice *
int len;
strfieldcpy(udev->name, class_dev->name);
+ /* look for permissions */
list_for_each(tmp, &config_device_list) {
dev = list_entry(tmp, struct config_device, node);
len = strlen(dev->name);
- if (dev->name[len-1] == '*') {
- len--;
- if (strncmp(dev->name, class_dev->name, len))
- continue;
- } else {
- if (strcmp(dev->name, class_dev->name))
- continue;
- }
+ if (strncmp_wildcard(class_dev->name, dev->name, sizeof(dev->name)))
+ continue;
if (dev->mode != 0) {
dbg_parse("found permissions for '%s'", class_dev->name);
udev->mode = dev->mode;
@@ -810,6 +808,7 @@ static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
struct sysfs_class_device *class_dev_parent = NULL;
int retval = 0;
char *temp = NULL;
+ char value[ID_SIZE];
udev->mode = 0;
@@ -852,7 +851,7 @@ static int get_attr(struct sysfs_class_device *class_dev, struct udevice *udev)
}
/* rules are looked at in priority order */
- retval = do_callout(class_dev, udev);
+ retval = do_callout(class_dev, udev, value, sizeof(value));
if (retval == 0)
goto found;
@@ -896,7 +895,7 @@ found:
dig = class_dev->name + strlen(class_dev->name);
while (isdigit(*(dig-1)))
dig--;
- strcat(udev->name, dig);
+ strcat(pos, dig);
dbg("substitute kernel number '%s'", dig);
break;
case 'm':
@@ -907,6 +906,10 @@ found:
sprintf(pos, "%u", udev->major);
dbg("substitute major number '%u'", udev->major);
break;
+ case 'c':
+ strcat(pos, value);
+ dbg("substitute callout output '%s'", value);
+ break;
default:
dbg("unknown substitution type '%%%c'", pos[1]);
break;