mirror of
https://github.com/tmux/tmux.git
synced 2024-12-13 01:48:47 +00:00
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 commit is contained in:
parent
a6dd9e8e7e
commit
5c60162e3c
@ -21,9 +21,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
|
||||||
#define TTYDEFCHARS
|
|
||||||
#include <sys/ttydefaults.h>
|
|
||||||
|
|
||||||
#include "tmux.h"
|
#include "tmux.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -116,7 +113,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
struct session *s;
|
struct session *s;
|
||||||
struct window *w;
|
struct window *w;
|
||||||
struct environ env;
|
struct environ env;
|
||||||
struct termios tio;
|
struct termios tio, *tiop;
|
||||||
const char *update;
|
const char *update;
|
||||||
char *overrides, *cmd, *cwd, *cause;
|
char *overrides, *cmd, *cwd, *cause;
|
||||||
int detached, idx;
|
int detached, idx;
|
||||||
@ -151,8 +148,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
detached = 1;
|
detached = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fill in the termios settings used for new windows in this session;
|
* Save the termios settings, part of which is used for new windows in
|
||||||
* if there is a command client, use the control characters from it.
|
* this session.
|
||||||
*
|
*
|
||||||
* This is read again with tcgetattr() rather than using tty.tio as if
|
* 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
|
* detached, tty_open won't be called. Because of this, it must be done
|
||||||
@ -162,15 +159,9 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
if (ctx->cmdclient != NULL && ctx->cmdclient->tty.fd != -1) {
|
||||||
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
if (tcgetattr(ctx->cmdclient->tty.fd, &tio) != 0)
|
||||||
fatal("tcgetattr failed");
|
fatal("tcgetattr failed");
|
||||||
|
tiop = &tio;
|
||||||
} else
|
} else
|
||||||
memcpy(tio.c_cc, ttydefchars, sizeof tio.c_cc);
|
tiop = NULL;
|
||||||
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);
|
|
||||||
|
|
||||||
/* Open the terminal if necessary. */
|
/* Open the terminal if necessary. */
|
||||||
if (!detached && ctx->cmdclient != NULL) {
|
if (!detached && ctx->cmdclient != NULL) {
|
||||||
@ -227,7 +218,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
/* Create the new session. */
|
/* Create the new session. */
|
||||||
idx = -1 - options_get_number(&global_s_options, "base-index");
|
idx = -1 - options_get_number(&global_s_options, "base-index");
|
||||||
s = session_create(
|
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) {
|
if (s == NULL) {
|
||||||
ctx->error(ctx, "create session failed: %s", cause);
|
ctx->error(ctx, "create session failed: %s", cause);
|
||||||
xfree(cause);
|
xfree(cause);
|
||||||
|
@ -76,7 +76,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
|
||||||
window_pane_resize(wp, w->sx, w->sy);
|
window_pane_resize(wp, w->sx, w->sy);
|
||||||
if (window_pane_spawn(
|
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);
|
ctx->error(ctx, "respawn window failed: %s", cause);
|
||||||
xfree(cause);
|
xfree(cause);
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
|
@ -190,7 +190,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
|
|||||||
shell = _PATH_BSHELL;
|
shell = _PATH_BSHELL;
|
||||||
|
|
||||||
wp = window_add_pane(w, hlimit);
|
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;
|
goto error;
|
||||||
if (layout_split_pane(w->active, type, size, wp) != 0) {
|
if (layout_split_pane(w->active, type, size, wp) != 0) {
|
||||||
cause = xstrdup("pane too small");
|
cause = xstrdup("pane too small");
|
||||||
|
12
session.c
12
session.c
@ -139,7 +139,12 @@ session_create(const char *name, const char *cmd, const char *cwd,
|
|||||||
environ_init(&s->environ);
|
environ_init(&s->environ);
|
||||||
if (env != NULL)
|
if (env != NULL)
|
||||||
environ_copy(env, &s->environ);
|
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->sx = sx;
|
||||||
s->sy = sy;
|
s->sy = sy;
|
||||||
@ -182,6 +187,9 @@ session_destroy(struct session *s)
|
|||||||
while (!ARRAY_EMPTY(&sessions) && ARRAY_LAST(&sessions) == NULL)
|
while (!ARRAY_EMPTY(&sessions) && ARRAY_LAST(&sessions) == NULL)
|
||||||
ARRAY_TRUNC(&sessions, 1);
|
ARRAY_TRUNC(&sessions, 1);
|
||||||
|
|
||||||
|
if (s->tio != NULL)
|
||||||
|
xfree(s->tio);
|
||||||
|
|
||||||
session_alert_cancel(s, NULL);
|
session_alert_cancel(s, NULL);
|
||||||
environ_free(&s->environ);
|
environ_free(&s->environ);
|
||||||
options_free(&s->options);
|
options_free(&s->options);
|
||||||
@ -237,7 +245,7 @@ session_new(struct session *s,
|
|||||||
|
|
||||||
hlimit = options_get_number(&s->options, "history-limit");
|
hlimit = options_get_number(&s->options, "history-limit");
|
||||||
w = window_create(
|
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) {
|
if (w == NULL) {
|
||||||
environ_free(&env);
|
environ_free(&env);
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
2
tmux.h
2
tmux.h
@ -815,7 +815,7 @@ struct session {
|
|||||||
#define SESSION_DEAD 0x2
|
#define SESSION_DEAD 0x2
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
struct termios tio;
|
struct termios *tio;
|
||||||
|
|
||||||
struct environ environ;
|
struct environ environ;
|
||||||
|
|
||||||
|
11
window.c
11
window.c
@ -454,6 +454,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
|||||||
struct environ_entry *envent;
|
struct environ_entry *envent;
|
||||||
const char *ptr;
|
const char *ptr;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
struct termios tio2;
|
||||||
u_int i;
|
u_int i;
|
||||||
|
|
||||||
if (wp->fd != -1)
|
if (wp->fd != -1)
|
||||||
@ -484,7 +485,7 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
|||||||
tv.tv_usec = NAME_INTERVAL * 1000L;
|
tv.tv_usec = NAME_INTERVAL * 1000L;
|
||||||
timeradd(&wp->window->name_timer, &tv, &wp->window->name_timer);
|
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:
|
case -1:
|
||||||
wp->fd = -1;
|
wp->fd = -1;
|
||||||
xasprintf(cause, "%s: %s", cmd, strerror(errno));
|
xasprintf(cause, "%s: %s", cmd, strerror(errno));
|
||||||
@ -493,6 +494,14 @@ window_pane_spawn(struct window_pane *wp, const char *cmd, const char *shell,
|
|||||||
if (chdir(wp->cwd) != 0)
|
if (chdir(wp->cwd) != 0)
|
||||||
chdir("/");
|
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);
|
ARRAY_INIT(&varlist);
|
||||||
for (varp = environ; *varp != NULL; varp++) {
|
for (varp = environ; *varp != NULL; varp++) {
|
||||||
var = xstrdup(*varp);
|
var = xstrdup(*varp);
|
||||||
|
Loading…
Reference in New Issue
Block a user