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.
This commit is contained in:
Nicholas Marriott
2009-07-01 19:42:55 +00:00
parent d50810267e
commit 22d1b9412e
3 changed files with 43 additions and 18 deletions

View File

@ -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");
}