2007-12-02 23:31:45 +00:00
|
|
|
/*-
|
2017-11-27 15:37:16 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2007-12-02 23:31:45 +00:00
|
|
|
* Copyright (c) 2007 Robert N. M. Watson
|
2015-09-05 17:02:01 +00:00
|
|
|
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
|
2007-12-02 23:31:45 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2020-09-27 23:01:54 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2008-12-29 18:58:22 +00:00
|
|
|
#include <sys/param.h>
|
2007-12-02 23:31:45 +00:00
|
|
|
#include <sys/sysctl.h>
|
2007-12-10 20:55:43 +00:00
|
|
|
#include <sys/user.h>
|
2007-12-02 23:31:45 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
2011-05-12 10:11:39 +00:00
|
|
|
#include <libprocstat.h>
|
2007-12-02 23:31:45 +00:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
2009-12-13 03:14:06 +00:00
|
|
|
#include <stdlib.h>
|
2007-12-02 23:31:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "procstat.h"
|
|
|
|
|
2015-09-05 17:02:01 +00:00
|
|
|
void
|
|
|
|
procstat_args(struct procstat *procstat, struct kinfo_proc *kipp)
|
2007-12-02 23:31:45 +00:00
|
|
|
{
|
2013-04-20 08:08:29 +00:00
|
|
|
int i;
|
|
|
|
char **args;
|
2007-12-02 23:31:45 +00:00
|
|
|
|
2017-10-14 18:38:36 +00:00
|
|
|
if ((procstat_opts & PS_OPT_NOHEADER) == 0) {
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{T:/%5s %-16s %-53s}\n", "PID", "COMM", "ARGS");
|
2007-12-02 23:31:45 +00:00
|
|
|
}
|
2013-04-20 08:08:29 +00:00
|
|
|
|
2015-09-05 17:02:01 +00:00
|
|
|
args = procstat_getargv(procstat, kipp, 0);
|
2013-04-20 08:08:29 +00:00
|
|
|
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{k:process_id/%5d/%d} {:command/%-16s/%s}", kipp->ki_pid,
|
|
|
|
kipp->ki_comm);
|
2013-04-20 08:08:29 +00:00
|
|
|
|
|
|
|
if (args == NULL) {
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit(" {d:args/-}\n");
|
2007-12-02 23:31:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_open_list("arguments");
|
2013-04-20 08:08:29 +00:00
|
|
|
for (i = 0; args[i] != NULL; i++)
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit(" {l:args/%s}", args[i]);
|
|
|
|
xo_close_list("arguments");
|
|
|
|
xo_emit("\n");
|
2011-11-22 20:59:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-04-20 08:08:29 +00:00
|
|
|
procstat_env(struct procstat *procstat, struct kinfo_proc *kipp)
|
2011-11-22 20:59:52 +00:00
|
|
|
{
|
2015-09-05 17:02:01 +00:00
|
|
|
int i;
|
|
|
|
char **envs;
|
|
|
|
|
2017-10-14 18:38:36 +00:00
|
|
|
if ((procstat_opts & PS_OPT_NOHEADER) == 0) {
|
2015-09-05 17:02:01 +00:00
|
|
|
xo_emit("{T:/%5s %-16s %-53s}\n", "PID", "COMM", "ENVIRONMENT");
|
|
|
|
}
|
|
|
|
|
|
|
|
envs = procstat_getenvv(procstat, kipp, 0);
|
|
|
|
|
|
|
|
xo_emit("{k:process_id/%5d/%d} {:command/%-16s/%s}", kipp->ki_pid,
|
|
|
|
kipp->ki_comm);
|
|
|
|
|
|
|
|
if (envs == NULL) {
|
|
|
|
xo_emit(" {d:env/-}\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xo_open_list("environment");
|
|
|
|
for (i = 0; envs[i] != NULL; i++)
|
|
|
|
xo_emit(" {l:env/%s}", envs[i]);
|
|
|
|
xo_close_list("environment");
|
|
|
|
xo_emit("\n");
|
2011-11-22 20:59:52 +00:00
|
|
|
}
|