diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-06-30 23:22:15 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-06-30 23:22:15 -0700 |
commit | c89270cf0d7c7b3f9c99075211a8178aca932f38 (patch) | |
tree | 7a8de89ffc56a5c52d903f57ca10ca0b0127117b /stream.c | |
parent | 8cd9963dac81f478b17b8b064aa59c97c05a6465 (diff) | |
download | txr-c89270cf0d7c7b3f9c99075211a8178aca932f38.tar.gz txr-c89270cf0d7c7b3f9c99075211a8178aca932f38.tar.bz2 txr-c89270cf0d7c7b3f9c99075211a8178aca932f38.zip |
Dynamically determine whether shell is cmd.exe.
* stream.c (shell, shell_arg): New variables.
(sh): Use shell and shell_arg, rather than hard-coded
"/bin/sh" and "-c".
(stream_init): Initialize shell and shell_arg to
POSIX values. On Cygwin, call getusershell, and if it
reports cmd.exe, use that instead, and adjust shell_arg
to "/c". This will happen if the Cygwin DLL being used
is the Cygnal version.
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -85,6 +85,8 @@ val stdio_stream_s; val socket_error_s; #endif +val shell, shell_arg; + void strm_base_init(struct strm_base *s) { static struct strm_base init = { indent_off, 60, 10, 0, 0 }; @@ -3855,7 +3857,7 @@ out: static val sh(val command) { - return run(lit("/bin/sh"), list(lit("-c"), command, nao)); + return run(shell, list(shell_arg, command, nao)); } #elif HAVE_WSPAWN static val run(val command, val args) @@ -4112,4 +4114,19 @@ void stream_init(void) record_adapter_ops.get_sock_peer = delegate_get_sock_peer; record_adapter_ops.set_sock_peer = delegate_set_sock_peer; #endif + + + shell = lit("/bin/sh"); + shell_arg = lit("-c"); + +#ifdef __CYGWIN__ + { + const char *sh = getusershell(); + if (sh && strstr(sh, "cmd.exe")) { + prot1(&shell); + shell = string_utf8(sh); + shell_arg = lit("/c"); + } + } +#endif } |