summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkn <kn@openbsd.org>2019-10-06 15:08:54 +0000
committerkn <kn@openbsd.org>2019-10-06 15:08:54 +0000
commit6f80dee34160eb9cbf4fc7dba3ec90d3886b9839 (patch)
treea01b2564f74ee202c1b2d04faf8cd3354176c710
parentZap intermediate structs in compare_*() (diff)
downloadwireguard-openbsd-6f80dee34160eb9cbf4fc7dba3ec90d3886b9839.tar.xz
wireguard-openbsd-6f80dee34160eb9cbf4fc7dba3ec90d3886b9839.zip
Avoid gasting around get_process_info()
get_process_info() returns a pointer to the global handle later only be used in format_next_process(); treat this struct handle as such without casting the pointer to caddr_t and back again. No object change. OK millert deraadt
-rw-r--r--usr.bin/top/machine.c14
-rw-r--r--usr.bin/top/machine.h9
-rw-r--r--usr.bin/top/top.c4
3 files changed, 13 insertions, 14 deletions
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 83fe21b51f7..af0e006e772 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.c,v 1.98 2019/10/06 15:05:35 kn Exp $ */
+/* $OpenBSD: machine.c,v 1.99 2019/10/06 15:08:54 kn Exp $ */
/*-
* Copyright (c) 1994 Thorsten Lockert <tholo@sigmasoft.com>
@@ -422,7 +422,7 @@ cmd_matches(struct kinfo_proc *proc, char *term)
return 0;
}
-caddr_t
+struct handle *
get_process_info(struct system_info *si, struct process_select *sel,
int (*compare) (const void *, const void *))
{
@@ -501,7 +501,7 @@ get_process_info(struct system_info *si, struct process_select *sel,
/* pass back a handle */
handle.next_proc = pref;
handle.remaining = active_procs;
- return ((caddr_t) & handle);
+ return &handle;
}
char fmt[MAX_COLS]; /* static area where result is built */
@@ -546,20 +546,18 @@ format_comm(struct kinfo_proc *kp)
}
char *
-format_next_process(caddr_t hndl, const char *(*get_userid)(uid_t, int),
+format_next_process(struct handle *hndl, const char *(*get_userid)(uid_t, int),
pid_t *pid, int show_threads)
{
char *p_wait;
struct kinfo_proc *pp;
- struct handle *hp;
int cputime;
double pct;
char buf[16];
/* find and remember the next proc structure */
- hp = (struct handle *) hndl;
- pp = *(hp->next_proc++);
- hp->remaining--;
+ pp = *(hndl->next_proc++);
+ hndl->remaining--;
cputime = pp->p_rtime_sec + ((pp->p_rtime_usec + 500000) / 1000000);
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index df683780745..a10192e4089 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: machine.h,v 1.25 2018/11/17 23:10:08 cheloha Exp $ */
+/* $OpenBSD: machine.h,v 1.26 2019/10/06 15:08:54 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -87,10 +87,11 @@ extern int display_init(struct statics *);
extern int machine_init(struct statics *);
extern char *format_header(char *, int);
extern void get_system_info(struct system_info *);
-extern caddr_t
-get_process_info(struct system_info *, struct process_select *,
+extern struct handle
+*get_process_info(struct system_info *, struct process_select *,
int (*) (const void *, const void *));
-extern char *format_next_process(caddr_t, const char *(*)(uid_t, int), pid_t *, int);
+extern char *format_next_process(struct handle *,
+ const char *(*)(uid_t, int), pid_t *, int);
extern uid_t proc_owner(pid_t);
extern struct kinfo_proc *getprocs(int, int, int *);
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 87b7eaace58..e1d10f2edd4 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: top.c,v 1.98 2018/11/28 22:00:30 kn Exp $ */
+/* $OpenBSD: top.c,v 1.99 2019/10/06 15:08:54 kn Exp $ */
/*
* Top users/processes display for Unix
@@ -336,7 +336,7 @@ main(int argc, char *argv[])
int preset_argc = 0, ac = argc, active_procs, i, ncpuonline_now;
sigset_t mask, oldmask;
time_t curr_time;
- caddr_t processes;
+ struct handle *processes;
/* set the buffer for stdout */
#ifdef DEBUG