mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-10 01:48:00 +00:00
If pterm's execvp fails when given the whole argument list after -e,
and the argument list contains only one string, try again by passing that single string to "$SHELL -c" to be parsed as a shell command. This matches xterm's behaviour (as of xterm 261, at least), and means in practice that users can do _either_ of 'pterm -e some command' and 'pterm -e "some command"'. (A quick survey suggests that the majority of X terminal programs agree with pterm's old behaviour of only supporting '-e some command', except that gnome-terminal only supports the other behaviour and xterm supports both. With that disagreement, I think supporting both is probably the sensible thing.) [originally from svn r9575]
This commit is contained in:
parent
a3f74661c8
commit
75239b955b
36
unix/uxpty.c
36
unix/uxpty.c
@ -835,9 +835,41 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf,
|
|||||||
putty_signal(SIGQUIT, SIG_DFL);
|
putty_signal(SIGQUIT, SIG_DFL);
|
||||||
putty_signal(SIGPIPE, SIG_DFL);
|
putty_signal(SIGPIPE, SIG_DFL);
|
||||||
block_signal(SIGCHLD, 0);
|
block_signal(SIGCHLD, 0);
|
||||||
if (pty_argv)
|
if (pty_argv) {
|
||||||
|
/*
|
||||||
|
* Exec the exact argument list we were given.
|
||||||
|
*/
|
||||||
execvp(pty_argv[0], pty_argv);
|
execvp(pty_argv[0], pty_argv);
|
||||||
else {
|
/*
|
||||||
|
* If that fails, and if we had exactly one argument, pass
|
||||||
|
* that argument to $SHELL -c.
|
||||||
|
*
|
||||||
|
* This arranges that we can _either_ follow 'pterm -e'
|
||||||
|
* with a list of argv elements to be fed directly to
|
||||||
|
* exec, _or_ with a single argument containing a command
|
||||||
|
* to be parsed by a shell (but, in cases of doubt, the
|
||||||
|
* former is more reliable).
|
||||||
|
*
|
||||||
|
* A quick survey of other terminal emulators' -e options
|
||||||
|
* (as of Debian squeeze) suggests that:
|
||||||
|
*
|
||||||
|
* - xterm supports both modes, more or less like this
|
||||||
|
* - gnome-terminal will only accept a one-string shell command
|
||||||
|
* - Eterm, kterm and rxvt will only accept a list of
|
||||||
|
* argv elements (as did older versions of pterm).
|
||||||
|
*
|
||||||
|
* It therefore seems important to support both usage
|
||||||
|
* modes in order to be a drop-in replacement for either
|
||||||
|
* xterm or gnome-terminal, and hence for anyone's
|
||||||
|
* plausible uses of the Debian-style alias
|
||||||
|
* 'x-terminal-emulator'...
|
||||||
|
*/
|
||||||
|
if (pty_argv[1] == NULL) {
|
||||||
|
char *shell = getenv("SHELL");
|
||||||
|
if (shell)
|
||||||
|
execl(shell, shell, "-c", pty_argv[0], (void *)NULL);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
char *shell = getenv("SHELL");
|
char *shell = getenv("SHELL");
|
||||||
char *shellname;
|
char *shellname;
|
||||||
if (conf_get_int(conf, CONF_login_shell)) {
|
if (conf_get_int(conf, CONF_login_shell)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user