Re: [PATCH 3/3] ash: exec: -a option for setting zeroth arg

2017-04-12 Thread Kaarle Ritvanen
On Wed, 12 Apr 2017, Denys Vlasenko wrote:

> I committed a change which implements "exec -a"
> in a slightly different way. Please try current git.

Works for me. Thanks a lot!

BR,
Kaarle
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 3/3] ash: exec: -a option for setting zeroth arg

2017-04-12 Thread Denys Vlasenko
On Tue, Apr 11, 2017 at 11:58 PM, Kaarle Ritvanen
 wrote:
> -execcmd(int argc UNUSED_PARAM, char **argv)
> +execcmd(int argc, char **argv)
>  {
> -   if (argv[1]) {
> +   int opt;
> +   char *argv0 = NULL;
> +   char *cmdname = NULL;
> +
> +   GETOPT_RESET
> +   while ((opt = getopt(argc, argv, "a:")) != -1)

(1) The rest of ash does not use getopt().

(2) Did you test this with, say, "exec stty -a" command?

I committed a change which implements "exec -a"
in a slightly different way. Please try current git.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 3/3] ash: exec: -a option for setting zeroth arg

2017-04-12 Thread Kaarle Ritvanen
On Wed, 12 Apr 2017, Kang-Che Sung wrote:

> Back in January 2017, a person named Patrick Pief has suggested a similar 
> patch
> to add "exec -a" support:
> 
> http://lists.busybox.net/pipermail/busybox/2017-January/085146.html
> 
> Is your patch same as his or is there any difference?

My patch parses the '-a' option in execcmd, thus not affecting the 
behavior of shellexec when called from evalcommand. In addition, my patch 
uses getopt, making it a bit easier to add more options later.

Is there any reason not to merge my or Patrick's patch? If you prefer my 
patch, I can make the changes requested by Bartosz.

BR,
Kaarle
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH 3/3] ash: exec: -a option for setting zeroth arg

2017-04-12 Thread Kang-Che Sung
Back in January 2017, a person named Patrick Pief has suggested a similar patch
to add "exec -a" support:

http://lists.busybox.net/pipermail/busybox/2017-January/085146.html

Is your patch same as his or is there any difference?
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH 3/3] ash: exec: -a option for setting zeroth arg

2017-04-11 Thread Kaarle Ritvanen
Signed-off-by: Kaarle Ritvanen 
---
 shell/ash.c | 42 --
 1 file changed, 32 insertions(+), 10 deletions(-)

diff --git a/shell/ash.c b/shell/ash.c
index 58ae950..b799b85 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -7744,9 +7744,9 @@ tryexec(IF_FEATURE_SH_STANDALONE(int applet_no,) char 
*cmd, char **argv, char **
  * have to change the find_command routine as well.
  * argv[-1] must exist and be writable! See tryexec() for why.
  */
-static void shellexec(char **, const char *, int) NORETURN;
+static void shellexec(const char *, char **, const char *, int) NORETURN;
 static void
-shellexec(char **argv, const char *path, int idx)
+shellexec(const char *cmdname, char **argv, const char *path, int idx)
 {
char *cmdpath;
int e;
@@ -7755,12 +7755,15 @@ shellexec(char **argv, const char *path, int idx)
int applet_no = -1; /* used only by FEATURE_SH_STANDALONE */
 
envp = listvars(VEXPORT, VUNSET, /*end:*/ NULL);
-   if (strchr(argv[0], '/') != NULL
+   if (!cmdname)
+   cmdname = argv[0];
+
+   if (strchr(cmdname, '/') != NULL
 #if ENABLE_FEATURE_SH_STANDALONE
-|| (applet_no = find_applet_by_name(argv[0])) >= 0
+|| (applet_no = find_applet_by_name(cmdname)) >= 0
 #endif
) {
-   tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) argv[0], argv, 
envp);
+   tryexec(IF_FEATURE_SH_STANDALONE(applet_no,) cmdname, argv, 
envp);
if (applet_no >= 0) {
/* We tried execing ourself, but it didn't work.
 * Maybe /proc/self/exe doesn't exist?
@@ -7772,7 +7775,7 @@ shellexec(char **argv, const char *path, int idx)
} else {
  try_PATH:
e = ENOENT;
-   while ((cmdpath = path_advance(, argv[0])) != NULL) {
+   while ((cmdpath = path_advance(, cmdname)) != NULL) {
if (--idx < 0 && pathopt == NULL) {
tryexec(IF_FEATURE_SH_STANDALONE(-1,) cmdpath, 
argv, envp);
if (errno != ENOENT && errno != ENOTDIR)
@@ -9353,9 +9356,28 @@ truecmd(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
 }
 
 static int FAST_FUNC
-execcmd(int argc UNUSED_PARAM, char **argv)
+execcmd(int argc, char **argv)
 {
-   if (argv[1]) {
+   int opt;
+   char *argv0 = NULL;
+   char *cmdname = NULL;
+
+   GETOPT_RESET
+   while ((opt = getopt(argc, argv, "a:")) != -1)
+   switch (opt) {
+   case 'a':
+   argv0 = optarg;
+   break;
+   default:
+   return 1;
+   }
+
+   if (argv[optind]) {
+   if (argv0) {
+   cmdname = argv[optind];
+   argv[optind] = argv0;
+   }
+
iflag = 0;  /* exit on error */
mflag = 0;
optschanged();
@@ -9371,7 +9393,7 @@ execcmd(int argc UNUSED_PARAM, char **argv)
/*setsignal(SIGTSTP); - unnecessary because of mflag=0 */
/*setsignal(SIGTTOU); - unnecessary because of mflag=0 */
 
-   shellexec(argv + 1, pathval(), 0);
+   shellexec(cmdname, argv + optind, pathval(), 0);
/* NOTREACHED */
}
return 0;
@@ -9773,7 +9795,7 @@ evalcommand(union node *cmd, int flags)
/* fall through to exec'ing external program */
}
listsetvar(varlist.list, VEXPORT|VSTACK);
-   shellexec(argv, path, cmdentry.u.index);
+   shellexec(NULL, argv, path, cmdentry.u.index);
/* NOTREACHED */
} /* default */
case CMDBUILTIN:
-- 
2.9.3

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox