[PATCH i-g-t 04/13] lib/igt_aux: Make procps optional

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Android does not have procps and it's not easy to compile it as a
dependency.

We can provide alternative, "naive" implementation that just shells out
to external commands (i.e. pkill and lsof) in case we do not have the
library.

Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@xxxxxxxxx>
---
 configure.ac  |  6 +++++-
 lib/igt_aux.c | 24 +++++++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 12b0ab0..a5a92d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,7 +123,11 @@ AC_SUBST(ASSEMBLER_WARN_CFLAGS)
 PKG_CHECK_MODULES(DRM, [libdrm])
 PKG_CHECK_MODULES(PCIACCESS, [pciaccess >= 0.10])
 PKG_CHECK_MODULES(KMOD, [libkmod])
-PKG_CHECK_MODULES(PROCPS, [libprocps])
+PKG_CHECK_MODULES(PROCPS, [libprocps], [procps=yes], [procps=no])
+AM_CONDITIONAL(HAVE_PROCPS, [test "x$procps" = xyes])
+if test x"$procps" = xyes; then
+	AC_DEFINE(HAVE_PROCPS,1,[Enable process managment without shelling out])
+fi
 PKG_CHECK_MODULES(VALGRIND, [valgrind], [have_valgrind=yes], [have_valgrind=no])
 
 if test x$have_valgrind = xyes; then
diff --git a/lib/igt_aux.c b/lib/igt_aux.c
index 2ec6b78..4efb45b 100644
--- a/lib/igt_aux.c
+++ b/lib/igt_aux.c
@@ -50,9 +50,7 @@
 #include <sys/utsname.h>
 #include <termios.h>
 #include <assert.h>
-
-#include <proc/readproc.h>
-
+#include <linux/limits.h>
 #include "drmtest.h"
 #include "i915_drm.h"
 #include "intel_chipset.h"
@@ -71,6 +69,10 @@
 #include <libgen.h>   /* for dirname() */
 #endif
 
+#ifdef HAVE_PROCPS
+#include <proc/readproc.h>
+#endif
+
 /**
  * SECTION:igt_aux
  * @short_description: Auxiliary libraries and support functions
@@ -1295,6 +1297,7 @@ void igt_set_module_param_int(const char *name, int val)
  */
 int igt_terminate_process(int sig, const char *comm)
 {
+#ifdef HAVE_PROCPS
 	PROCTAB *proc;
 	proc_t *proc_info;
 	int err = 0;
@@ -1316,6 +1319,12 @@ int igt_terminate_process(int sig, const char *comm)
 
 	closeproc(proc);
 	return err;
+#else
+#warning "No procps, using naive implementation of igt_terminate_process"
+	char pkill_cmd[NAME_MAX];
+	snprintf(pkill_cmd, sizeof(pkill_cmd), "pkill -x -%d %s", sig, comm);
+	return system(pkill_cmd);
+#endif
 }
 
 struct pinfo {
@@ -1324,6 +1333,7 @@ struct pinfo {
 	const char *fn;
 };
 
+#ifdef HAVE_PROCPS
 static void
 __igt_show_stat(struct pinfo *info)
 {
@@ -1499,6 +1509,7 @@ __igt_lsof(const char *dir)
 
 	closeproc(proc);
 }
+#endif
 
 /**
  * igt_lsof: Lists information about files opened by processes.
@@ -1510,6 +1521,7 @@ __igt_lsof(const char *dir)
 void
 igt_lsof(const char *dpath)
 {
+#ifdef HAVE_PROCPS
 	struct stat st;
 	size_t len = strlen(dpath);
 	char *sanitized;
@@ -1530,6 +1542,12 @@ igt_lsof(const char *dpath)
 	__igt_lsof(sanitized);
 
 	free(sanitized);
+#else
+#warning "No procps, using naive implementation of igt_lsof"
+	char lsof_cmd[NAME_MAX];
+	snprintf(lsof_cmd, sizeof(lsof_cmd), "lsof +d %s", dpath);
+	system(lsof_cmd);
+#endif
 }
 
 static struct igt_siglatency {
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/intel-gfx




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]
  Powered by Linux