version 1.75, 2015/10/28 09:51:55 |
version 1.76, 2015/10/31 08:13:58 |
|
|
struct environ *env; |
struct environ *env; |
struct termios tio, *tiop; |
struct termios tio, *tiop; |
const char *newname, *target, *update, *errstr, *template; |
const char *newname, *target, *update, *errstr, *template; |
const char *path; |
const char *path, *cwd, *to_free; |
char **argv, *cmd, *cause, *cp; |
char **argv, *cmd, *cause, *cp; |
int detached, already_attached, idx, cwd, fd = -1; |
int detached, already_attached, idx, argc; |
int argc; |
|
u_int sx, sy; |
u_int sx, sy; |
struct format_tree *ft; |
struct format_tree *ft; |
struct environ_entry *envent; |
struct environ_entry *envent; |
|
|
already_attached = 1; |
already_attached = 1; |
|
|
/* Get the new session working directory. */ |
/* Get the new session working directory. */ |
|
to_free = NULL; |
if (args_has(args, 'c')) { |
if (args_has(args, 'c')) { |
ft = format_create(); |
ft = format_create(); |
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL, |
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL, |
NULL); |
NULL); |
cp = format_expand(ft, args_get(args, 'c')); |
to_free = cwd = format_expand(ft, args_get(args, 'c')); |
format_free(ft); |
format_free(ft); |
|
|
if (cp != NULL && *cp != '\0') { |
if (access(cwd, X_OK) != 0) { |
fd = open(cp, O_RDONLY|O_DIRECTORY); |
free((void *)cwd); |
free(cp); |
cmdq_error(cmdq, "bad working directory: %s", |
if (fd == -1) { |
strerror(errno)); |
cmdq_error(cmdq, "bad working directory: %s", |
return (CMD_RETURN_ERROR); |
strerror(errno)); |
} |
return (CMD_RETURN_ERROR); |
|
} |
|
} else |
|
free(cp); |
|
cwd = fd; |
|
} else if (c != NULL && c->session == NULL) |
} else if (c != NULL && c->session == NULL) |
cwd = c->cwd; |
cwd = c->cwd; |
else if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL) |
else if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL) |
cwd = c0->session->cwd; |
cwd = c0->session->cwd; |
else { |
else |
fd = open(".", O_RDONLY); |
cwd = "."; |
cwd = fd; |
|
} |
|
|
|
/* |
/* |
* If this is a new client, check for nesting and save the termios |
* If this is a new client, check for nesting and save the termios |
|
|
if (!detached) |
if (!detached) |
cmdq->client_exit = 0; |
cmdq->client_exit = 0; |
|
|
if (fd != -1) |
if (to_free != NULL) |
close(fd); |
free((void *)to_free); |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
|
|
error: |
error: |
if (fd != -1) |
if (to_free != NULL) |
close(fd); |
free((void *)to_free); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |