better handling of long usernames

This commit is contained in:
albert 2004-07-20 23:31:12 +00:00
parent 5a8a11c88d
commit f1db79c042
7 changed files with 59 additions and 51 deletions

7
NEWS
View File

@ -1,3 +1,10 @@
procps-3.2.2 --> procps-3.2.3
avoid truncating long usernames
avoid warning about -lncurses when not linking (more)
new names for shared libraries (packagers: watch out!)
"make install" no longer rebuilds everything
procps-3.2.1 --> procps-3.2.2 procps-3.2.1 --> procps-3.2.2
new packager (downstream maintainer) guidelines in README new packager (downstream maintainer) guidelines in README

View File

@ -17,15 +17,13 @@
# numbers for future use, the ELF soname can be set equal to the # numbers for future use, the ELF soname can be set equal to the
# file name until some future date when a stable ABI is declared. # file name until some future date when a stable ABI is declared.
SHARED := 1
# for lib$(NAME).so and /usr/include/($NAME) and such # for lib$(NAME).so and /usr/include/($NAME) and such
NAME := proc NAME := proc
SHARED := 1
###########
LIBVERSION := $(VERSION).$(SUBVERSION).$(MINORVERSION) LIBVERSION := $(VERSION).$(SUBVERSION).$(MINORVERSION)
ABIVERSION := 1 ABIVERSION := 0
SOFILE := lib$(NAME)-$(LIBVERSION).so SOFILE := lib$(NAME)-$(LIBVERSION).so
ifneq ($(ABIVERSION),0) ifneq ($(ABIVERSION),0)
@ -74,7 +72,7 @@ DIRS += proc/
proc/$(ANAME): $(LIBOBJ) proc/$(ANAME): $(LIBOBJ)
$(AR) rcs $@ $^ $(AR) rcs $@ $^
proc/$(SONAME): proc/library.map #proc/$(SONAME): proc/library.map
proc/$(SONAME): $(LIBOBJ) proc/$(SONAME): $(LIBOBJ)
$(CC) -shared -Wl,-soname,$(SONAME) -Wl,--version-script=proc/library.map -o $@ $^ -lc $(CC) -shared -Wl,-soname,$(SONAME) -Wl,--version-script=proc/library.map -o $@ $^ -lc

View File

@ -20,19 +20,16 @@
#define HASHSIZE 64 /* power of 2 */ #define HASHSIZE 64 /* power of 2 */
#define HASH(x) ((x) & (HASHSIZE - 1)) #define HASH(x) ((x) & (HASHSIZE - 1))
#define NAMESIZE 20
#define NAMELENGTH "19"
static struct pwbuf { static struct pwbuf {
struct pwbuf *next; struct pwbuf *next;
uid_t uid; uid_t uid;
char name[NAMESIZE]; char name[P_G_SZ];
} *pwhash[HASHSIZE]; } *pwhash[HASHSIZE];
char *user_from_uid(uid_t uid) char *user_from_uid(uid_t uid) {
{
struct pwbuf **p; struct pwbuf **p;
struct passwd *pw; struct passwd *pw;
size_t len;
p = &pwhash[HASH(uid)]; p = &pwhash[HASH(uid)];
while (*p) { while (*p) {
@ -43,10 +40,11 @@ char *user_from_uid(uid_t uid)
*p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf)); *p = (struct pwbuf *) xmalloc(sizeof(struct pwbuf));
(*p)->uid = uid; (*p)->uid = uid;
pw = getpwuid(uid); pw = getpwuid(uid);
if (!pw) len = pw ? strlen(pw) : 0;
sprintf((*p)->name, "%d", uid); if (len >= P_G_SZ)
sprintf((*p)->name, "%u", uid);
else else
sprintf((*p)->name, "%-." NAMELENGTH "s", pw->pw_name); strcpy((*p)->name, pw->pw_name);
(*p)->next = NULL; (*p)->next = NULL;
return((*p)->name); return((*p)->name);
} }
@ -54,13 +52,13 @@ char *user_from_uid(uid_t uid)
static struct grpbuf { static struct grpbuf {
struct grpbuf *next; struct grpbuf *next;
gid_t gid; gid_t gid;
char name[NAMESIZE]; char name[P_G_SZ];
} *grphash[HASHSIZE]; } *grphash[HASHSIZE];
char *group_from_gid(gid_t gid) char *group_from_gid(gid_t gid) {
{
struct grpbuf **g; struct grpbuf **g;
struct group *gr; struct group *gr;
size_t len;
g = &grphash[HASH(gid)]; g = &grphash[HASH(gid)];
while (*g) { while (*g) {
@ -71,10 +69,11 @@ char *group_from_gid(gid_t gid)
*g = (struct grpbuf *) malloc(sizeof(struct grpbuf)); *g = (struct grpbuf *) malloc(sizeof(struct grpbuf));
(*g)->gid = gid; (*g)->gid = gid;
gr = getgrgid(gid); gr = getgrgid(gid);
if (!gr) len = gr ? strlen(gr) : 0;
sprintf((*g)->name, "%d", gid); if (len >= P_G_SZ)
sprintf((*g)->name, "%u", gid);
else else
sprintf((*g)->name, "%-." NAMELENGTH "s", gr->gr_name); strcpy((*g)->name, gr->gr_name);
(*g)->next = NULL; (*g)->next = NULL;
return((*g)->name); return((*g)->name);
} }

View File

@ -6,6 +6,9 @@
EXTERN_C_BEGIN EXTERN_C_BEGIN
// used in pwcache and in readproc to set size of username or groupname
#define P_G_SZ 20
extern char *user_from_uid(uid_t uid); extern char *user_from_uid(uid_t uid);
extern char *group_from_gid(gid_t gid); extern char *group_from_gid(gid_t gid);

View File

@ -523,21 +523,21 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
/* some number->text resolving which is time consuming */ /* some number->text resolving which is time consuming */
if (flags & PROC_FILLUSR){ if (flags & PROC_FILLUSR){
strncpy(p->euser, user_from_uid(p->euid), sizeof p->euser); memcpy(p->euser, user_from_uid(p->euid), sizeof p->euser);
if(flags & PROC_FILLSTATUS) { if(flags & PROC_FILLSTATUS) {
strncpy(p->ruser, user_from_uid(p->ruid), sizeof p->ruser); memcpy(p->ruser, user_from_uid(p->ruid), sizeof p->ruser);
strncpy(p->suser, user_from_uid(p->suid), sizeof p->suser); memcpy(p->suser, user_from_uid(p->suid), sizeof p->suser);
strncpy(p->fuser, user_from_uid(p->fuid), sizeof p->fuser); memcpy(p->fuser, user_from_uid(p->fuid), sizeof p->fuser);
} }
} }
/* some number->text resolving which is time consuming */ /* some number->text resolving which is time consuming */
if (flags & PROC_FILLGRP){ if (flags & PROC_FILLGRP){
strncpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup); memcpy(p->egroup, group_from_gid(p->egid), sizeof p->egroup);
if(flags & PROC_FILLSTATUS) { if(flags & PROC_FILLSTATUS) {
strncpy(p->rgroup, group_from_gid(p->rgid), sizeof p->rgroup); memcpy(p->rgroup, group_from_gid(p->rgid), sizeof p->rgroup);
strncpy(p->sgroup, group_from_gid(p->sgid), sizeof p->sgroup); memcpy(p->sgroup, group_from_gid(p->sgid), sizeof p->sgroup);
strncpy(p->fgroup, group_from_gid(p->fgid), sizeof p->fgroup); memcpy(p->fgroup, group_from_gid(p->fgid), sizeof p->fgroup);
} }
} }
@ -606,21 +606,21 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, const proc_t *restric
/* some number->text resolving which is time consuming */ /* some number->text resolving which is time consuming */
if (flags & PROC_FILLUSR){ if (flags & PROC_FILLUSR){
strncpy(t->euser, user_from_uid(t->euid), sizeof t->euser); memcpy(t->euser, user_from_uid(t->euid), sizeof t->euser);
if(flags & PROC_FILLSTATUS) { if(flags & PROC_FILLSTATUS) {
strncpy(t->ruser, user_from_uid(t->ruid), sizeof t->ruser); memcpy(t->ruser, user_from_uid(t->ruid), sizeof t->ruser);
strncpy(t->suser, user_from_uid(t->suid), sizeof t->suser); memcpy(t->suser, user_from_uid(t->suid), sizeof t->suser);
strncpy(t->fuser, user_from_uid(t->fuid), sizeof t->fuser); memcpy(t->fuser, user_from_uid(t->fuid), sizeof t->fuser);
} }
} }
/* some number->text resolving which is time consuming */ /* some number->text resolving which is time consuming */
if (flags & PROC_FILLGRP){ if (flags & PROC_FILLGRP){
strncpy(t->egroup, group_from_gid(t->egid), sizeof t->egroup); memcpy(t->egroup, group_from_gid(t->egid), sizeof t->egroup);
if(flags & PROC_FILLSTATUS) { if(flags & PROC_FILLSTATUS) {
strncpy(t->rgroup, group_from_gid(t->rgid), sizeof t->rgroup); memcpy(t->rgroup, group_from_gid(t->rgid), sizeof t->rgroup);
strncpy(t->sgroup, group_from_gid(t->sgid), sizeof t->sgroup); memcpy(t->sgroup, group_from_gid(t->sgid), sizeof t->sgroup);
strncpy(t->fgroup, group_from_gid(t->fgid), sizeof t->fgroup); memcpy(t->fgroup, group_from_gid(t->fgid), sizeof t->fgroup);
} }
} }

View File

@ -11,6 +11,7 @@
#include "procps.h" #include "procps.h"
#include "pwcache.h"
#define SIGNAL_STRING #define SIGNAL_STRING
@ -111,14 +112,14 @@ typedef struct proc_t {
**cmdline; // (special) command line string vector (/proc/#/cmdline) **cmdline; // (special) command line string vector (/proc/#/cmdline)
char char
// Be compatible: Digital allows 16 and NT allows 14 ??? // Be compatible: Digital allows 16 and NT allows 14 ???
euser[16], // stat(),status effective user name euser[P_G_SZ], // stat(),status effective user name
ruser[16], // status real user name ruser[P_G_SZ], // status real user name
suser[16], // status saved user name suser[P_G_SZ], // status saved user name
fuser[16], // status filesystem user name fuser[P_G_SZ], // status filesystem user name
rgroup[16], // status real group name rgroup[P_G_SZ], // status real group name
egroup[16], // status effective group name egroup[P_G_SZ], // status effective group name
sgroup[16], // status saved group name sgroup[P_G_SZ], // status saved group name
fgroup[16], // status filesystem group name fgroup[P_G_SZ], // status filesystem group name
cmd[16]; // stat,status basename of executable file in call to exec(2) cmd[16]; // stat,status basename of executable file in call to exec(2)
struct proc_t struct proc_t
*ring, // n/a thread group ring *ring, // n/a thread group ring

View File

@ -81,7 +81,7 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd)
dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV); dev_to_tty(dn_buf, 999, tty, pid, ABBREV_DEV);
if(i_flag){ if(i_flag){
char buf[8]; char buf[8];
fprintf(stderr, "%-8.8s %-8.8s %5d %-16.16s ? ", fprintf(stderr, "%-8s %-8s %5d %-16.16s ? ",
(char*)dn_buf,user_from_uid(uid),pid,cmd (char*)dn_buf,user_from_uid(uid),pid,cmd
); );
if(!fgets(buf,7,stdin)){ if(!fgets(buf,7,stdin)){
@ -95,7 +95,7 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd)
else failed=setpriority(PRIO_PROCESS,pid,sig_or_pri); else failed=setpriority(PRIO_PROCESS,pid,sig_or_pri);
saved_errno = errno; saved_errno = errno;
if(w_flag && failed){ if(w_flag && failed){
fprintf(stderr, "%-8.8s %-8.8s %5d %-16.16s ", fprintf(stderr, "%-8s %-8s %5d %-16.16s ",
(char*)dn_buf,user_from_uid(uid),pid,cmd (char*)dn_buf,user_from_uid(uid),pid,cmd
); );
errno = saved_errno; errno = saved_errno;
@ -104,7 +104,7 @@ static void hurt_proc(int tty, int uid, int pid, const char *restrict const cmd)
} }
if(i_flag) return; if(i_flag) return;
if(v_flag){ if(v_flag){
printf("%-8.8s %-8.8s %5d %-16.16s\n", printf("%-8s %-8s %5d %-16.16s\n",
(char*)dn_buf,user_from_uid(uid),pid,cmd (char*)dn_buf,user_from_uid(uid),pid,cmd
); );
return; return;