summaryrefslogtreecommitdiffstats
path: root/server-client.c
diff options
context:
space:
mode:
authornicm <nicm>2015-07-13 15:49:31 +0000
committernicm <nicm>2015-07-13 15:49:31 +0000
commitc7374c31c4ba176e94825e8d734b5abe8a6879b1 (patch)
tree862211dc6d3c5137f9aee3b8feb19ea9ddcd9eaf /server-client.c
parent81069f66f96dd83025fc6f2990619eb861199e10 (diff)
Initialize cwd fd to -1 so that we don't close fd 0 if the client is
destroyed before it is changed. Also allow ttyname() to fail. Fixes problems when running out of file descriptors reported by Bruno Sutic.
Diffstat (limited to 'server-client.c')
-rw-r--r--server-client.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/server-client.c b/server-client.c
index 9beef4bc..4c03de91 100644
--- a/server-client.c
+++ b/server-client.c
@@ -96,6 +96,8 @@ server_client_create(int fd)
environ_init(&c->environ);
+ c->cwd = -1;
+
c->cmdq = cmdq_new(c);
c->cmdq->client_exit = 1;
@@ -1253,12 +1255,11 @@ server_client_msg_identify(struct client *c, struct imsg *imsg)
if (c->fd == -1)
return;
- if (!isatty(c->fd)) {
+ if (tty_init(&c->tty, c, c->fd, c->term) != 0) {
close(c->fd);
c->fd = -1;
return;
}
- tty_init(&c->tty, c, c->fd, c->term);
if (c->flags & CLIENT_UTF8)
c->tty.flags |= TTY_UTF8;
if (c->flags & CLIENT_256COLOURS)