From 01a55f006af7a324eaa9f77e3f91c557a21100b3 Mon Sep 17 00:00:00 2001 From: Eitan Adler Date: Sun, 3 Jun 2018 05:20:11 +0000 Subject: [PATCH] top(1): partial revert of r334517 In fixing issues with uid > INT_MAX, I broke the uid without username case. The latter is more important so return the old state. Discussed with: allanjude --- usr.bin/top/machine.c | 2 +- usr.bin/top/machine.h | 2 +- usr.bin/top/top.c | 2 +- usr.bin/top/username.c | 13 ++++++------- usr.bin/top/username.h | 9 ++++----- usr.bin/top/utils.c | 4 ++-- usr.bin/top/utils.h | 2 +- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c index 8726ebc15045..a8243ee55fee 100644 --- a/usr.bin/top/machine.c +++ b/usr.bin/top/machine.c @@ -918,7 +918,7 @@ get_process_info(struct system_info *si, struct process_select *sel, static char fmt[512]; /* static area where result is built */ char * -format_next_process(caddr_t xhandle, char *(*get_userid)(uid_t), int flags) +format_next_process(caddr_t xhandle, char *(*get_userid)(int), int flags) { struct kinfo_proc *pp; const struct kinfo_proc *oldp; diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h index 26c467b6efef..d80592d437c9 100644 --- a/usr.bin/top/machine.h +++ b/usr.bin/top/machine.h @@ -76,7 +76,7 @@ struct process_select /* routines defined by the machine dependent module */ char *format_header(char *uname_field); -char *format_next_process(caddr_t handle, char *(*get_userid)(uid_t), +char *format_next_process(caddr_t handle, char *(*get_userid)(int), int flags); void toggle_pcpustats(void); void get_system_info(struct system_info *si); diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c index b4f9bec5d7ae..172bb9649550 100644 --- a/usr.bin/top/top.c +++ b/usr.bin/top/top.c @@ -206,7 +206,7 @@ main(int argc, char *argv[]) int displays = 0; /* indicates unspecified */ int sel_ret = 0; time_t curr_time; - char *(*get_userid)(uid_t) = username; + char *(*get_userid)(int) = username; char *uname_field = "USERNAME"; char *header_text; char *env_top; diff --git a/usr.bin/top/username.c b/usr.bin/top/username.c index c962751090ad..89db6f9c5b09 100644 --- a/usr.bin/top/username.c +++ b/usr.bin/top/username.c @@ -37,27 +37,26 @@ #include #include #include -#include #include "utils.h" #include "username.h" struct hash_el { - uid_t uid; + int uid; char name[MAXLOGNAME]; }; #define is_empty_hash(x) (hash_table[x].name[0] == 0) /* simple minded hashing function */ -#define hashit(i) (i % Table_size) +#define hashit(i) (abs(i) % Table_size) /* K&R requires that statically declared tables be initialized to zero. */ /* We depend on that for hash_table and YOUR compiler had BETTER do it! */ static struct hash_el hash_table[Table_size]; -char *username(uid_t uid) +char *username(int uid) { int hashindex; @@ -70,7 +69,7 @@ char *username(uid_t uid) return(hash_table[hashindex].name); } -uid_t userid(char username[]) +int userid(char username[]) { struct passwd *pwd; @@ -91,7 +90,7 @@ uid_t userid(char username[]) } /* wecare 1 = enter it always, 0 = nice to have */ -int enter_user(uid_t uid, char name[], bool wecare) +int enter_user(int uid, char name[], bool wecare) { int hashindex; @@ -122,7 +121,7 @@ int enter_user(uid_t uid, char name[], bool wecare) */ int -get_user(uid_t uid) +get_user(int uid) { struct passwd *pwd; diff --git a/usr.bin/top/username.h b/usr.bin/top/username.h index 2975a9ee9480..b06a227890fc 100644 --- a/usr.bin/top/username.h +++ b/usr.bin/top/username.h @@ -12,13 +12,12 @@ #define USERNAME_H #include -#include -int enter_user(uid_t uid, char *name, bool wecare); -int get_user(uid_t uid); +int enter_user(int uid, char *name, bool wecare); +int get_user(int uid); void init_hash(void); -char *username(uid_t uid); -uid_t userid(char *username); +char *username(int uid); +int userid(char *username); /* * "Table_size" defines the size of the hash tables used to map uid to diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c index 4f5ff1eae643..cdfe352c09c4 100644 --- a/usr.bin/top/utils.c +++ b/usr.bin/top/utils.c @@ -89,12 +89,12 @@ char *itoa(unsigned int val) } /* - * itoa7(val) - like itoa, except the number is right justified in a 7 + * (val) - like itoa, except the number is right justified in a 7 * character field. This code is a duplication of itoa instead of * a front end to a more general routine for efficiency. */ -char *itoa7(unsigned int val) +char *itoa7(int val) { char *ptr; static char buffer[16]; /* result is built here */ diff --git a/usr.bin/top/utils.h b/usr.bin/top/utils.h index 2125f82e901e..f904fcf34316 100644 --- a/usr.bin/top/utils.h +++ b/usr.bin/top/utils.h @@ -14,7 +14,7 @@ int atoiwi(const char *); char *itoa(unsigned int); -char *itoa7(unsigned int); +char *itoa7(int); int digits(int); char **argparse(char *, int *); long percentages(int, int *, long *, long *, long *);