From 89da93d07eeb3629858011358a4f07ded2f64df0 Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Tue, 31 Jan 2006 18:34:38 +0000 Subject: fix --- .cvsignore | 2 -- ChangeLog | 4 ++++ Makefile.am | 20 +++++++++++++------- bin2c.c | 36 ------------------------------------ configure.ac | 5 +++++ sshfs.c | 53 +++++++++++++++++++++++++++++++++++++---------------- sshnodelay.c | 1 + 7 files changed, 60 insertions(+), 61 deletions(-) delete mode 100644 bin2c.c diff --git a/.cvsignore b/.cvsignore index a91f036..3a39ae6 100644 --- a/.cvsignore +++ b/.cvsignore @@ -14,5 +14,3 @@ missing sshfs stamp* .deps -bin2c -sshnodelay_so.c diff --git a/ChangeLog b/ChangeLog index e09462e..dab6e0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-01-31 Miklos Szeredi + + * Fix problems with nodelay workaround on FreeBSD. + 2006-01-30 Miklos Szeredi * Fix data consitency bug if readahead is enabled and writes are diff --git a/Makefile.am b/Makefile.am index 8869467..8c0ca99 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,18 +2,24 @@ bin_PROGRAMS = sshfs -sshfs_SOURCES = sshfs.c cache.c cache.h sshnodelay_so.c +sshfs_SOURCES = sshfs.c cache.c cache.h if FUSE_OPT_COMPAT sshfs_SOURCES += compat/fuse_opt.c compat/fuse_opt.h endif -sshfs_CPPFLAGS = -DFUSE_USE_VERSION=26 +sshfs_CPPFLAGS = -DFUSE_USE_VERSION=26 -DLIBDIR=\"$(libdir)\" -EXTRA_DIST = sshnodelay.c bin2c.c -CLEANFILES = sshnodelay.so sshnodelay_so.c bin2c +EXTRA_DIST = sshnodelay.c +CLEANFILES = sshnodelay.so -sshnodelay_so.c: bin2c sshnodelay.so - ./bin2c sshnodelay_so < sshnodelay.so > sshnodelay_so.c +all-local: sshnodelay.so + +install-exec-local: sshnodelay.so + test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)" + $(INSTALL) -m 755 sshnodelay.so "$(DESTDIR)$(libdir)/sshnodelay.so" + +uninstall-local: + rm -f "$(DESTDIR)$(libdir)/sshnodelay.so" sshnodelay.so: - $(CC) -Wall -W -s --shared -ldl sshnodelay.c -o sshnodelay.so + $(CC) -Wall -W -s --shared $(sshnodelay_libs) sshnodelay.c -o sshnodelay.so diff --git a/bin2c.c b/bin2c.c deleted file mode 100644 index 96dd2bc..0000000 --- a/bin2c.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Unloved program to convert a binary on stdin to a C include on stdout - * - * Jan 1999 Matt Mackall - * - * This software may be used and distributed according to the terms - * of the GNU General Public License, incorporated herein by reference. - */ - -#include - -int main(int argc, char *argv[]) -{ - int ch, total=0; - - if (argc > 1) - printf("const char %s[] %s=\n", - argv[1], argc > 2 ? argv[2] : ""); - - do { - printf("\t\""); - while ((ch = getchar()) != EOF) - { - total++; - printf("\\x%02x",ch); - if (total % 16 == 0) - break; - } - printf("\"\n"); - } while (ch != EOF); - - if (argc > 1) - printf("\t;\n\nconst int %s_size = %d;\n", argv[1], total); - - return 0; -} diff --git a/configure.ac b/configure.ac index 177ee9f..bcb6ca4 100644 --- a/configure.ac +++ b/configure.ac @@ -3,6 +3,11 @@ AM_INIT_AUTOMAKE AM_CONFIG_HEADER(config.h) AC_PROG_CC +LIBS= +AC_SEARCH_LIBS(dlsym, [dl]) +sshnodelay_libs=$LIBS +AC_SUBST(sshnodelay_libs) + export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH PKG_CHECK_MODULES(SSHFS, [fuse >= 2.2 glib-2.0]) CFLAGS="$CFLAGS -Wall -W -D_REENTRANT $SSHFS_CFLAGS" diff --git a/sshfs.c b/sshfs.c index 9e5efd9..e0ce4bf 100644 --- a/sshfs.c +++ b/sshfs.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,8 @@ #define SFTP_SERVER_PATH "/usr/lib/sftp-server" +#define SSHNODELAY_SO "sshnodelay.so" + struct buffer { uint8_t *p; size_t len; @@ -176,6 +179,7 @@ struct sshfs { unsigned local_uid; int remote_uid_detected; unsigned blksize; + char *progname; }; static struct sshfs sshfs; @@ -612,30 +616,46 @@ static void ssh_add_arg(const char *arg) _exit(1); } -static void do_ssh_nodelay_workaround(void) +static int do_ssh_nodelay_workaround(void) { - FILE *tmp = tmpfile(); - int fd = tmp ? dup(fileno(tmp)) : -1; - extern const char sshnodelay_so[]; - extern const int sshnodelay_so_size; char *oldpreload = getenv("LD_PRELOAD"); char *newpreload; + char sopath[PATH_MAX]; + int res; - fclose(tmp); - if (fd == -1 || write(fd, sshnodelay_so, sshnodelay_so_size) == -1) { - fprintf(stderr, "warning: failed to write file for ssh nodelay workaround\n"); - return; + snprintf(sopath, sizeof(sopath), "%s/%s", LIBDIR, SSHNODELAY_SO); + res = access(sopath, R_OK); + if (res == -1) { + char *s; + if (!realpath(sshfs.progname, sopath)) + return -1; + + s = strrchr(sopath, '/'); + if (!s) + s = sopath; + else + s++; + + if (s + strlen(SSHNODELAY_SO) >= sopath + sizeof(sopath)) + return -1; + + strcpy(s, SSHNODELAY_SO); + res = access(sopath, R_OK); + if (res == -1) { + fprintf(stderr, "sshfs: cannot find %s\n", SSHNODELAY_SO); + return -1; + } } - newpreload = g_strdup_printf("%s%s/proc/self/fd/%i", + newpreload = g_strdup_printf("%s%s%s", oldpreload ? oldpreload : "", - oldpreload ? " " : "", fd); + oldpreload ? " " : "", + sopath); - if (!newpreload || setenv("LD_PRELOAD", newpreload, 1) == -1) { + if (!newpreload || setenv("LD_PRELOAD", newpreload, 1) == -1) fprintf(stderr, "warning: failed set LD_PRELOAD for ssh nodelay workaround\n"); - close(fd); - } g_free(newpreload); + return 0; } static int start_ssh(void) @@ -658,8 +678,8 @@ static int start_ssh(void) } else if (pid == 0) { int devnull; - if (sshfs.nodelay_workaround) - do_ssh_nodelay_workaround(); + if (sshfs.nodelay_workaround && do_ssh_nodelay_workaround() == -1) + fprintf(stderr, "warning: ssh nodelay workaround disabled\n"); devnull = open("/dev/null", O_WRONLY); @@ -2214,6 +2234,7 @@ int main(int argc, char *argv[]) sshfs.nodelay_workaround = 1; sshfs.rename_workaround = 1; sshfs.ssh_ver = 2; + sshfs.progname = argv[0]; ssh_add_arg("ssh"); ssh_add_arg("-x"); ssh_add_arg("-a"); diff --git a/sshnodelay.c b/sshnodelay.c index 9e30f27..03a4756 100644 --- a/sshnodelay.c +++ b/sshnodelay.c @@ -1,5 +1,6 @@ #define _GNU_SOURCE #include +#include #include #include #include -- cgit v1.2.3