diff options
author | Arkadiusz Hiler <arkadiusz.hiler@intel.com> | 2017-04-12 12:24:42 +0200 |
---|---|---|
committer | Arkadiusz Hiler <arkadiusz.hiler@intel.com> | 2017-06-07 13:26:29 +0300 |
commit | d7d3f4e87b827152f00bdf89a67871736672b492 (patch) | |
tree | 888848e2c53af222744643fcb38794157e2f8894 /lib/igt_aux.c | |
parent | 86b59f8474a38b7a0e9c4cf68e32aba664878107 (diff) |
lib/igt_aux: Make procps optional
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.
v2: have separate functions for naive impls (J. Nikula)
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Signed-off-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
Diffstat (limited to 'lib/igt_aux.c')
-rw-r--r-- | lib/igt_aux.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/lib/igt_aux.c b/lib/igt_aux.c index 2ec6b78e..f76e55d5 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 @@ -1293,6 +1295,7 @@ void igt_set_module_param_int(const char *name, int val) * This function sends the signal @sig for a process found in process table * with name @comm. */ +#ifdef HAVE_PROCPS int igt_terminate_process(int sig, const char *comm) { PROCTAB *proc; @@ -1317,7 +1320,19 @@ int igt_terminate_process(int sig, const char *comm) closeproc(proc); return err; } +#else +#warning "No procps, using naive implementation of igt_terminate_process" + +int igt_terminate_process(int sig, const char *comm) +{ + char pkill_cmd[NAME_MAX]; + + snprintf(pkill_cmd, sizeof(pkill_cmd), "pkill -x -%d %s", sig, comm); + return system(pkill_cmd); +} +#endif +#ifdef HAVE_PROCPS struct pinfo { pid_t pid; const char *comm; @@ -1499,6 +1514,7 @@ __igt_lsof(const char *dir) closeproc(proc); } +#endif /** * igt_lsof: Lists information about files opened by processes. @@ -1507,6 +1523,7 @@ __igt_lsof(const char *dir) * This function mimics (a restrictive form of) lsof(8), but also shows * information about opened fds. */ +#ifdef HAVE_PROCPS void igt_lsof(const char *dpath) { @@ -1531,6 +1548,18 @@ igt_lsof(const char *dpath) free(sanitized); } +#else +#warning "No procps, using naive implementation of igt_lsof" + +void +igt_lsof(const char *dpath) +{ + char lsof_cmd[NAME_MAX]; + + snprintf(lsof_cmd, sizeof(lsof_cmd), "lsof +d %s", dpath); + system(lsof_cmd); +} +#endif static struct igt_siglatency { timer_t timer; |