PERFORCE change 40848 for review
Chris Vance
cvance at FreeBSD.org
Thu Oct 30 18:22:55 GMT 2003
http://perforce.freebsd.org/chv.cgi?CH=40848
Change 40848 by cvance at cvance_osx_laptop on 2003/10/30 10:22:00
Print MAC labels. The makefile is currently hardcoded to link in libmac.a
You also need to install a copy of mac.conf into /etc for this to work
correctly.
Affected files ...
.. //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/Makefile#2 edit
.. //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/extern.h#2 edit
.. //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/keyword.c#2 edit
.. //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/print.c#2 edit
.. //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/ps.c#2 edit
Differences ...
==== //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/Makefile#2 (text+ko) ====
@@ -26,7 +26,7 @@
NEXTSTEP_INSTALLDIR = /bin
WINDOWS_INSTALLDIR = /Library/Executables
PDO_UNIX_INSTALLDIR = /bin
-LIBS =
+LIBS = ../../../libmac/libmac.a
DEBUG_LIBS = $(LIBS)
PROF_LIBS = $(LIBS)
==== //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/extern.h#2 (text+ko) ====
@@ -55,6 +55,8 @@
char *fmt_argv __P((char **, char *, int));
int getpcpu __P((KINFO *));
double getpmem __P((KINFO *));
+void label(KINFO *, VARENT *);
+int s_label(KINFO *);
void logname __P((KINFO *, VARENT *));
void longtname __P((KINFO *, VARENT *));
void lstarted __P((KINFO *, VARENT *));
==== //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/keyword.c#2 (text+ko) ====
@@ -104,6 +104,8 @@
NULL, 0, pvar, NULL, 8, POFF(p_traceflag), INT, "x"},
{"ktracep", "KTRACEP",
NULL, 0, pvar, NULL, 8, POFF(p_tracep), LONG, "lx"},
+ {"label", "LABEL", NULL, LJUST|DSIZ, label, s_label, SHRT_MAX, 0, CHAR,
+ NULL},
{"lim", "LIM", NULL, 0, maxrss, NULL, 5},
{"login", "LOGIN", NULL, LJUST, logname, NULL, MAXLOGNAME-1},
{"logname", "", "login"},
==== //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/print.c#2 (text+ko) ====
@@ -45,6 +45,7 @@
#include <sys/proc.h>
#include <sys/stat.h>
+#include <sys/mac.h>
#include <sys/ucred.h>
#include <sys/user.h>
#include <sys/sysctl.h>
@@ -1049,3 +1050,53 @@
else
(void)printf("%*s", v->width, "-");
}
+
+void
+label(KINFO *k, VARENT *ve)
+{
+ char *string;
+ VAR *v;
+ mac_t proclabel;
+ int error;
+
+ v = ve->var;
+ string = NULL;
+ if (mac_prepare_process_label(&proclabel) == -1) {
+ perror("mac_prepare_process_label");
+ goto out;
+ }
+ error = mac_get_pid(KI_PROC(k)->p_pid, proclabel);
+ if (error == 0) {
+ if (mac_to_text(proclabel, &string) == -1)
+ string = NULL;
+ }
+ mac_free(proclabel);
+ out:
+ if (string != NULL) {
+ (void)printf("%-*s", v->width, string);
+ free(string);
+ } else
+ (void)printf("%-*s", v->width, "");
+ return;
+}
+
+int
+s_label(KINFO *k)
+{
+ char *string = NULL;
+ mac_t proclabel;
+ int error, size = 0;
+
+ error = mac_prepare_process_label(&proclabel);
+ if (error != 0) {
+ perror("mac_prepare_process_label");
+ return (0);
+ }
+ error = mac_get_pid(KI_PROC(k)->p_pid, proclabel);
+ if (error == 0 && mac_to_text(proclabel, &string) == 0) {
+ size = strlen(string);
+ free(string);
+ }
+ mac_free(proclabel);
+ return (size);
+}
==== //depot/projects/trustedbsd/sedarwin/other/adv_cmds/ps.tproj/ps.c#2 (text+ko) ====
@@ -108,6 +108,7 @@
char ufmt[] = "user pid %cpu %mem vsz rss tt state start time command";
char mfmt[] = "user pid tt %cpu state pri stime utime command";
char vfmt[] = "pid state time sl re pagein vsz rss lim tsiz %cpu %mem command";
+char Zfmt[] = "label";
int mflg = 0; /* if -M option to display all mach threads */
int print_thread_num=0;
@@ -157,9 +158,9 @@
memf = _PATH_MEM;
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
- "aCceghjLlMmO:o:p:rSTt:U:uvwx")) != -1)
+ "aCceghjLlMmO:o:p:rSTt:U:uvwxZ")) != -1)
#endif
switch((char)ch) {
case 'a':
@@ -299,6 +300,10 @@
case 'x':
xflg = 1;
break;
+ case 'Z':
+ parsefmt(Zfmt);
+ Zfmt[0] = '\0';
+ break;
case '?':
default:
usage();
@@ -743,7 +748,7 @@
{
(void)fprintf(stderr, "%s\n%s\n%s\n",
- "usage: ps [-aChjlmMrSTuvwx] [-O|o fmt] [-p pid] [-t tty] [-U user]",
+ "usage: ps [-aChjlmMrSTuvwxZ] [-O|o fmt] [-p pid] [-t tty] [-U user]",
" [-N system] [-W swap]",
" ps [-L]");
exit(1);
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list