On Mon, 27 Mar 2023 20:06:30 +0200, Omar Polo wrote:
> Is _PATH_BSHELL portable though? I can see a few stuff that uses it
> (vi among others) but I'm not sure.
The paths.h header is a BSD invention, though it may be present on
some other systems. I don't think that's a reason not to use it
though.
> Also, if you look at the callers of shellcmdoutput() they all prepare
> the argv array as {"sh", "-c", "command provided", NULL} so I'm
> wondering if we should just ignore $SHELL and always use /bin/sh, or
> change that "sh" accordingly to $SHELL.
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.
OK millert@ for the diff as-is.
- todd
> Index: region.c
> ===================================================================
> RCS file: /cvs/src/usr.bin/mg/region.c,v
> retrieving revision 1.42
> diff -u -p -r1.42 region.c
> --- region.c 27 Mar 2023 17:54:20 -0000 1.42
> +++ region.c 27 Mar 2023 17:58:11 -0000
> @@ -15,6 +15,7 @@
> #include <sys/wait.h>
> #include <errno.h>
> #include <fcntl.h>
> +#include <paths.h>
> #include <poll.h>
> #include <signal.h>
> #include <stdio.h>
> @@ -483,7 +484,8 @@ shellcmdoutput(char* const argv[], char*
> return (FALSE);
> }
>
> - shellp = getenv("SHELL");
> + if ((shellp = getenv("SHELL")) == NULL)
> + shellp = _PATH_BSHELL;
>
> ret = pipeio(shellp, argv, text, len, bp);
>
> @@ -529,8 +531,6 @@ pipeio(const char* const path, char* con
> if (dup2(s[1], STDOUT_FILENO) == -1)
> _exit(1);
> if (dup2(s[1], STDERR_FILENO) == -1)
> - _exit(1);
> - if (path == NULL)
> _exit(1);
>
> execv(path, argv);
>