Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F108312369
D26310.id77024.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
25 KB
Referenced Files
None
Subscribers
None
D26310.id77024.diff
View Options
Index: usr.bin/procstat/Makefile
===================================================================
--- usr.bin/procstat/Makefile
+++ usr.bin/procstat/Makefile
@@ -9,6 +9,8 @@
procstat_auxv.c \
procstat_basic.c \
procstat_bin.c \
+ procstat_penv.c \
+ procstat_pwdx.c \
procstat_cred.c \
procstat_cs.c \
procstat_files.c \
@@ -20,8 +22,16 @@
procstat_threads.c \
procstat_vm.c
+MLINKS+= procstat.1 pargs.1
+MLINKS+= procstat.1 penv.1
+MLINKS+= procstat.1 pwdx.1
+
LIBADD+= procstat xo util sbuf
+LINKS+= ${BINDIR}/procstat ${BINDIR}/pargs
+LINKS+= ${BINDIR}/procstat ${BINDIR}/penv
+LINKS+= ${BINDIR}/procstat ${BINDIR}/pwdx
+
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
Index: usr.bin/procstat/procstat.h
===================================================================
--- usr.bin/procstat/procstat.h
+++ usr.bin/procstat/procstat.h
@@ -4,6 +4,7 @@
* Copyright (c) 2007 Robert N. M. Watson
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
* Copyright (c) 2017 Dell EMC
+ * Copyright (c) 2020 Juraj Lutter <juraj@lutter.sk>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,9 +28,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <libxo/xo.h>
#ifndef PROCSTAT_H
@@ -42,7 +45,10 @@
PS_OPT_NOHEADER = 0x02,
PS_OPT_PERTHREAD = 0x04,
PS_OPT_SIGNUM = 0x08,
- PS_OPT_VERBOSE = 0x10
+ PS_OPT_VERBOSE = 0x10,
+ PS_OPT_NOPIDSTR = 0x20,
+ PS_OPT_LISTOPENED = 0x40,
+ PS_MODE_COMPAT = 0x80
};
#define PS_SUBCOMMAND_OPTS \
@@ -50,6 +56,8 @@
PS_OPT_PERTHREAD | PS_OPT_VERBOSE)
extern int procstat_opts;
+extern int procstat_mode;
+extern const char * xocontainer;
struct kinfo_proc;
void kinfo_proc_sort(struct kinfo_proc *kipp, int count);
@@ -64,7 +72,10 @@
void procstat_env(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_files(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_kstack(struct procstat *prstat, struct kinfo_proc *kipp);
+void procstat_pargs(struct procstat *prstat, struct kinfo_proc *kipp);
+void procstat_penv(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_ptlwpinfo(struct procstat *prstat, struct kinfo_proc *kipp);
+void procstat_pwdx(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_rlimit(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_rusage(struct procstat *prstat, struct kinfo_proc *kipp);
void procstat_sigfastblock(struct procstat *procstat,
Index: usr.bin/procstat/procstat.1
===================================================================
--- usr.bin/procstat/procstat.1
+++ usr.bin/procstat/procstat.1
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 4, 2019
+.Dd September 14, 2020
.Dt PROCSTAT 1
.Os
.Sh NAME
@@ -102,6 +102,9 @@
.Op Fl N Ar system
.Op Fl w Ar interval
.Ar core ...
+.Nm pargs | penv | pwdx
+.Op Fl -libxo
+.Ar pid ...
.Sh DESCRIPTION
.Nm
utility displays detailed information about the processes identified by the
@@ -112,6 +115,17 @@
It can also display information extracted from a process core file, if
the core file is specified as the argument.
.Pp
+The
+.Nm pargs ,
+.Nm penv
+and
+.Nm pwdx
+utilities display the arguments, environment and current working directory,
+respectively of the process specified by
+.Ar pid
+argument.
+They mimic the behavior of Solaris utilities of the same names.
+.Pp
If the
.Fl -libxo
flag is specified the output is generated via
@@ -121,7 +135,8 @@
.Xr xo_parse_args 3
for details on command line arguments.
.Pp
-The following commands are available:
+The following commands are available for
+.Nm :
.Bl -tag -width indent
.It Ar basic
Print basic process statistics (this is the default).
@@ -430,7 +445,7 @@
if signal is pending in the global process queue; - otherwise.
.It I
if signal delivery disposition is
-.Dv SIG_IGN;
+.Dv SIG_IGN ;
- otherwise.
.It C
if the signal will be caught; - otherwise.
@@ -711,6 +726,10 @@
.An -nosplit
Allan Jude
.Aq Mt allanjude@FreeBSD.org .
+.br
+.An Juraj Lutter
+.Aq Mt juraj@lutter.sk
+added the pargs, penv and pwdx functionality.
.Sh BUGS
The display of open file or memory mapping pathnames is implemented using the
kernel's name cache.
Index: usr.bin/procstat/procstat.c
===================================================================
--- usr.bin/procstat/procstat.c
+++ usr.bin/procstat/procstat.c
@@ -4,6 +4,7 @@
* Copyright (c) 2007, 2011 Robert N. M. Watson
* Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
* Copyright (c) 2017 Dell EMC
+ * Copyright (c) 2020 Juraj Lutter <juraj@lutter.sk>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,9 +28,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
@@ -60,6 +64,7 @@
};
int procstat_opts = 0;
+const char * xocontainer;
static void cmdopt_none(int argc, char * const argv[]);
static void cmdopt_verbose(int argc, char * const argv[]);
@@ -68,6 +73,26 @@
static void cmdopt_files(int argc, char * const argv[]);
static void cmdopt_cpuset(int argc, char * const argv[]);
+static void usage_procstat(void);
+static void usage_compat(void);
+
+static const char *progname;
+
+/* aliased program parameters and arguments
+ * - usage field is abused to hold the pointer to the function
+ * displaying program usage
+ */
+static const struct procstat_cmd pacmd_table[] = {
+ { "pwdx", "pwd", NULL, &procstat_pwdx, &cmdopt_none,
+ PS_CMP_NORMAL | PS_MODE_COMPAT },
+ /* arguments are the same as for pwdx: pid or core file */
+ { "penv", "env", NULL, &procstat_penv, &cmdopt_none,
+ PS_CMP_NORMAL | PS_MODE_COMPAT },
+ { "pargs", "args", NULL, &procstat_pargs, &cmdopt_none,
+ PS_CMP_NORMAL | PS_MODE_COMPAT }
+};
+
+/* procstat parameters and arguments */
static const struct procstat_cmd cmd_table[] = {
{ "argument", "arguments", NULL, &procstat_args, &cmdopt_none,
PS_CMP_PLURAL | PS_CMP_SUBSTR },
@@ -106,7 +131,7 @@
};
static void
-usage(void)
+usage_procstat(void)
{
size_t i, l;
int multi;
@@ -149,18 +174,39 @@
}
static void
+usage_compat(void)
+{
+ xo_error("usage: %s [--libxo] pid ...\n", progname);
+ xo_finish();
+ exit(EX_USAGE);
+}
+
+static void
+usage(const struct procstat_cmd *cmd)
+{
+ if (cmd == NULL || (cmd->cmp & PS_MODE_COMPAT) == 0)
+ usage_procstat();
+ else
+ usage_compat();
+}
+
+static void
procstat(const struct procstat_cmd *cmd, struct procstat *prstat,
struct kinfo_proc *kipp)
{
char *pidstr = NULL;
- asprintf(&pidstr, "%d", kipp->ki_pid);
- if (pidstr == NULL)
- xo_errc(1, ENOMEM, "Failed to allocate memory in procstat()");
- xo_open_container(pidstr);
+ if ((procstat_opts & PS_OPT_NOPIDSTR) == 0) {
+ asprintf(&pidstr, "%d", kipp->ki_pid);
+ if (pidstr == NULL)
+ xo_errc(1, ENOMEM, "Failed to allocate memory in procstat()");
+ xo_open_container(pidstr);
+ }
cmd->cmd(prstat, kipp);
- xo_close_container(pidstr);
- free(pidstr);
+ if ((procstat_opts & PS_OPT_NOPIDSTR) == 0) {
+ xo_close_container(pidstr);
+ free(pidstr);
+ }
}
/*
@@ -203,6 +249,27 @@
}
static const struct procstat_cmd *
+getcmdbyprogname(const char *pprogname)
+{
+ size_t i, len;
+ const char *ca;
+
+ if (pprogname == NULL)
+ return (NULL);
+ len = strlen(pprogname);
+
+ for (i = 0; i < nitems(pacmd_table); i++) {
+ ca = pacmd_table[i].command;
+ if (ca != NULL &&
+ strncmp(pprogname, ca, strlen(pprogname)) == 0) {
+ return (&pacmd_table[i]);
+ }
+ }
+
+ return (NULL);
+}
+
+static const struct procstat_cmd *
getcmd(const char *str)
{
const struct procstat_cmd *cmd;
@@ -240,7 +307,7 @@
int ch, interval;
int i;
struct kinfo_proc *p;
- const struct procstat_cmd *cmd;
+ const struct procstat_cmd *cmd = NULL;
struct procstat *prstat, *cprstat;
long l;
pid_t pid;
@@ -252,9 +319,13 @@
interval = 0;
cmd = NULL;
memf = nlistf = NULL;
+ progname = NULL;
aflag = 0;
argc = xo_parse_args(argc, argv);
+ progname = getprogname();
+ cmd = getcmdbyprogname(progname);
+
while ((ch = getopt(argc, argv, "abCcefHhijkLlM:N:nrSstvw:x")) != -1) {
switch (ch) {
case 'a':
@@ -262,7 +333,7 @@
break;
case 'b':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("binary");
break;
case 'C':
@@ -270,17 +341,17 @@
break;
case 'c':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("arguments");
break;
case 'e':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("environment");
break;
case 'f':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("files");
break;
case 'H':
@@ -291,33 +362,33 @@
break;
case 'i':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("signals");
break;
case 'j':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("tsignals");
break;
case 'k':
if (cmd != NULL && cmd->cmd == procstat_kstack) {
if ((procstat_opts & PS_OPT_VERBOSE) != 0)
- usage();
+ usage(cmd);
procstat_opts |= PS_OPT_VERBOSE;
} else {
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("kstack");
}
break;
case 'L':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("ptlwpinfo");
break;
case 'l':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("rlimit");
break;
case 'M':
@@ -331,75 +402,79 @@
break;
case 'r':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("rusage");
break;
case 'S':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("cpuset");
break;
case 's':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("credentials");
break;
case 't':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("threads");
break;
case 'v':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("vm");
break;
case 'w':
l = strtol(optarg, &dummy, 10);
if (*dummy != '\0')
- usage();
+ usage(cmd);
if (l < 1 || l > INT_MAX)
- usage();
+ usage(cmd);
interval = l;
break;
case 'x':
if (cmd != NULL)
- usage();
+ usage(cmd);
cmd = getcmd("auxv");
break;
case '?':
default:
- usage();
+ usage(cmd);
}
}
argc -= optind;
argv += optind;
- if (cmd == NULL && argv[0] != NULL && (cmd = getcmd(argv[0])) != NULL) {
+ if (cmd == NULL && argv[0] != NULL)
+ cmd = getcmd(argv[0]);
+ if (cmd != NULL) {
if ((procstat_opts & PS_SUBCOMMAND_OPTS) != 0)
- usage();
+ usage(cmd);
if (cmd->opt != NULL) {
optreset = 1;
optind = 1;
cmd->opt(argc, argv);
- argc -= optind;
- argv += optind;
+ if ((cmd->cmp & PS_MODE_COMPAT) == 0) {
+ argc -= optind;
+ argv += optind;
+ }
} else {
argc -= 1;
argv += 1;
}
} else {
- if (cmd == NULL)
- cmd = getcmd("basic");
- if (cmd->cmd != procstat_files &&
- (procstat_opts & PS_OPT_CAPABILITIES) != 0)
- usage();
+ cmd = getcmd("basic");
}
+ if (cmd->cmd != procstat_files &&
+ (procstat_opts & PS_OPT_CAPABILITIES) != 0 &&
+ (cmd->cmp & PS_MODE_COMPAT) == 0)
+ usage(cmd);
/* Must specify either the -a flag or a list of pids. */
if (!(aflag == 1 && argc == 0) && !(aflag == 0 && argc > 0))
- usage();
+ usage(cmd);
if (memf != NULL)
prstat = procstat_open_kvm(nlistf, memf);
@@ -408,9 +483,10 @@
if (prstat == NULL)
xo_errx(1, "procstat_open()");
do {
+ xocontainer = cmd->xocontainer != NULL ? cmd->xocontainer : cmd->command;
xo_set_version(PROCSTAT_XO_VERSION);
- xo_open_container("procstat");
- xo_open_container(cmd->xocontainer);
+ xo_open_container(progname);
+ xo_open_container(xocontainer);
if (aflag) {
p = procstat_getprocs(prstat, KERN_PROC_PROC, 0, &cnt);
@@ -430,7 +506,7 @@
l = strtol(argv[i], &dummy, 10);
if (*dummy == '\0') {
if (l < 0)
- usage();
+ usage(cmd);
pid = l;
p = procstat_getprocs(prstat, KERN_PROC_PID,
@@ -441,26 +517,32 @@
procstat(cmd, prstat, p);
procstat_freeprocs(prstat, p);
} else {
- cprstat = procstat_open_core(argv[i]);
- if (cprstat == NULL) {
- warnx("procstat_open()");
- continue;
+ if ((cmd->cmp & PS_MODE_COMPAT) == 0) {
+ cprstat = procstat_open_core(argv[i]);
+ if (cprstat == NULL) {
+ warnx("procstat_open()");
+ continue;
+ }
+ p = procstat_getprocs(cprstat, KERN_PROC_PID,
+ -1, &cnt);
+ if (p == NULL)
+ xo_errx(1, "procstat_getprocs()");
+ if (cnt != 0)
+ procstat(cmd, cprstat, p);
+ procstat_freeprocs(cprstat, p);
+ procstat_close(cprstat);
+ } else {
+ usage(cmd);
}
- p = procstat_getprocs(cprstat, KERN_PROC_PID,
- -1, &cnt);
- if (p == NULL)
- xo_errx(1, "procstat_getprocs()");
- if (cnt != 0)
- procstat(cmd, cprstat, p);
- procstat_freeprocs(cprstat, p);
- procstat_close(cprstat);
}
- /* Suppress header after first process. */
- procstat_opts |= PS_OPT_NOHEADER;
+ if ((cmd->cmp & PS_MODE_COMPAT) == 0) {
+ /* Suppress header after first process. */
+ procstat_opts |= PS_OPT_NOHEADER;
+ }
}
- xo_close_container(cmd->xocontainer);
- xo_close_container("procstat");
+ xo_close_container(xocontainer);
+ xo_close_container(progname);
xo_finish();
if (interval)
sleep(interval);
@@ -480,7 +562,7 @@
switch (ch) {
case '?':
default:
- usage();
+ usage(NULL);
}
}
}
@@ -497,7 +579,7 @@
break;
case '?':
default:
- usage();
+ usage(NULL);
}
}
}
@@ -514,7 +596,7 @@
break;
case '?':
default:
- usage();
+ usage(NULL);
}
}
}
@@ -533,7 +615,7 @@
break;
case '?':
default:
- usage();
+ usage(NULL);
}
}
}
@@ -550,7 +632,7 @@
break;
case '?':
default:
- usage();
+ usage(NULL);
}
}
}
Index: usr.bin/procstat/procstat_args.c
===================================================================
--- usr.bin/procstat/procstat_args.c
+++ usr.bin/procstat/procstat_args.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
Index: usr.bin/procstat/procstat_auxv.c
===================================================================
--- usr.bin/procstat/procstat_auxv.c
+++ usr.bin/procstat/procstat_auxv.c
@@ -26,9 +26,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/elf.h>
#include <sys/sysctl.h>
Index: usr.bin/procstat/procstat_basic.c
===================================================================
--- usr.bin/procstat/procstat_basic.c
+++ usr.bin/procstat/procstat_basic.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
Index: usr.bin/procstat/procstat_bin.c
===================================================================
--- usr.bin/procstat/procstat_bin.c
+++ usr.bin/procstat/procstat_bin.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
Index: usr.bin/procstat/procstat_cred.c
===================================================================
--- usr.bin/procstat/procstat_cred.c
+++ usr.bin/procstat/procstat_cred.c
@@ -26,9 +26,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
Index: usr.bin/procstat/procstat_cs.c
===================================================================
--- usr.bin/procstat/procstat_cs.c
+++ usr.bin/procstat/procstat_cs.c
@@ -24,9 +24,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/cpuset.h>
#include <sys/sbuf.h>
Index: usr.bin/procstat/procstat_files.c
===================================================================
--- usr.bin/procstat/procstat_files.c
+++ usr.bin/procstat/procstat_files.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/capsicum.h>
#include <sys/socket.h>
Index: usr.bin/procstat/procstat_kstack.c
===================================================================
--- usr.bin/procstat/procstat_kstack.c
+++ usr.bin/procstat/procstat_kstack.c
@@ -26,9 +26,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
@@ -68,7 +70,7 @@
return (TS_OFF);
case TS_OFF:
- return TS_FRAMENUM;
+ return (TS_FRAMENUM);
default:
errx(-1, "kstack_nextstate");
Index: usr.bin/procstat/procstat_penv.c
===================================================================
--- usr.bin/procstat/procstat_penv.c
+++ usr.bin/procstat/procstat_penv.c
@@ -0,0 +1,85 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2007 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
+ * Copyright (c) 2020 Juraj Lutter <juraj@lutter.sk>
+ * 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.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <sys/user.h>
+
+#include <err.h>
+#include <errno.h>
+#include <libprocstat.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "procstat.h"
+
+void
+procstat_pargs(struct procstat *procstat, struct kinfo_proc *kipp)
+{
+ int i;
+ char **args;
+
+ args = procstat_getargv(procstat, kipp, 0);
+
+ xo_emit("{k:process_id/%d}: {:command/%s/%s}\n", kipp->ki_pid,
+ kipp->ki_comm);
+
+ if (args == NULL) {
+ xo_emit("{d:args/-}\n");
+ } else {
+ for (i = 0; args[i] != NULL; i++)
+ xo_emit("{Ld:args[}{Ld:/%d}{Ldwc:]}{l:args/%s}\n", i, args[i]);
+ }
+}
+
+void
+procstat_penv(struct procstat *procstat, struct kinfo_proc *kipp)
+{
+ int i;
+ char **envs;
+
+ envs = procstat_getenvv(procstat, kipp, 0);
+
+ xo_emit("{k:process_id/%d}: {:command/%s/%s}\n", kipp->ki_pid,
+ kipp->ki_comm);
+
+ if (envs == NULL) {
+ xo_emit("{d:env/-}\n");
+ } else {
+ for (i = 0; envs[i] != NULL; i++)
+ xo_emit("{Ld:envp[}{Ld:/%d}{Ldwc:]}{l:envp/%s}\n", i, envs[i]);
+ }
+}
Index: usr.bin/procstat/procstat_pwdx.c
===================================================================
--- usr.bin/procstat/procstat_pwdx.c
+++ usr.bin/procstat/procstat_pwdx.c
@@ -0,0 +1,73 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2007-2011 Robert N. M. Watson
+ * Copyright (c) 2015 Allan Jude <allanjude@freebsd.org>
+ * Copyright (c) 2020 Juraj Lutter <juraj@lutter.sk>
+ * 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.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/capsicum.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+#include <sys/un.h>
+#include <sys/user.h>
+
+#include <netinet/in.h>
+
+#include <arpa/inet.h>
+
+#include <err.h>
+#include <libprocstat.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "procstat.h"
+
+void
+procstat_pwdx(struct procstat *procstat, struct kinfo_proc *kipp)
+{
+ struct filestat_list *head;
+ struct filestat *fst;
+
+ head = procstat_getfiles(procstat, kipp, 0);
+ if (head == NULL)
+ return;
+ STAILQ_FOREACH(fst, head, next) {
+ if ((fst->fs_uflags & PS_FST_UFLAG_CDIR) &&
+ (fst->fs_path != NULL)) {
+ xo_emit("{k:process_id/%d}{P:: }", kipp->ki_pid);
+ xo_emit("{:cwd/%s}", fst->fs_path);
+ xo_emit("\n");
+ }
+ }
+ procstat_freefiles(procstat, head);
+}
Index: usr.bin/procstat/procstat_rlimit.c
===================================================================
--- usr.bin/procstat/procstat_rlimit.c
+++ usr.bin/procstat/procstat_rlimit.c
@@ -26,9 +26,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/time.h>
#include <sys/resource.h>
Index: usr.bin/procstat/procstat_sigs.c
===================================================================
--- usr.bin/procstat/procstat_sigs.c
+++ usr.bin/procstat/procstat_sigs.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
Index: usr.bin/procstat/procstat_threads.c
===================================================================
--- usr.bin/procstat/procstat_threads.c
+++ usr.bin/procstat/procstat_threads.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
Index: usr.bin/procstat/procstat_vm.c
===================================================================
--- usr.bin/procstat/procstat_vm.c
+++ usr.bin/procstat/procstat_vm.c
@@ -25,10 +25,12 @@
* 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.
- *
- * $FreeBSD$
+ *
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/user.h>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 24, 6:55 PM (18 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16097796
Default Alt Text
D26310.id77024.diff (25 KB)
Attached To
Mode
D26310: Mimic behavior of Solaris' pargs, penv, pwdx commands
Attached
Detach File
Event Timeline
Log In to Comment