mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-01 12:19:28 +00:00
Use libprocstat(3) to retrieve process command line arguments and
environment variables. MFC after: 1 month
This commit is contained in:
parent
4482b5e320
commit
729e63c34b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=249680
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user