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
This commit is contained in:
parent
b7128a09ce
commit
01a55f006a
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -37,27 +37,26 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -12,13 +12,12 @@
|
||||
#define USERNAME_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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
|
||||
|
@ -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 */
|
||||
|
@ -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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user