From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Thu, 20 Nov 2003 03:21:11 +0000 Subject: Re: [udev] support arguments in callout exec MIME-Version: 1 Content-Type: multipart/mixed; boundary="ZGiS0Q5IWpPtfppv" Message-Id: List-Id: References: In-Reply-To: To: linux-hotplug@vger.kernel.org --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sorry, please ignore the previous version it breaks scsi_id by eating main_argv. Now, with no arguments are given, behavior isn't changed. 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 --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="09-namedev.c-callout-argument-support.diff" --- ../udev/namedev.c 2003-11-19 12:56:50.000000000 +0100 +++ namedev.c 2003-11-20 04:14:54.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,19 @@ */ close(STDOUT_FILENO); dup(fds[1]); /* dup write side of pipe to STDOUT */ - retval = execve(dev->exec_program, main_argv, main_envp); + if (strchr(dev->exec_program, ' ')) { + /* callout with arguments */ + 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); + } else { + retval = execve(dev->exec_program, main_argv, main_envp); + } if (retval != 0) { dbg("child execve failed"); exit(1); @@ -528,6 +543,7 @@ strncpy(value, buffer, len); } } + dbg("callout returned '%s'", value); close(fds[0]); res = wait(&status); if (res < 0) { --ZGiS0Q5IWpPtfppv-- ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel