summaryrefslogtreecommitdiffstats
path: root/cmd-new-window.c
diff options
context:
space:
mode:
Diffstat (limited to 'cmd-new-window.c')
-rw-r--r--cmd-new-window.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 70e70c68..a5085fff 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -49,9 +49,9 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct session *s;
struct winlink *wl;
- const char *cmd, *path, *template;
+ const char *cmd, *path, *template, *cwd, *to_free;
char **argv, *cause, *cp;
- int argc, idx, detached, cwd, fd = -1;
+ int argc, idx, detached;
struct format_tree *ft;
struct environ_entry *envent;
@@ -92,24 +92,20 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
if (envent != NULL)
path = envent->value;
+ to_free = NULL;
if (args_has(args, 'c')) {
ft = format_create();
format_defaults(ft, cmd_find_client(cmdq, NULL, 1), s, NULL,
NULL);
- cp = format_expand(ft, args_get(args, 'c'));
+ cwd = 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;
+ if (access(cwd, X_OK) != 0) {
+ free((void *)cwd);
+ cmdq_error(cmdq, "bad working directory: %s",
+ strerror(errno));
+ return (CMD_RETURN_ERROR);
+ }
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;
else
@@ -165,12 +161,12 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
format_free(ft);
}
- if (fd != -1)
- close(fd);
+ if (to_free != NULL)
+ free((void *)to_free);
return (CMD_RETURN_NORMAL);
error:
- if (fd != -1)
- close(fd);
+ if (to_free != NULL)
+ free((void *)to_free);
return (CMD_RETURN_ERROR);
}