From b899c55dca00eee8dd9c29bbc4b32f3598ad51f6 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Thu, 8 Sep 2016 11:11:11 -0500 Subject: [PATCH] pmap: fix printing bug associated with the '-x' option Ever since its introduction, the 'x' (extended format) option has employed strncmp to parse those smaps keys. Such an approach worked well as long as those prefixes were guaranteed to be unique. But, with the 4.3 kernel a new 'SwapPss' field was added to those within smaps. That triggered a 2nd match for the 'Swap' logic which, in turn, resulted in a duplicate output line of zeros. So this patch just trades strncmp for strcmp, avoiding potential future problems when /proc/$$/smaps evolves. Reference(s): . recent bug report https://bugzilla.redhat.com/show_bug.cgi?id=1374061 . linux 4.3 kernel introduces SwapPss commit 8334b96221ff0dcbde4873d31eb4d84774ed8ed4 . original pmap -x option introduction commit 380cc1e9082d662d09dd80fcbb73de9dc98b3ea1 Signed-off-by: Jim Warner --- NEWS | 1 + pmap.c | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index dcb92ff0..c38c904a 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ procps-ng-NEXT * watch: define HOST_NAME_MAX where not defined Debian #830734 * library: dont use vm_min_free on non Linux Debian #831396 * library: dont use SIGPWR on FreeBSD Debian #832148 + * pmap: fix duplicate output line under '-x' option Redhat #1374061 procps-ng-3.3.12 ---------------- diff --git a/pmap.c b/pmap.c index 61aca2c3..41116edc 100644 --- a/pmap.c +++ b/pmap.c @@ -597,25 +597,23 @@ static int one_proc(proc_t * p) /* hex values are lower case or numeric, keys are upper */ if (mapbuf[0] >= 'A' && mapbuf[0] <= 'Z') { /* Its a key */ - if (sscanf - (mapbuf, "%20[^:]: %llu", smap_key, - &smap_value) == 2) { - if (strncmp("Rss", smap_key, 3) == 0) { + if (sscanf(mapbuf, "%20[^:]: %llu", smap_key, &smap_value) == 2) { + if (strcmp("Rss", smap_key) == 0) { rss = smap_value; total_rss += smap_value; continue; } - if (strncmp("Shared_Dirty", smap_key, 12) == 0) { + if (strcmp("Shared_Dirty", smap_key) == 0) { shared_dirty = smap_value; total_shared_dirty += smap_value; continue; } - if (strncmp("Private_Dirty", smap_key, 13) == 0) { + if (strcmp("Private_Dirty", smap_key) == 0) { private_dirty = smap_value; total_private_dirty += smap_value; continue; } - if (strncmp("Swap", smap_key, 4) == 0) { + if (strcmp("Swap", smap_key) == 0) { /*doesn't matter as long as last */ printf("%0*" KLF "x %*lu %*llu %*llu %*s %s\n", maxw1, start,