From: Chris W. <cw...@ch...> - 2012-02-07 20:02:24
|
Hi all, Simplified this to always use stdin/stdout, and took the "-o slave" naming from last year's proposal. The earlier patch has now been split into three: the whitespace change posted earlier, a refactoring to support separate read and write pipes, and code for the actual slave option. Chris |
From: Chris W. <cw...@ch...> - 2012-02-07 20:02:23
|
--- sshfs.1 | 2 ++ sshfs.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletions(-) diff --git a/sshfs.1 b/sshfs.1 index 99d1e05..12cc974 100644 --- a/sshfs.1 +++ b/sshfs.1 @@ -127,6 +127,8 @@ path to sftp server or subsystem (default: sftp) .TP \fB\-o\fR directport=PORT directly connect to PORT bypassing ssh +\fB\-o\fR slave +communicate over stdin and stdout bypassing network .TP \fB\-o\fR transform_symlinks transform absolute symlinks to relative diff --git a/sshfs.c b/sshfs.c index 1afefb8..77e2fd2 100644 --- a/sshfs.c +++ b/sshfs.c @@ -216,6 +216,7 @@ struct sshfs { int foreground; int reconnect; int delay_connect; + int slave; char *host; char *base_path; GHashTable *reqtab; @@ -347,6 +348,7 @@ static struct fuse_opt sshfs_opts[] = { SSHFS_OPT("no_check_root", no_check_root, 1), SSHFS_OPT("password_stdin", password_stdin, 1), SSHFS_OPT("delay_connect", delay_connect, 1), + SSHFS_OPT("slave", slave, 1), FUSE_OPT_KEY("-p ", KEY_PORT), FUSE_OPT_KEY("-C", KEY_COMPRESS), @@ -1072,6 +1074,13 @@ static int start_ssh(void) return 0; } +static int connect_slave() +{ + sshfs.rfd = STDIN_FILENO; + sshfs.wfd = STDOUT_FILENO; + return 0; +} + static int connect_to(char *host, char *port) { int err; @@ -1644,7 +1653,9 @@ static int connect_remote(void) { int err; - if (sshfs.directport) + if (sshfs.slave) + err = connect_slave(); + else if (sshfs.directport) err = connect_to(sshfs.host, sshfs.directport); else err = start_ssh(); @@ -3153,6 +3164,7 @@ static void usage(const char *progname) " -o ssh_protocol=N ssh protocol to use (default: 2)\n" " -o sftp_server=SERV path to sftp server or subsystem (default: sftp)\n" " -o directport=PORT directly connect to PORT bypassing ssh\n" +" -o slave communicate over stdin and stdout bypassing network\n" " -o transform_symlinks transform absolute symlinks to relative\n" " -o follow_symlinks follow symlinks on the server\n" " -o no_check_root don't check for existence of 'dir' on server\n" @@ -3652,6 +3664,7 @@ int main(int argc, char *argv[]) sshfs.ptyfd = -1; sshfs.ptyslavefd = -1; sshfs.delay_connect = 0; + sshfs.slave = 0; sshfs.detect_uid = 0; sshfs.idmap = IDMAP_NONE; ssh_add_arg("ssh"); -- 1.7.7.3 |
From: Miklos S. <mi...@sz...> - 2012-02-08 09:27:55
|
You mentioned that this conflicts with the password_stdin option. Shouldn't it exit with an error mesage if both are given? Also could you please add a ChangeLog entry? Other than that all looks good. Thanks, Miklos Chris Wolfe <cw...@ch...> writes: > --- > sshfs.1 | 2 ++ > sshfs.c | 15 ++++++++++++++- > 2 files changed, 16 insertions(+), 1 deletions(-) > > diff --git a/sshfs.1 b/sshfs.1 > index 99d1e05..12cc974 100644 > --- a/sshfs.1 > +++ b/sshfs.1 > @@ -127,6 +127,8 @@ path to sftp server or subsystem (default: sftp) > .TP > \fB\-o\fR directport=PORT > directly connect to PORT bypassing ssh > +\fB\-o\fR slave > +communicate over stdin and stdout bypassing network > .TP > \fB\-o\fR transform_symlinks > transform absolute symlinks to relative > diff --git a/sshfs.c b/sshfs.c > index 1afefb8..77e2fd2 100644 > --- a/sshfs.c > +++ b/sshfs.c > @@ -216,6 +216,7 @@ struct sshfs { > int foreground; > int reconnect; > int delay_connect; > + int slave; > char *host; > char *base_path; > GHashTable *reqtab; > @@ -347,6 +348,7 @@ static struct fuse_opt sshfs_opts[] = { > SSHFS_OPT("no_check_root", no_check_root, 1), > SSHFS_OPT("password_stdin", password_stdin, 1), > SSHFS_OPT("delay_connect", delay_connect, 1), > + SSHFS_OPT("slave", slave, 1), > > FUSE_OPT_KEY("-p ", KEY_PORT), > FUSE_OPT_KEY("-C", KEY_COMPRESS), > @@ -1072,6 +1074,13 @@ static int start_ssh(void) > return 0; > } > > +static int connect_slave() > +{ > + sshfs.rfd = STDIN_FILENO; > + sshfs.wfd = STDOUT_FILENO; > + return 0; > +} > + > static int connect_to(char *host, char *port) > { > int err; > @@ -1644,7 +1653,9 @@ static int connect_remote(void) > { > int err; > > - if (sshfs.directport) > + if (sshfs.slave) > + err = connect_slave(); > + else if (sshfs.directport) > err = connect_to(sshfs.host, sshfs.directport); > else > err = start_ssh(); > @@ -3153,6 +3164,7 @@ static void usage(const char *progname) > " -o ssh_protocol=N ssh protocol to use (default: 2)\n" > " -o sftp_server=SERV path to sftp server or subsystem (default: sftp)\n" > " -o directport=PORT directly connect to PORT bypassing ssh\n" > +" -o slave communicate over stdin and stdout bypassing network\n" > " -o transform_symlinks transform absolute symlinks to relative\n" > " -o follow_symlinks follow symlinks on the server\n" > " -o no_check_root don't check for existence of 'dir' on server\n" > @@ -3652,6 +3664,7 @@ int main(int argc, char *argv[]) > sshfs.ptyfd = -1; > sshfs.ptyslavefd = -1; > sshfs.delay_connect = 0; > + sshfs.slave = 0; > sshfs.detect_uid = 0; > sshfs.idmap = IDMAP_NONE; > ssh_add_arg("ssh"); |
From: Chris W. <cw...@ch...> - 2012-02-07 20:02:25
|
--- sshfs.c | 27 +++++++++++++++++---------- 1 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sshfs.c b/sshfs.c index 32c0002..1afefb8 100644 --- a/sshfs.c +++ b/sshfs.c @@ -223,7 +223,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; @@ -871,7 +872,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; @@ -979,7 +980,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) { @@ -1104,7 +1106,8 @@ static int connect_to(char *host, char *port) freeaddrinfo(ai); - sshfs.fd = sock; + sshfs.rfd = sock; + sshfs.wfd = sock; return 0; } @@ -1112,7 +1115,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; @@ -1189,7 +1192,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; @@ -1350,8 +1353,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; @@ -1663,7 +1669,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; @@ -3641,7 +3647,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; -- 1.7.7.3 |