commit fe5b0c42f9891dae8c49d59aabc2d2a971a4e01b
Author: Michael Hanselmann <hansmi@google.com>
Date:   Wed Nov 11 14:00:17 2009 +0100

    Fix and simplify socat escape detection
    
    - Program paths should not be --with-… options (see
      Autoconf docs)
    - Simplify checks for escape functionality
    - Make SOCAT_USE_ESCAPE variable a bool
    
    Signed-off-by: Michael Hanselmann <hansmi@google.com>
    Reviewed-by: Guido Trotter <ultrotter@google.com>

diff --git a/Makefile.am b/Makefile.am
index 6edaff5..cedd207 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -416,8 +416,8 @@ lib/_autoconf.py: Makefile stamp-directories
 	  echo "FILE_STORAGE_DIR = '$(FILE_STORAGE_DIR)'"; \
 	  echo "IALLOCATOR_SEARCH_PATH = [$(IALLOCATOR_SEARCH_PATH)]"; \
 	  echo "KVM_PATH = '$(KVM_PATH)'"; \
-	  echo "SOCAT_PATH = '$(SOCAT_PATH)'"; \
-	  echo "SOCAT_ESCAPE = '$(SOCAT_ESCAPE)'"; \
+	  echo "SOCAT_PATH = '$(SOCAT)'"; \
+	  echo "SOCAT_USE_ESCAPE = $(SOCAT_USE_ESCAPE)"; \
 	  echo "LVM_STRIPECOUNT = $(LVM_STRIPECOUNT)"; \
 	  echo "TOOLSDIR = '$(toolsdir)'"; \
 	  echo "GNT_SCRIPTS = [$(foreach i,$(notdir $(gnt_scripts)),'$(i)',)]"; \
diff --git a/configure.ac b/configure.ac
index 06a24a9..b47bc6c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -108,21 +108,6 @@ AC_ARG_WITH([kvm-path],
   [kvm_path="/usr/bin/kvm"])
 AC_SUBST(KVM_PATH, $kvm_path)
 
-# --with-socat-path=...
-AC_ARG_WITH([socat-path],
-  [AS_HELP_STRING([--with-socat-path=PATH],
-    [absolute path to the socat binary]
-    [ (default is to let configure search for it)]
-  )],
-  [SOCAT="$withval"],
-  [])
-
-AC_ARG_WITH([socat-escape],
-  [AS_HELP_STRING([--with-socat-escape],
-    [enable escape functionality found in newer socat])],
-  [],
-  [check_socat_escape=yes])
-
 # ---with-lvm-stripecount=...
 AC_ARG_WITH([lvm-stripecount],
   [AS_HELP_STRING([--with-lvm-stripecount=NUM],
@@ -168,32 +153,37 @@ then
   AC_MSG_WARN([dot (from the graphviz suite) not found, documentation rebuild not possible])
 fi
 
-if test -z "$SOCAT" -a -n "$check_socat_escape"
-then
-AC_CACHE_CHECK([for socat with the escape feature], [ac_cv_path_SOCAT],
-  [AC_PATH_PROGS_FEATURE_CHECK(SOCAT, [socat],
-            [[$ac_path_SOCAT -hh | grep -q escape \
-              && ac_cv_path_SOCAT=$ac_path_SOCAT \
-                 SOCAT=$ac_cv_path_SOCAT \
-                 with_socat_escape=yes ac_path_SOCAT_found=:]],
-            [AC_MSG_WARN([no escape feature found])])])
-fi
-
+# Check for socat
+AC_ARG_VAR(SOCAT, [socat path])
+AC_PATH_PROG(SOCAT, [socat], [])
 if test -z "$SOCAT"
 then
-AC_CACHE_CHECK([for socat], [ac_cv_path_SOCAT],
-  [AC_PATH_PROGS_FEATURE_CHECK(SOCAT, [socat],
-            [[ac_cv_path_SOCAT=$ac_path_SOCAT \
-              SOCAT=$ac_cv_path_SOCAT ac_path_SOCAT_found=:]],
-            [AC_MSG_ERROR([socat not found])])])
+  AC_MSG_ERROR([socat not found])
 fi
 
-AC_SUBST([SOCAT_PATH], [$SOCAT])
-if test "x$with_socat_escape" = xyes
+SOCAT_USE_ESCAPE=
+AC_ARG_ENABLE([socat-escape],
+  [AS_HELP_STRING([--enable-socat-escape],
+    [use escape functionality available in socat >= 1.7 (default: detect
+     automatically)])],
+  [[if test "$enableval" = yes; then
+      SOCAT_USE_ESCAPE=True
+    else
+      SOCAT_USE_ESCAPE=False
+    fi
+  ]])
+
+if test -z "$SOCAT_USE_ESCAPE"
 then
-  AC_SUBST([SOCAT_ESCAPE], [1])
+  if $SOCAT -hh | grep -w -q escape; then
+    SOCAT_USE_ESCAPE=True
+  else
+    SOCAT_USE_ESCAPE=False
+  fi
 fi
 
+AC_SUBST(SOCAT_USE_ESCAPE)
+
 # Check for Python
 AM_PATH_PYTHON(2.4)
 
diff --git a/lib/constants.py b/lib/constants.py
index b3a20a9..0f035ef 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -164,7 +164,7 @@ XEN_INITRD = _autoconf.XEN_INITRD
 
 KVM_PATH = _autoconf.KVM_PATH
 SOCAT_PATH = _autoconf.SOCAT_PATH
-SOCAT_ESCAPE = _autoconf.SOCAT_ESCAPE
+SOCAT_USE_ESCAPE = _autoconf.SOCAT_USE_ESCAPE
 SOCAT_ESCAPE_CODE = "0x1d"
 
 VALUE_DEFAULT = "default"
diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py
index 262a6fe..a153d36 100644
--- a/lib/hypervisor/hv_kvm.py
+++ b/lib/hypervisor/hv_kvm.py
@@ -123,7 +123,7 @@ class KVMHypervisor(hv_base.BaseHypervisor):
     If we have a new-enough socat we can use raw mode with an escape character.
 
     """
-    if constants.SOCAT_ESCAPE:
+    if constants.SOCAT_USE_ESCAPE:
       return "raw,echo=0,escape=%s" % constants.SOCAT_ESCAPE_CODE
     else:
       return "echo=0,icanon=0"
