From 1aa8b1644118ee84ff02158e1a9f409527fb5a96 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 30 Jun 2020 00:00:00 -0500 Subject: [PATCH] library: eliminated the questionable 'procps.h' header There was a time when that procps.h file served a more traditional role. Prior to the commit referenced below it held just macros plus manifest constants. But, with that change, such items were replaced with a series of includes embracing all the library exported functions. That approach was known to disguise errors which would have otherwise yielded a compiler warning. And without such a warning, there was no way to address the error. So this patch will trade the all inclusive header file approach for individual includes only where necessary. Reference(s): . April 2016, procps.h header file revamped commit ccb6ae8de14b0cde25b84369ef995bcd69cbf7b6 . Sept 2018, top abandoned use of procps.h commit a6dfc2382ed1e023dd345cdb1d2388c9b67bcc7f Signed-off-by: Jim Warner --- Makefile.am | 2 -- free.c | 14 +++++++------- pgrep.c | 5 ++++- pidof.c | 3 ++- pmap.c | 3 ++- proc/escape.c | 1 - proc/escape.h | 4 +++- proc/procps.h | 37 ------------------------------------- proc/readproc.c | 14 +++++++------- proc/test_namespace.c | 2 +- proc/test_uptime.c | 2 +- ps/common.h | 6 +++++- skill.c | 5 +++-- slabtop.c | 3 ++- tload.c | 15 ++++++++------- uptime.c | 3 ++- vmstat.c | 8 +++++++- w.c | 13 ++++++++----- 18 files changed, 62 insertions(+), 78 deletions(-) delete mode 100644 proc/procps.h diff --git a/Makefile.am b/Makefile.am index 181edb5b..3c21658e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -252,7 +252,6 @@ proc_libprocps_la_SOURCES = \ proc/numa.h \ proc/pids.c \ proc/pids.h \ - proc/procps.h \ proc/pwcache.c \ proc/pwcache.h \ proc/readproc.c \ @@ -282,7 +281,6 @@ proc_libprocps_la_include_HEADERS = \ proc/namespace.h \ proc/numa.h \ proc/pids.h \ - proc/procps.h \ proc/pwcache.h \ proc/readproc.h \ proc/slabinfo.h \ diff --git a/free.c b/free.c index 9bc34d35..6a075041 100644 --- a/free.c +++ b/free.c @@ -26,12 +26,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "config.h" -#include "c.h" -#include "nls.h" -#include "strutils.h" -#include "fileutils.h" - #include #include #include @@ -41,7 +35,13 @@ #include #include -#include +#include "config.h" +#include "c.h" +#include "nls.h" +#include "strutils.h" +#include "fileutils.h" + +#include #ifndef SIZE_MAX #define SIZE_MAX 32 diff --git a/pgrep.c b/pgrep.c index d753cc91..899d49cc 100644 --- a/pgrep.c +++ b/pgrep.c @@ -49,7 +49,10 @@ #include "nls.h" #include "signals.h" #include "xalloc.h" -#include + +#include +#include +#include enum pids_item Items[] = { PIDS_ID_PID, diff --git a/pidof.c b/pidof.c index 87a08584..bf89420b 100644 --- a/pidof.c +++ b/pidof.c @@ -28,7 +28,8 @@ #include "fileutils.h" #include "nls.h" #include "xalloc.h" -#include + +#include #define grow_size(x) do { \ diff --git a/pmap.c b/pmap.c index 9f06c918..42144971 100644 --- a/pmap.c +++ b/pmap.c @@ -36,7 +36,8 @@ #include "fileutils.h" #include "nls.h" #include "xalloc.h" -#include + +#include static struct pids_info *Pids_info; diff --git a/proc/escape.c b/proc/escape.c index acbdb03b..9546ed77 100644 --- a/proc/escape.c +++ b/proc/escape.c @@ -21,7 +21,6 @@ #include #include #include -#include #include "escape.h" #include "readproc.h" diff --git a/proc/escape.h b/proc/escape.h index 871ac761..75e830bf 100644 --- a/proc/escape.h +++ b/proc/escape.h @@ -8,7 +8,9 @@ #define ESC_BRACKETS 0x2 // if using cmd, put '[' and ']' around it #define ESC_DEFUNCT 0x4 // mark zombies with " " - int escape_command(char *__restrict const outbuf, const proc_t *__restrict const pp, int bytes, int *cells, unsigned flags); +#define ESC_STRETCH 1 // since we mangle to '?' this is 1 (would be 4 for octal escapes) +int escape_str(char *__restrict dst, const char *__restrict src, int bufsize, int *maxcells); + #endif diff --git a/proc/procps.h b/proc/procps.h deleted file mode 100644 index 53033e98..00000000 --- a/proc/procps.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * libprocps - Library to read proc filesystem - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -#ifndef PROCPS_PROC_PROCPS_H -#define PROCPS_PROC_PROCPS_H - -/* includes that show public exports go here */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// FIXME: only public function in escape.c -#define ESC_STRETCH 1 // since we mangle to '?' this is 1 (would be 4 for octal escapes) -int escape_str(char *__restrict dst, const char *__restrict src, int bufsize, int *maxcells); - -#endif diff --git a/proc/readproc.c b/proc/readproc.c index 7264ad59..5d648337 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -19,12 +19,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "version.h" -#include "readproc.h" -#include "escape.h" -#include "pwcache.h" -#include "devname.h" -#include "procps.h" #include #include #include @@ -41,7 +35,13 @@ #ifdef WITH_SYSTEMD #include #endif -#include + +#include "devname.h" +#include "escape.h" +#include "namespace.h" +#include "pwcache.h" +#include "readproc.h" +#include "version.h" // sometimes it's easier to do this manually, w/o gcc helping #ifdef PROF diff --git a/proc/test_namespace.c b/proc/test_namespace.c index d39f03d8..4ac052a1 100644 --- a/proc/test_namespace.c +++ b/proc/test_namespace.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include "tests.h" int check_name_minus(void *data) diff --git a/proc/test_uptime.c b/proc/test_uptime.c index c9d4fb85..f9799116 100644 --- a/proc/test_uptime.c +++ b/proc/test_uptime.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include "tests.h" int check_uptime(void *data) diff --git a/ps/common.h b/ps/common.h index 8c61eb8e..097b89d2 100644 --- a/ps/common.h +++ b/ps/common.h @@ -13,7 +13,11 @@ #define PROCPS_PS_H #include "../include/nls.h" -#include +#include +#include +#include +#include +#include // --- interface begin |||||||||||||||||||||||||||||||||||||||||||| // ----------------------------------------------------------------------- diff --git a/skill.c b/skill.c index 3a92f091..83b2fb16 100644 --- a/skill.c +++ b/skill.c @@ -34,8 +34,6 @@ #include #include -#include - #include "c.h" #include "fileutils.h" #include "signals.h" @@ -44,6 +42,9 @@ #include "xalloc.h" #include "rpmatch.h" +#include +#include + #define DEFAULT_NICE 4 struct run_time_conf_t { diff --git a/slabtop.c b/slabtop.c index 510a62e9..9966af1e 100644 --- a/slabtop.c +++ b/slabtop.c @@ -42,7 +42,8 @@ #include "fileutils.h" #include "nls.h" #include "strutils.h" -#include + +#include #define DEFAULT_SORT SLAB_NUM_OBJS #define CHAINS_ALLOC 150 diff --git a/tload.c b/tload.c index a2cebdfb..eca9ef6c 100644 --- a/tload.c +++ b/tload.c @@ -24,13 +24,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include "c.h" -#include "fileutils.h" -#include "nls.h" -#include "strutils.h" -#include "xalloc.h" - #include #include #include @@ -44,6 +37,14 @@ #include #include +#include "c.h" +#include "fileutils.h" +#include "nls.h" +#include "strutils.h" +#include "xalloc.h" + +#include + static char *screen; static int nrows = 25; diff --git a/uptime.c b/uptime.c index 6134950e..2fdef849 100644 --- a/uptime.c +++ b/uptime.c @@ -27,7 +27,8 @@ #include "c.h" #include "fileutils.h" #include "nls.h" -#include + +#include static void print_uptime_since() { diff --git a/vmstat.c b/vmstat.c index 3bbc6080..71f518a7 100644 --- a/vmstat.c +++ b/vmstat.c @@ -48,7 +48,13 @@ #include "fileutils.h" #include "nls.h" #include "strutils.h" -#include + +#include +#include +#include +#include +#include +#include #define UNIT_B 1 #define UNIT_k 1000 diff --git a/w.c b/w.c index 73bc3b97..bf275631 100644 --- a/w.c +++ b/w.c @@ -23,11 +23,6 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "c.h" -#include "fileutils.h" -#include "nls.h" -#include - #include #include #include @@ -51,6 +46,14 @@ #include #include +#include "c.h" +#include "fileutils.h" +#include "nls.h" + +#include +#include +#include + static int ignoreuser = 0; /* for '-u' */ static int oldstyle = 0; /* for '-o' */