diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2009-07-08 05:26:45 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2009-07-08 05:26:45 +0000 |
commit | 084d07f4eb5dc3d90e28725524147e66a25b869b (patch) | |
tree | 0cbfab6bd64ee71d1023e83930ec7e6b8aeea2da /window.c | |
parent | b4efd1ca89132dcf24acd6dc7b1ccee369b7d90c (diff) | |
download | rtmux-084d07f4eb5dc3d90e28725524147e66a25b869b.tar.gz rtmux-084d07f4eb5dc3d90e28725524147e66a25b869b.tar.bz2 rtmux-084d07f4eb5dc3d90e28725524147e66a25b869b.zip |
Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).
Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 34 |
1 files changed, 32 insertions, 2 deletions
@@ -23,6 +23,7 @@ #include <fcntl.h> #include <fnmatch.h> #include <paths.h> +#include <pwd.h> #include <signal.h> #include <stdint.h> #include <stdlib.h> @@ -57,6 +58,23 @@ struct windows windows; RB_GENERATE(winlinks, winlink, entry, winlink_cmp); +const char * +window_default_command(void) +{ + const char *shell; + struct passwd *pw; + + shell = getenv("SHELL"); + if (shell != NULL && *shell != '\0') + return (shell); + + pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_shell != NULL && *pw->pw_shell != '\0') + return (pw->pw_shell); + + return (_PATH_BSHELL); +} + int winlink_cmp(struct winlink *wl1, struct winlink *wl2) { @@ -424,7 +442,8 @@ window_pane_spawn(struct window_pane *wp, { struct winsize ws; int mode; - const char **envq; + const char **envq, *ptr; + char *argv0; struct timeval tv; if (wp->fd != -1) @@ -465,7 +484,18 @@ window_pane_spawn(struct window_pane *wp, sigreset(); log_close(); - execl(_PATH_BSHELL, "sh", "-c", wp->cmd, (char *) NULL); + if (*wp->cmd != '\0') { + execl(_PATH_BSHELL, "sh", "-c", wp->cmd, (char *) NULL); + fatal("execl failed"); + } + + /* No command; fork a login shell. */ + cmd = window_default_command(); + if ((ptr = strrchr(cmd, '/')) != NULL && *(ptr + 1) != '\0') + xasprintf(&argv0, "-%s", ptr + 1); + else + xasprintf(&argv0, "-%s", cmd); + execl(cmd, argv0, (char *) NULL); fatal("execl failed"); } |