version 1.115, 2019/03/12 13:56:30 |
version 1.116, 2019/04/17 14:37:48 |
|
|
struct args *args = self->args; |
struct args *args = self->args; |
struct client *c = item->client; |
struct client *c = item->client; |
struct session *s, *as, *groupwith; |
struct session *s, *as, *groupwith; |
struct window *w; |
|
struct environ *env; |
struct environ *env; |
struct options *oo; |
struct options *oo; |
struct termios tio, *tiop; |
struct termios tio, *tiop; |
struct session_group *sg; |
struct session_group *sg; |
const char *errstr, *template, *group, *prefix; |
const char *errstr, *template, *group, *prefix, *tmp; |
const char *path, *cmd, *tmp, *value; |
char *cause, *cwd = NULL, *cp, *newname = NULL; |
char **argv, *cause, *cp, *newname, *cwd = NULL; |
int detached, already_attached, is_control = 0; |
int detached, already_attached, idx, argc; |
u_int sx, sy, dsx, dsy; |
int is_control = 0; |
struct spawn_context sc; |
u_int sx, sy, dsx = 80, dsy = 24; |
|
struct environ_entry *envent; |
|
struct cmd_find_state fs; |
|
enum cmd_retval retval; |
enum cmd_retval retval; |
|
struct cmd_find_state fs; |
|
|
if (self->entry == &cmd_has_session_entry) { |
if (self->entry == &cmd_has_session_entry) { |
/* |
/* |
|
|
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
|
|
newname = NULL; |
|
if (args_has(args, 's')) { |
if (args_has(args, 's')) { |
newname = format_single(item, args_get(args, 's'), c, NULL, |
newname = format_single(item, args_get(args, 's'), c, NULL, |
NULL, NULL); |
NULL, NULL); |
if (!session_check_name(newname)) { |
if (!session_check_name(newname)) { |
cmdq_error(item, "bad session name: %s", newname); |
cmdq_error(item, "bad session name: %s", newname); |
goto error; |
goto fail; |
} |
} |
if ((as = session_find(newname)) != NULL) { |
if ((as = session_find(newname)) != NULL) { |
if (args_has(args, 'A')) { |
if (args_has(args, 'A')) { |
|
|
return (retval); |
return (retval); |
} |
} |
cmdq_error(item, "duplicate session: %s", newname); |
cmdq_error(item, "duplicate session: %s", newname); |
goto error; |
goto fail; |
} |
} |
} |
} |
|
|
|
|
if (groupwith == NULL) { |
if (groupwith == NULL) { |
if (!session_check_name(group)) { |
if (!session_check_name(group)) { |
cmdq_error(item, "bad group name: %s", group); |
cmdq_error(item, "bad group name: %s", group); |
goto error; |
goto fail; |
} |
} |
sg = session_group_find(group); |
sg = session_group_find(group); |
} else |
} else |
|
|
if (server_client_check_nested(item->client)) { |
if (server_client_check_nested(item->client)) { |
cmdq_error(item, "sessions should be nested with care, " |
cmdq_error(item, "sessions should be nested with care, " |
"unset $TMUX to force"); |
"unset $TMUX to force"); |
return (CMD_RETURN_ERROR); |
goto fail; |
} |
} |
if (tcgetattr(c->tty.fd, &tio) != 0) |
if (tcgetattr(c->tty.fd, &tio) != 0) |
fatal("tcgetattr failed"); |
fatal("tcgetattr failed"); |
|
|
if (server_client_open(c, &cause) != 0) { |
if (server_client_open(c, &cause) != 0) { |
cmdq_error(item, "open terminal failed: %s", cause); |
cmdq_error(item, "open terminal failed: %s", cause); |
free(cause); |
free(cause); |
goto error; |
goto fail; |
} |
} |
} |
} |
|
|
|
|
dsx = strtonum(tmp, 1, USHRT_MAX, &errstr); |
dsx = strtonum(tmp, 1, USHRT_MAX, &errstr); |
if (errstr != NULL) { |
if (errstr != NULL) { |
cmdq_error(item, "width %s", errstr); |
cmdq_error(item, "width %s", errstr); |
goto error; |
goto fail; |
} |
} |
} |
} |
} |
} |
|
|
dsy = strtonum(tmp, 1, USHRT_MAX, &errstr); |
dsy = strtonum(tmp, 1, USHRT_MAX, &errstr); |
if (errstr != NULL) { |
if (errstr != NULL) { |
cmdq_error(item, "height %s", errstr); |
cmdq_error(item, "height %s", errstr); |
goto error; |
goto fail; |
} |
} |
} |
} |
} |
} |
|
|
if (sy > 0 && options_get_number(global_s_options, "status")) |
if (sy > 0 && options_get_number(global_s_options, "status")) |
sy--; |
sy--; |
} else { |
} else { |
value = options_get_string(global_s_options, "default-size"); |
tmp = options_get_string(global_s_options, "default-size"); |
if (sscanf(value, "%ux%u", &sx, &sy) != 2) { |
if (sscanf(tmp, "%ux%u", &sx, &sy) != 2) { |
sx = 80; |
sx = 80; |
sy = 24; |
sy = 24; |
} |
} |
|
|
if (sy == 0) |
if (sy == 0) |
sy = 1; |
sy = 1; |
|
|
/* Figure out the command for the new window. */ |
/* Create the new session. */ |
argc = -1; |
oo = options_create(global_s_options); |
argv = NULL; |
if (args_has(args, 'x') || args_has(args, 'y')) |
if (!args_has(args, 't') && args->argc != 0) { |
options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy); |
argc = args->argc; |
|
argv = args->argv; |
|
} else if (sg == NULL && groupwith == NULL) { |
|
cmd = options_get_string(global_s_options, "default-command"); |
|
if (cmd != NULL && *cmd != '\0') { |
|
argc = 1; |
|
argv = (char **)&cmd; |
|
} else { |
|
argc = 0; |
|
argv = NULL; |
|
} |
|
} |
|
|
|
path = NULL; |
|
if (c != NULL && c->session == NULL) |
|
envent = environ_find(c->environ, "PATH"); |
|
else |
|
envent = environ_find(global_environ, "PATH"); |
|
if (envent != NULL) |
|
path = envent->value; |
|
|
|
/* Construct the environment. */ |
|
env = environ_create(); |
env = environ_create(); |
if (c != NULL && !args_has(args, 'E')) |
if (c != NULL && !args_has(args, 'E')) |
environ_update(global_s_options, c->environ, env); |
environ_update(global_s_options, c->environ, env); |
|
s = session_create(prefix, newname, cwd, env, oo, tiop); |
|
|
/* Set up the options. */ |
/* Spawn the initial window. */ |
oo = options_create(global_s_options); |
memset(&sc, 0, sizeof sc); |
if (args_has(args, 'x') || args_has(args, 'y')) |
sc.item = item; |
options_set_string(oo, "default-size", 0, "%ux%u", dsx, dsy); |
sc.s = s; |
|
|
/* Create the new session. */ |
sc.name = args_get(args, 'n'); |
idx = -1 - options_get_number(global_s_options, "base-index"); |
sc.argc = args->argc; |
s = session_create(prefix, newname, argc, argv, path, cwd, env, oo, |
sc.argv = args->argv; |
tiop, idx, &cause); |
|
environ_free(env); |
sc.idx = -1; |
if (s == NULL) { |
sc.cwd = args_get(args, 'c'); |
cmdq_error(item, "create session failed: %s", cause); |
|
|
sc.flags = 0; |
|
|
|
if (spawn_window(&sc, &cause) == NULL) { |
|
session_destroy(s, 0, __func__); |
|
cmdq_error(item, "create window failed: %s", cause); |
free(cause); |
free(cause); |
goto error; |
goto fail; |
} |
} |
|
|
/* Set the initial window name if one given. */ |
|
if (argc >= 0 && (tmp = args_get(args, 'n')) != NULL) { |
|
cp = format_single(item, tmp, c, s, NULL, NULL); |
|
w = s->curw->window; |
|
window_set_name(w, cp); |
|
options_set_number(w->options, "automatic-rename", 0); |
|
free(cp); |
|
} |
|
|
|
/* |
/* |
* If a target session is given, this is to be part of a session group, |
* If a target session is given, this is to be part of a session group, |
* so add it to the group and synchronize. |
* so add it to the group and synchronize. |
|
|
free(newname); |
free(newname); |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
|
|
error: |
fail: |
free(cwd); |
free(cwd); |
free(newname); |
free(newname); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |