linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [udev] support arguments in callout exec
@ 2003-11-20  1:42 Kay Sievers
  0 siblings, 0 replies; 11+ messages in thread
From: Kay Sievers @ 2003-11-20  1:42 UTC (permalink / raw)
  To: linux-hotplug

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

Hi,
here is argument support for CALLOUT exec:

CALLOUT, PROGRAM="/bin/echo -n xxx", BUS="usb", ID="xxx", NAME="webcam%n"

results in:

Nov 20 02:35:20 pim udev[30422]: get_major_minor: found major = 81, minor = 0
Nov 20 02:35:20 pim udev[30422]: exec_callout: callout to /bin/echo -n xxx
Nov 20 02:35:20 pim udev[30422]: exec_callout: callout returned 'xxx'
Nov 20 02:35:20 pim udev[30422]: get_attr: kernel number appended: 0

The feature is really nice, but the maximum argument count is hard coded to 8.
What do you think?

thanks,
Kay



09-namedev.c-callout-argument-support.diff
  namdev.c - support for argument in CALLOUT exec


[-- Attachment #2: 09-namedev.c-callout-argument-support.diff --]
[-- Type: text/plain, Size: 904 bytes --]

--- ../udev/namedev.c	2003-11-19 12:56:50.000000000 +0100
+++ namedev.c	2003-11-20 02:34:05.000000000 +0100
@@ -480,6 +480,9 @@
 	pid_t pid;
 	int value_set = 0;
 	char buffer[256];
+	char *prog;
+	char *args[8];
+	int i;
 
 	dbg("callout to %s\n", dev->exec_program);
 	retval = pipe(fds);
@@ -499,7 +502,14 @@
 		 */
 		close(STDOUT_FILENO);
 		dup(fds[1]);	/* dup write side of pipe to STDOUT */
-		retval = execve(dev->exec_program, main_argv, main_envp);
+		strcpy(buffer, dev->exec_program);
+		prog = strtok(buffer, " ");
+		for(i=1; i<=8; i++) {
+			args[i] = strtok(NULL, " ");
+			if (args[i] == NULL)
+				break;
+		}
+		retval = execve(prog, args, main_envp);
 		if (retval != 0) {
 			dbg("child execve failed");
 			exit(1);
@@ -528,6 +538,7 @@
 				strncpy(value, buffer, len);
 			}
 		}
+		dbg("callout returned '%s'", value);
 		close(fds[0]);
 		res = wait(&status);
 		if (res < 0) {

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [udev] support arguments in callout exec
@ 2003-11-20  0:47 Arnd Bergmann
  2003-11-20  2:59 ` Arnd Bergmann
                   ` (8 more replies)
  0 siblings, 9 replies; 11+ messages in thread
From: Arnd Bergmann @ 2003-11-20  0:47 UTC (permalink / raw)
  To: linux-hotplug

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="windows-1252", Size: 1759 bytes --]

On Thursday 20 November 2003 13:31, Kay Sievers wrote:> +                       for (i=0; i < CALLOUT_MAXARG; i++) {> +                               args[i] = strsep(&arg, " ");> +                               if (args[i] = NULL)> +                                       break;> +                       }> +                       if (args[i])> +                               dbg("to many args");
This still doesn't look correct: args[i] will be out of boundswhen the loop has finished on CALLOUT_MAXARG, and the argsarray is not zero terminated when calling execve.
I haven't tried it yet, but I think this would make more sense:
+                       for (i=0; i < CALLOUT_MAXARG-1; i++) {+                               args[i] = strsep(&arg, " ");+                               if (args[i] = NULL)+                                       break;+                       }+			args[i] = arg;+                       if (args[i])+                               dbg("to many args");
Aside from that, it looks good. Maybe there should be a way to escapespaces in the argument in case someone wants to do something like that:
CALLOUT, PROGRAM="sh -c 'echo ${DEVPATH} | tr a-z A-Z'", BUS="usb", ID="XXX", NAME="webcam%n"
To take that even further, do you think it might be a good idea to preprocess the string in the same way as the NAME= argument, allowing e.g.PROGRAM="/bin/devname %b %M:%m" ?
	Arnd <><ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÓ†+\x12\x17ù޵隊X¬²š'²ŠÞu¼ÿH_çzÑ¢½æÚrCë¢Ú›ðèzĨº·\x1e\x16Šà{ùÞ¶\x17¥§*.m騭êk¡Ûœ¶+Þü:\x1e²+azZr¢ç+y«^mëmz·(uïÒ\x1c\x04DLq\v9QÿjwazZn²\x17¥¥ƒ”ü)brAÞ­ïá¶Úÿÿû(º·\x1e~Šà{ùÞ·÷h«^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ.)îÇøh¶™nƒ÷^½éfj)bž	b²Øm¶ŸÿþX§»\x1fá¢Úeº\x0fì¢êÜyú+ïçzÒâžìÿ†‹i–èÿuëÞ—ùb²Ûÿ²‹«qçè®\aÿëa¶ÚlÿÿåŠËlþÊ.­ÇŸ¢¸\x1eþw­þX¬¶ÏåŠËbú?–)îÇøh¶™nƒ÷^

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-11-22 18:14 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-20  1:42 [udev] support arguments in callout exec Kay Sievers
  -- strict thread matches above, loose matches on Subject: below --
2003-11-20  0:47 Arnd Bergmann
2003-11-20  2:59 ` Arnd Bergmann
2003-11-20  3:21 ` Kay Sievers
2003-11-20 12:31 ` Kay Sievers
2003-11-20 16:07 ` Kay Sievers
2003-11-20 17:31 ` Kay Sievers
2003-11-20 20:14 ` Arnd Bergmann
2003-11-21  6:50 ` Greg KH
2003-11-21  6:53 ` Greg KH
2003-11-22 18:14 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).