]> granicus.if.org Git - procps-ng/commitdiff
big header clean-up
authoralbert <>
Mon, 9 Dec 2002 07:00:07 +0000 (07:00 +0000)
committeralbert <>
Mon, 9 Dec 2002 07:00:07 +0000 (07:00 +0000)
23 files changed:
proc/alloc.c
proc/alloc.h [new file with mode: 0644]
proc/devname.h
proc/ksym.c
proc/output.c
proc/output.h [new file with mode: 0644]
proc/procps.h
proc/pwcache.c
proc/pwcache.h [new file with mode: 0644]
proc/readproc.c
proc/readproc.h
proc/sig.h
proc/status.h
proc/sysinfo.h
proc/version.h
proc/wchan.h [new file with mode: 0644]
proc/whattime.h
ps/display.c
ps/global.c
ps/output.c
skill.c
top.c
w.c

index 0868c68a6ee562726c1f00cdd9bb3901ad7645c7..a4ed1b196bfbedc115aabc534a4dbe61984a26fd 100644 (file)
@@ -7,7 +7,7 @@
 \***********************************************************************/
 #include <stdlib.h>
 #include <stdio.h>
-#include "procps.h"
+#include "alloc.h"
 
 void *xcalloc(void *pointer, int size) {
     void * ret;
diff --git a/proc/alloc.h b/proc/alloc.h
new file mode 100644 (file)
index 0000000..8c5016d
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef PROCPS_PROC_ALLOC_H
+#define PROCPS_PROC_ALLOC_H
+
+#include "procps.h"
+
+EXTERN_C_BEGIN
+
+extern void *xrealloc(void *oldp, unsigned int size) MALLOC;
+extern void *xmalloc(unsigned int size) MALLOC;
+extern void *xcalloc(void *pointer, int size) MALLOC;
+
+EXTERN_C_END
+
+#endif
index 60b8e75aab7d7ec0acd86c073c2cc55b03be85bb..b04bd9052e636e26508a57c0e4c278465ffab5d7 100644 (file)
@@ -1,5 +1,10 @@
+#ifndef PROC_DEVNAME_H
+#define PROC_DEVNAME_H
+
 #include "procps.h"
 
+EXTERN_C_BEGIN
+
 #define ABBREV_DEV  1     /* remove /dev/         */
 #define ABBREV_TTY  2     /* remove tty           */
 #define ABBREV_PTS  4     /* remove pts/          */
@@ -7,3 +12,6 @@
 extern unsigned dev_to_tty(char *restrict ret, unsigned chop, int dev, int pid, unsigned int flags);
 
 extern int tty_to_dev(const char *restrict const name);
+
+EXTERN_C_END
+#endif
index f572becc25d52e5651d57ad77fc904c59b5ef840..f2eea82ec1e4c6367a2cf9037ac6a3d71030dd66 100644 (file)
@@ -8,6 +8,7 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU Library General Public License for more details.
  */
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
index 4ea73cf614bba90ca1f4e30e1e13de76d52edc31..3863dc2560ebcecc5b9f9a9a7e6dbad5c5abac58 100644 (file)
@@ -5,16 +5,16 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
-#include "procps.h"
+#include "output.h"
 
-#if 0
+#if 1
 /* output a string, converting unprintables to octal as we go, and stopping after
    processing max chars of output (accounting for expansion due to octal rep).
 */
 unsigned print_str(FILE *restrict file, const char *restrict const s, unsigned max) {
     unsigned i;
-    for (i=0; s[i] && i < max; i++)
-       if (isprint(s[i]) || s[i] == ' ')
+    for (i=0; likely(s[i]) && likely(i<max); i++)
+       if (likely(isprint(s[i]) || s[i] == ' '))
            fputc(s[i], file);
        else {
            if (max > i+3) {
@@ -33,9 +33,9 @@ unsigned print_str(FILE *restrict file, const char *restrict const s, unsigned m
 */
 unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max) {
     unsigned i, n;
-    for (n=0; *strs && n < max; strs++) {
+    for (n=0; *strs && n<max; strs++) {
        for (i=0; strs[0][i] && n+i < max; i++)
-           if (isprint(strs[0][i]) || strs[0][i] == ' ')
+           if (likely(isprint(strs[0][i]) || strs[0][i] == ' '))
                fputc(strs[0][i], file);
            else {
                if (max > n+i+3) {
diff --git a/proc/output.h b/proc/output.h
new file mode 100644 (file)
index 0000000..a2a0541
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef PROCPS_PROC_OUTPUT_H
+#define PROCPS_PROC_OUTPUT_H
+
+#include <stdio.h>
+#include <sys/types.h>
+#include "procps.h"
+
+EXTERN_C_BEGIN
+
+extern unsigned print_str    (FILE *restrict file, const char *restrict s, unsigned max);
+extern unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max);
+
+EXTERN_C_END
+
+#endif
index 76cc707a695355ece97ec6de61eba38cc24dea77..44aab672692c98c17f9bffa47316531115f8114f 100644 (file)
@@ -1,16 +1,13 @@
 #ifndef PROCPS_PROC_PROCPS_H
 #define PROCPS_PROC_PROCPS_H
 
-/* The shadow of the original with only common prototypes now. */
-#include <stdio.h>
-#include <sys/types.h>
-
-/* The HZ constant from <asm/param.h> is replaced by the Hertz variable
- * available from "proc/sysinfo.h".
- */
-
-/* get page info */
-#include <asm/page.h>
+#ifdef  __cplusplus
+#define EXTERN_C_BEGIN extern "C" {
+#define EXTERN_C_END }
+#else
+#define EXTERN_C_BEGIN
+#define EXTERN_C_END
+#endif
 
 #if !defined(restrict) && __STDC_VERSION__ < 199901
 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 91    // maybe 92 or 95 ?
 // 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 likely(x)       (x)
 #define unlikely(x)     (x)
+#define expected(x,y)   (x)
 #endif
 
-
-extern void *xrealloc(void *oldp, unsigned int size) MALLOC;
-extern void *xmalloc(unsigned int size) MALLOC;
-extern void *xcalloc(void *pointer, int size) MALLOC;
-       
-extern int   mult_lvl_cmp(void* a, void* b);
-       
-extern char *user_from_uid(uid_t uid);
-extern char *group_from_gid(gid_t gid);
-
-extern const char * wchan(unsigned long address);
-extern int   open_psdb(const char *restrict override);
-extern int   open_psdb_message(const char *restrict override, void (*message)(const char *, ...));
-
-extern unsigned print_str    (FILE *restrict file, const char *restrict s, unsigned max);
-extern unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max);
-
 #endif
index c8bb18c955a33672b368a230e867eb3c26d685db..51dd2d20acc2d88cfd8b5cfb5d6051cf53c0f76b 100644 (file)
 #include <sys/types.h>
 #include <stdlib.h>
 #include <pwd.h>
-#include "procps.h"
+#include "alloc.h"
+#include "pwcache.h"
 #include <grp.h>
 
 // might as well fill cache lines... else we waste memory anyway
 
-#define        HASHSIZE        32                      /* power of 2 */
+#define        HASHSIZE        64              /* power of 2 */
 #define        HASH(x)         ((x) & (HASHSIZE - 1))
 
 #define NAMESIZE       20
diff --git a/proc/pwcache.h b/proc/pwcache.h
new file mode 100644 (file)
index 0000000..244ce6d
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef PROCPS_PROC_PWCACHE_H
+#define PROCPS_PROC_PWCACHE_H
+
+#include <sys/types.h>
+#include "procps.h"
+
+EXTERN_C_BEGIN
+
+extern char *user_from_uid(uid_t uid);
+extern char *group_from_gid(gid_t gid);
+
+EXTERN_C_END
+
+#endif
index 4cd0627cb509e41025bd15b651f56f56372f1293..132462f95ca25923bc4c49301c10d86fc771578b 100644 (file)
@@ -10,6 +10,8 @@
 #endif
 #include "version.h"
 #include "readproc.h"
+#include "alloc.h"
+#include "pwcache.h"
 #include "devname.h"
 #include "procps.h"
 #include <stdio.h>
index 2b0947f573bffd63f7d1ae09caa94e93c9df2e81..4bb24bd5d9788fdef4f8dd72af677c0a5d122094 100644 (file)
@@ -17,6 +17,8 @@
 #include <fs_secure.h>
 #endif
 
+EXTERN_C_BEGIN
+
 /*
  ld    cutime, cstime, priority, nice, timeout, it_real_value, rss,
  c     state,
@@ -221,4 +223,5 @@ extern void freeproc(proc_t* p);
 #define PROC_SPARE_3 0x04000000
 #define PROC_SPARE_4 0x08000000
 
+EXTERN_C_END
 #endif
index 9640f9891085afa8b6206078e0db64f3cb424fdb..9e8e07b18aa9282ce535916bd9a200f09b9f37e8 100644 (file)
@@ -1,3 +1,5 @@
+#ifndef PROC_SIG_H
+#define PROC_SIG_H
 /*
  * Copyright 1998 by Albert Cahalan; all rights resered.
  * This file may be used subject to the terms and conditions of the
@@ -11,6 +13,8 @@
 
 #include "procps.h"
 
+EXTERN_C_BEGIN
+
 /* return -1 on failure */
 extern int signal_name_to_number(const char *restrict name);
 
@@ -19,3 +23,6 @@ extern int print_given_signals(int argc, const char *restrict const *restrict ar
 extern void pretty_print_signals(void);
 
 extern void unix_print_signals(void);
+
+EXTERN_C_END
+#endif
index 8eefe790bc4ba98d6da133e6e5d999e8ca5e243e..f1e141f03efb49c3db2b353318a0a9474a09e9a4 100644 (file)
@@ -1,4 +1,12 @@
-#ifndef __PROC_STATUS_H
-#define __PROC_STATUS_H
+#ifndef PROC_STATUS_H
+#define PROC_STATUS_H
+
+#include "procps.h"
+
+EXTERN_C_BEGIN
+
 extern const char * status(const proc_t *restrict task);
+
+EXTERN_C_END
+
 #endif
index 7c81954b77cee0af31f3d73b83a7f9c77f3584f1..70f681afca68b4da379139417467f006f7406f75 100644 (file)
@@ -1,8 +1,10 @@
-#ifndef SYSINFO_H
-#define SYSINFO_H
+#ifndef PROC_SYSINFO_H
+#define PROC_SYSINFO_H
 
 #include "procps.h"
 
+EXTERN_C_BEGIN
+
 extern unsigned long long Hertz;   /* clock tick frequency */
 extern long smp_num_cpus;     /* number of CPUs */
 
@@ -77,4 +79,5 @@ extern unsigned vm_allocstall;
 
 extern void vminfo(void);
 
+EXTERN_C_END
 #endif /* SYSINFO_H */
index 6a93d8938008fda150f609733703d1d104d6d979..15fa96f7a1ebdcd634e1563a258268eea991441f 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef PROC_VERSION_H
 #define PROC_VERSION_H
 
+#include "procps.h"
+
 /* Suite version information for procps utilities
  * Copyright (c) 1995 Martin Schulze <joey@infodrom.north.de>
  * Linux kernel version information for procps utilities
@@ -8,6 +10,8 @@
  * Distributable under the terms of the GNU Library General Public License
  */
 
+EXTERN_C_BEGIN
+
 extern void display_version(void);     /* display suite version */
 extern const char procps_version[];            /* global buf for suite version */
 
@@ -20,4 +24,6 @@ extern int linux_version_code;                /* runtime version of LINUX_VERSION_CODE
 #define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
 #define LINUX_VERSION_PATCH(x) ( (x)      & 0xFF)
 
+EXTERN_C_END
+
 #endif /* PROC_VERSION_H */
diff --git a/proc/wchan.h b/proc/wchan.h
new file mode 100644 (file)
index 0000000..ad71b71
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef PROCPS_PROC_WCHAN_H
+#define PROCPS_PROC_WCHAN_H
+
+#include "procps.h"
+
+EXTERN_C_BEGIN
+
+extern const char * wchan(unsigned long address);
+extern int   open_psdb(const char *restrict override);
+extern int   open_psdb_message(const char *restrict override, void (*message)(const char *, ...));
+
+EXTERN_C_END
+
+#endif
index 3d37bfa27525813bbedcba335e106b39284fd8f0..891ccd35c89d436dbe50cffc3473a1c9cf74411a 100644 (file)
@@ -1,9 +1,13 @@
-/* whattime.h --- see whattime.c for explanation */
+#ifndef PROC_WHATTIME_H
+#define PROC_WHATTIME_H
 
-#ifndef __WHATTIME_H
-#define __WHATTIME_H
+#include "procps.h"
+
+EXTERN_C_BEGIN
 
 extern void print_uptime(void);
 extern char *sprint_uptime(void);
 
+EXTERN_C_END
+
 #endif
index 3ddd97e45d24a64b7fde62b8ad9825fefb8a0d36..704606b6a707dc9a9cce98db549c0065a8999380 100644 (file)
@@ -25,7 +25,7 @@
 #include <signal.h>   /* catch signals */
 
 #include "common.h"
-#include "../proc/procps.h"
+#include "../proc/wchan.h"
 #include "../proc/version.h"
 #include "../proc/readproc.h"
 #include "../proc/sysinfo.h"
index c23ec7327e87ecce8f81623a550428a42b77bb87..7330f04daa66a674f673c18b123f668d2ac85ee7 100644 (file)
@@ -20,6 +20,7 @@
 #include "common.h"
 
 #include <sys/sysmacros.h>
+#include "../proc/wchan.h"
 #include "../proc/version.h"
 #include "../proc/sysinfo.h"
 
index 7fb28cdb627745bf5bda2b97625163d8f794b924..16ae3770e3f3b62a5704c2d732426fae436f9b0b 100644 (file)
@@ -62,6 +62,7 @@
 
 #include "../proc/readproc.h"
 #include "../proc/sysinfo.h"
+#include "../proc/wchan.h"
 #include "../proc/procps.h"
 #include "../proc/devname.h"
 #include "common.h"
diff --git a/skill.c b/skill.c
index 6d6ed278800bbfe0537b184e73c3434caec5fabe..b58200bb3234c2b30abdef1107604fe83175a5b7 100644 (file)
--- a/skill.c
+++ b/skill.c
@@ -21,6 +21,7 @@
 #include <sys/time.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include "proc/pwcache.h"
 #include "proc/sig.h"
 #include "proc/devname.h"
 #include "proc/procps.h"  /* char *user_from_uid(uid_t uid) */
diff --git a/top.c b/top.c
index 4399376ae15474accd97a9eab16c8448f17c8a48..295db89ab45cf873d558cf03d3d54b79de63a46e 100644 (file)
--- a/top.c
+++ b/top.c
@@ -38,6 +38,7 @@
 #include <values.h>
 
 #include "proc/devname.h"
+#include "proc/wchan.h"
 #include "proc/procps.h"
 #include "proc/readproc.h"
 #include "proc/sig.h"
diff --git a/w.c b/w.c
index 2806993bc9bed2e82bf45c4f8c5140736bc5a4b9..f8d5b5117b8e2a605ff1afc1559faa4fe4be8516 100644 (file)
--- a/w.c
+++ b/w.c
@@ -8,6 +8,7 @@
 #include "proc/readproc.h"
 #include "proc/devname.h"
 #include "proc/procps.h"
+#include "proc/output.h"
 #include "proc/sysinfo.h"
 #include <ctype.h>
 #include <errno.h>
@@ -143,7 +144,7 @@ static const proc_t *getproc(const utmp_t *restrict const u, const char *restric
     *found_utpid = 0;
     for(; *pptr; pptr++) {
        const proc_t *restrict const tmp = *pptr;
-       if(tmp->pid == u->ut_pid) {
+       if(unlikely(tmp->pid == u->ut_pid)) {
            *found_utpid = 1;
            best = tmp;
        }
@@ -212,8 +213,8 @@ static void showinfo(utmp_t *u, int formtype, int maxcmd, int from) {
        else
            print_time_ival7(idletime(tty), 0, stdout);
     }
-    fputs("  ", stdout);
-    if (best) {
+    fputs(" ", stdout);
+    if (likely(best)) {
        if (best->cmdline)
            print_strlist(stdout, best->cmdline, maxcmd);
        else
@@ -276,17 +277,27 @@ int main(int argc, char **argv) {
        if (from)
            printf("FROM            ");
        if (longform)
-           printf("  LOGIN@   IDLE   JCPU   PCPU  WHAT\n");
+           printf("  LOGIN@   IDLE   JCPU   PCPU WHAT\n");
        else
-           printf("   IDLE  WHAT\n");
+           printf("   IDLE WHAT\n");
     }
 
     utmpname(UTMP_FILE);
     setutent();
-    while ((u=getutent())) {
-       if (u->ut_type == USER_PROCESS &&
-           (user ? !strncmp(u->ut_user, user, USERSZ) : *u->ut_user))
-           showinfo(u, longform, maxcmd, from);
+    if (user) {
+       for (;;) {
+           u = getutent();
+           if (unlikely(!u)) break;
+           if (u->ut_type != USER_PROCESS) continue;
+           if (!strncmp(u->ut_user, user, USERSZ)) showinfo(u, longform, maxcmd, from);
+       }
+    } else {
+       for (;;) {
+           u = getutent();
+           if (unlikely(!u)) break;
+           if (u->ut_type != USER_PROCESS) continue;
+           if (*u->ut_user) showinfo(u, longform, maxcmd, from);
+       }
     }
     endutent();