From 01cafef0dd87b6afda41942070e73b55b45a5ed2 Mon Sep 17 00:00:00 2001
From: "Artyom V. Poptsov" <poptsov.artyom@gmail.com>
Date: Mon, 1 Oct 2018 05:11:27 +0300
Subject: [PATCH] libguile-ssh: Fix building with libssh 0.8

The 'libguile-ssh' library would fail to build due to missing 'libssh_threads'
library that was removed libssh 0.8.  This patch fixes that.

Reported by lantw44 in
<https://github.com/artyom-poptsov/guile-ssh/issues/9>

* configure.ac: Add check for libssh 0.8
* libguile-ssh/Makefile.am: Don't use 'libssh_threads' library when building
  with libssh 0.8+.
* NEWS: Update.
---
 NEWS                     | 17 +++++++++++++++++
 configure.ac             |  7 +++++++
 libguile-ssh/Makefile.am |  7 ++++++-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 84d455b..8c73d1b 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,23 @@ Copyright (C) Artyom V. Poptsov <poptsov.artyom@gmail.com>
   are permitted in any medium without royalty provided the copyright
   notice and this notice are preserved.
 
+* Unreleased
+** Bugfixes
+*** Fix a segfault in 'libguile-ssh'
+    The library would always fail with segmentation fault error when an
+    application tried to free a closed channel.  Now it should be fixed.
+
+    Reported by Michael Bowcutt <mbowcutt@case.edu> in
+    <https://github.com/artyom-poptsov/guile-ssh/issues/8>
+    and Njagi Mwaniki in a personal email.
+*** Fix building with libssh 0.8
+    The 'libguile-ssh' library would fail to build due to missing
+    'libssh_threads' library that was removed libssh 0.8.  Now 'libguile-ssh'
+    builds without 'libssh_threads' when using libssh 0.8+.
+
+    Reported by lantw44 in
+    <https://github.com/artyom-poptsov/guile-ssh/issues/9>
+
 * Changes in version 0.11.3 (2018-03-27)
 ** Bugfixes
 *** 'node-run-server' now checks for errors
diff --git a/configure.ac b/configure.ac
index c818208..74271f7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -64,6 +64,13 @@ PKG_CHECK_MODULES([LIBSSH_0_7_3], [libssh >= 0.7.3],
   Using a potentially vulnerable version of libssh
   <https://www.libssh.org/2016/02/23/libssh-0-7-3-security-and-bugfix-release/>])])
 
+dnl Checking for libssh 0.8.x
+PKG_CHECK_MODULES([LIBSSH_0_8], [libssh >= 0.8.0],
+                                [AC_DEFINE(HAVE_LIBSSH_0_8, 1, [Use libssh 0.8])],
+                                [AC_DEFINE(HAVE_LIBSSH_0_8, 0, [Use libssh < 0.8])])
+
+AM_CONDITIONAL(HAVE_LIBSSH_0_8, $HAVE_LIBSSH_0_8)
+
 # -------------------------------------------------------------------------------
 
 dnl These macros must be provided by guile.m4.
diff --git a/libguile-ssh/Makefile.am b/libguile-ssh/Makefile.am
index 1ffb6c0..523d77a 100644
--- a/libguile-ssh/Makefile.am
+++ b/libguile-ssh/Makefile.am
@@ -44,7 +44,12 @@ BUILT_SOURCES = auth.x channel-func.x channel-type.x error.x \
 
 libguile_ssh_la_CPPFLAGS = $(GUILE_CFLAGS)
 
-libguile_ssh_la_LDFLAGS = -module -no-undefined -lssh_threads -lssh \
+SSH_LD_FLAGS = -lssh
+if ! HAVE_LIBSSH_0_8
+SSH_LD_FLAGS += -lssh_threads
+endif
+
+libguile_ssh_la_LDFLAGS = -module -no-undefined $(SSH_LD_FLAGS)  \
 	-version-info $(LIBGUILE_SSH_INTERFACE) $(GUILE_LDFLAGS)
 
 AM_CFLAGS = $(WARN_CFLAGS)
-- 
2.20.1

