\***********************************************************************/
#include <stdlib.h>
#include <stdio.h>
-#include "procps.h"
+#include "alloc.h"
void *xcalloc(void *pointer, int size) {
void * ret;
--- /dev/null
+#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
+#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/ */
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
* 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>
#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) {
*/
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) {
--- /dev/null
+#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
#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
#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
--- /dev/null
+#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
#endif
#include "version.h"
#include "readproc.h"
+#include "alloc.h"
+#include "pwcache.h"
#include "devname.h"
#include "procps.h"
#include <stdio.h>
#include <fs_secure.h>
#endif
+EXTERN_C_BEGIN
+
/*
ld cutime, cstime, priority, nice, timeout, it_real_value, rss,
c state,
#define PROC_SPARE_3 0x04000000
#define PROC_SPARE_4 0x08000000
+EXTERN_C_END
#endif
+#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
#include "procps.h"
+EXTERN_C_BEGIN
+
/* return -1 on failure */
extern int signal_name_to_number(const char *restrict name);
extern void pretty_print_signals(void);
extern void unix_print_signals(void);
+
+EXTERN_C_END
+#endif
-#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
-#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 */
extern void vminfo(void);
+EXTERN_C_END
#endif /* SYSINFO_H */
#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
* 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 */
#define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
#define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
+EXTERN_C_END
+
#endif /* PROC_VERSION_H */
--- /dev/null
+#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
-/* 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
#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"
#include "common.h"
#include <sys/sysmacros.h>
+#include "../proc/wchan.h"
#include "../proc/version.h"
#include "../proc/sysinfo.h"
#include "../proc/readproc.h"
#include "../proc/sysinfo.h"
+#include "../proc/wchan.h"
#include "../proc/procps.h"
#include "../proc/devname.h"
#include "common.h"
#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) */
#include <values.h>
#include "proc/devname.h"
+#include "proc/wchan.h"
#include "proc/procps.h"
#include "proc/readproc.h"
#include "proc/sig.h"
#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>
*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;
}
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
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();