mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Sync from OpenBSD:
== Rather than constructing an entire termios struct from ttydefaults.h, just let forkpty do it and then alter the bits that should be changed after fork. A little neater and more portable. == This should fix problems caused by glibc's broken ttydefaults.h file.
This commit is contained in:
parent
150fba5ecd
commit
15b643fc11
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-new-session.c,v 1.65 2009-09-15 23:52:30 tcunha Exp $ */
|
||||
/* $Id: cmd-new-session.c,v 1.66 2009-09-16 12:36:27 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -24,18 +24,6 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
#ifdef HAVE_TTYDEFAULTS_H
|
||||
#ifdef HAVE_TTYDEFCHARS
|
||||
#define TTYDEFCHARS
|
||||
#endif
|
||||
#include <sys/ttydefaults.h>
|
||||
#else
|
||||
#ifndef OXTABS
|
||||
#define OXTABS 0
|
||||
#endif
|
||||
#include "compat/ttydefaults.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Create a new session and attach to the current terminal unless -d is given.
|
||||
*/
|
||||
@ -126,7 +114,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
struct session *s;
|
||||
struct window *w;
|
||||
struct environ env;
|
||||
struct termios tio;
|
||||
struct termios tio, *tiop;
|
||||
const char *update;
|
||||
char *overrides, *cmd, *cwd, *cause;
|
||||
int detached, idx;
|
||||
@ -161,8 +149,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
detached = 1;
|
||||
|
||||
/*
|
||||
* Fill in the termios settings used for new windows in this session;
|
||||
* if there is a command client, use the control characters from it.
|
||||
* Save the termios settings, part of which is used for new windows in
|
||||
* this session.
|
||||
*
|
||||
* This is read again with tcgetattr() rather than using tty.tio as if
|
||||
* detached, tty_open won't be called. Because of this, it must be done
|
||||
@ -172,32 +160,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
||||
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
} else {
|
||||
#ifdef HAVE_TTYDEFCHARS
|
||||
memcpy(tio.c_cc, ttydefchars, sizeof tio.c_cc);
|
||||
#else
|
||||
memset(tio.c_cc, _POSIX_VDISABLE, sizeof tio.c_cc);
|
||||
tio.c_cc[VINTR] = CINTR;
|
||||
tio.c_cc[VQUIT] = CQUIT;
|
||||
tio.c_cc[VKILL] = CKILL;
|
||||
tio.c_cc[VEOF] = CEOF;
|
||||
tio.c_cc[VSTART] = CSTART;
|
||||
tio.c_cc[VSTOP] = CSTOP;
|
||||
tio.c_cc[VSUSP] = CSUSP;
|
||||
tio.c_cc[VEOL] = CEOL;
|
||||
tio.c_cc[VREPRINT] = CREPRINT;
|
||||
tio.c_cc[VDISCARD] = CDISCARD;
|
||||
tio.c_cc[VWERASE] = CWERASE;
|
||||
tio.c_cc[VLNEXT] = CLNEXT;
|
||||
#endif
|
||||
}
|
||||
tio.c_cc[VERASE] = '\177';
|
||||
tio.c_iflag = TTYDEF_IFLAG;
|
||||
tio.c_oflag = TTYDEF_OFLAG;
|
||||
tio.c_lflag = TTYDEF_LFLAG;
|
||||
tio.c_cflag = TTYDEF_CFLAG;
|
||||
cfsetispeed(&tio, TTYDEF_SPEED);
|
||||
cfsetospeed(&tio, TTYDEF_SPEED);
|
||||
tiop = &tio;
|
||||
} else
|
||||
tiop = NULL;
|
||||
|
||||
/* Open the terminal if necessary. */
|
||||
if (!detached && ctx->cmdclient != NULL) {
|
||||
@ -254,7 +219,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
/* Create the new session. */
|
||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||
s = session_create(
|
||||
data->newname, cmd, cwd, &env, &tio, idx, sx, sy, &cause);
|
||||
data->newname, cmd, cwd, &env, tiop, idx, sx, sy, &cause);
|
||||
if (s == NULL) {
|
||||
ctx->error(ctx, "create session failed: %s", cause);
|
||||
xfree(cause);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-respawn-window.c,v 1.21 2009-09-02 01:02:44 tcunha Exp $ */
|
||||
/* $Id: cmd-respawn-window.c,v 1.22 2009-09-16 12:36:27 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -76,7 +76,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||
window_pane_resize(wp, w->sx, w->sy);
|
||||
if (window_pane_spawn(
|
||||
wp, data->arg, NULL, NULL, &env, &s->tio, &cause) != 0) {
|
||||
wp, data->arg, NULL, NULL, &env, s->tio, &cause) != 0) {
|
||||
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||
xfree(cause);
|
||||
environ_free(&env);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-split-window.c,v 1.26 2009-09-02 01:05:55 tcunha Exp $ */
|
||||
/* $Id: cmd-split-window.c,v 1.27 2009-09-16 12:36:27 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -189,7 +189,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
||||
shell = _PATH_BSHELL;
|
||||
|
||||
wp = window_add_pane(w, hlimit);
|
||||
if (window_pane_spawn(wp, cmd, shell, cwd, &env, &s->tio, &cause) != 0)
|
||||
if (window_pane_spawn(wp, cmd, shell, cwd, &env, s->tio, &cause) != 0)
|
||||
goto error;
|
||||
if (layout_split_pane(w->active, type, size, wp) != 0) {
|
||||
cause = xstrdup("pane too small");
|
||||
|
@ -1,139 +0,0 @@
|
||||
/* $Id: ttydefaults.h,v 1.3 2009-08-20 12:38:37 nicm Exp $ */
|
||||
/* $OpenBSD: ttydefaults.h,v 1.6 2003/06/02 23:28:22 millert Exp $ */
|
||||
/* $NetBSD: ttydefaults.h,v 1.8 1996/04/09 20:55:45 cgd Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1982, 1986, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* (c) UNIX System Laboratories, Inc.
|
||||
* All or some portions of this file are derived from material licensed
|
||||
* to the University of California by American Telephone and Telegraph
|
||||
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||
* the permission of UNIX System Laboratories, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94
|
||||
*/
|
||||
|
||||
/*
|
||||
* System wide defaults for terminal state.
|
||||
*/
|
||||
#ifndef _SYS_TTYDEFAULTS_H_
|
||||
#define _SYS_TTYDEFAULTS_H_
|
||||
|
||||
/*
|
||||
* Defaults on "first" open.
|
||||
*/
|
||||
#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
|
||||
#define TTYDEF_OFLAG (OPOST | ONLCR | OXTABS)
|
||||
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
|
||||
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
|
||||
#define TTYDEF_SPEED (B9600)
|
||||
|
||||
/*
|
||||
* Control Character Defaults
|
||||
*/
|
||||
#undef CTRL
|
||||
#define CTRL(x) (x&037)
|
||||
#ifndef CEOF
|
||||
#define CEOF CTRL('d')
|
||||
#endif
|
||||
#ifndef CEOL
|
||||
#define CEOL ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */
|
||||
#endif
|
||||
#ifndef CERASE
|
||||
#define CERASE 0177
|
||||
#endif
|
||||
#ifndef CINTR
|
||||
#define CINTR CTRL('c')
|
||||
#endif
|
||||
#ifndef CSTATUS
|
||||
#define CSTATUS ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */
|
||||
#endif
|
||||
#ifndef CKILL
|
||||
#define CKILL CTRL('u')
|
||||
#endif
|
||||
#ifndef CMIN
|
||||
#define CMIN 1
|
||||
#endif
|
||||
#ifndef CQUIT
|
||||
#define CQUIT 034 /* FS, ^\ */
|
||||
#endif
|
||||
#ifndef CSUSP
|
||||
#define CSUSP CTRL('z')
|
||||
#endif
|
||||
#ifndef CTIME
|
||||
#define CTIME 0
|
||||
#endif
|
||||
#ifndef CDSUSP
|
||||
#define CDSUSP CTRL('y')
|
||||
#endif
|
||||
#ifndef CSTART
|
||||
#define CSTART CTRL('q')
|
||||
#endif
|
||||
#ifndef CSTOP
|
||||
#define CSTOP CTRL('s')
|
||||
#endif
|
||||
#ifndef CLNEXT
|
||||
#define CLNEXT CTRL('v')
|
||||
#endif
|
||||
#ifndef CDISCARD
|
||||
#define CDISCARD CTRL('o')
|
||||
#endif
|
||||
#ifndef CWERASE
|
||||
#define CWERASE CTRL('w')
|
||||
#endif
|
||||
#ifndef CREPRINT
|
||||
#define CREPRINT CTRL('r')
|
||||
#endif
|
||||
#ifndef CEOT
|
||||
#define CEOT CEOF
|
||||
#endif
|
||||
/* compat */
|
||||
#ifndef CBRK
|
||||
#define CBRK CEOL
|
||||
#endif
|
||||
#ifndef CRPRNT
|
||||
#define CRPRNT CREPRINT
|
||||
#endif
|
||||
#ifndef CFLUSH
|
||||
#define CFLUSH CDISCARD
|
||||
#endif
|
||||
|
||||
/* PROTECTED INCLUSION ENDS HERE */
|
||||
#endif /* !_SYS_TTYDEFAULTS_H_ */
|
||||
|
||||
/*
|
||||
* #define TTYDEFCHARS to include an array of default control characters.
|
||||
*/
|
||||
#ifdef TTYDEFCHARS
|
||||
cc_t ttydefchars[NCCS] = {
|
||||
CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT,
|
||||
_POSIX_VDISABLE, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT,
|
||||
CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE
|
||||
};
|
||||
#undef TTYDEFCHARS
|
||||
#endif
|
13
configure
vendored
13
configure
vendored
@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
# $Id: configure,v 1.36 2009-09-04 14:48:25 nicm Exp $
|
||||
# $Id: configure,v 1.37 2009-09-16 12:36:27 nicm Exp $
|
||||
|
||||
TMUX_PLATFORM=${TMUX_PLATFORM:-`uname -s`}
|
||||
|
||||
@ -35,8 +35,6 @@ cat <<EOF >>$CONFIG_H
|
||||
#undef HAVE_STRSEP
|
||||
#undef HAVE_STRTONUM
|
||||
#undef HAVE_TREE_H
|
||||
#undef HAVE_TTYDEFAULTS_H
|
||||
#undef HAVE_TTYDEFCHARS
|
||||
#undef HAVE_UTIL_H
|
||||
#undef HAVE_U_INT
|
||||
#undef HAVE_VIS
|
||||
@ -65,8 +63,6 @@ case $TMUX_PLATFORM in
|
||||
#define HAVE_STRSEP
|
||||
#define HAVE_STRTONUM
|
||||
#define HAVE_TREE_H
|
||||
#define HAVE_TTYDEFAULTS_H
|
||||
#define HAVE_TTYDEFCHARS
|
||||
#define HAVE_UTIL_H
|
||||
#define HAVE_U_INT
|
||||
#define HAVE_VIS
|
||||
@ -91,7 +87,6 @@ EOF
|
||||
#define HAVE_PTY_H
|
||||
#define HAVE_STRCASESTR
|
||||
#define HAVE_STRSEP
|
||||
#define HAVE_TTYDEFAULTS_H
|
||||
#define HAVE_U_INT
|
||||
EOF
|
||||
cat <<EOF >>$CONFIG_MK
|
||||
@ -183,8 +178,6 @@ EOF
|
||||
#define HAVE_STRLCAT
|
||||
#define HAVE_STRLCPY
|
||||
#define HAVE_STRSEP
|
||||
#define HAVE_TTYDEFAULTS_H
|
||||
#define HAVE_TTYDEFCHARS
|
||||
#define HAVE_UTIL_H
|
||||
#define HAVE_U_INT
|
||||
EOF
|
||||
@ -219,8 +212,6 @@ EOF
|
||||
#define HAVE_STRLCPY
|
||||
#define HAVE_STRTONUM
|
||||
#define HAVE_STRSEP
|
||||
#define HAVE_TTYDEFAULTS_H
|
||||
#define HAVE_TTYDEFCHARS
|
||||
#define HAVE_U_INT
|
||||
EOF
|
||||
cat <<EOF >>$CONFIG_MK
|
||||
@ -250,8 +241,6 @@ EOF
|
||||
#define HAVE_STRLCAT
|
||||
#define HAVE_STRLCPY
|
||||
#define HAVE_STRSEP
|
||||
#define HAVE_TTYDEFAULTS_H
|
||||
#define HAVE_TTYDEFCHARS
|
||||
#define HAVE_UTIL_H
|
||||
#define HAVE_U_INT
|
||||
EOF
|
||||
|
14
session.c
14
session.c
@ -1,4 +1,4 @@
|
||||
/* $Id: session.c,v 1.65 2009-09-07 23:59:19 tcunha Exp $ */
|
||||
/* $Id: session.c,v 1.66 2009-09-16 12:36:27 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -138,7 +138,12 @@ session_create(const char *name, const char *cmd, const char *cwd,
|
||||
environ_init(&s->environ);
|
||||
if (env != NULL)
|
||||
environ_copy(env, &s->environ);
|
||||
memcpy(&s->tio, tio, sizeof s->tio);
|
||||
|
||||
s->tio = NULL;
|
||||
if (tio != NULL) {
|
||||
s->tio = xmalloc(sizeof *s->tio);
|
||||
memcpy(s->tio, tio, sizeof *s->tio);
|
||||
}
|
||||
|
||||
s->sx = sx;
|
||||
s->sy = sy;
|
||||
@ -181,6 +186,9 @@ session_destroy(struct session *s)
|
||||
while (!ARRAY_EMPTY(&sessions) && ARRAY_LAST(&sessions) == NULL)
|
||||
ARRAY_TRUNC(&sessions, 1);
|
||||
|
||||
if (s->tio != NULL)
|
||||
xfree(s->tio);
|
||||
|
||||
session_alert_cancel(s, NULL);
|
||||
environ_free(&s->environ);
|
||||
options_free(&s->options);
|
||||
@ -236,7 +244,7 @@ session_new(struct session *s,
|
||||
|
||||
hlimit = options_get_number(&s->options, "history-limit");
|
||||
w = window_create(
|
||||
name, cmd, shell, cwd, &env, &s->tio, s->sx, s->sy, hlimit, cause);
|
||||
name, cmd, shell, cwd, &env, s->tio, s->sx, s->sy, hlimit, cause);
|
||||
if (w == NULL) {
|
||||
environ_free(&env);
|
||||
return (NULL);
|
||||
|
4
tmux.h
4
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.442 2009-09-15 23:50:32 tcunha Exp $ */
|
||||
/* $Id: tmux.h,v 1.443 2009-09-16 12:36:27 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -813,7 +813,7 @@ struct session {
|
||||
#define SESSION_DEAD 0x2
|
||||
int flags;
|
||||
|
||||
struct termios tio;
|
||||
struct termios *tio;
|
||||
|
||||
struct environ environ;
|
||||
|
||||
|
13
window.c
13
window.c
@ -1,4 +1,4 @@
|
||||
/* $Id: window.c,v 1.106 2009-09-02 01:08:32 tcunha Exp $ */
|
||||
/* $Id: window.c,v 1.107 2009-09-16 12:36:28 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -452,6 +452,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
||||
struct environ_entry *envent;
|
||||
const char *ptr;
|
||||
struct timeval tv;
|
||||
struct termios tio2;
|
||||
u_int i;
|
||||
|
||||
if (wp->fd != -1)
|
||||
@ -482,7 +483,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
||||
tv.tv_usec = NAME_INTERVAL * 1000L;
|
||||
timeradd(&wp->window->name_timer, &tv, &wp->window->name_timer);
|
||||
|
||||
switch (wp->pid = forkpty(&wp->fd, wp->tty, tio, &ws)) {
|
||||
switch (wp->pid = forkpty(&wp->fd, wp->tty, NULL, &ws)) {
|
||||
case -1:
|
||||
wp->fd = -1;
|
||||
xasprintf(cause, "%s: %s", cmd, strerror(errno));
|
||||
@ -491,6 +492,14 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
||||
if (chdir(wp->cwd) != 0)
|
||||
chdir("/");
|
||||
|
||||
if (tcgetattr(STDIN_FILENO, &tio2) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
if (tio != NULL)
|
||||
memcpy(tio2.c_cc, tio->c_cc, sizeof tio2.c_cc);
|
||||
tio2.c_cc[VERASE] = '\177';
|
||||
if (tcsetattr(STDIN_FILENO, TCSANOW, &tio2) != 0)
|
||||
fatal("tcgetattr failed");
|
||||
|
||||
ARRAY_INIT(&varlist);
|
||||
for (varp = environ; *varp != NULL; varp++) {
|
||||
var = xstrdup(*varp);
|
||||
|
Loading…
Reference in New Issue
Block a user