Browse Source

Actually work again with kproc_infoX member checks that work; add an
option to disable terminfo checks; fix man page version info.

Douglas William Thrift 13 years ago
parent
commit
2eaf7365c6
5 changed files with 1490 additions and 80 deletions
  1. 1 1
      GNUmakefile.in
  2. 1421 35
      configure
  3. 20 9
      configure.ac
  4. 47 34
      dtpstree.cpp
  5. 1 1
      man1/dtpstree.1

+ 1 - 1
GNUmakefile.in

@@ -73,7 +73,7 @@ ifneq ($(REALPATH),:)
 man: $(srcdir)/man1/dtpstree.1
 
 $(srcdir)/man1/%.1: % %.1.in
-	$(HELP2MAN) -I $*.1.in -Nn '$(shell sed -e '$$ s|^// ||p;d' $<.cpp)' -o $@ $(shell $(REALPATH) $<)
+	$(HELP2MAN) -I $*.1.in -Nn '$(shell sed -e '$$ s|^// ||p;d' $<.cpp)' -o $@ -v -Vs $(shell $(REALPATH) $<)
 endif
 endif
 

File diff suppressed because it is too large
+ 1421 - 35
configure


+ 20 - 9
configure.ac

@@ -66,14 +66,23 @@ AC_DEFUN([DT_CHECK_TERMCAP], [AC_CHECK_HEADERS([termcap.h])
 		[AC_SEARCH_LIBS([tgetent], [termcap termlib], [], [DT_MSG_TERMCAP])]
 	)]
 )
-AC_CHECK_HEADERS([ncurses/curses.h curses.h], [break])
-AS_CASE([$ac_cv_header_curses_h$ac_cv_header_ncurses_curses_h], [*yes*],
-	[AC_CHECK_HEADERS([ncurses/term.h term.h], [break])
-	AS_CASE([$ac_cv_header_term_h$ac_cv_header_ncurses_term_h], [*yes*],
-		[AC_SEARCH_LIBS([setupterm], [ncurses curses terminfo tinfo], [],
-			[DT_CHECK_TERMCAP]
+AC_DEFUN([DT_CHECK_TERMINFO],
+	[AC_CHECK_HEADERS([ncurses/ncurses.h curses.h],
+	[break])
+	AS_CASE([$ac_cv_header_curses_h$ac_cv_header_ncurses_ncurses_h], [*yes*],
+		[AC_CHECK_HEADERS([ncurses/term.h term.h], [break])
+		AS_CASE([$ac_cv_header_term_h$ac_cv_header_ncurses_term_h], [*yes*],
+			[AC_SEARCH_LIBS([setupterm], [ncurses terminfo tinfo], [],
+				[DT_CHECK_TERMCAP]
+			)], [DT_CHECK_TERMCAP]
 		)], [DT_CHECK_TERMCAP]
-	)], [DT_CHECK_TERMCAP]
+	)]
+)
+AC_ARG_ENABLE([terminfo],
+	[AS_HELP_STRING([--disable-terminfo],
+		[do not try to use the terminfo interface]
+	)], [AS_CASE([$enableval], [no], [DT_CHECK_TERMCAP], [DT_CHECK_TERMINFO])],
+	[DT_CHECK_TERMINFO]
 )
 AC_DEFUN([DT_MSG_KVM], [AC_MSG_ERROR([You need libkvm])])
 AC_CHECK_HEADER([kvm.h], [], [DT_MSG_KVM])
@@ -85,8 +94,10 @@ AC_DEFUN([DT_INCLUDES_KVM], [#include <kvm.h>
 AC_INCLUDES_DEFAULT])
 AC_DEFUN([DT_CHECK_MEMBERS_KVM],
 	[m4_foreach_w([dt_member_suffix], [pid ppid ruid comm],
-		[AC_CHECK_MEMBER([struct ]$1[.]$2[_]dt_member_suffix, [], # TODO
-			[AC_CHECK_MEMBER([struct ]$1[.]$3[_]dt_member_suffix, [], # TODO
+		[AC_CHECK_MEMBER([struct ]$1[.]$2[_]dt_member_suffix,
+			[AC_DEFINE([HAVE_STRUCT_KINFO_PROCX_]m4_toupper($2)[_]m4_toupper(dt_member_suffix))],
+			[AC_CHECK_MEMBER([struct ]$1[.]$3[_]dt_member_suffix,
+				[AC_DEFINE([HAVE_STRUCT_KINFO_PROCX_]m4_toupper($4)[_]m4_toupper(dt_member_suffix))],
 				[DT_MSG_KVM], [DT_INCLUDES_KVM]
 			)], [DT_INCLUDES_KVM]
 		)]

+ 47 - 34
dtpstree.cpp

@@ -41,7 +41,7 @@
 #ifdef HAVE_TERMCAP_H
 #include <termcap.h>
 #elif defined(HAVE_NCURSES_TERM_H)
-#include <ncurses/curses.h>
+#include <ncurses/ncurses.h>
 #include <ncurses/term.h>
 #elif defined(HAVE_TERM_H)
 #include <curses.h>
@@ -118,51 +118,43 @@ inline char **getargv(kvm_t *kd, const kinfo_proc2 *proc)
 #endif
 
 template <>
-inline pid_t pid(kinfo_proc *proc)
+inline pid_t pid(Proc *proc)
 {
+#	ifdef HAVE_STRUCT_KINFO_PROCX_KI_PID
 	return proc->ki_pid;
-}
-
-template <>
-inline pid_t ppid(kinfo_proc *proc)
-{
-	return proc->ki_ppid;
-}
-
-template <>
-inline uid_t ruid(kinfo_proc *proc)
-{
-	return proc->ki_ruid;
-}
-
-template <>
-inline char *comm(kinfo_proc *proc)
-{
-	return proc->ki_comm;
-}
-
-template <>
-inline pid_t pid(kinfo_proc2 *proc)
-{
+#	elif defined(HAVE_STRUCT_KINFO_PROCX_P_PID)
 	return proc->p_pid;
+#	endif
 }
 
 template <>
-inline pid_t ppid(kinfo_proc2 *proc)
+inline pid_t ppid(Proc *proc)
 {
+#	ifdef HAVE_STRUCT_KINFO_PROCX_KI_PPID
+	return proc->ki_ppid;
+#	elif defined(HAVE_STRUCT_KINFO_PROCX_P_PPID)
 	return proc->p_ppid;
+#	endif
 }
 
 template <>
-inline uid_t ruid(kinfo_proc2 *proc)
+inline uid_t ruid(Proc *proc)
 {
+#	ifdef HAVE_STRUCT_KINFO_PROCX_KI_RUID
+	return proc->ki_ruid;
+#	elif defined(HAVE_STRUCT_KINFO_PROCX_P_RUID)
 	return proc->p_ruid;
+#	endif
 }
 
 template <>
-inline char *comm(kinfo_proc2 *proc)
+inline char *comm(Proc *proc)
 {
+#	ifdef HAVE_STRUCT_KINFO_PROCX_KI_COMM
+	return proc->ki_comm;
+#	elif defined(HAVE_STRUCT_KINFO_PROCX_P_COMM)
 	return proc->p_comm;
+#	endif
 }
 
 }
@@ -920,7 +912,7 @@ static uint16_t options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&
 		{ "show-titles", no_argument, NULL, 't' },
 		{ "uid-changes", no_argument, NULL, 'u' },
 		{ "unicode", no_argument, NULL, 'U' },
-		{ "version", no_argument, NULL, 'V' },
+		{ "version", optional_argument, NULL, 'V' },
 		{ "pid", required_argument, NULL, 0 },
 		{ "user", required_argument, NULL, 0 },
 		{ NULL, 0, NULL, 0 }
@@ -929,7 +921,7 @@ static uint16_t options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&
 	uint16_t flags(0);
 	char *program(argv[0]);
 
-	while ((option = getopt_long(argc, argv, "aAchH::GklnptuUV", options, &index)) != -1)
+	while ((option = getopt_long(argc, argv, "aAchH::GklnptuUV::", options, &index)) != -1)
 		switch (option)
 		{
 		case 'a':
@@ -975,12 +967,33 @@ static uint16_t options(int argc, char *argv[], pid_t &hpid, pid_t &pid, char *&
 			break;
 		case 'V':
 			{
-				utsname name;
+				std::string version(optarg ?: "");
+
+				if (version == "s" || version == "short")
+					std::printf(PACKAGE_TARNAME " " PACKAGE_VERSION "\n");
+				else
+				{
+					utsname name;
+
+					if (uname(&name))
+						err(1, NULL);
+
+					std::printf(PACKAGE_TARNAME " " PACKAGE_VERSION " - %s %s %s\n", name.sysname, name.release, name.machine);
+				}
 
-				if (uname(&name))
-					err(1, NULL);
+				if (version == "l" || version == "license")
+					std::printf("\n"
+						"   Copyright 2010 Douglas Thrift\n\n"
+						"   Licensed under the Apache License, Version 2.0 (the \"License\");\n"
+						"   you may not use this file except in compliance with the License.\n"
+						"   You may obtain a copy of the License at\n\n"
+						"       http://www.apache.org/licenses/LICENSE-2.0\n\n"
+						"   Unless required by applicable law or agreed to in writing, software\n"
+						"   distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+						"   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
+						"   See the License for the specific language governing permissions and\n"
+						"   limitations under the License.\n");
 
-				std::printf(PACKAGE_TARNAME " " PACKAGE_VERSION " - %s %s %s\n", name.sysname, name.release, name.machine);
 				std::exit(0);
 			}
 		case 0:

+ 1 - 1
man1/dtpstree.1

@@ -1,5 +1,5 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.38.2.
-.TH DTPSTREE "1" "June 2010" "dtpstree 1.0.2" "User Commands"
+.TH DTPSTREE "1" "July 2010" "dtpstree 1.0.2" "User Commands"
 .SH NAME
 dtpstree \- display a tree of processes
 .SH SYNOPSIS

Some files were not shown because too many files changed in this diff