|
| 1 | +/* |
| 2 | + * dprint.c -- Darwin file processing functions for libproc-based lsof |
| 3 | + */ |
| 4 | + |
| 5 | +/* |
| 6 | + * Portions Copyright 2005-2007 Apple Inc. All rights reserved. |
| 7 | + * |
| 8 | + * Copyright 2005 Purdue Research Foundation, West Lafayette, Indiana |
| 9 | + * 47907. All rights reserved. |
| 10 | + * |
| 11 | + * Written by Allan Nathanson, Apple Inc., and Victor A. Abell, Purdue |
| 12 | + * University. |
| 13 | + * |
| 14 | + * This software is not subject to any license of the American Telephone |
| 15 | + * and Telegraph Company or the Regents of the University of California. |
| 16 | + * |
| 17 | + * Permission is granted to anyone to use this software for any purpose on |
| 18 | + * any computer system, and to alter it and redistribute it freely, subject |
| 19 | + * to the following restrictions: |
| 20 | + * |
| 21 | + * 1. Neither the authors, nor Apple Inc. nor Purdue University are |
| 22 | + * responsible for any consequences of the use of this software. |
| 23 | + * |
| 24 | + * 2. The origin of this software must not be misrepresented, either |
| 25 | + * by explicit claim or by omission. Credit to the authors, Apple |
| 26 | + * Inc. and Purdue University must appear in documentation and sources. |
| 27 | + * |
| 28 | + * 3. Altered versions must be plainly marked as such, and must not be |
| 29 | + * misrepresented as being the original software. |
| 30 | + * |
| 31 | + * 4. This notice may not be removed or altered. |
| 32 | + */ |
| 33 | + |
| 34 | +#ifndef lint |
| 35 | +static char copyright[] = "@(#) Copyright 2005-2007 Apple Inc. and Purdue " |
| 36 | + "Research Foundation.\nAll rights reserved.\n"; |
| 37 | +#endif |
| 38 | + |
| 39 | +#include "common.h" |
| 40 | + |
| 41 | +#if defined(PROC_FP_GUARDED) |
| 42 | +extern struct pff_tab Pgf_tab[]; |
| 43 | +#endif /* defined(PROC_FP_GUARDED) */ |
| 44 | + |
| 45 | +/* |
| 46 | + * print_nm() -- print Name column |
| 47 | + */ |
| 48 | +void print_nm(struct lsof_context *ctx, struct lfile *lf) { |
| 49 | + unsigned char extra = 0; |
| 50 | + |
| 51 | + printname(ctx, 0); |
| 52 | + |
| 53 | +#if defined(PROC_PIDLISTFILEPORTS) |
| 54 | + if (lf->fileport) |
| 55 | + extra++; |
| 56 | +#endif /* defined(PROC_PIDLISTFILEPORTS) */ |
| 57 | + |
| 58 | +#if defined(PROC_FP_GUARDED) |
| 59 | + if (lf->guardflags) |
| 60 | + extra++; |
| 61 | +#endif /* defined(PROC_FP_GUARDED) */ |
| 62 | + |
| 63 | + if (extra) |
| 64 | + (void)printf(" ("); |
| 65 | + |
| 66 | +#if defined(PROC_PIDLISTFILEPORTS) |
| 67 | + if (lf->fileport) |
| 68 | + (void)printf("fileport=0x%04x", lf->fileport); |
| 69 | +#endif /* defined(PROC_PIDLISTFILEPORTS) */ |
| 70 | + |
| 71 | +#if defined(PROC_FP_GUARDED) |
| 72 | + if (extra > 1) |
| 73 | + putchar(','); |
| 74 | + if (lf->guardflags) { |
| 75 | + struct pff_tab *tp; |
| 76 | + long gf; |
| 77 | + |
| 78 | + (void)printf("guard="); |
| 79 | + tp = Pgf_tab; |
| 80 | + gf = lf->guardflags; |
| 81 | + while (gf && !FsvFlagX) { |
| 82 | + while (tp->nm) { |
| 83 | + if (gf & tp->val) |
| 84 | + break; |
| 85 | + tp++; |
| 86 | + } |
| 87 | + if (!tp->nm) |
| 88 | + break; |
| 89 | + gf &= ~(tp->val); |
| 90 | + (void)printf("%s%s", tp->nm, gf ? "," : ""); |
| 91 | + } |
| 92 | + /* |
| 93 | + * If flag bits remain, print them in hex. If hex output was |
| 94 | + * specified with +fG, print all flag values, including zero, |
| 95 | + * in hex. |
| 96 | + */ |
| 97 | + if (gf || FsvFlagX) |
| 98 | + (void)printf("0x%lx", gf); |
| 99 | + } |
| 100 | +#endif /* defined(PROC_FP_GUARDED) */ |
| 101 | + |
| 102 | + if (extra) |
| 103 | + (void)printf(")\n"); |
| 104 | + else |
| 105 | + putchar('\n'); |
| 106 | +} |
0 commit comments