aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Ludd <solar@gentoo.org>2005-05-06 02:22:12 +0000
committerNed Ludd <solar@gentoo.org>2005-05-06 02:22:12 +0000
commite36e40d88ece1beea6b44996ac6bde8c90559499 (patch)
tree8baaf7a089b33c36bbd185db1c78198a7a2a0c94 /pspax.c
parentinclude offset info in comments (diff)
downloadpax-utils-e36e40d88ece1beea6b44996ac6bde8c90559499.tar.gz
pax-utils-e36e40d88ece1beea6b44996ac6bde8c90559499.tar.bz2
pax-utils-e36e40d88ece1beea6b44996ac6bde8c90559499.zip
- speed up attr handling when the host system does not support them.. Tracking down the same invalid memory leak more than one time can be nerve racking so added note for myself so I do not do it again
Diffstat (limited to 'pspax.c')
-rw-r--r--pspax.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/pspax.c b/pspax.c
index a27bd58..3e54485 100644
--- a/pspax.c
+++ b/pspax.c
@@ -41,7 +41,7 @@
#define PROC_DIR "/proc"
-static const char *rcsid = "$Id: pspax.c,v 1.11 2005/04/15 22:02:03 vapier Exp $";
+static const char *rcsid = "$Id: pspax.c,v 1.12 2005/05/06 02:22:12 solar Exp $";
#define argv0 "pspax"
@@ -80,6 +80,15 @@ static struct passwd *get_proc_uid(pid_t pid)
static char s[PATH_MAX];
snprintf(s, sizeof(s), PROC_DIR "/%d/stat", (int) pid);
+
+ /* this is bullshit but getpwuid() is leaking memory
+ * and I've wasted a few hrs 1 day tracking it down.
+ * I forgot I tracked it down before and saw pspax leaking
+ * memory so I tracked it down again (silly me)
+ * anyway.. please leave this comment here so I don't waste my
+ * time again the next time I forget.
+ * and till such time as getpwuid()/nis/nss/pam or whatever does not suck.
+ */
if ((stat(s, &st)) != (-1))
if ((pwd = getpwuid(st.st_uid)) != NULL)
return pwd;
@@ -148,6 +157,7 @@ static void pspax()
register DIR *dir;
register struct dirent *de;
pid_t pid;
+ int have_attr;
struct passwd *uid;
struct stat st;
const char *pax, *type, *name, *caps, *attr;
@@ -155,15 +165,21 @@ static void pspax()
ssize_t length;
cap_t cap_d;
cap_d = cap_init();
-#else
- caps = NULL;
#endif
+ caps = NULL;
+
chdir(PROC_DIR);
if (!(dir = opendir(PROC_DIR))) {
perror(PROC_DIR);
exit(EXIT_FAILURE);
}
+
+ if (access("/proc/self/attr/current", R_OK) != (-1))
+ have_attr = 1;
+ else
+ have_attr = 0;
+
if (show_banner)
printf("%-8s %-6s %-6s %-10s %-16s %-4s %-4s\n",
"USER", "PID", "PAX", "ELF_TYPE", "NAME", "CAPS", "ATTR");
@@ -186,7 +202,7 @@ static void pspax()
pax = get_proc_status(pid, "PAX");
type = get_pid_type(pid);
name = get_proc_name(pid);
- attr = get_pid_attr(pid);
+ attr = (have_attr ? get_pid_attr(pid) : NULL);
if (show_all || type)
printf("%-8s %-6d %-6s %-10s %-16s %-4s %s\n",