Index: pspax.c =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v retrieving revision 1.43 diff -u -b -B -r1.43 pspax.c --- pspax.c 30 Dec 2008 13:50:04 -0000 1.43 +++ pspax.c 25 Jan 2009 18:39:06 -0000 @@ -41,6 +41,23 @@ static uid_t show_uid = -1; static gid_t show_gid = -1; + +/* removed leading/trailing extraneous white space */ +static char *rmspace(char *s) +{ + register char *p; + /* find the start of trailing space and set it to \0 */ + for (p = s + strlen(s) - 1; (p >= s && isspace(*p)); --p); + if (p != s + strlen(s) - 1) + *(p + 1) = 0; + /* find the end of leading space and set p to it */ + for (p = s; (isspace(*p) && *p); ++p); + /* move the memory backward to overwrite leading space */ + if (p != s) + memmove(s, p, strlen(p)+1); + return s; +} + static FILE *proc_fopen(pid_t pid, const char *file) { char path[__PAX_UTILS_PATH_MAX]; @@ -185,6 +202,39 @@ return NULL; } +static char *get_proc_status_field(pid_t pid, const char *name, int field) { + char *buf, *p; + int i; + + p = buf = NULL; + + if ((buf = get_proc_status(pid, name)) == NULL) + return NULL; + for (i = 0; i < field; i++) { + buf = rmspace(buf); + if ((p = strchr(buf , '\t')) == NULL) + continue; + buf = p + 1; + buf = rmspace(buf); + while ((i == field) && (p = strrchr(buf , '\t')) != NULL) + *p = 0; + } + return buf; +} + +static char *get_pid_euid(pid_t pid) +{ + struct passwd *pwd = NULL; + char *euid; + static char buf[1024]; + if ((euid = get_proc_status_field(pid, "Uid", 3)) == NULL) + return NULL; + if ((pwd = getpwuid(atoi(euid))) == NULL) + return NULL; + snprintf(buf, sizeof(buf), "%s/%s", euid, pwd->pw_name); + return (char *) buf; +} + static char *get_pid_attr(pid_t pid) { FILE *fp; @@ -325,6 +375,7 @@ errno = 0; stat(de->d_name, &st); if ((errno != ENOENT) && (errno != EACCES)) { + char *enam; pid = (pid_t) atoi((char *) basename((char *) de->d_name)); if (find_name && pid) { char *str = get_proc_name(pid); @@ -346,8 +397,9 @@ goto next_pid; } - pwd = get_proc_passwd(pid); pax = get_proc_status(pid, "PAX"); + enam = get_pid_euid(pid); + pwd = get_proc_passwd(pid); type = get_proc_type(pid); name = get_proc_name(pid); attr = (have_attr ? get_pid_attr(pid) : NULL); @@ -369,7 +421,7 @@ pwd->pw_name[8] = 0; if (show_all || type) { - printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s\n", + printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s %s\n", pwd ? pwd->pw_name : "--------", pid, pax ? pax : "---", @@ -379,6 +431,7 @@ caps ? caps : " = ", attr ? attr : "", addr ? addr : "", + enam ? enam : "", show_phdr ? get_proc_phdr(pid) : ""); if (verbose && wx) print_executable_mappings(pid);