version 1.81, 2018/08/18 20:08:52 |
version 1.82, 2018/10/18 08:38:01 |
|
|
/* Create a new session. */ |
/* Create a new session. */ |
struct session * |
struct session * |
session_create(const char *prefix, const char *name, int argc, char **argv, |
session_create(const char *prefix, const char *name, int argc, char **argv, |
const char *path, const char *cwd, struct environ *env, struct termios *tio, |
const char *path, const char *cwd, struct environ *env, struct options *oo, |
int idx, u_int sx, u_int sy, char **cause) |
struct termios *tio, int idx, char **cause) |
{ |
{ |
struct session *s; |
struct session *s; |
struct winlink *wl; |
struct winlink *wl; |
|
|
if (env != NULL) |
if (env != NULL) |
environ_copy(env, s->environ); |
environ_copy(env, s->environ); |
|
|
s->options = options_create(global_s_options); |
s->options = oo; |
s->hooks = hooks_create(global_hooks); |
s->hooks = hooks_create(global_hooks); |
|
|
status_update_saved(s); |
status_update_saved(s); |
|
|
memcpy(s->tio, tio, sizeof *s->tio); |
memcpy(s->tio, tio, sizeof *s->tio); |
} |
} |
|
|
s->sx = sx; |
|
s->sy = sy; |
|
|
|
if (name != NULL) { |
if (name != NULL) { |
s->name = xstrdup(name); |
s->name = xstrdup(name); |
s->id = next_session_id++; |
s->id = next_session_id++; |
|
|
struct winlink *wl; |
struct winlink *wl; |
struct environ *env; |
struct environ *env; |
const char *shell; |
const char *shell; |
u_int hlimit; |
u_int hlimit, sx, sy; |
|
|
if ((wl = winlink_add(&s->windows, idx)) == NULL) { |
if ((wl = winlink_add(&s->windows, idx)) == NULL) { |
xasprintf(cause, "index in use: %d", idx); |
xasprintf(cause, "index in use: %d", idx); |
|
|
if (*shell == '\0' || areshell(shell)) |
if (*shell == '\0' || areshell(shell)) |
shell = _PATH_BSHELL; |
shell = _PATH_BSHELL; |
|
|
|
default_window_size(s, NULL, &sx, &sy, -1); |
hlimit = options_get_number(s->options, "history-limit"); |
hlimit = options_get_number(s->options, "history-limit"); |
env = environ_for_session(s, 0); |
env = environ_for_session(s, 0); |
w = window_create_spawn(name, argc, argv, path, shell, cwd, env, s->tio, |
w = window_create_spawn(name, argc, argv, path, shell, cwd, env, s->tio, |
s->sx, s->sy, hlimit, cause); |
sx, sy, hlimit, cause); |
if (w == NULL) { |
if (w == NULL) { |
winlink_remove(&s->windows, wl); |
winlink_remove(&s->windows, wl); |
environ_free(env); |
environ_free(env); |
|
|
s->curw = wl; |
s->curw = wl; |
winlink_clear_flags(wl); |
winlink_clear_flags(wl); |
window_update_activity(wl->window); |
window_update_activity(wl->window); |
|
tty_update_window_offset(wl->window); |
notify_session("session-window-changed", s); |
notify_session("session-window-changed", s); |
return (0); |
return (0); |
} |
} |