summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorgreen <green@FreeBSD.org>2001-11-26 22:21:15 +0000
committergreen <green@FreeBSD.org>2001-11-26 22:21:15 +0000
commitd741ed6f56790f6d4459cd3edc5ca52989829373 (patch)
treec1032133ec49d0a5bd94f26101cdf04f6159d448 /bin/ps
parentd60fa5f434d39572b6ea9de4953a228e3b87d41d (diff)
downloadFreeBSD-src-d741ed6f56790f6d4459cd3edc5ca52989829373.zip
FreeBSD-src-d741ed6f56790f6d4459cd3edc5ca52989829373.tar.gz
Add LOMAC options (the "Z" flag in both cases) to display extra information
in ls(1) and ps(1). Sponsored by: DARPA, NAI Labs
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/Makefile2
-rw-r--r--bin/ps/extern.h1
-rw-r--r--bin/ps/keyword.c1
-rw-r--r--bin/ps/lomac.c113
-rw-r--r--bin/ps/lomac.h40
-rw-r--r--bin/ps/print.c11
-rw-r--r--bin/ps/ps.113
-rw-r--r--bin/ps/ps.c10
8 files changed, 187 insertions, 4 deletions
diff --git a/bin/ps/Makefile b/bin/ps/Makefile
index 08ea30b..1381ee9 100644
--- a/bin/ps/Makefile
+++ b/bin/ps/Makefile
@@ -2,7 +2,7 @@
# @(#)Makefile 8.1 (Berkeley) 6/2/93
PROG= ps
-SRCS= fmt.c keyword.c nlist.c print.c ps.c
+SRCS= fmt.c keyword.c nlist.c print.c ps.c lomac.c
#
# To support "lazy" ps for non root/wheel users
# add -DLAZY_PS to the cflags. This helps
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index dedac7e..42977e8 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -82,4 +82,5 @@ void uname __P((KINFO *, VARENT *));
int s_uname __P((KINFO *));
void vsize __P((KINFO *, VARENT *));
void wchan __P((KINFO *, VARENT *));
+void lattr __P((KINFO *, VARENT *));
__END_DECLS
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 63693d7..70ad5a9 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -105,6 +105,7 @@ VAR var[] = {
{"login", "LOGIN", NULL, LJUST, logname, NULL, MAXLOGNAME-1},
{"logname", "", "login"},
{"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28},
+ {"lvl", "LVL", NULL, LJUST, lattr, NULL, 3},
{"majflt", "MAJFLT",
NULL, USER, rvar, NULL, 4, ROFF(ru_majflt), LONG, "ld"},
{"minflt", "MINFLT",
diff --git a/bin/ps/lomac.c b/bin/ps/lomac.c
new file mode 100644
index 0000000..9ad9aa4
--- /dev/null
+++ b/bin/ps/lomac.c
@@ -0,0 +1,113 @@
+/*-
+ * Copyright (c) 2001 Networks Associates Technologies, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by NAI Labs, the
+ * Security Research Division of Network Associates, Inc. under
+ * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
+ * CHATS research program.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * 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.
+ *
+ * $Id: lomac.c,v 1.3 2001/11/26 21:04:04 bfeldman Exp $
+ * $FreeBSD$
+ */
+
+/*
+ * This file encapsulates ls's use of LOMAC's ioctl interface. ls uses
+ * this interface to determine the LOMAC attributes of files.
+ */
+
+#include <sys/types.h>
+#include <sys/lomacio.h>
+
+#include <err.h>
+#include <fts.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "lomac.h"
+
+#define LOMAC_DEVICE "/dev/lomac"
+
+static int devlomac = -1; /* file descriptor for LOMAC_DEVICE */
+
+/* lomac_start()
+ *
+ * in: nothing
+ * out: nothing
+ * return: nothing
+ *
+ * Makes `devlomac' a fd to LOMAC_DEVICE
+ */
+
+void
+lomac_start(void) {
+
+ if ((devlomac = open(LOMAC_DEVICE, O_RDWR)) == -1)
+ err(1, "cannot open %s", LOMAC_DEVICE);
+}
+
+/* lomac_stop()
+ *
+ * in: nothing
+ * out: nothing
+ * return: nothing
+ *
+ * Closes `devlomac', the fd to LOMAC_DEVICE.
+ */
+
+void
+lomac_stop(void) {
+
+ if (devlomac != -1 && close(devlomac) == -1)
+ err(1, "cannot close %s", LOMAC_DEVICE);
+}
+
+/* get_lattr()
+ *
+ * in: pid - pid of process whose level we want to know
+ * out: nothing
+ * return: level of proces `pid'
+ *
+ * This function uses LOMAC's ioctl interface to determine the LOMAC
+ * attributes of the process with pid `pid'.
+ *
+ * This function presently reports only levels. When LOMAC's ioctl
+ * interface is expanded to report levels and flags, this function
+ * will also need expansion.
+ */
+
+int
+get_lattr(int pid) {
+
+ if (devlomac == -1)
+ lomac_start();
+ if (ioctl(devlomac, LIOGETPLEVEL, &pid) == -1)
+ err(1, NULL);
+ return (pid);
+}
diff --git a/bin/ps/lomac.h b/bin/ps/lomac.h
new file mode 100644
index 0000000..36a08c4
--- /dev/null
+++ b/bin/ps/lomac.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2001 Networks Associates Technologies, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by NAI Labs, the
+ * Security Research Division of Network Associates, Inc. under
+ * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
+ * CHATS research program.
+ *
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * 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.
+ *
+ * $Id: lomac.h,v 1.2 2001/11/26 19:27:23 bfeldman Exp $
+ * $FreeBSD$
+ */
+
+void lomac_start(void);
+void lomac_stop(void);
+int get_lattr(int);
diff --git a/bin/ps/print.c b/bin/ps/print.c
index 471f3fe..6212295 100644
--- a/bin/ps/print.c
+++ b/bin/ps/print.c
@@ -726,3 +726,14 @@ rvar(k, ve)
else
(void)printf("%*s", v->width, "-");
}
+
+void
+lattr(k, ve)
+ KINFO *k;
+ VARENT *ve;
+{
+ VAR *v;
+
+ v = ve->var;
+ (void)printf("%-*d", (int)v->width, get_lattr(k->ki_p->ki_pid));
+}
diff --git a/bin/ps/ps.1 b/bin/ps/ps.1
index 5052206..a9970b6 100644
--- a/bin/ps/ps.1
+++ b/bin/ps/ps.1
@@ -40,7 +40,7 @@
.Nd process status
.Sh SYNOPSIS
.Nm
-.Op Fl aCcefhjlmrSTuvwx
+.Op Fl aCcefhjlmrSTuvwxZ
.Op Fl M Ar core
.Op Fl N Ar system
.Op Fl O Ar fmt
@@ -182,6 +182,10 @@ option is specified more than once,
will use as many columns as necessary without regard for your window size.
.It Fl x
Display information about processes without controlling terminals.
+.It Fl Z
+Add lvl to the list of keywords for which
+.Nm
+will display information.
.El
.Pp
A complete list of the available keywords are listed below.
@@ -225,6 +229,8 @@ The soft limit on memory used, specified via a call to
.It lstart
The exact time the command started, using the ``%c'' format described in
.Xr strftime 3 .
+.It lvl
+The LOMAC level of the process.
.It mtxname
The name of the
.Xr mutex 9
@@ -376,6 +382,8 @@ memoryuse limit
login name of user who started the process
.It lstart
time started
+.It lvl
+LOMAC level
.It majflt
total page faults
.It minflt
@@ -498,6 +506,8 @@ special files and device names
default swap device
.It Pa /dev/kmem
default kernel memory
+.It Pa /dev/lomac
+interface used to query the LOMAC LKM
.It Pa /var/run/dev.db
/dev name database
.It Pa /var/db/kvm_kernel.db
@@ -514,6 +524,7 @@ the mount point of
.Xr kvm 3 ,
.Xr strftime 3 ,
.Xr procfs 5 ,
+.Xr lomac 4 ,
.Xr pstat 8 ,
.Xr sysctl 8 ,
.Xr mutex 9
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 7bc0c24..691b7f5 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -110,6 +110,7 @@ char o1[] = "pid";
char o2[] = "tt state time command";
char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command";
char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command";
+char Zfmt[] = "lvl";
kvm_t *kd;
@@ -150,9 +151,9 @@ main(argc, argv)
memf = nlistf = swapf = _PATH_DEVNULL;
while ((ch = getopt(argc, argv,
#if defined(LAZY_PS)
- "aCcefghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1)
+ "aCcefghjLlM:mN:O:o:p:rSTt:U:uvW:wxZ")) != -1)
#else
- "aCceghjLlM:mN:O:o:p:rSTt:U:uvW:wx")) != -1)
+ "aCceghjLlM:mN:O:o:p:rSTt:U:uvW:wxZ")) != -1)
#endif
switch((char)ch) {
case 'a':
@@ -275,6 +276,10 @@ main(argc, argv)
case 'x':
xflg = 1;
break;
+ case 'Z':
+ parsefmt(Zfmt);
+ Zfmt[0] = '\0';
+ break;
case '?':
default:
usage();
@@ -391,6 +396,7 @@ main(argc, argv)
}
}
free(uids);
+ lomac_stop();
exit(eval);
}
OpenPOWER on IntegriCloud