diff options
author | Chris Wolfe <cwolfe@chromium.org> | 2012-02-07 15:01:50 -0500 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2012-02-14 12:55:14 +0100 |
commit | acb0832ffd780b8615b213c3141073dffcea3723 (patch) | |
tree | 4d0a55356fad770ce896aac13e63e20ec6458c19 | |
parent | c5949f06fa9052b6ae846f7f61abf71829cac481 (diff) | |
download | sshfs-acb0832ffd780b8615b213c3141073dffcea3723.tar sshfs-acb0832ffd780b8615b213c3141073dffcea3723.tar.gz sshfs-acb0832ffd780b8615b213c3141073dffcea3723.tar.bz2 sshfs-acb0832ffd780b8615b213c3141073dffcea3723.zip |
Split fd into separate read and write pipes
-rw-r--r-- | sshfs.c | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -225,7 +225,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; @@ -891,7 +892,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; @@ -999,7 +1000,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) { @@ -1124,7 +1126,8 @@ static int connect_to(char *host, char *port) freeaddrinfo(ai); - sshfs.fd = sock; + sshfs.rfd = sock; + sshfs.wfd = sock; return 0; } @@ -1132,7 +1135,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; @@ -1209,7 +1212,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; @@ -1370,8 +1373,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; @@ -1687,7 +1693,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; @@ -3665,7 +3671,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; |