summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortrociny <trociny@FreeBSD.org>2013-04-20 08:15:43 +0000
committertrociny <trociny@FreeBSD.org>2013-04-20 08:15:43 +0000
commit814255607be8d0162a05c8b6c4291a57b7744e53 (patch)
tree221fb77b82f865e098660f635d320768c57e11bd
parent1b45c5f76cea7ca80fc73e39f2a44c38141c123f (diff)
downloadFreeBSD-src-814255607be8d0162a05c8b6c4291a57b7744e53.zip
FreeBSD-src-814255607be8d0162a05c8b6c4291a57b7744e53.tar.gz
Use libprocstat(3) to retrieve ELF auxiliary vector.
MFC after: 1 month
-rw-r--r--usr.bin/procstat/procstat.c2
-rw-r--r--usr.bin/procstat/procstat.h2
-rw-r--r--usr.bin/procstat/procstat_auxv.c102
3 files changed, 10 insertions, 96 deletions
diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
index 73c3372..1e28341 100644
--- a/usr.bin/procstat/procstat.c
+++ b/usr.bin/procstat/procstat.c
@@ -81,7 +81,7 @@ procstat(struct procstat *prstat, struct kinfo_proc *kipp)
else if (vflag)
procstat_vm(prstat, kipp);
else if (xflag)
- procstat_auxv(kipp);
+ procstat_auxv(prstat, kipp);
else
procstat_basic(kipp);
}
diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
index 5d8d773..a0ec2e5d 100644
--- a/usr.bin/procstat/procstat.h
+++ b/usr.bin/procstat/procstat.h
@@ -35,7 +35,7 @@ struct kinfo_proc;
void kinfo_proc_sort(struct kinfo_proc *kipp, int count);
void procstat_args(struct procstat *prstat, struct kinfo_proc *kipp);
-void procstat_auxv(struct kinfo_proc *kipp);
+void procstat_auxv(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_basic(struct kinfo_proc *kipp);
void procstat_bin(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_cred(struct procstat *prstat, struct kinfo_proc *kipp);
diff --git a/usr.bin/procstat/procstat_auxv.c b/usr.bin/procstat/procstat_auxv.c
index b78e13a..aa62594 100644
--- a/usr.bin/procstat/procstat_auxv.c
+++ b/usr.bin/procstat/procstat_auxv.c
@@ -43,113 +43,26 @@
#include "procstat.h"
-#define PROC_AUXV_MAX 256
-
-static Elf_Auxinfo auxv[PROC_AUXV_MAX];
-static char prefix[256];
-
-#if __ELF_WORD_SIZE == 64
-static Elf32_Auxinfo auxv32[PROC_AUXV_MAX];
-
-static const char *elf32_sv_names[] = {
- "Linux ELF32",
- "FreeBSD ELF32",
-};
-
-static int
-is_elf32(pid_t pid)
-{
- int error, name[4];
- size_t len, i;
- static char sv_name[256];
-
- name[0] = CTL_KERN;
- name[1] = KERN_PROC;
- name[2] = KERN_PROC_SV_NAME;
- name[3] = pid;
- len = sizeof(sv_name);
- error = sysctl(name, 4, sv_name, &len, NULL, 0);
- if (error != 0 || len == 0)
- return (0);
- for (i = 0; i < sizeof(elf32_sv_names) / sizeof(*elf32_sv_names); i++) {
- if (strncmp(sv_name, elf32_sv_names[i], sizeof(sv_name)) == 0)
- return (1);
- }
- return (0);
-}
-
-static size_t
-retrieve_auxv32(pid_t pid)
-{
- int name[4];
- size_t len, i;
- void *ptr;
-
- name[0] = CTL_KERN;
- name[1] = KERN_PROC;
- name[2] = KERN_PROC_AUXV;
- name[3] = pid;
- len = sizeof(auxv32);
- if (sysctl(name, 4, auxv32, &len, NULL, 0) == -1) {
- if (errno != ESRCH && errno != EPERM)
- warn("sysctl: kern.proc.auxv: %d: %d", pid, errno);
- return (0);
- }
- for (i = 0; i < len; i++) {
- /*
- * XXX: We expect that values for a_type on a 32-bit platform
- * are directly mapped to those on 64-bit one, which is not
- * necessarily true.
- */
- auxv[i].a_type = auxv32[i].a_type;
- ptr = &auxv32[i].a_un;
- auxv[i].a_un.a_val = *((uint32_t *)ptr);
- }
- return (len);
-}
-#endif /* __ELF_WORD_SIZE == 64 */
-
#define PRINT(name, spec, val) \
printf("%s %-16s " #spec "\n", prefix, #name, (val))
#define PRINT_UNKNOWN(type, val) \
printf("%s %16ld %#lx\n", prefix, (long)type, (u_long)(val))
-static size_t
-retrieve_auxv(pid_t pid)
-{
- int name[4];
- size_t len;
-
-#if __ELF_WORD_SIZE == 64
- if (is_elf32(pid))
- return (retrieve_auxv32(pid));
-#endif
- name[0] = CTL_KERN;
- name[1] = KERN_PROC;
- name[2] = KERN_PROC_AUXV;
- name[3] = pid;
- len = sizeof(auxv);
- if (sysctl(name, 4, auxv, &len, NULL, 0) == -1) {
- if (errno != ESRCH && errno != EPERM)
- warn("sysctl: kern.proc.auxv: %d: %d", pid, errno);
- return (0);
- }
- return (len);
-}
-
void
-procstat_auxv(struct kinfo_proc *kipp)
+procstat_auxv(struct procstat *procstat, struct kinfo_proc *kipp)
{
- size_t len, i;
+ Elf_Auxinfo *auxv;
+ u_int count, i;
+ static char prefix[256];
if (!hflag)
printf("%5s %-16s %-16s %-16s\n", "PID", "COMM", "AUXV", "VALUE");
- len = retrieve_auxv(kipp->ki_pid);
- if (len == 0)
+ auxv = procstat_getauxv(procstat, kipp, &count);
+ if (auxv == NULL)
return;
snprintf(prefix, sizeof(prefix), "%5d %-16s", kipp->ki_pid,
kipp->ki_comm);
- for (i = 0; i < len; i++) {
+ for (i = 0; i < count; i++) {
switch(auxv[i].a_type) {
case AT_NULL:
return;
@@ -242,5 +155,6 @@ procstat_auxv(struct kinfo_proc *kipp)
}
}
printf("\n");
+ procstat_freeauxv(procstat, auxv);
}
OpenPOWER on IntegriCloud