0095-pmap: Fix extended mode in one_proc().
Check the return value of sscanf() to make sure that all input items are properly initialized. In extended mode (x_option), one_proc() loads the values of start and perms during one iteration of the while loop, and displays them during one of the following iterations, but start and perms are variables local to the while loop: move them out of the while loop, to the beginning of the function. Also, display a mapping only if cp2 is properly initialized; otherwise (for example), mappings that do not belong to a selected range are displayed, and with a NULL mapping name: $ pmap -x -A 6FFF00000000,7FFF00000000 $$ ... Address Kbytes RSS Dirty Mode Mapping 000055b3d1e9b000 0 912 0 r-xp (null) 000055b3d2194000 0 16 16 r--p (null) 000055b3d2198000 0 36 36 rw-p (null) ... Removed const as this causes problems elsewhere. Signed-off-by: Craig Small <csmall@enc.com.au>
This commit is contained in:
parent
7d3b4bcaf2
commit
7bc4779718
25
pmap.c
25
pmap.c
@ -525,6 +525,8 @@ static int one_proc (struct pids_stack *p)
|
|||||||
unsigned long total_private_readonly = 0ul;
|
unsigned long total_private_readonly = 0ul;
|
||||||
unsigned long total_private_writeable = 0ul;
|
unsigned long total_private_writeable = 0ul;
|
||||||
unsigned long diff = 0;
|
unsigned long diff = 0;
|
||||||
|
unsigned long end;
|
||||||
|
char perms[32] = "";
|
||||||
const char *cp2 = NULL;
|
const char *cp2 = NULL;
|
||||||
unsigned long long rss = 0ull;
|
unsigned long long rss = 0ull;
|
||||||
unsigned long long private_dirty = 0ull;
|
unsigned long long private_dirty = 0ull;
|
||||||
@ -585,10 +587,8 @@ static int one_proc (struct pids_stack *p)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (fgets(mapbuf, sizeof mapbuf, fp)) {
|
while (fgets(mapbuf, sizeof mapbuf, fp)) {
|
||||||
char perms[32];
|
|
||||||
/* to clean up unprintables */
|
/* to clean up unprintables */
|
||||||
char *tmp;
|
char *tmp;
|
||||||
unsigned long end;
|
|
||||||
unsigned long long file_offset, inode;
|
unsigned long long file_offset, inode;
|
||||||
unsigned dev_major, dev_minor;
|
unsigned dev_major, dev_minor;
|
||||||
unsigned long long smap_value;
|
unsigned long long smap_value;
|
||||||
@ -614,17 +614,20 @@ static int one_proc (struct pids_stack *p)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp("Swap", smap_key) == 0) {
|
if (strcmp("Swap", smap_key) == 0) {
|
||||||
/*doesn't matter as long as last */
|
/* doesn't matter as long as last */
|
||||||
printf("%0*lx %*lu %*llu %*llu %*s %s\n",
|
if (cp2)
|
||||||
maxw1, start_To_Avoid_Warning,
|
printf("%0*lx %*lu %*llu %*llu %*s %s\n",
|
||||||
maxw2, (unsigned long)(diff >> 10),
|
maxw1, start_To_Avoid_Warning,
|
||||||
maxw3, rss,
|
maxw2, (unsigned long)(diff >> 10),
|
||||||
maxw4, (private_dirty + shared_dirty),
|
maxw3, rss,
|
||||||
maxw5, perms,
|
maxw4, (private_dirty + shared_dirty),
|
||||||
cp2);
|
maxw5, perms,
|
||||||
|
cp2);
|
||||||
/* reset some counters */
|
/* reset some counters */
|
||||||
rss = shared_dirty = private_dirty = 0ull;
|
rss = shared_dirty = private_dirty = 0ull;
|
||||||
diff = 0;
|
diff = end = 0;
|
||||||
|
perms[0] = '\0';
|
||||||
|
cp2 = NULL;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user