Skip to content

Commit

Permalink
Add option 'delay_connect': This will always create the sshfs mount,
Browse files Browse the repository at this point in the history
even if the connection to the server can't be established.
  • Loading branch information
szmi committed Jul 15, 2009
1 parent b1fa040 commit ae4614e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2008-07-15 Sebastian Dransfeld <sebastid@tango.flipp.net>

* Add option 'delay_connect': This will always create the sshfs mount,
even if the connection to the server can't be established.

2009-01-27 Miklos Szeredi <miklos@szeredi.hu>

* Print usage information and version to stdout, not stderr.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi
AM_CONDITIONAL(SSH_NODELAY_SO, test "$enable_sshnodelay" = "yes")

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
PKG_CHECK_MODULES(SSHFS, [fuse >= 2.2 glib-2.0 gthread-2.0])
PKG_CHECK_MODULES(SSHFS, [fuse >= 2.3 glib-2.0 gthread-2.0])
have_fuse_opt_parse=no
oldlibs="$LIBS"
LIBS="$LIBS $SSHFS_LIBS"
Expand Down
3 changes: 3 additions & 0 deletions sshfs.1
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ equivalent to '\-o ssh_protocol=1'
\fB\-o\fR reconnect
reconnect to server
.TP
\fB\-o\fR delay_connect
delay connection to server
.TP
\fB\-o\fR sshfs_sync
synchronous writes
.TP
Expand Down
39 changes: 18 additions & 21 deletions sshfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
#endif


#if FUSE_VERSION >= 23
#define SSHFS_USE_INIT
#endif

#define SSH_FXP_INIT 1
#define SSH_FXP_VERSION 2
#define SSH_FXP_OPEN 3
Expand Down Expand Up @@ -194,6 +190,7 @@ struct sshfs {
int debug;
int foreground;
int reconnect;
int delay_connect;
char *host;
char *base_path;
GHashTable *reqtab;
Expand Down Expand Up @@ -312,6 +309,7 @@ static struct fuse_opt sshfs_opts[] = {
SSHFS_OPT("follow_symlinks", follow_symlinks, 1),
SSHFS_OPT("no_check_root", no_check_root, 1),
SSHFS_OPT("password_stdin", password_stdin, 1),
SSHFS_OPT("delay_connect", delay_connect, 1),

FUSE_OPT_KEY("-p ", KEY_PORT),
FUSE_OPT_KEY("-C", KEY_COMPRESS),
Expand Down Expand Up @@ -1580,6 +1578,11 @@ static int start_processing_thread(void)
return -EIO;
}

if (sshfs.detect_uid) {
sftp_detect_uid();
sshfs.detect_uid = 0;
}

sigemptyset(&newset);
sigaddset(&newset, SIGTERM);
sigaddset(&newset, SIGINT);
Expand All @@ -1597,11 +1600,10 @@ static int start_processing_thread(void)
return 0;
}

#ifdef SSHFS_USE_INIT
#if FUSE_VERSION >= 26
static void *sshfs_init(struct fuse_conn_info *conn)
#else
static void *sshfs_init(void)
static void *sshfs_init(void)
#endif
{
#if FUSE_VERSION >= 26
Expand All @@ -1610,13 +1612,11 @@ static void *sshfs_init(struct fuse_conn_info *conn)
sshfs.sync_read = 1;
#endif

if (sshfs.detect_uid)
sftp_detect_uid();
if (!sshfs.delay_connect)
start_processing_thread();

start_processing_thread();
return NULL;
}
#endif

static int sftp_request_wait(struct request *req, uint8_t type,
uint8_t expect_type, struct buffer *outbuf)
Expand Down Expand Up @@ -2794,9 +2794,7 @@ static int processing_init(void)

static struct fuse_cache_operations sshfs_oper = {
.oper = {
#ifdef SSHFS_USE_INIT
.init = sshfs_init,
#endif
.getattr = sshfs_getattr,
.readlink = sshfs_readlink,
.mknod = sshfs_mknod,
Expand Down Expand Up @@ -2841,6 +2839,7 @@ static void usage(const char *progname)
" -F ssh_configfile specifies alternative ssh configuration file\n"
" -1 equivalent to '-o ssh_protocol=1'\n"
" -o reconnect reconnect to server\n"
" -o delay_connect delay connection to server\n"
" -o sshfs_sync synchronous writes\n"
" -o no_readahead synchronous reads (no speculative readahead)\n"
" -o sshfs_debug print some debugging information\n"
Expand Down Expand Up @@ -3182,6 +3181,7 @@ int main(int argc, char *argv[])
sshfs.fd = -1;
sshfs.ptyfd = -1;
sshfs.ptyslavefd = -1;
sshfs.delay_connect = 0;
ssh_add_arg("ssh");
ssh_add_arg("-x");
ssh_add_arg("-a");
Expand Down Expand Up @@ -3244,16 +3244,13 @@ int main(int argc, char *argv[])
if (res == -1)
exit(1);

if (connect_remote() == -1)
exit(1);

#ifndef SSHFS_USE_INIT
if (sshfs.detect_uid)
sftp_detect_uid();
#endif
if (!sshfs.delay_connect) {
if (connect_remote() == -1)
exit(1);

if (!sshfs.no_check_root && sftp_check_root(base_path) == -1)
exit(1);
if (!sshfs.no_check_root && sftp_check_root(sshfs.base_path) == -1)
exit(1);
}

res = cache_parse_options(&args);
if (res == -1)
Expand Down

0 comments on commit ae4614e

Please sign in to comment.