All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: [udev] - format char for CALLOUT output
Date: Fri, 21 Nov 2003 16:53:32 +0000	[thread overview]
Message-ID: <marc-linux-hotplug-106943373014034@msgid-missing> (raw)

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

Hi Greg,
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)


thanks,
Kay

[-- Attachment #2: 11-namedev.c-whitespace+debug.diff --]
[-- Type: text/plain, Size: 1747 bytes --]

--- ../udev/namedev.c	2003-11-21 08:48:32.000000000 +0100
+++ namedev.c	2003-11-21 17:12:24.000000000 +0100
@@ -82,9 +82,9 @@
 			  dev->owner, dev->group, dev->mode);
 		break;
 	case CALLOUT:
-		dbg_parse("CALLOUT name='%s', program='%s', bus='%s', id='%s', "
+		dbg_parse("CALLOUT name='%s', bus='%s', program='%s', id='%s', "
 			  "owner='%s', group='%s', mode=%#o",
-			  dev->name, dev->exec_program, dev->bus, dev->id,
+			  dev->name, dev->bus, dev->exec_program, dev->id,
 			  dev->owner, dev->group, dev->mode);
 		break;
 	default:
@@ -270,8 +270,8 @@
 			strfieldcpy(dev.name, temp3);
 
 			dbg_parse("LABEL name='%s', bus='%s', "
-				  "sysfs_file='%s', sysfs_value='%s'", 
-				  dev.name, dev.bus, dev.sysfs_file, 
+				  "sysfs_file='%s', sysfs_value='%s'",
+				  dev.name, dev.bus, dev.sysfs_file,
 				  dev.sysfs_value);
 		}
 
@@ -416,7 +416,6 @@
 
 	/* loop through the whole file */
 	while (1) {
-		/* get a line */
 		temp = fgets(line, sizeof(line), fd);
 		if (temp == NULL)
 			break;
@@ -509,7 +508,7 @@
 					break;
 			}
 			if (args[i]) {
-				dbg("to many args - %d", i);
+				dbg("too many args - %d", i);
 				args[i] = NULL;
 			}
 			retval = execve(args[0], args, main_envp);
@@ -869,6 +868,7 @@
 		char *pos = strchr(udev->name, '%');
 		char *dig;
 		char name[NAME_SIZE];
+
 		if (pos) {
 			strfieldcpy(name, pos+2);
 			*pos = 0x00;
@@ -877,8 +877,7 @@
 				if (!sysfs_device)
 					break;
 				strcat(udev->name, sysfs_device->bus_id);
-				dbg("bus_id inserted: %s", 
-						sysfs_device->bus_id);
+				dbg("substitute bus_id '%s'", sysfs_device->bus_id);
 				break;
 			case 'n':
 				dig = class_dev->name + strlen(class_dev->name);
@@ -944,5 +943,3 @@
 	dump_dev_list();
 	return retval;
 }
-
-

[-- Attachment #3: 12-namedev.c-callout-return-substitution.diff --]
[-- Type: text/plain, Size: 3434 bytes --]

--- ../namedev.c	2003-11-21 17:42:48.000000000 +0100
+++ namedev.c	2003-11-21 17:43:52.000000000 +0100
@@ -49,6 +49,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) {
@@ -108,16 +121,8 @@
 	/* 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);
@@ -559,20 +564,18 @@
 	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) {
@@ -771,17 +774,12 @@
 	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;
@@ -797,6 +795,7 @@
 	struct sysfs_class_device *class_dev_parent = NULL;
 	int retval = 0;
 	char *temp = NULL;
+	char value[ID_SIZE];
 
 	udev->mode = 0;
 
@@ -839,7 +838,7 @@
 	}
 
 	/* 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;
 
@@ -883,7 +882,7 @@
 				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':
@@ -894,6 +893,10 @@
 				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;

             reply	other threads:[~2003-11-21 16:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-21 16:53 Kay Sievers [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-11-23 21:18 [udev] - format char for CALLOUT output Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-hotplug-106943373014034@msgid-missing \
    --to=kay.sievers@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.