pmap: a spade is a spade, so let's call a Flags a Perm

For some reason when the new -X/-XX options were added
what was always displayed as 'Mode' became 'Flags'. So
now a precious horizontal space is wasted because that
field's data has only 4 bytes whereas the header is 5.

Moreover, this created a conflict with the top program
which used that name in a column header already. Plus,
top emitted a 'Translation Hint' that suggests the max
chars should be 8 which is a limit pmap needn't share!

The xgettext program provides no way to keep identical
strings separate. This meant both top and pmap will be
sharing not only the msgid but a Translation Hint too.
So, the solution will now be two distinct field names.

Besides the kernel folks document it as 'perm' anyway!

Reference(s):
       new options for pmap
commit faec340719

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2013-03-16 00:00:00 -05:00 committed by Jaromir Capik
parent 0c0c543466
commit c80e93be47

52
pmap.c
View File

@ -43,7 +43,7 @@ const char *nls_Address,
*nls_Offset, *nls_Offset,
*nls_Device, *nls_Device,
*nls_Mapping, *nls_Mapping,
*nls_Flags, *nls_Perm,
*nls_Inode, *nls_Inode,
*nls_Kbytes, *nls_Kbytes,
*nls_Mode, *nls_Mode,
@ -65,7 +65,7 @@ static void nls_initialize(void)
/* these headings are used only by the -X/-XX options, /* these headings are used only by the -X/-XX options,
and are not derived literally from /proc/#/smaps */ and are not derived literally from /proc/#/smaps */
nls_Flags = _("Flags"); nls_Perm = _("Perm");
nls_Inode = _("Inode"); nls_Inode = _("Inode");
/* these are potentially used for options other than -X/-XX, */ /* these are potentially used for options other than -X/-XX, */
@ -167,14 +167,14 @@ static void discover_shm_minor(void)
goto out_destroy; goto out_destroy;
while (fgets(mapbuf_b, sizeof mapbuf_b, stdin)) { while (fgets(mapbuf_b, sizeof mapbuf_b, stdin)) {
char flags[32]; char perms[32];
/* to clean up unprintables */ /* to clean up unprintables */
char *tmp; char *tmp;
unsigned KLONG start, end; unsigned KLONG start, end;
unsigned long long file_offset, inode; unsigned long long file_offset, inode;
unsigned dev_major, dev_minor; unsigned dev_major, dev_minor;
sscanf(mapbuf_b, "%" KLF "x-%" KLF "x %31s %llx %x:%x %llu", &start, sscanf(mapbuf_b, "%" KLF "x-%" KLF "x %31s %llx %x:%x %llu", &start,
&end, flags, &file_offset, &dev_major, &dev_minor, &end, perms, &file_offset, &dev_major, &dev_minor,
&inode); &inode);
tmp = strchr(mapbuf_b, '\n'); tmp = strchr(mapbuf_b, '\n');
if (tmp) if (tmp)
@ -189,7 +189,7 @@ static void discover_shm_minor(void)
continue; continue;
if (dev_major) if (dev_major)
continue; continue;
if (flags[3] != 's') if (perms[3] != 's')
continue; continue;
if (strstr(mapbuf_b, "/SYSV")) { if (strstr(mapbuf_b, "/SYSV")) {
shm_minor = dev_minor; shm_minor = dev_minor;
@ -300,7 +300,7 @@ static int is_enabled (const char *s)
static void print_extended_maps (FILE *f) static void print_extended_maps (FILE *f)
{ {
char flags[DETAIL_LENGTH], map_desc[128], char perms[DETAIL_LENGTH], map_desc[128],
detail_desc[DETAIL_LENGTH], value_str[NUM_LENGTH], detail_desc[DETAIL_LENGTH], value_str[NUM_LENGTH],
start[NUM_LENGTH], end[NUM_LENGTH], start[NUM_LENGTH], end[NUM_LENGTH],
offset[NUM_LENGTH], inode[NUM_LENGTH], offset[NUM_LENGTH], inode[NUM_LENGTH],
@ -319,7 +319,7 @@ static void print_extended_maps (FILE *f)
"%"NUML"[0-9a-f]-%"NUML"[0-9a-f] " "%"NUML"[0-9a-f]-%"NUML"[0-9a-f] "
"%"DETL"s %"NUML"[0-9a-f] " "%"DETL"s %"NUML"[0-9a-f] "
"%63[0-9a-f:] %"NUML"s %127[^\n]%c", "%63[0-9a-f:] %"NUML"s %127[^\n]%c",
start, end, flags, offset, start, end, perms, offset,
dev, inode, map_desc, &c); dev, inode, map_desc, &c);
/* Must read at least up to inode, else something has changed! */ /* Must read at least up to inode, else something has changed! */
if (nfields < 6) if (nfields < 6)
@ -332,7 +332,7 @@ static void print_extended_maps (FILE *f)
/* Store maximum widths for printing nice later */ /* Store maximum widths for printing nice later */
if (strlen(start ) > maxw1) maxw1 = strlen(start); if (strlen(start ) > maxw1) maxw1 = strlen(start);
if (strlen(flags ) > maxw2) maxw2 = strlen(flags); if (strlen(perms ) > maxw2) maxw2 = strlen(perms);
if (strlen(offset) > maxw3) maxw3 = strlen(offset); if (strlen(offset) > maxw3) maxw3 = strlen(offset);
if (strlen(dev ) > maxw4) maxw4 = strlen(dev); if (strlen(dev ) > maxw4) maxw4 = strlen(dev);
if (strlen(inode ) > maxw5) maxw5 = strlen(inode); if (strlen(inode ) > maxw5) maxw5 = strlen(inode);
@ -409,8 +409,8 @@ loop_end:
maxw1 = justify_print(nls_Address, maxw1, 1); maxw1 = justify_print(nls_Address, maxw1, 1);
if (is_enabled(nls_Flags)) if (is_enabled(nls_Perm))
maxw2 = justify_print(nls_Flags, maxw2, 1); maxw2 = justify_print(nls_Perm, maxw2, 1);
if (is_enabled(nls_Offset)) if (is_enabled(nls_Offset))
maxw3 = justify_print(nls_Offset, maxw3, 1); maxw3 = justify_print(nls_Offset, maxw3, 1);
@ -436,8 +436,8 @@ loop_end:
/* Print data */ /* Print data */
printf("%*s", maxw1, start); /* Address field is always enabled */ printf("%*s", maxw1, start); /* Address field is always enabled */
if (is_enabled(nls_Flags)) if (is_enabled(nls_Perm))
printf(" %*s", maxw2, flags); printf(" %*s", maxw2, perms);
if (is_enabled(nls_Offset)) if (is_enabled(nls_Offset))
printf(" %*s", maxw3, offset); printf(" %*s", maxw3, offset);
@ -454,7 +454,7 @@ loop_end:
if (has_vmflags && is_enabled("VmFlags")) if (has_vmflags && is_enabled("VmFlags"))
printf(" %*s", maxwv, vmflags); printf(" %*s", maxwv, vmflags);
if (is_enabled("Mapping")) { if (is_enabled(nls_Mapping)) {
if (map_desc_showpath) { if (map_desc_showpath) {
printf(" %s", map_desc); printf(" %s", map_desc);
} else { } else {
@ -478,7 +478,7 @@ loop_end:
if (!q_option && listhead!=NULL) { /* footer enabled and non-empty */ if (!q_option && listhead!=NULL) { /* footer enabled and non-empty */
footer_gap = maxw1 + 1; /* Address field is always enabled */ footer_gap = maxw1 + 1; /* Address field is always enabled */
if (is_enabled(nls_Flags )) footer_gap += maxw2 + 1; if (is_enabled(nls_Perm )) footer_gap += maxw2 + 1;
if (is_enabled(nls_Offset)) footer_gap += maxw3 + 1; if (is_enabled(nls_Offset)) footer_gap += maxw3 + 1;
if (is_enabled(nls_Device)) footer_gap += maxw4 + 1; if (is_enabled(nls_Device)) footer_gap += maxw4 + 1;
if (is_enabled(nls_Inode )) footer_gap += maxw5 + 1; if (is_enabled(nls_Inode )) footer_gap += maxw5 + 1;
@ -577,7 +577,7 @@ static int one_proc(proc_t * p)
} }
while (fgets(mapbuf, sizeof mapbuf, fp)) { while (fgets(mapbuf, sizeof mapbuf, fp)) {
char flags[32]; char perms[32];
/* to clean up unprintables */ /* to clean up unprintables */
char *tmp; char *tmp;
unsigned KLONG start, end; unsigned KLONG start, end;
@ -614,7 +614,7 @@ static int one_proc(proc_t * p)
maxw2, (unsigned long)(diff >> 10), maxw2, (unsigned long)(diff >> 10),
maxw3, rss, maxw3, rss,
maxw4, (private_dirty + shared_dirty), maxw4, (private_dirty + shared_dirty),
maxw5, flags, maxw5, perms,
cp2); cp2);
/* reset some counters */ /* reset some counters */
rss = shared_dirty = private_dirty = 0ull; rss = shared_dirty = private_dirty = 0ull;
@ -626,7 +626,7 @@ static int one_proc(proc_t * p)
} }
} }
sscanf(mapbuf, "%" KLF "x-%" KLF "x %31s %llx %x:%x %llu", &start, sscanf(mapbuf, "%" KLF "x-%" KLF "x %31s %llx %x:%x %llu", &start,
&end, flags, &file_offset, &dev_major, &dev_minor, &end, perms, &file_offset, &dev_major, &dev_minor,
&inode); &inode);
if (end - 1 < range_low) if (end - 1 < range_low)
@ -645,11 +645,11 @@ static int one_proc(proc_t * p)
} }
diff = end - start; diff = end - start;
if (flags[3] == 's') if (perms[3] == 's')
total_shared += diff; total_shared += diff;
if (flags[3] == 'p') { if (perms[3] == 'p') {
flags[3] = '-'; perms[3] = '-';
if (flags[1] == 'w') if (perms[1] == 'w')
total_private_writeable += diff; total_private_writeable += diff;
else else
total_private_readonly += diff; total_private_readonly += diff;
@ -658,8 +658,8 @@ static int one_proc(proc_t * p)
* if swap not reserved (MAP_NORESERVE, SysV ISM * if swap not reserved (MAP_NORESERVE, SysV ISM
* shared mem, etc.) * shared mem, etc.)
*/ */
flags[4] = '-'; perms[4] = '-';
flags[5] = '\0'; perms[5] = '\0';
if (x_option) { if (x_option) {
cp2 = cp2 =
@ -675,7 +675,7 @@ static int one_proc(proc_t * p)
printf("%0*" KLF "x %*lu %*s %0*llx %*.*s%03x:%05x %s\n", printf("%0*" KLF "x %*lu %*s %0*llx %*.*s%03x:%05x %s\n",
maxw1, start, maxw1, start,
maxw2, (unsigned long)(diff >> 10), maxw2, (unsigned long)(diff >> 10),
maxw3, flags, maxw3, perms,
maxw4, file_offset, maxw4, file_offset,
(maxw5-9), (maxw5-9), " ", dev_major, dev_minor, (maxw5-9), (maxw5-9), " ", dev_major, dev_minor,
cp); cp);
@ -687,7 +687,7 @@ static int one_proc(proc_t * p)
printf((sizeof(KLONG) == 8) printf((sizeof(KLONG) == 8)
? "%016" KLF "x %6luK %s %s\n" ? "%016" KLF "x %6luK %s %s\n"
: "%08lx %6luK %s %s\n", : "%08lx %6luK %s %s\n",
start, (unsigned long)(diff >> 10), flags, cp); start, (unsigned long)(diff >> 10), perms, cp);
} }
} }
@ -920,7 +920,7 @@ static int config_create (char *rc_filename)
fprintf(f,"\n"); fprintf(f,"\n");
fprintf(f,"# To enable a field uncomment its entry\n"); fprintf(f,"# To enable a field uncomment its entry\n");
fprintf(f,"\n"); fprintf(f,"\n");
fprintf(f,"#%s\n", nls_Flags); fprintf(f,"#%s\n", nls_Perm);
fprintf(f,"#%s\n", nls_Offset); fprintf(f,"#%s\n", nls_Offset);
fprintf(f,"#%s\n", nls_Device); fprintf(f,"#%s\n", nls_Device);
fprintf(f,"#%s\n", nls_Inode); fprintf(f,"#%s\n", nls_Inode);