From 22d1b9412e52c98cbdf52a3a5185a416c6d26c64 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Wed, 1 Jul 2009 19:42:55 +0000 Subject: 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. --- window.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'window.c') 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 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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"); } -- cgit