linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] udev - simpler PROGRAM execution with arguments
Date: Thu, 26 Feb 2004 21:31:56 +0000	[thread overview]
Message-ID: <20040226213156.GG13134@kroah.com> (raw)
In-Reply-To: <20040225011944.GA25022@vrfy.org>

On Wed, Feb 25, 2004 at 02:42:09AM +0100, Kay Sievers wrote:
> On Wed, 2004-02-25 at 02:34, Patrick Mansfield wrote:
> > On Wed, Feb 25, 2004 at 02:19:44AM +0100, Kay Sievers wrote:
> > > While putting the limitations of our PROGRAM execution with arguments in
> > > the man page, I asked myself why we don't simply use a subshell if a space
> > > is found in the PROGRAM key.
> > > It would be possible to use all shell functions like pipe or diversion
> > > and we get rid of the hardcoded argument limit.
> > 
> > But now you depend on /bin/sh, is that acceptable?
> 
> If it's not there, only the PROGRAM call with arguments will fail.
> I think there are only few systems without /bin/sh but udev :)

Hm, but some initramfs systems will probably not have a /bin/sh.

So I've made the following change instead.  If we go over our internal
limit of arguments then we will call /bin/sh, otherwise we handle it
ourselves.  This should make the initramfs people happy, and everyone
else too.

Any complaints?

thanks,

greg k-h


# remove limit of the number of args passed to PROGRAM
#
# If we go over our internal limit of 7, then we call out to /bin/sh
# otherwise we handle it ourself without relying on a shell.

diff -Nru a/namedev.c b/namedev.c
--- a/namedev.c	Thu Feb 26 13:30:02 2004
+++ b/namedev.c	Thu Feb 26 13:30:02 2004
@@ -421,7 +421,13 @@
 	case 0:
 		/* child */
 		close(STDOUT_FILENO);
-		dup(fds[1]);	/* dup write side of pipe to STDOUT */
+
+		/* dup write side of pipe to STDOUT */
+		dup(fds[1]);
+
+		/* copy off our path to use incase we have too many args */
+		strnfieldcpy(buffer, path, sizeof(buffer));
+
 		if (strchr(path, ' ')) {
 			/* exec with arguments */
 			pos = path;
@@ -431,14 +437,16 @@
 					break;
 			}
 			if (args[i]) {
-				dbg("too many args - %d", i);
-				args[i] = NULL;
+				dbg("too many args - %d, using subshell instead '%s'", i, buffer);
+				retval = execl("/bin/sh", "sh", "-c", buffer, NULL);
+			} else {
+				dbg("execute program '%s'", path);
+				retval = execv(args[0], args);
 			}
-			retval = execv(args[0], args);
 		} else {
 			retval = execv(path, main_argv);
 		}
-		dbg("child execve failed");
+		info(FIELD_PROGRAM " execution of '%s' failed", path);
 		exit(1);
 	case -1:
 		dbg("fork failed");
diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl	Thu Feb 26 13:30:02 2004
+++ b/test/udev-test.pl	Thu Feb 26 13:30:02 2004
@@ -244,6 +244,15 @@
 EOF
 	},
 	{
+		desc     => "program with lots of arguments",
+		subsys   => "block",
+		devpath  => "block/sda/sda3",
+		expected => "foo9" ,
+		conf     => <<EOF
+BUS="scsi", PROGRAM="/bin/echo -n foo3 foo4 foo5 foo6 foo7 foo8 foo9", KERNEL="sda3", NAME="%c{7}"
+EOF
+	},
+	{
 		desc     => "program result substitution (numbered part of)",
 		subsys   => "block",
 		devpath  => "block/sda/sda3",
diff -Nru a/udev.8 b/udev.8
--- a/udev.8	Thu Feb 26 13:30:02 2004
+++ b/udev.8	Thu Feb 26 13:30:02 2004
@@ -182,8 +182,7 @@
 .TP
 .B PROGRAM
 Call external program. This key is valid if the program returns successful.
-A few command line options may specified, but shell characters like pipe,
-diversion or similiar options are not available. The environment variables of
+The environment variables of
 .B udev
 are also available for the program.
 .br


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id\x1356&alloc_id438&op=click
_______________________________________________
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

      parent reply	other threads:[~2004-02-26 21:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-25  1:19 [PATCH] udev - simpler PROGRAM execution with arguments Kay Sievers
2004-02-25  1:34 ` Patrick Mansfield
2004-02-25  1:42 ` Kay Sievers
2004-02-26 21:31 ` Greg KH [this message]

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=20040226213156.GG13134@kroah.com \
    --to=greg@kroah.com \
    --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 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).