From 82a528d96fc49338441e93d1b04d51d6585f114f Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 29 Sep 2014 23:29:56 +0000 Subject: [PATCH] Enhance sysinfo decoding * configure.ac (AC_CHECK_MEMBERS): Check for struct sysinfo.totalhigh, struct sysinfo.freehigh, and struct sysinfo.mem_unit. * sysinfo.c (sys_sysinfo): Treat failed umove() call as syserror(). Print totalhigh, freehigh, and mem_unit members when struct sysinfo supports them. --- configure.ac | 4 ++++ sysinfo.c | 63 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index 6fe83cfb..9caa8359 100644 --- a/configure.ac +++ b/configure.ac @@ -272,6 +272,10 @@ AC_CHECK_MEMBERS([struct sigevent._sigev_un._pad, struct sigevent.__pad, siginfo_t.si_syscall],,, [#include ]) +AC_CHECK_MEMBERS([struct sysinfo.totalhigh, + struct sysinfo.freehigh, + struct sysinfo.mem_unit],,, [#include ]) + AC_CHECK_TYPES([struct flock64],,, [#include ]) AC_CHECK_HEADERS([libaio.h], [ diff --git a/sysinfo.c b/sysinfo.c index e37c4a2c..ab5044b2 100644 --- a/sysinfo.c +++ b/sysinfo.c @@ -6,23 +6,52 @@ sys_sysinfo(struct tcb *tcp) { struct sysinfo si; - if (exiting(tcp)) { - if (syserror(tcp) || !verbose(tcp)) - tprintf("%#lx", tcp->u_arg[0]); - else if (umove(tcp, tcp->u_arg[0], &si) < 0) - tprints("{...}"); - else { - tprintf("{uptime=%lu, loads=[%lu, %lu, %lu] ", - (long) si.uptime, (long) si.loads[0], - (long) si.loads[1], (long) si.loads[2]); - tprintf("totalram=%lu, freeram=%lu, ", - (long) si.totalram, (long) si.freeram); - tprintf("sharedram=%lu, bufferram=%lu} ", - (long) si.sharedram, (long) si.bufferram); - tprintf("totalswap=%lu, freeswap=%lu, procs=%u}", - (long) si.totalswap, (long) si.freeswap, - (unsigned)si.procs); - } + if (entering(tcp)) + return 0; + + if (syserror(tcp) || !verbose(tcp) || + umove(tcp, tcp->u_arg[0], &si) < 0) { + tprintf("%#lx", tcp->u_arg[0]); + } else { + tprintf("{uptime=%lu" + ", loads=[%lu, %lu, %lu]" + ", totalram=%lu" + ", freeram=%lu" + ", sharedram=%lu" + ", bufferram=%lu" + ", totalswap=%lu" + ", freeswap=%lu" + ", procs=%u" +#ifdef HAVE_STRUCT_SYSINFO_TOTALHIGH + ", totalhigh=%lu" +#endif +#ifdef HAVE_STRUCT_SYSINFO_FREEHIGH + ", freehigh=%lu" +#endif +#ifdef HAVE_STRUCT_SYSINFO_MEM_UNIT + ", mem_unit=%u" +#endif + "}", + si.uptime + , si.loads[0], si.loads[1], si.loads[2] + , si.totalram + , si.freeram + , si.sharedram + , si.bufferram + , si.totalswap + , si.freeswap + , (unsigned) si.procs +#ifdef HAVE_STRUCT_SYSINFO_TOTALHIGH + , si.totalhigh +#endif +#ifdef HAVE_STRUCT_SYSINFO_FREEHIGH + , si.freehigh +#endif +#ifdef HAVE_STRUCT_SYSINFO_MEM_UNIT + , si.mem_unit +#endif + ); } + return 0; } -- 2.40.0