aboutsummaryrefslogtreecommitdiff
path: root/sshfs.c
diff options
context:
space:
mode:
authorChris Wolfe <cwolfe@chromium.org>2012-02-07 15:01:50 -0500
committerBenjamin Fleischer <fleiben@gmail.com>2012-03-09 22:48:58 +0100
commitff32332e8331e8d7cfb08fec90b087437731a4c5 (patch)
treebe5b0232163a9acea8e7a2d23efaf18e7955f461 /sshfs.c
parentc1284b4089ced2df04752e144817a4d5182434a9 (diff)
downloadsshfs-ff32332e8331e8d7cfb08fec90b087437731a4c5.tar
sshfs-ff32332e8331e8d7cfb08fec90b087437731a4c5.tar.gz
sshfs-ff32332e8331e8d7cfb08fec90b087437731a4c5.tar.bz2
sshfs-ff32332e8331e8d7cfb08fec90b087437731a4c5.zip
Split fd into separate read and write pipes
Diffstat (limited to 'sshfs.c')
-rw-r--r--sshfs.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/sshfs.c b/sshfs.c
index 284283b..a441a58 100644
--- a/sshfs.c
+++ b/sshfs.c
@@ -251,7 +251,8 @@ struct sshfs {
pthread_mutex_t lock_write;
int processing_thread_started;
unsigned int randseed;
- int fd;
+ int rfd;
+ int wfd;
int ptyfd;
int ptyslavefd;
int connver;
@@ -963,7 +964,7 @@ static int pty_expect_loop(void)
while (1) {
struct pollfd fds[2];
- fds[0].fd = sshfs.fd;
+ fds[0].fd = sshfs.rfd;
fds[0].events = POLLIN;
fds[1].fd = sshfs.ptyfd;
fds[1].events = POLLIN;
@@ -1071,7 +1072,8 @@ static int start_ssh(void)
perror("failed to create socket pair");
return -1;
}
- sshfs.fd = sockpair[0];
+ sshfs.rfd = sockpair[0];
+ sshfs.wfd = sockpair[0];
pid = fork();
if (pid == -1) {
@@ -1196,7 +1198,8 @@ static int connect_to(char *host, char *port)
freeaddrinfo(ai);
- sshfs.fd = sock;
+ sshfs.rfd = sock;
+ sshfs.wfd = sock;
return 0;
}
@@ -1204,7 +1207,7 @@ static int do_write(struct iovec *iov, size_t count)
{
int res;
while (count) {
- res = writev(sshfs.fd, iov, count);
+ res = writev(sshfs.wfd, iov, count);
if (res == -1) {
perror("write");
return -1;
@@ -1281,7 +1284,7 @@ static int do_read(struct buffer *buf)
uint8_t *p = buf->p;
size_t size = buf->size;
while (size) {
- res = read(sshfs.fd, p, size);
+ res = read(sshfs.rfd, p, size);
if (res == -1) {
perror("read");
return -1;
@@ -1442,8 +1445,11 @@ static int process_one_request(void)
static void close_conn(void)
{
- close(sshfs.fd);
- sshfs.fd = -1;
+ close(sshfs.rfd);
+ if (sshfs.rfd != sshfs.wfd)
+ close(sshfs.wfd);
+ sshfs.rfd = -1;
+ sshfs.wfd = -1;
if (sshfs.ptyfd != -1) {
close(sshfs.ptyfd);
sshfs.ptyfd = -1;
@@ -1763,7 +1769,7 @@ static int start_processing_thread(void)
if (sshfs.processing_thread_started)
return 0;
- if (sshfs.fd == -1) {
+ if (sshfs.rfd == -1) {
err = connect_remote();
if (err)
return -EIO;
@@ -3816,7 +3822,8 @@ int main(int argc, char *argv[])
sshfs.buflimit_workaround = 1;
sshfs.ssh_ver = 2;
sshfs.progname = argv[0];
- sshfs.fd = -1;
+ sshfs.rfd = -1;
+ sshfs.wfd = -1;
sshfs.ptyfd = -1;
sshfs.ptyslavefd = -1;
sshfs.delay_connect = 0;