On 2023/03/28 10:21:59 +0200, Omar Polo <[email protected]> wrote:
> On 2023/03/27 18:58:07 -0600, Todd C. Miller <[email protected]> wrote:
> > It might be best to use the basename of the actual shell for argv[0].
> > Our ksh for instance has slightly different behavior when invoked
> > as sh.
>
> like this? :)
>
> (need an up-to-date tree since it builds on the previous, committed,
> diff.)
>
> I've tested with ksh and csh. I guess it's fine to assume the user'
> shell has a -c flag. (vi does the same.)
>
>
> Thanks!
sigh... forgot to advance the pointer after strrchr otherwise argv[0]
would have been /ksh instead of "ksh".
Index: region.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/region.c,v
retrieving revision 1.43
diff -u -p -r1.43 region.c
--- region.c 28 Mar 2023 08:01:40 -0000 1.43
+++ region.c 28 Mar 2023 14:13:26 -0000
@@ -34,7 +34,7 @@ static int iomux(int, char * const, int,
static int preadin(int, struct buffer *);
static void pwriteout(int, char **, int *);
static int setsize(struct region *, RSIZE);
-static int shellcmdoutput(char * const[], char * const, int);
+static int shellcmdoutput(char * const, char * const, int);
/*
* Kill the region. Ask "getregion" to figure out the bounds of the region.
@@ -415,7 +415,6 @@ piperegion(int f, int n)
struct region region;
int len;
char *cmd, cmdbuf[NFILEN], *text;
- char *argv[] = {"sh", "-c", (char *) NULL, (char *) NULL};
/* C-u M-| is not supported yet */
if (n > 1)
@@ -431,8 +430,6 @@ piperegion(int f, int n)
EFNEW | EFCR)) == NULL || (cmd[0] == '\0'))
return (ABORT);
- argv[2] = cmd;
-
if (getregion(®ion) != TRUE)
return (FALSE);
@@ -446,7 +443,7 @@ piperegion(int f, int n)
region_get_data(®ion, text, len);
- return shellcmdoutput(argv, text, len);
+ return shellcmdoutput(cmd, text, len);
}
/*
@@ -456,7 +453,6 @@ int
shellcommand(int f, int n)
{
char *cmd, cmdbuf[NFILEN];
- char *argv[] = {"sh", "-c", (char *) NULL, (char *) NULL};
if (n > 1)
return (ABORT);
@@ -465,15 +461,14 @@ shellcommand(int f, int n)
EFNEW | EFCR)) == NULL || (cmd[0] == '\0'))
return (ABORT);
- argv[2] = cmd;
-
- return shellcmdoutput(argv, NULL, 0);
+ return shellcmdoutput(cmd, NULL, 0);
}
int
-shellcmdoutput(char* const argv[], char* const text, int len)
+shellcmdoutput(char* const cmd, char* const text, int len)
{
struct buffer *bp;
+ char *argv[] = {NULL, "-c", cmd, NULL};
char *shellp;
int ret;
@@ -486,6 +481,11 @@ shellcmdoutput(char* const argv[], char*
if ((shellp = getenv("SHELL")) == NULL)
shellp = _PATH_BSHELL;
+
+ if ((argv[0] = strrchr(shellp, '/')) != NULL)
+ argv[0]++;
+ else
+ argv[0] = shellp;
ret = pipeio(shellp, argv, text, len, bp);