aboutsummaryrefslogtreecommitdiff
path: root/window.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2009-07-01 19:42:55 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2009-07-01 19:42:55 +0000
commit22d1b9412e52c98cbdf52a3a5185a416c6d26c64 (patch)
tree9670391a25d42bf45bebf18f81729f5123704940 /window.c
parentd50810267eb471a8a6739897efaf49e369e14c65 (diff)
downloadrtmux-22d1b9412e52c98cbdf52a3a5185a416c6d26c64.tar.gz
rtmux-22d1b9412e52c98cbdf52a3a5185a416c6d26c64.tar.bz2
rtmux-22d1b9412e52c98cbdf52a3a5185a416c6d26c64.zip
Using -l to specify a login shell is non-POSIX and causes problems with shells
that do not support it. Instead, set an empty default-command to invoke $SHELL with - prefixed to argv[0], and make this the default setting.
Diffstat (limited to 'window.c')
-rw-r--r--window.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/window.c b/window.c
index 240a5ffa..3b9f3123 100644
--- a/window.c
+++ b/window.c
@@ -1,4 +1,4 @@
-/* $Id: window.c,v 1.85 2009-06-25 16:47:00 nicm Exp $ */
+/* $Id: window.c,v 1.86 2009-07-01 19:42:55 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -22,6 +22,7 @@
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <pwd.h>
#include <signal.h>
#include <stdint.h>
#include <stdlib.h>
@@ -53,8 +54,27 @@
/* Global window list. */
struct windows windows;
+const char *window_default_command(void);
+
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)
{
@@ -422,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)
@@ -463,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");
}