From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] udev - simpler PROGRAM execution with arguments
Date: Wed, 25 Feb 2004 01:19:44 +0000 [thread overview]
Message-ID: <20040225011944.GA25022@vrfy.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 457 bytes --]
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.
Pat, is this fine with you? scsi_id without arguments is still called
directly. As promised, I've added a info() for a failing PROGRAM execution.
thanks,
Kay
[-- Attachment #2: 04-exec-in-subshell.patch --]
[-- Type: text/plain, Size: 1994 bytes --]
===== namedev.c 1.112 vs edited =====
--- 1.112/namedev.c Wed Feb 25 00:46:55 2004
+++ edited/namedev.c Wed Feb 25 02:01:54 2004
@@ -405,38 +405,28 @@
int value_set = 0;
char buffer[256];
char *pos;
- char *args[PROGRAM_MAXARG];
- int i;
- dbg("executing '%s'", path);
retval = pipe(fds);
if (retval != 0) {
dbg("pipe failed");
return -1;
}
+
pid = fork();
switch(pid) {
case 0:
/* child */
close(STDOUT_FILENO);
dup(fds[1]); /* dup write side of pipe to STDOUT */
+
if (strchr(path, ' ')) {
- /* exec with arguments */
- pos = path;
- for (i=0; i < PROGRAM_MAXARG-1; i++) {
- args[i] = strsep(&pos, " ");
- if (args[i] == NULL)
- break;
- }
- if (args[i]) {
- dbg("too many args - %d", i);
- args[i] = NULL;
- }
- retval = execv(args[0], args);
+ dbg("execute program in subshell '%s'", path);
+ retval = execl("/bin/sh", "sh", "-c", path, NULL);
} else {
+ dbg("execute program '%s'", path);
retval = execv(path, main_argv);
}
- dbg("child execve failed");
+ info(FIELD_PROGRAM " execution of '%s' failed", path);
exit(1);
case -1:
dbg("fork failed");
@@ -478,6 +468,7 @@
retval = -1;
}
}
+
return retval;
}
===== namedev.h 1.26 vs edited =====
--- 1.26/namedev.h Thu Feb 19 15:56:44 2004
+++ edited/namedev.h Wed Feb 25 02:13:54 2004
@@ -48,7 +48,6 @@
#define ATTR_PARTITIONS "all_partitions"
#define PARTITIONS_COUNT 15
-#define PROGRAM_MAXARG 10
#define MAX_SYSFS_PAIRS 5
#define RULEFILE_EXT ".rules"
===== udev.8 1.42 vs edited =====
--- 1.42/udev.8 Wed Feb 25 01:38:29 2004
+++ edited/udev.8 Wed Feb 25 02:04:29 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
next reply other threads:[~2004-02-25 1:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-02-25 1:19 Kay Sievers [this message]
2004-02-25 1:34 ` [PATCH] udev - simpler PROGRAM execution with arguments Patrick Mansfield
2004-02-25 1:42 ` Kay Sievers
2004-02-26 21:31 ` 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=20040225011944.GA25022@vrfy.org \
--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 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).