From 2c1973d64c7a0a9c40387b5f1315e8b524674489 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 22 Aug 2020 00:00:00 -0500 Subject: [PATCH] library: eliminate one potential source of human error There's a huge toe-stubber awaiting future maintenance as reflected in that commit below which deals with the addition of new enumerators to the Item_table. Namely, whenever the table is grown, one must remember to also change that existing 'logical_end' enumerator's value. Well, not anymore! Since that MAXTABLE macro was added to the procps-private.h header we can now also exploit it so a 'logical_end' automatically tracks table size. This change also renders some code associated with the ITEMTABLE_DEBUG #define unnecessary. So it's gone too. Reference(s): . 08/2016, add new enumerators commit 09e1886c9e731f8b8c89a55d11f72f53f030b2de . 08/2020, added MAXTABLE macro commit c865b06c304e645c05eae0f5e06a1f49ea105285 . 08/2020, introduced ITEMTABLE_DEBUG commit 92d0297e1e4d5946c5b098e37c91c7e524a0eca0 Signed-off-by: Jim Warner --- proc/diskstats.c | 7 +------ proc/meminfo.c | 7 +------ proc/pids.c | 7 +------ proc/slabinfo.c | 7 +------ proc/stat.c | 7 +------ proc/vmstat.c | 7 +------ 6 files changed, 6 insertions(+), 36 deletions(-) diff --git a/proc/diskstats.c b/proc/diskstats.c index 0fb5d58b..fb8aa00d 100644 --- a/proc/diskstats.c +++ b/proc/diskstats.c @@ -270,7 +270,7 @@ static struct { /* please note, * this enum MUST be 1 greater than the highest value of any enum */ -enum diskstats_item DISKSTATS_logical_end = DISKSTATS_DELTA_WEIGHTED_TIME + 1; +enum diskstats_item DISKSTATS_logical_end = MAXTABLE(Item_table); #undef setNAME #undef srtNAME @@ -725,11 +725,6 @@ PROCPS_EXPORT int procps_diskstats_new ( failed = 1; } } - if (i != DISKSTATS_logical_end) { - fprintf(stderr, "%s: DISKSTATS_logical_end is %d, expected %d\n" - , __FILE__, DISKSTATS_logical_end, i); - failed = 1; - } if (failed) _Exit(EXIT_FAILURE); #endif diff --git a/proc/meminfo.c b/proc/meminfo.c index 2ae28763..4ab767b0 100644 --- a/proc/meminfo.c +++ b/proc/meminfo.c @@ -454,7 +454,7 @@ static struct { /* please note, * this enum MUST be 1 greater than the highest value of any enum */ -enum meminfo_item MEMINFO_logical_end = MEMINFO_SWAP_DELTA_USED + 1; +enum meminfo_item MEMINFO_logical_end = MAXTABLE(Item_table); #undef setNAME #undef RS @@ -808,11 +808,6 @@ PROCPS_EXPORT int procps_meminfo_new ( failed = 1; } } - if (i != MEMINFO_logical_end) { - fprintf(stderr, "%s: MEMINFO_logical_end is %d, expected %d\n" - , __FILE__, MEMINFO_logical_end, i); - failed = 1; - } if (failed) _Exit(EXIT_FAILURE); #endif diff --git a/proc/pids.c b/proc/pids.c index a17245d0..53d36482 100644 --- a/proc/pids.c +++ b/proc/pids.c @@ -518,7 +518,7 @@ static struct { /* please note, * this enum MUST be 1 greater than the highest value of any enum */ -enum pids_item PIDS_logical_end = PIDS_WCHAN_NAME + 1; +enum pids_item PIDS_logical_end = MAXTABLE(Item_table); #undef setNAME #undef freNAME @@ -1137,11 +1137,6 @@ PROCPS_EXPORT int procps_pids_new ( failed = 1; } } - if (i != PIDS_logical_end) { - fprintf(stderr, "%s: PIDS_logical_end is %d, expected %d\n" - , __FILE__, PIDS_logical_end, i); - failed = 1; - } if (failed) _Exit(EXIT_FAILURE); #endif diff --git a/proc/slabinfo.c b/proc/slabinfo.c index e3b7598a..c3645041 100644 --- a/proc/slabinfo.c +++ b/proc/slabinfo.c @@ -311,7 +311,7 @@ static struct { /* please note, * this enum MUST be 1 greater than the highest value of any enum */ -enum slabinfo_item SLABINFO_logical_end = SLABS_DELTA_SIZE_TOTAL + 1; +enum slabinfo_item SLABINFO_logical_end = MAXTABLE(Item_table); #undef setNAME #undef srtNAME @@ -753,11 +753,6 @@ PROCPS_EXPORT int procps_slabinfo_new ( failed = 1; } } - if (i != SLABINFO_logical_end) { - fprintf(stderr, "%s: SLABINFO_logical_end is %d, expected %d\n" - , __FILE__, SLABINFO_logical_end, i); - failed = 1; - } if (failed) _Exit(EXIT_FAILURE); #endif diff --git a/proc/stat.c b/proc/stat.c index 110932ad..ff138adc 100644 --- a/proc/stat.c +++ b/proc/stat.c @@ -361,7 +361,7 @@ static struct { #ifdef ENFORCE_LOGICAL enum stat_item STAT_TIC_highest = STAT_TIC_DELTA_GUEST_NICE; #endif -enum stat_item STAT_logical_end = STAT_SYS_DELTA_PROC_RUNNING + 1; +enum stat_item STAT_logical_end = MAXTABLE(Item_table); #undef setNAME #undef srtNAME @@ -875,11 +875,6 @@ PROCPS_EXPORT int procps_stat_new ( failed = 1; } } - if (i != STAT_logical_end) { - fprintf(stderr, "%s: STAT_logical_end is %d, expected %d\n" - , __FILE__, STAT_logical_end, i); - failed = 1; - } if (failed) _Exit(EXIT_FAILURE); #endif diff --git a/proc/vmstat.c b/proc/vmstat.c index 331659a4..3a81f238 100644 --- a/proc/vmstat.c +++ b/proc/vmstat.c @@ -898,7 +898,7 @@ static struct { /* please note, * this enum MUST be 1 greater than the highest value of any enum */ -enum vmstat_item VMSTAT_logical_end = VMSTAT_DELTA_ZONE_RECLAIM_FAILED + 1; +enum vmstat_item VMSTAT_logical_end = MAXTABLE(Item_table); #undef setNAME #undef RS @@ -1305,11 +1305,6 @@ PROCPS_EXPORT int procps_vmstat_new ( failed = 1; } } - if (i != VMSTAT_logical_end) { - fprintf(stderr, "%s: VMSTAT_logical_end is %d, expected %d\n" - , __FILE__, VMSTAT_logical_end, i); - failed = 1; - } if (failed) _Exit(EXIT_FAILURE); #endif