summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/session.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2019-04-17 14:37:49 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2019-04-17 14:37:49 +0000
commitddd9feaf012765cc8a535fff0ceda103da7f7610 (patch)
tree6965433e13502baf0b5d11d30c4c06f9cb48034e /usr.bin/tmux/session.c
parent4d0445e68e521952f9d36dbe08966b4996118c8a (diff)
Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.
Diffstat (limited to 'usr.bin/tmux/session.c')
-rw-r--r--usr.bin/tmux/session.c70
1 files changed, 8 insertions, 62 deletions
diff --git a/usr.bin/tmux/session.c b/usr.bin/tmux/session.c
index 37868f95544..347f91b6699 100644
--- a/usr.bin/tmux/session.c
+++ b/usr.bin/tmux/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.83 2019/03/16 17:14:07 nicm Exp $ */
+/* $OpenBSD: session.c,v 1.84 2019/04/17 14:37:48 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -112,12 +112,10 @@ session_find_by_id(u_int id)
/* Create a new session. */
struct session *
-session_create(const char *prefix, const char *name, int argc, char **argv,
- const char *path, const char *cwd, struct environ *env, struct options *oo,
- struct termios *tio, int idx, char **cause)
+session_create(const char *prefix, const char *name, const char *cwd,
+ struct environ *env, struct options *oo, struct termios *tio)
{
struct session *s;
- struct winlink *wl;
s = xcalloc(1, sizeof *s);
s->references = 1;
@@ -129,10 +127,7 @@ session_create(const char *prefix, const char *name, int argc, char **argv,
TAILQ_INIT(&s->lastw);
RB_INIT(&s->windows);
- s->environ = environ_create();
- if (env != NULL)
- environ_copy(env, s->environ);
-
+ s->environ = env;
s->options = oo;
s->hooks = hooks_create(global_hooks);
@@ -166,17 +161,6 @@ session_create(const char *prefix, const char *name, int argc, char **argv,
fatal("gettimeofday failed");
session_update_activity(s, &s->creation_time);
- if (argc >= 0) {
- wl = session_new(s, NULL, argc, argv, path, cwd, idx, cause);
- if (wl == NULL) {
- session_destroy(s, __func__);
- return (NULL);
- }
- session_select(s, RB_ROOT(&s->windows)->idx);
- }
-
- log_debug("session %s created", s->name);
-
return (s);
}
@@ -220,7 +204,7 @@ session_free(__unused int fd, __unused short events, void *arg)
/* Destroy a session. */
void
-session_destroy(struct session *s, const char *from)
+session_destroy(struct session *s, int notify, const char *from)
{
struct winlink *wl;
@@ -228,7 +212,8 @@ session_destroy(struct session *s, const char *from)
s->curw = NULL;
RB_REMOVE(sessions, &sessions, s);
- notify_session("session-closed", s);
+ if (notify)
+ notify_session("session-closed", s);
free(s->tio);
@@ -338,45 +323,6 @@ session_previous_session(struct session *s)
return (s2);
}
-/* Create a new window on a session. */
-struct winlink *
-session_new(struct session *s, const char *name, int argc, char **argv,
- const char *path, const char *cwd, int idx, char **cause)
-{
- struct window *w;
- struct winlink *wl;
- struct environ *env;
- const char *shell;
- u_int hlimit, sx, sy;
-
- if ((wl = winlink_add(&s->windows, idx)) == NULL) {
- xasprintf(cause, "index in use: %d", idx);
- return (NULL);
- }
- wl->session = s;
-
- shell = options_get_string(s->options, "default-shell");
- if (*shell == '\0' || areshell(shell))
- shell = _PATH_BSHELL;
-
- default_window_size(s, NULL, &sx, &sy, -1);
- hlimit = options_get_number(s->options, "history-limit");
- env = environ_for_session(s, 0);
- w = window_create_spawn(name, argc, argv, path, shell, cwd, env, s->tio,
- sx, sy, hlimit, cause);
- if (w == NULL) {
- winlink_remove(&s->windows, wl);
- environ_free(env);
- return (NULL);
- }
- winlink_set_window(wl, w);
- environ_free(env);
- notify_session_window("window-linked", s, w);
-
- session_group_synchronize_from(s);
- return (wl);
-}
-
/* Attach a window to a session. */
struct winlink *
session_attach(struct session *s, struct window *w, int idx, char **cause)
@@ -412,7 +358,7 @@ session_detach(struct session *s, struct winlink *wl)
session_group_synchronize_from(s);
if (RB_EMPTY(&s->windows)) {
- session_destroy(s, __func__);
+ session_destroy(s, 1, __func__);
return (1);
}
return (0);