Browse Source

PS:
I've committed the fix below. The core change is a configure check
if kvm_getprocs() takes five arguments.

Signed-off-by: Douglas William Thrift <douglas@douglasthrift.net>

Christian Weisgerber 7 years ago
parent
commit
9191b16e5b
4 changed files with 48 additions and 4 deletions
  1. 1 1
      GNUmakefile.in
  2. 24 2
      configure
  3. 5 1
      configure.ac
  4. 18 0
      dtpstree.cpp

+ 1 - 1
GNUmakefile.in

@@ -23,7 +23,7 @@ VPATH := @srcdir@
 srcdir := @srcdir@
 top_builddir := @top_builddir@
 
-CPPFLAGS := @CPPFLAGS@ $(filter -DPACKAGE_TARNAME% -DPACKAGE_VERSION% -DHAVE_NCURSES% -DHAVE_TERM% -DHAVE_STRUCT_KINFO_PROC% -DHAVE_DECL_KERN_PROC_PROC% -DHAVE_DECL_KERN_PROC_KTHREAD%,@DEFS@)
+CPPFLAGS := @CPPFLAGS@ $(filter -DPACKAGE_TARNAME% -DPACKAGE_VERSION% -DHAVE_NCURSES% -DHAVE_TERM% -DHAVE_STRUCT_KINFO_PROC% -DHAVE_KINFO_NEWABI% -DHAVE_DECL_KERN_PROC_PROC% -DHAVE_DECL_KERN_PROC_KTHREAD%,@DEFS@)
 CXX := @CXX@
 CXXFLAGS := @CXXFLAGS@ -Wall -Wno-long-long -Wno-parentheses
 LDFLAGS := @LDFLAGS@

+ 24 - 2
configure

@@ -675,8 +675,7 @@ LDFLAGS
 LIBS
 CPPFLAGS
 CCC
-CXXCPP
-CPPFLAGS'
+CXXCPP'
 
 
 # Initialize some variables set by options.
@@ -4602,7 +4601,30 @@ fi
 
 		ac_fn_cxx_check_func "$LINENO" "kvm_getprocs" "ac_cv_func_kvm_getprocs"
 if test "x$ac_cv_func_kvm_getprocs" = xyes; then :
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifdef HAVE_KINFO_H
+#include <kinfo.h>
+#endif
+#include <kvm.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+$ac_includes_default
+int
+main ()
+{
+kvm_getprocs(NULL, 0, 0, 0, NULL);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  $as_echo "#define HAVE_KINFO_NEWABI 1" >>confdefs.h
+
 
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 else
   as_fn_error $? "You need libkvm" "$LINENO" 5
 fi

+ 5 - 1
configure.ac

@@ -124,7 +124,11 @@ AC_CHECK_TYPE([struct kinfo_proc2],
 	[AC_CHECK_TYPE([struct kinfo_proc],
 		[AC_DEFINE([HAVE_STRUCT_KINFO_PROC])
 		AC_CHECK_FUNC([kvm_getargv], [], [DT_MSG_KVM])
-		AC_CHECK_FUNC([kvm_getprocs], [], [DT_MSG_KVM])
+		AC_CHECK_FUNC([kvm_getprocs],
+			[AC_TRY_COMPILE(DT_INCLUDES_KVM,
+				[kvm_getprocs(NULL, 0, 0, 0, NULL);],
+				[AC_DEFINE([HAVE_KINFO_NEWABI])]
+			)], [DT_MSG_KVM])
 		DT_CHECK_MEMBERS_KVM([kinfo_proc], [ki], [kp], [p])],
 		[DT_MSG_KVM], [DT_INCLUDES_KVM]
 	)], [DT_INCLUDES_KVM]

+ 18 - 0
dtpstree.cpp

@@ -92,6 +92,23 @@ template <typename Type>
 inline char *comm(Type *proc);
 
 #ifndef HAVE_STRUCT_KINFO_PROC2
+#ifdef HAVE_KINFO_NEWABI
+typedef kinfo_proc Proc;
+
+const int Flags(KVM_NO_FILES);
+
+template <>
+inline kinfo_proc *getprocs(kvm_t *kd, int &count)
+{
+	return kvm_getprocs(kd, All, 0, sizeof (kinfo_proc), &count);
+}
+
+template <>
+inline char **getargv(kvm_t *kd, const kinfo_proc *proc)
+{
+	return kvm_getargv(kd, proc, 0);
+}
+#else
 typedef kinfo_proc Proc;
 
 const int Flags(O_RDONLY);
@@ -107,6 +124,7 @@ inline char **getargv(kvm_t *kd, const kinfo_proc *proc)
 {
 	return kvm_getargv(kd, proc, 0);
 }
+#endif
 #else
 typedef kinfo_proc2 Proc;