summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authortrociny <trociny@FreeBSD.org>2013-04-20 08:08:29 +0000
committertrociny <trociny@FreeBSD.org>2013-04-20 08:08:29 +0000
commit5a7b01c81a73882e035c38149a851ac183f07984 (patch)
tree9670c32733ff9311f4600d8d343a9a810c85464e /usr.bin
parent890cfdcd4f22a72faa1ac356436926ed16e08270 (diff)
downloadFreeBSD-src-5a7b01c81a73882e035c38149a851ac183f07984.zip
FreeBSD-src-5a7b01c81a73882e035c38149a851ac183f07984.tar.gz
Use libprocstat(3) to retrieve process command line arguments and
environment variables. MFC after: 1 month
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/procstat/procstat.c4
-rw-r--r--usr.bin/procstat/procstat.h4
-rw-r--r--usr.bin/procstat/procstat_args.c48
3 files changed, 22 insertions, 34 deletions
diff --git a/usr.bin/procstat/procstat.c b/usr.bin/procstat/procstat.c
index 16f2c99..73c3372 100644
--- a/usr.bin/procstat/procstat.c
+++ b/usr.bin/procstat/procstat.c
@@ -61,9 +61,9 @@ procstat(struct procstat *prstat, struct kinfo_proc *kipp)
if (bflag)
procstat_bin(prstat, kipp);
else if (cflag)
- procstat_args(kipp);
+ procstat_args(prstat, kipp);
else if (eflag)
- procstat_env(kipp);
+ procstat_env(prstat, kipp);
else if (fflag)
procstat_files(prstat, kipp);
else if (iflag)
diff --git a/usr.bin/procstat/procstat.h b/usr.bin/procstat/procstat.h
index e651665..5d8d773 100644
--- a/usr.bin/procstat/procstat.h
+++ b/usr.bin/procstat/procstat.h
@@ -34,12 +34,12 @@ extern int hflag, nflag, Cflag;
struct kinfo_proc;
void kinfo_proc_sort(struct kinfo_proc *kipp, int count);
-void procstat_args(struct kinfo_proc *kipp);
+void procstat_args(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_auxv(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);
-void procstat_env(struct kinfo_proc *kipp);
+void procstat_env(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_kstack(struct kinfo_proc *kipp, int kflag);
void procstat_rlimit(struct procstat *prstat, struct kinfo_proc *kipp);
diff --git a/usr.bin/procstat/procstat_args.c b/usr.bin/procstat/procstat_args.c
index b13aa72..342b60f 100644
--- a/usr.bin/procstat/procstat_args.c
+++ b/usr.bin/procstat/procstat_args.c
@@ -40,52 +40,40 @@
#include "procstat.h"
-static char args[ARG_MAX];
-
static void
-do_args(struct kinfo_proc *kipp, int env)
+do_args(struct procstat *procstat, struct kinfo_proc *kipp, int env)
{
- int error, name[4];
- size_t len;
- char *cp;
+ int i;
+ char **args;
- if (!hflag)
+ if (!hflag) {
printf("%5s %-16s %-53s\n", "PID", "COMM",
env ? "ENVIRONMENT" : "ARGS");
-
- name[0] = CTL_KERN;
- name[1] = KERN_PROC;
- name[2] = env ? KERN_PROC_ENV : KERN_PROC_ARGS;
- name[3] = kipp->ki_pid;
- len = sizeof(args);
- error = sysctl(name, 4, args, &len, NULL, 0);
- if (error < 0 && errno != ESRCH && errno != EPERM) {
- warn("sysctl: kern.proc.%s: %d: %d", env ? "env" : "args",
- kipp->ki_pid, errno);
- return;
}
- if (error < 0)
+
+ args = env ? procstat_getenvv(procstat, kipp, 0) :
+ procstat_getargv(procstat, kipp, 0);
+
+ printf("%5d %-16s", kipp->ki_pid, kipp->ki_comm);
+
+ if (args == NULL) {
+ printf(" -\n");
return;
- if (len == 0 || strlen(args) == 0) {
- strcpy(args, "-");
- len = strlen(args) + 1;
}
- printf("%5d ", kipp->ki_pid);
- printf("%-16s ", kipp->ki_comm);
- for (cp = args; cp < args + len; cp += strlen(cp) + 1)
- printf("%s%s", cp != args ? " " : "", cp);
+ for (i = 0; args[i] != NULL; i++)
+ printf(" %s", args[i]);
printf("\n");
}
void
-procstat_args(struct kinfo_proc *kipp)
+procstat_args(struct procstat *procstat, struct kinfo_proc *kipp)
{
- do_args(kipp, 0);
+ do_args(procstat, kipp, 0);
}
void
-procstat_env(struct kinfo_proc *kipp)
+procstat_env(struct procstat *procstat, struct kinfo_proc *kipp)
{
- do_args(kipp, 1);
+ do_args(procstat, kipp, 1);
}
OpenPOWER on IntegriCloud