]> granicus.if.org Git - procps-ng/commitdiff
library: cleanup of library includes
authorCraig Small <csmall@enc.com.au>
Sat, 16 Apr 2016 07:03:57 +0000 (17:03 +1000)
committerCraig Small <csmall@enc.com.au>
Sat, 16 Apr 2016 07:03:57 +0000 (17:03 +1000)
The includes used to define a lot of things a library include
should not. It was also a bit messy what was exposed in the library
and what was not.

get_pid_digits -> procps_pid_length and exported correctly

MALLOC attribute move into relevant .c files
NORETURN attribute moved to relevant .c, not used in library
PURE attribute removed, it wasn't used
KLONG/KLF/STRTOUKL were fixed for long, so now just use long

HIDDEN attribute removed. It was for 3 functions. The PROCPS_EXPORT
seems to do the same (opposite) thing.

likely/unlikely removed from most places, its highly debateable
this does anything useful as CPUs have gotten smarter about branches.

Re-arranged the includes, ALL external programs should just #include
<proc/procps.h> then proc/procps.h includes headers for files that
have exported functions. procps.h and the headers it includes should
not use items that are not exportable (e.g. hidden functions or
macros) they go in procps-private.h

38 files changed:
free.c
pgrep.c
pidof.c
pmap.c
proc/alloc.c
proc/alloc.h
proc/devname.h
proc/diskstat.h
proc/escape.h
proc/libprocps.sym
proc/meminfo.h
proc/namespace.h
proc/pids.h
proc/procps-private.h
proc/procps.h
proc/pwcache.h
proc/readproc.c
proc/readproc.h
proc/slab.h
proc/sysinfo.c
proc/sysinfo.h
proc/uptime.h
proc/version.h
proc/vmstat.h
proc/wchan.h
ps/common.h
ps/display.c
ps/global.c
ps/help.c
ps/output.c
ps/sortformat.c
skill.c
slabtop.c
tload.c
top/top.c
uptime.c
vmstat.c
w.c

diff --git a/free.c b/free.c
index 4a9686a83657f136840c331b5193d65ea757a6be..e73716045878ed6aac9c18cf058f898ab0cf6cb9 100644 (file)
--- a/free.c
+++ b/free.c
@@ -41,9 +41,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include <proc/sysinfo.h>
-#include <proc/version.h>
-#include <proc/meminfo.h>
+#include <proc/procps.h>
 
 #ifndef SIZE_MAX
 #define SIZE_MAX               32
diff --git a/pgrep.c b/pgrep.c
index ed2f02c0b7111614422b103b54de1bf3e2e76b82..85e703ad86b02fd99a5f2f1590880b5a6b3d6bc8 100644 (file)
--- a/pgrep.c
+++ b/pgrep.c
@@ -49,9 +49,7 @@
 #include "nls.h"
 #include "signals.h"
 #include "xalloc.h"
-#include <proc/pids.h>
-#include <proc/namespace.h>
-#include <proc/devname.h>
+#include <proc/procps.h>
 
 enum pids_item Items[] = {
     PROCPS_PIDS_ID_PID,
diff --git a/pidof.c b/pidof.c
index 9e53393c455a42505a31553da5ecf8879ff29c78..c8d1175f21af6f6d699de56bb9b550e811c8e0fd 100644 (file)
--- a/pidof.c
+++ b/pidof.c
@@ -27,9 +27,7 @@
 #include "fileutils.h"
 #include "nls.h"
 #include "xalloc.h"
-//#include "proc/readproc.h"
-#include <proc/pids.h>
-#include "proc/version.h" /* procps_version */
+#include <proc/procps.h>
 
 
 #define grow_size(x)   (x = x * 5 / 4 + 1024)
diff --git a/pmap.c b/pmap.c
index d8d163f7eb6ec18313ddb76646ae759d044a9e78..1cc719e3863febe303d2106b0f415b9af8e0c7b6 100644 (file)
--- a/pmap.c
+++ b/pmap.c
@@ -35,8 +35,7 @@
 #include "fileutils.h"
 #include "nls.h"
 #include "xalloc.h"
-#include "proc/version.h"
-#include <proc/pids.h>
+#include <proc/procps.h>
 
 enum pids_item Pid_items[] = {
     PROCPS_PIDS_ID_PID,  PROCPS_PIDS_ID_TGID,
@@ -176,7 +175,7 @@ static void discover_shm_minor(void)
                unsigned long start, end;
                unsigned long long file_offset, inode;
                unsigned dev_major, dev_minor;
-               sscanf(mapbuf_b, "%" KLF "x-%" KLF "x %31s %llx %x:%x %llu", &start,
+               sscanf(mapbuf_b, "%lx-%lx %31s %llx %x:%x %llu", &start,
                       &end, perms, &file_offset, &dev_major, &dev_minor,
                       &inode);
                tmp = strchr(mapbuf_b, '\n');
@@ -373,7 +372,7 @@ static void print_extended_maps (FILE *f)
                                              mapbuf);
                        }
                        strcpy(listnode->value_str, value_str);
-                       sscanf(value_str, "%"KLF"u", &listnode->value);
+                       sscanf(value_str, "%lu", &listnode->value);
                        if (firstmapping == 2) {
                                listnode->total += listnode->value;
                                if (q_option) {
@@ -614,7 +613,7 @@ static int one_proc (struct pids_stack *p)
                                }
                                if (strncmp("Swap", smap_key, 4) == 0) {
                                        /*doesn't matter as long as last */
-                                       printf("%0*" KLF "x %*lu %*llu %*llu %*s %s\n",
+                                       printf("%0*lx %*lu %*llu %*llu %*s %s\n",
                                               maxw1, start,
                                               maxw2, (unsigned long)(diff >> 10),
                                               maxw3, rss,
@@ -630,7 +629,7 @@ static int one_proc (struct pids_stack *p)
                                continue;
                        }
                }
-               sscanf(mapbuf, "%" KLF "x-%" KLF "x %31s %llx %x:%x %llu", &start,
+               sscanf(mapbuf, "%lx-%lx %31s %llx %x:%x %llu", &start,
                       &end, perms, &file_offset, &dev_major, &dev_minor,
                       &inode);
 
@@ -677,7 +676,7 @@ static int one_proc (struct pids_stack *p)
                        const char *cp =
                            mapping_name(p, start, diff, mapbuf, map_desc_showpath, dev_major,
                                         dev_minor, inode);
-                       printf("%0*" KLF "x %*lu %*s %0*llx %*.*s%03x:%05x %s\n",
+                       printf("%0*lx %*lu %*s %0*llx %*.*s%03x:%05x %s\n",
                               maxw1, start,
                               maxw2, (unsigned long)(diff >> 10),
                               maxw3, perms,
@@ -690,7 +689,7 @@ static int one_proc (struct pids_stack *p)
                            mapping_name(p, start, diff, mapbuf, map_desc_showpath, dev_major,
                                         dev_minor, inode);
                        printf((sizeof(long) == 8)
-                              ? "%016" KLF "x %6luK %s %s\n"
+                              ? "%016lx %6luK %s %s\n"
                               : "%08lx %6luK %s %s\n",
                               start, (unsigned long)(diff >> 10), perms, cp);
                }
@@ -757,9 +756,9 @@ static void range_arguments(char *optarg)
        else
                arg2 = arg1;
        if (arg1 && *arg1)
-               range_low = STRTOUKL(arg1, &arg1, 16);
+               range_low = strtoul(arg1, &arg1, 16);
        if (*arg2)
-               range_high = STRTOUKL(arg2, &arg2, 16);
+               range_high = strtoul(arg2, &arg2, 16);
        if (arg1 && (*arg1 || *arg2))
                xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"),
                      optarg);
index 94af47f7231406839308d79c8943b44c413a34a2..7d9d69c513e714a1c4bed5393ac478ea069f5786 100644 (file)
 
 #include "alloc.h"
 
+typedef void (*message_fn)(const char *__restrict, ...) __attribute__((format(printf,1,2)));
+ /* change xalloc_err_handler to override the default fprintf(stderr... */
+extern message_fn xalloc_err_handler;
+
 static void xdefault_error(const char *restrict fmts, ...) __attribute__((format(printf,1,2)));
 static void xdefault_error(const char *restrict fmts, ...) {
     va_list va;
index 3afec5db38a7317332ab930d31cf9209579c0868..c1d3e9d458716fb3f670a2fa18bddd3485e5c807 100644 (file)
@@ -1,12 +1,11 @@
 #ifndef PROCPS_PROC_ALLOC_H
 #define PROCPS_PROC_ALLOC_H
 
-#include <proc/procps.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
- /* change xalloc_err_handler to override the default fprintf(stderr... */
-extern message_fn xalloc_err_handler;
+#define MALLOC __attribute__ ((__malloc__))
 
 extern void *xcalloc(unsigned int size) MALLOC;
 extern void *xmalloc(size_t size) MALLOC;
index 4517cc682d63f9ee2a385f48b80c33c2ba74bc41..7aa1f408f6c04bc7f8492aa8bd383e654f44c9fc 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef PROC_DEVNAME_H
 #define PROC_DEVNAME_H
 
-#include <proc/procps.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
index adf9cfb487f358c3336cdec87b9c12a1d53d654f..29dc8fce16eedc8abb8d528267dde678324e379a 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef PROC_DISKSTAT_H
 #define PROC_DISKSTAT_H
 
-#include <proc/procps.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
index 5ec59f67a000bf87515f8c18f34df4c452e3ad65..c2f3c45b15c63ee3821d8528c1241d9b61254a4e 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef PROCPS_PROC_ESCAPE_H
 #define PROCPS_PROC_ESCAPE_H
 
-#include <proc/procps.h>
 #include <proc/readproc.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
index 997bd69980f13123d7518b337f7f579dc58c511b..77a1bda47c803fd6cecf0791e2d88720bc0dee13 100644 (file)
@@ -7,7 +7,6 @@ global:
        escape_strlist;
        escaped_copy;
        fatal_proc_unmounted;
-       get_pid_digits;
        look_up_our_self;
        lookup_wchan;
        openproc;
@@ -40,6 +39,7 @@ global:
        procps_ns_get_name;
        procps_ns_get_id;
        procps_ns_read_pid;
+       procps_pid_length;
        procps_pids_new;
        procps_pids_read_next;
        procps_pids_read_open;
index 9006ce09a3fdbea92741476a7d730103707ea4e6..7300f70a69f38cef4aece76a523acef686d8ead4 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef PROC_MEMINFO_H
 #define PROC_MEMINFO_H
 
-#include <proc/procps.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
index 69254a800ec4e063e9653e0a02faec8218c3fd53..2aaea5c07fd8291118ac87bdd17704d47150bffd 100644 (file)
@@ -23,8 +23,6 @@
 #ifndef PROC_NAMESPACE_H
 #define PROC_NAMESPACE_H
 
-#include <proc/procps.h>
-
 __BEGIN_DECLS
 
 enum namespace_type {
index 630e9e86205a2db5e0c292bd3de8246179ebc73d..bfc977c4a8c312fdc3cd652b0bc5de0a3494cce8 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef _PROC_PIDS_H
 #define _PROC_PIDS_H
 
+#include <features.h>
 __BEGIN_DECLS
 
 enum pids_item {
index ea9479b96b3d979c4cfe88a7c8104dcf0d8066fb..579636955b8b680bc689192eb55903550d55d030 100644 (file)
 
 #include <proc/procps.h>
 
+#define FUNCTION __attribute__((__const__))  // no access to global mem, even via ptr, and no side effect
 #define PROCPS_EXPORT __attribute__ ((visibility("default")))
 
+#define STRINGIFY_ARG(a)       #a
+#define STRINGIFY(a)           STRINGIFY_ARG(a)
+
+
 #endif
index 7ee2cdf306feffec1e4d88ab9a71bcfb2e750a8a..2bf042e7cd129ed70bdc679d3e0982e4c916559c 100644 (file)
@@ -1,59 +1,35 @@
+/*
+ * 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
 
-#include <features.h>
-
-#define KLONG long
-#define KLF "l"
-#define STRTOUKL strtoul
-
-// since gcc-2.5
-#define NORETURN __attribute__((__noreturn__))
-#define FUNCTION __attribute__((__const__))  // no access to global mem, even via ptr, and no side effect
-
-#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
-// won't alias anything, and aligned enough for anything
-#define MALLOC __attribute__ ((__malloc__))
-// no side effect, may read globals
-#define PURE __attribute__ ((__pure__))
-// tell gcc what to expect:   if(unlikely(err)) die(err);
-#define likely(x)       __builtin_expect(!!(x),1)
-#define unlikely(x)     __builtin_expect(!!(x),0)
-#define expected(x,y)   __builtin_expect((x),(y))
-#else
-#define MALLOC
-#define PURE
-#define likely(x)       (x)
-#define unlikely(x)     (x)
-#define expected(x,y)   (x)
-#endif
-
-#ifdef SHARED
-# if SHARED==1 && (__GNUC__ > 2 || __GNUC_MINOR__ >= 96)
-#  define LABEL_OFFSET
-# endif
-#endif
-
-#define STRINGIFY_ARG(a)       #a
-#define STRINGIFY(a)           STRINGIFY_ARG(a)
-
-// marks old junk, to warn non-procps-ng library users
-#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 0 ) || __GNUC__ > 3
-#define OBSOLETE __attribute__((deprecated))
-#else
-#define OBSOLETE
-#endif
-
-// Like HIDDEN, but for an alias that gets created.
-// In gcc-3.2 there is an alias+hidden conflict.
-// Many will have patched this bug, but oh well.
-#if ( __GNUC__ == 3 && __GNUC_MINOR__ > 2 ) || __GNUC__ > 3
-#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x),visibility("hidden")))
-#else
-#define HIDDEN_ALIAS(x) extern __typeof(x) x##_direct __attribute__((alias(#x)))
-#endif
-
-
-typedef void (*message_fn)(const char *__restrict, ...) __attribute__((format(printf,1,2)));
+/* includes that show public exports go here */
+#include <proc/diskstat.h>
+#include <proc/escape.h>
+#include <proc/meminfo.h>
+#include <proc/namespace.h>
+#include <proc/pids.h>
+#include <proc/readproc.h>
+#include <proc/readstat.h>
+#include <proc/slab.h>
+#include <proc/sysinfo.h>
+#include <proc/version.h>
+#include <proc/vmstat.h>
+#include <proc/uptime.h>
 
 #endif
index 1fab493ba04ba50baaea228379467a7daa7672c5..b0c7353ffb3d14b3e01e5d964f913565edb6b27f 100644 (file)
@@ -1,8 +1,8 @@
 #ifndef PROCPS_PROC_PWCACHE_H
 #define PROCPS_PROC_PWCACHE_H
 
+#include <features.h>
 #include <sys/types.h>
-#include <proc/procps.h>
 
 __BEGIN_DECLS
 
index cebb22530f72d549376ad06a9848bda9e7e7d9ca..aaf3466dc66be983d8f36c24af94b820286ac2cc 100644 (file)
 #endif
 #include <proc/namespace.h>
 
+#define likely(x)       __builtin_expect(!!(x),1)
+#define unlikely(x)     __builtin_expect(!!(x),0)
+#define expected(x,y)   __builtin_expect((x),(y))
+
 // sometimes it's easier to do this manually, w/o gcc helping
 #ifdef PROF
 extern void __cyg_profile_func_enter(void*,void*);
@@ -550,9 +554,9 @@ ENTER(0x160);
        "%llu "  /* start_time */
        "%lu "
        "%ld "
-       "%lu %"KLF"u %"KLF"u %"KLF"u %"KLF"u %"KLF"u "
+       "%lu %lu %lu %lu %lu %lu "
        "%*s %*s %*s %*s " /* discard, no RT signals & Linux 2.1 used hex */
-       "%"KLF"u %*u %*u "
+       "%lu %*u %*u "
        "%d %d "
        "%lu %lu",
        &P->state,
@@ -906,7 +910,7 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
 
     // if multithreaded, some values are crap
     if(p->nlwp > 1){
-      p->wchan = (KLONG)~0ull;
+      p->wchan = ~0ul;
     }
 
     /* some number->text resolving which is time consuming */
@@ -1403,9 +1407,6 @@ void look_up_our_self(proc_t *p) {
     free(ub.buf);
 }
 
-HIDDEN_ALIAS(readproc);
-HIDDEN_ALIAS(readtask);
-HIDDEN_ALIAS(readeither);
 
 /* Convenient wrapper around openproc and readproc to slurp in the whole process
  * table subset satisfying the constraints of flags and the optional PID list.
@@ -1439,7 +1440,7 @@ proc_t** readproctab(unsigned flags, ...) {
       return 0;
     do {                                       /* read table: */
        tab = xrealloc(tab, (n+1)*sizeof(proc_t*));/* realloc as we go, using */
-       tab[n] = readproc_direct(PT, NULL);     /* final null to terminate */
+       tab[n] = readproc(PT, NULL);     /* final null to terminate */
     } while (tab[n++]);                                  /* stop when NULL reached */
     closeproc(PT);
     return tab;
@@ -1473,7 +1474,7 @@ proc_data_t *readproctab2(int(*want_proc)(proc_t *buf), int(*want_task)(proc_t *
           n_proc_alloc = n_proc_alloc*5/4+30;  // grow by over 25%
           ptab = xrealloc(ptab,sizeof(proc_t*)*n_proc_alloc);
         }
-        tmp = readproc_direct(PT, data+n_used);
+        tmp = readproc(PT, data+n_used);
         if(!tmp) break;
         if(!want_proc(tmp)) continue;
         ptab[n_proc++] = (proc_t*)(n_used++);
@@ -1493,7 +1494,7 @@ proc_data_t *readproctab2(int(*want_proc)(proc_t *buf), int(*want_task)(proc_t *
             n_task_alloc = n_task_alloc*5/4+1;  // grow by over 25%
             ttab = xrealloc(ttab,sizeof(proc_t*)*n_task_alloc);
           }
-          t = readtask_direct(PT, tmp, data+n_used);
+          t = readtask(PT, tmp, data+n_used);
           if(!t) break;
           if(!want_task(t)) continue;
           ttab[n_task++] = (proc_t*)(n_used++);
@@ -1533,7 +1534,7 @@ proc_data_t *readproctab3 (int(*want_task)(proc_t *buf), PROCTAB *restrict const
         }
         // let this next guy allocate the necessary proc_t storage
         // (or recycle it) since he can't tolerate realloc relocations
-        if (!(p = readeither_direct(PT,p))) break;
+        if (!(p = readeither(PT,p))) break;
         if (want_task(p)) {
             tab[n_used++] = p;
             p = NULL;
index 10160b40a5989825e60567f70b673badd7fbbe41..3fd7007aba9edde36722f0fc1613f3c86cd25410 100644 (file)
@@ -10,8 +10,7 @@
 // in the file COPYING
 
 
-#include <proc/procps.h>
-#include <proc/pwcache.h>
+// #include <proc/pwcache.h>
 #include <proc/namespace.h>
 
 #define SIGNAL_STRING
@@ -93,7 +92,7 @@ typedef struct proc_t {
        sigcatch,       // status          mask of caught  signals
        _sigpnd;        // status          mask of PER TASK pending signals
 #endif
-    unsigned KLONG
+    unsigned long
        start_code,     // stat            address of beginning of code segment
        end_code,       // stat            address of end of code segment
        start_stack,    // stat            address of the bottom of stack for the process
index 5f565ef3fe5003a47c60819e6af4b307deb86075..0aed7f44fdd92c10094789346a34e76c726380ba 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef _PROC_SLAB_H
 #define _PROC_SLAB_H
 
+#include <features.h>
+
 __BEGIN_DECLS
 
 enum slabs_item {
index f58d139c50de85d5f84a1569b6625f8792bb2e22..0cd8759f758b7fe4aab4c3732ce1e5fbe06c2ebc 100644 (file)
@@ -173,34 +173,36 @@ unsigned int getslabinfo (struct slab_cache **slab){
   return cSlab;
 }
 
-///////////////////////////////////////////////////////////////////////////
+#define PROCFS_PID_MAX "/proc/sys/kernel/pid_max"
+#define DEFAULT_PID_LENGTH 5
 
-unsigned get_pid_digits(void){
-  char pidbuf[24];
-  char *endp;
-  long rc;
-  int fd;
-  static unsigned ret;
-
-  if(ret) goto out;
-  ret = 5;
-  fd = open("/proc/sys/kernel/pid_max", O_RDONLY);
-  if(fd==-1) goto out;
-  rc = read(fd, pidbuf, sizeof pidbuf);
-  close(fd);
-  if(rc<3) goto out;
-  pidbuf[rc] = '\0';
-  rc = strtol(pidbuf,&endp,10);
-  if(rc<42) goto out;
-  if(*endp && *endp!='\n') goto out;
-  rc--;  // the pid_max value is really the max PID plus 1
-  ret = 0;
-  while(rc){
-    rc /= 10;
-    ret++;
-  }
-out:
-  return ret;
+/*
+ * procps_pid_length
+ *
+ * Return the length of the maximum possible pid.
+ *
+ * Returns either the strlen of PROCFS_PID_MAX or the
+ * best-guess DEFAULT_PID_LENGTH
+ */
+PROCPS_EXPORT unsigned int procps_pid_length(void)
+{
+    FILE *fp;
+    char pidbuf[24];
+    char *endp;
+    unsigned long int max_pid;
+    static int pid_length=0;
+
+    if (pid_length)
+        return pid_length;
+
+    pid_length = DEFAULT_PID_LENGTH;
+    if ((fp = fopen(PROCFS_PID_MAX, "r")) != NULL) {
+        if (fgets(buf, 24, fp) != NULL) {
+            pid_length = strlen(buf);
+        }
+        fclose(fp);
+    }
+    return pid_length;
 }
 
 ///////////////////////////////////////////////////////////////////////////
index dbb8bef932602d3acabc5c8311932f1f1ac68d36..7573068641f435197d968768bcb09b6a456f5c01 100644 (file)
@@ -2,8 +2,8 @@
 #define PROC_SYSINFO_H
 #include <sys/types.h>
 #include <dirent.h>
-#include <proc/procps.h>
 
+#include <features.h>
 __BEGIN_DECLS
 
 extern int have_privs;             /* boolean, true if setuid or similar */
@@ -11,6 +11,7 @@ extern int have_privs;             /* boolean, true if setuid or similar */
 long procps_cpu_count(void);
 long procps_hertz_get(void);
 int procps_loadavg(double *av1, double *av5, double *av15);
+unsigned int procps_pid_length(void);
 
 #define BUFFSIZE (64*1024)
 typedef unsigned long long jiff;
@@ -25,7 +26,6 @@ typedef struct slab_cache{
 
 extern unsigned int getslabinfo (struct slab_cache**);
 
-extern unsigned get_pid_digits(void) FUNCTION;
 
 __END_DECLS
 #endif /* SYSINFO_H */
index 6175937a87c2e7ebe6ccb6de3f6ab1f28716b6d1..8d00854d8b02e70920c6ad9392245b599466ca65 100644 (file)
@@ -25,8 +25,7 @@
 #ifndef PROC_UPTIME_H
 #define PROC_UPTIME_H
 
-#include <proc/procps.h>
-
+#include <features.h>
 __BEGIN_DECLS
 
 int procps_uptime(double *uptime_secs, double *idle_secs);
index 0b63b0313ac3c9ce544156be7c7b5fe04f0eb10b..ba86250babd9d10d25c29fd5235d78d750dc0b60 100644 (file)
@@ -23,8 +23,7 @@
 #ifndef PROC_VERSION_H
 #define PROC_VERSION_H
 
-#include <proc/procps.h>
-
+#include <features.h>
 __BEGIN_DECLS
 
 int procps_linux_version(void);
index 1179aa3bb88adf8b1ff7b99a00840e09b9e09e18..9a0fa549c39b87f3edf8537c23ce2c6e3665c274 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef PROC_VMSTAT_H
 #define PROC_VMSTAT_H
 
-#include <proc/procps.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
index fd5d29e7ac386102928b86db9843afd8aa19b710..5a54862b5ced55b3ce4e8e20a9b76fb1a10993a3 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef PROCPS_PROC_WCHAN_H
 #define PROCPS_PROC_WCHAN_H
 
-#include <proc/procps.h>
+#include <features.h>
 
 __BEGIN_DECLS
 
index 8a9eb0c5ae98edc090183f6544a5a92a97771c03..fc1b160c186a7d5bf1d50b4dae23ac63f8780312 100644 (file)
 #define PROCPS_PS_H
 
 #include "../include/nls.h"
-#include "../proc/escape.h"
+#include <proc/procps.h>
 
 // --- <pids> interface begin ||||||||||||||||||||||||||||||||||||||||||||
 // -----------------------------------------------------------------------
-#include <proc/pids.h>
 
 // hack to minimize code impact
 #undef  proc_t
index 43e67ce20eb6ed7474f7a924f73d5ffd14133ba0..448d61f6e3319bba70b64a40c7827e9843d4efb5 100644 (file)
@@ -28,9 +28,6 @@
 #include <sys/sysmacros.h>
 #include <sys/types.h>
 
-#include <proc/pids.h>
-#include "../proc/sysinfo.h"
-
 #include "../include/c.h"
 #include "../include/fileutils.h"
 #include "../include/signals.h"
index 4f45bcf96f5cc7fa4c5badc0f2ae8cc5ea4f84ff..21c4e419de71f5b97152fdf571d50a25eaeb879b 100644 (file)
@@ -31,8 +31,6 @@
 #include <sys/sysmacros.h>
 #include <sys/types.h>
 
-#include <proc/uptime.h>
-
 #include "../include/c.h"
 #include "../include/xalloc.h"
 
@@ -614,8 +612,8 @@ void self_info(void){
   );
 
   fprintf(stderr,
-    "sizeof(proc_t)=%d sizeof(long)=%d sizeof(KLONG)=%d\n",
-    (int)sizeof(proc_t), (int)sizeof(long), (int)sizeof(KLONG)
+    "sizeof(proc_t)=%d sizeof(long)=%d sizeof(long)=%d\n",
+    (int)sizeof(proc_t), (int)sizeof(long), (int)sizeof(long)
   );
 
   fprintf(stderr, "archdefs:%s\n", archdefs);
index 4c3e9966610ce70db32e80599bd9655b9a4c947c..e283c2cb22bbcbbfc4e8c5deded4e752bf729efa 100644 (file)
--- a/ps/help.c
+++ b/ps/help.c
@@ -86,7 +86,7 @@ static int parse_help_opt (const char *opt) {
 }
 
 
-void do_help (const char *opt, int rc) NORETURN;
+void do_help (const char *opt, int rc);
 void do_help (const char *opt, int rc) {
   FILE *out = (rc == EXIT_SUCCESS) ? stdout : stderr;
   int section = parse_help_opt(opt);
index 0d637d676db66e1caa916397d8d8d2fab6d4c426..b31ce6b512e4c86f960dad143808215827e0688c 100644 (file)
 #include <sys/resource.h>
 #include <sys/types.h>
 
-#include <proc/meminfo.h>
-#include <proc/readstat.h>
 
 #include "../include/c.h"
-#include "../proc/escape.h"
 
 #include "common.h"
 
@@ -1896,7 +1893,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
   char *restrict const outbuf = saved_outbuf;
   static int did_stuff = 0;  /* have we ever printed anything? */
 
-  if(unlikely(-1==(long)p)){    /* true only once, at the end */
+  if(-1==(long)p){    /* true only once, at the end */
     if(did_stuff) return;
     /* have _never_ printed anything, but might need a header */
     if(!--lines_to_next_header){
@@ -1906,14 +1903,14 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
     /* fprintf(stderr, "No processes available.\n"); */  /* legal? */
     exit(1);
   }
-  if(likely(p)){  /* not header, maybe we should call ourselves for it */
-    if(unlikely(!--lines_to_next_header)){
+  if(p){  /* not header, maybe we should call ourselves for it */
+    if(!--lines_to_next_header){
       lines_to_next_header = header_gap;
       show_one_proc(NULL,fmt);
     }
   }
   did_stuff = 1;
-  if(unlikely(active_cols>(int)OUTBUF_SIZE)) fprintf(stderr,_("fix bigness error\n"));
+  if(active_cols>(int)OUTBUF_SIZE) fprintf(stderr,_("fix bigness error\n"));
 
   /* print row start sequence */
   for(;;){
@@ -1922,7 +1919,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
 //    if(likely(fmt->next)) max_rightward = fmt->width;
 //    else max_rightward = active_cols-((correct>actual) ? correct : actual);
 
-    if(likely(fmt->next)){
+    if(fmt->next){
       max_rightward = fmt->width;
       tmpspace = 0;
     }else{
@@ -1940,7 +1937,7 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
 //                 active_cols, max_rightward, max_leftward, actual, correct);
 
     /* prepare data and calculate leftpad */
-    if(likely(p) && likely(fmt->pr)) amount = (*fmt->pr)(outbuf,p);
+    if(p && fmt->pr) amount = (*fmt->pr)(outbuf,p);
     else amount = strlen(strcpy(outbuf, fmt->name)); /* AIX or headers */
 
     switch((fmt->flags) & CF_JUST_MASK){
@@ -2003,13 +2000,13 @@ void show_one_proc(const proc_t *restrict const p, const format_node *restrict f
      */
     space = correct - actual + leftpad;
     if(space<1) space=dospace;
-    if(unlikely(space>SPACE_AMOUNT)) space=SPACE_AMOUNT;  // only so much available
+    if(space>SPACE_AMOUNT) space=SPACE_AMOUNT;  // only so much available
 
     /* real size -- don't forget in 'amount' is number of cells */
     sz = strlen(outbuf);
 
     /* print data, set x position stuff */
-    if(unlikely(!fmt->next)){
+    if(!fmt->next){
       /* Last column. Write padding + data + newline all together. */
       outbuf[sz] = '\n';
       fwrite(outbuf-space, space+sz+1, 1, stdout);
index bab6014aab8e42080aaffaff16bd5ee41ca718a3..ba6cbf37b9aa401dbca04b2109958fa1092554e3 100644 (file)
@@ -47,7 +47,7 @@ static format_node *do_one_spec(const char *spec, const char *override){
     format_node *thisnode;
     thisnode = xmalloc(sizeof(format_node));
     if(fs->flags & CF_PIDMAX){
-      w1 = (int)get_pid_digits();
+      w1 = (int)procps_pid_length();
       w2 = strlen(fs->head);
       if(w2>w1) w1=w2; // FIXME w/ separate header/body column sizing
     }else{
diff --git a/skill.c b/skill.c
index dbd4600d307f7e59a7e405cba2b58ecdd6210bb0..7becbd0de1c014afb1adf1d7e2cbe081a8bb6a75 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -34,8 +34,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <proc/namespace.h>
-#include <proc/pids.h>
+#include <proc/procps.h>
 
 #include "c.h"
 #include "fileutils.h"
index 0d48288b57a91883ffb753bdf817eefff2c90d6f..e3bc3ad05052e41a5a955961515950022046e0eb 100644 (file)
--- a/slabtop.c
+++ b/slabtop.c
@@ -42,7 +42,7 @@
 #include "fileutils.h"
 #include "nls.h"
 #include "strutils.h"
-#include <proc/slab.h>
+#include <proc/procps.h>
 
 #define DEFAULT_SORT  PROCPS_SLABNODE_OBJS
 #define CHAINS_ALLOC  150
diff --git a/tload.c b/tload.c
index a1fc03ffb6ef34c5173a98e224e7748f588d86e9..8b9fab33f37ca09f4d2b4e4416b4a8f9ef3baa52 100644 (file)
--- a/tload.c
+++ b/tload.c
@@ -24,7 +24,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <proc/sysinfo.h>
+#include <proc/procps.h>
 #include "c.h"
 #include "fileutils.h"
 #include "nls.h"
index 98615beab3e541c76dec40d9d740644c6d6cd151..c857f87ea9384c7aa2a658833de647724cf92e0e 100644 (file)
--- a/top/top.c
+++ b/top/top.c
 #include "../include/signals.h"
 #include "../include/nls.h"
 
-#include <proc/meminfo.h>
-#include <proc/pids.h>
-#include <proc/readstat.h>
-#include <proc/sysinfo.h>
-#include <proc/version.h>
-#include <proc/uptime.h>
+#include <proc/procps.h>
 
 #include "top.h"
 #include "top_nls.h"
 
+#define NORETURN __attribute__((__noreturn__))
 
 /*######  Miscellaneous global stuff  ####################################*/
 
@@ -744,6 +740,7 @@ static void updt_scroll_msg (void) {
         /*
          * Handle our own memory stuff without the risk of leaving the
          * user's terminal in an ugly state should things go sour. */
+#define MALLOC __attribute__ ((__malloc__))
 
 static void *alloc_c (size_t num) MALLOC;
 static void *alloc_c (size_t num) {
@@ -1174,14 +1171,14 @@ static int get_int (const char *prompt) {
 
         /*
          * Make a hex value, and maybe suppress zeroes. */
-static inline const char *hex_make (KLONG num, int noz) {
+static inline const char *hex_make (long num, int noz) {
    static char buf[SMLBUFSIZ];
    int i;
 
 #ifdef CASEUP_HEXES
-   snprintf(buf, sizeof(buf), "%08" KLF "X", num);
+   snprintf(buf, sizeof(buf), "%08lX", num);
 #else
-   snprintf(buf, sizeof(buf), "%08" KLF "x", num);
+   snprintf(buf, sizeof(buf), "%08lx", num);
 #endif
    if (noz)
       for (i = 0; buf[i]; i++)
@@ -2097,7 +2094,7 @@ static void zap_fieldstab (void) {
       Fieldstab[EU_PID].width = Fieldstab[EU_PPD].width
          = Fieldstab[EU_PGD].width = Fieldstab[EU_SID].width
          = Fieldstab[EU_TGD].width = Fieldstab[EU_TPG].width = 5;
-      if (5 < (digits = get_pid_digits())) {
+      if (5 < (digits = procps_pid_length())) {
          if (10 < digits) error_exit(N_txt(FAIL_widepid_txt));
          Fieldstab[EU_PID].width = Fieldstab[EU_PPD].width
             = Fieldstab[EU_PGD].width = Fieldstab[EU_SID].width
index 64ff6ac4fc0570e47bf6977debc7fdcaf726ae75..be3d01a9d2a8f37dda1b9dedabef894ae8090f41 100644 (file)
--- a/uptime.c
+++ b/uptime.c
@@ -27,9 +27,7 @@
 #include "c.h"
 #include "fileutils.h"
 #include "nls.h"
-#include "proc/sysinfo.h"
-#include <proc/uptime.h>
-#include "proc/version.h"
+#include <proc/procps.h>
 
 static void print_uptime_since()
 {
index f53eaac940378c7319c6392358c8998de7ccac2a..85c28a25f608613d4f323eb35fd86d45c1b43526 100644 (file)
--- a/vmstat.c
+++ b/vmstat.c
 #include "fileutils.h"
 #include "nls.h"
 #include "strutils.h"
-#include "proc/sysinfo.h"
-#include <proc/vmstat.h>
-#include <proc/readstat.h>
-#include <proc/meminfo.h>
-#include <proc/diskstat.h>
-#include <proc/slab.h>
+#include <proc/procps.h>
 
 #define UNIT_B        1
 #define UNIT_k        1000
diff --git a/w.c b/w.c
index ec7995b1f814cb38d40c2609973d017a3c32ec26..934e5e730a0662e542f02e9932900f6c24858af8 100644 (file)
--- a/w.c
+++ b/w.c
@@ -26,9 +26,7 @@
 #include "c.h"
 #include "fileutils.h"
 #include "nls.h"
-#include <proc/sysinfo.h>
-#include <proc/uptime.h>
-#include <proc/pids.h>
+#include <proc/procps.h>
 
 #include <ctype.h>
 #include <errno.h>
@@ -652,7 +650,7 @@ int main(int argc, char **argv)
        if (user) {
                for (;;) {
                        u = getutent();
-                       if (unlikely(!u))
+                       if (!u)
                                break;
                        if (u->ut_type != USER_PROCESS)
                                continue;
@@ -663,7 +661,7 @@ int main(int argc, char **argv)
        } else {
                for (;;) {
                        u = getutent();
-                       if (unlikely(!u))
+                       if (!u)
                                break;
                        if (u->ut_type != USER_PROCESS)
                                continue;