summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tmux/cmd-attach-session.c15
-rw-r--r--usr.bin/tmux/cmd-new-session.c13
-rw-r--r--usr.bin/tmux/server-client.c21
-rw-r--r--usr.bin/tmux/tmux.h3
4 files changed, 29 insertions, 23 deletions
diff --git a/usr.bin/tmux/cmd-attach-session.c b/usr.bin/tmux/cmd-attach-session.c
index cbb9d50ea77..b5576890ec2 100644
--- a/usr.bin/tmux/cmd-attach-session.c
+++ b/usr.bin/tmux/cmd-attach-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-attach-session.c,v 1.18 2012/03/17 22:35:09 nicm Exp $ */
+/* $OpenBSD: cmd-attach-session.c,v 1.19 2012/05/06 07:38:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -43,7 +43,7 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct session *s;
struct client *c;
const char *update;
- char *overrides, *cause;
+ char *cause;
u_int i;
if (RB_EMPTY(&sessions)) {
@@ -79,15 +79,8 @@ cmd_attach_session_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_client(ctx->curclient);
s->curw->flags &= ~WINLINK_ALERTFLAGS;
} else {
- if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
- ctx->error(ctx, "not a terminal");
- return (-1);
- }
-
- overrides =
- options_get_string(&s->options, "terminal-overrides");
- if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
- ctx->error(ctx, "terminal open failed: %s", cause);
+ if (server_client_open(ctx->cmdclient, s, &cause) != 0) {
+ ctx->error(ctx, "open terminal failed: %s", cause);
xfree(cause);
return (-1);
}
diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c
index c538ac936ef..5ebc4e3e5bd 100644
--- a/usr.bin/tmux/cmd-new-session.c
+++ b/usr.bin/tmux/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-new-session.c,v 1.41 2012/03/17 22:35:09 nicm Exp $ */
+/* $OpenBSD: cmd-new-session.c,v 1.42 2012/05/06 07:38:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -63,7 +63,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct termios tio, *tiop;
struct passwd *pw;
const char *newname, *target, *update, *cwd, *errstr;
- char *overrides, *cmd, *cause;
+ char *cmd, *cause;
int detached, idx;
u_int sx, sy, i;
@@ -128,14 +128,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
/* Open the terminal if necessary. */
if (!detached && ctx->cmdclient != NULL) {
- if (!(ctx->cmdclient->flags & CLIENT_TERMINAL)) {
- ctx->error(ctx, "not a terminal");
- return (-1);
- }
-
- overrides =
- options_get_string(&global_s_options, "terminal-overrides");
- if (tty_open(&ctx->cmdclient->tty, overrides, &cause) != 0) {
+ if (server_client_open(ctx->cmdclient, NULL, &cause) != 0) {
ctx->error(ctx, "open terminal failed: %s", cause);
xfree(cause);
return (-1);
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 604a2255a31..a9c5a1c41c1 100644
--- a/usr.bin/tmux/server-client.c
+++ b/usr.bin/tmux/server-client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server-client.c,v 1.71 2012/04/11 06:16:14 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.72 2012/05/06 07:38:17 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -105,6 +105,25 @@ server_client_create(int fd)
log_debug("new client %d", fd);
}
+/* Open client terminal if needed. */
+int
+server_client_open(struct client *c, struct session *s, char **cause)
+{
+ struct options *oo = s != NULL ? &s->options : &global_s_options;
+ char *overrides;
+
+ if (!(c->flags & CLIENT_TERMINAL)) {
+ *cause = xstrdup ("not a terminal");
+ return (-1);
+ }
+
+ overrides = options_get_string(oo, "terminal-overrides");
+ if (tty_open(&c->tty, overrides, cause) != 0)
+ return (-1);
+
+ return (0);
+}
+
/* Lost a client. */
void
server_client_lost(struct client *c)
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index dda6c1968e8..3c426e4ad9a 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.330 2012/04/29 17:20:01 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.331 2012/05/06 07:38:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1723,6 +1723,7 @@ void server_add_accept(int);
/* server-client.c */
void server_client_create(int);
+int server_client_open(struct client *, struct session *, char **);
void server_client_lost(struct client *);
void server_client_callback(int, short, void *);
void server_client_status_timer(void);