=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd-new-session.c,v retrieving revision 1.75 retrieving revision 1.76 diff -c -r1.75 -r1.76 *** src/usr.bin/tmux/cmd-new-session.c 2015/10/28 09:51:55 1.75 --- src/usr.bin/tmux/cmd-new-session.c 2015/10/31 08:13:58 1.76 *************** *** 1,4 **** ! /* $OpenBSD: cmd-new-session.c,v 1.75 2015/10/28 09:51:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: cmd-new-session.c,v 1.76 2015/10/31 08:13:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott *************** *** 63,72 **** struct environ *env; struct termios tio, *tiop; const char *newname, *target, *update, *errstr, *template; ! const char *path; char **argv, *cmd, *cause, *cp; ! int detached, already_attached, idx, cwd, fd = -1; ! int argc; u_int sx, sy; struct format_tree *ft; struct environ_entry *envent; --- 63,71 ---- struct environ *env; struct termios tio, *tiop; const char *newname, *target, *update, *errstr, *template; ! const char *path, *cwd, *to_free; char **argv, *cmd, *cause, *cp; ! int detached, already_attached, idx, argc; u_int sx, sy; struct format_tree *ft; struct environ_entry *envent; *************** *** 118,149 **** already_attached = 1; /* Get the new session working directory. */ if (args_has(args, 'c')) { ft = format_create(); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL, NULL); ! cp = format_expand(ft, args_get(args, 'c')); format_free(ft); ! if (cp != NULL && *cp != '\0') { ! fd = open(cp, O_RDONLY|O_DIRECTORY); ! free(cp); ! if (fd == -1) { ! cmdq_error(cmdq, "bad working directory: %s", ! strerror(errno)); ! return (CMD_RETURN_ERROR); ! } ! } else ! free(cp); ! cwd = fd; } else if (c != NULL && c->session == NULL) cwd = c->cwd; else if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL) cwd = c0->session->cwd; ! else { ! fd = open(".", O_RDONLY); ! cwd = fd; ! } /* * If this is a new client, check for nesting and save the termios --- 117,142 ---- already_attached = 1; /* Get the new session working directory. */ + to_free = NULL; if (args_has(args, 'c')) { ft = format_create(); format_defaults(ft, cmd_find_client(cmdq, NULL, 1), NULL, NULL, NULL); ! to_free = cwd = format_expand(ft, args_get(args, 'c')); format_free(ft); ! if (access(cwd, X_OK) != 0) { ! free((void *)cwd); ! cmdq_error(cmdq, "bad working directory: %s", ! strerror(errno)); ! return (CMD_RETURN_ERROR); ! } } else if (c != NULL && c->session == NULL) cwd = c->cwd; else if ((c0 = cmd_find_client(cmdq, NULL, 1)) != NULL) cwd = c0->session->cwd; ! else ! cwd = "."; /* * If this is a new client, check for nesting and save the termios *************** *** 311,322 **** if (!detached) cmdq->client_exit = 0; ! if (fd != -1) ! close(fd); return (CMD_RETURN_NORMAL); error: ! if (fd != -1) ! close(fd); return (CMD_RETURN_ERROR); } --- 304,315 ---- if (!detached) cmdq->client_exit = 0; ! if (to_free != NULL) ! free((void *)to_free); return (CMD_RETURN_NORMAL); error: ! if (to_free != NULL) ! free((void *)to_free); return (CMD_RETURN_ERROR); }