#ifndef lint
static char copyright[] =
"@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n";
static char *rcsid = "$Id: proc.c,v 1.46 2010/07/29 15:59:28 abe Exp $";
#endif
#include "lsof.h"
_PROTOTYPE(static int is_file_sel,(struct lproc *lp, struct lfile *lf));
void
add_nma(cp, len)
char *cp;
int len;
{
int nl;
if (!cp || !len)
return;
if (Lf->nma) {
nl = (int)strlen(Lf->nma);
Lf->nma = (char *)realloc((MALLOC_P *)Lf->nma,
(MALLOC_S)(len + nl + 2));
} else {
nl = 0;
Lf->nma = (char *)malloc((MALLOC_S)(len + 1));
}
if (!Lf->nma) {
(void) fprintf(stderr, "%s: no name addition space: PID %ld, FD %s",
Pn, (long)Lp->pid, Lf->fd);
Exit(1);
}
if (nl) {
Lf->nma[nl] = ' ';
(void) strncpy(&Lf->nma[nl + 1], cp, len);
Lf->nma[nl + 1 + len] = '\0';
} else {
(void) strncpy(Lf->nma, cp, len);
Lf->nma[len] = '\0';
}
}
#if defined(HASFSTRUCT)
_PROTOTYPE(static char *alloc_fflbuf,(char **bp, int *al, int lr));
static char *
alloc_fflbuf(bp, al, lr)
char **bp;
int *al;
int lr;
{
int sz;
sz = (int)(lr + 1);
if (*bp && (sz <= *al))
return(*bp);
if (*bp)
*bp = (char *)realloc((MALLOC_P *)*bp, (MALLOC_S)sz);
else
*bp = (char *)malloc((MALLOC_S)sz);
if (!*bp) {
(void) fprintf(stderr, "%s: no space (%d) for print flags\n",
Pn, sz);
Exit(1);
}
*al = sz;
return(*bp);
}
#endif
void
alloc_lfile(nm, num)
char *nm;
int num;
{
int fds;
if (Lf) {
if (Lf->dev_ch)
(void) free((FREE_P *)Lf->dev_ch);
if (Lf->nm)
(void) free((FREE_P *)Lf->nm);
if (Lf->nma)
(void) free((FREE_P *)Lf->nma);
#if defined(HASLFILEADD) && defined(CLRLFILEADD)
CLRLFILEADD(Lf)
#endif
} else if (!(Lf = (struct lfile *)malloc(sizeof(struct lfile)))) {
(void) fprintf(stderr, "%s: no local file space at PID %d\n",
Pn, Lp->pid);
Exit(1);
}
Lf->access = Lf->lock = ' ';
Lf->dev_def = Lf->inp_ty = Lf->is_com = Lf->is_nfs = Lf->is_stream
= Lf->lmi_srch = Lf->nlink_def = Lf->off_def = Lf->sz_def
= Lf->rdev_def
= (unsigned char)0;
Lf->li[0].af = Lf->li[1].af = 0;
Lf->lts.type = -1;
Lf->nlink = 0l;
#if defined(HASMNTSTAT)
Lf->mnt_stat = (unsigned char)0;
#endif
#if defined(HASSOOPT)
Lf->lts.kai = Lf->lts.ltm = 0;
Lf->lts.opt = Lf->lts.qlen = Lf->lts.qlim = Lf->lts.pqlen
= (unsigned int)0;
Lf->lts.rbsz = Lf->lts.sbsz = (unsigned long)0;
Lf->lts.qlens = Lf->lts.qlims = Lf->lts.pqlens = Lf->lts.rbszs
= Lf->lts.sbszs = (unsigned char)0;
#endif
#if defined(HASSOSTATE)
Lf->lts.ss = 0;
#endif
#if defined(HASTCPOPT)
Lf->lts.mss = (unsigned long)0;
Lf->lts.msss = (unsigned char)0;
Lf->lts.topt = (unsigned int)0;
#endif
#if defined(HASTCPTPIQ)
Lf->lts.rqs = Lf->lts.sqs = (unsigned char)0;
#endif
#if defined(HASTCPTPIW)
Lf->lts.rws = Lf->lts.wws = (unsigned char)0;
#endif
#if defined(HASFSINO)
Lf->fs_ino = 0;
#endif
#if defined(HASVXFS) && defined(HASVXFSDNLC)
Lf->is_vxfs = 0;
#endif
Lf->inode = (INODETYPE)0;
Lf->off = (SZOFFTYPE)0;
if (Lp->pss & PS_PRI)
Lf->sf = Lp->sf;
else
Lf->sf = 0;
Lf->iproto[0] = Lf->type[0] = '\0';
if (nm) {
(void) strncpy(Lf->fd, nm, FDLEN - 1);
Lf->fd[FDLEN - 1] = '\0';
} else if (num >= 0) {
if (num < 10000)
(void) snpf(Lf->fd, sizeof(Lf->fd), "%4d", num);
else
(void) snpf(Lf->fd, sizeof(Lf->fd), "*%03d", num % 1000);
} else
Lf->fd[0] = '\0';
Lf->dev_ch = Lf->fsdir = Lf->fsdev = Lf->nm = Lf->nma = (char *)NULL;
Lf->ch = -1;
#if defined(HASNCACHE) && HASNCACHE<2
Lf->na = (KA_T)NULL;
#endif
Lf->next = (struct lfile *)NULL;
Lf->ntype = Ntype = N_REGLR;
Namech[0] = '\0';
#if defined(HASFSTRUCT)
Lf->fct = Lf->ffg = Lf->pof = (long)0;
Lf->fna = (KA_T)NULL;
Lf->fsv = (unsigned char)0;
#endif
#if defined(HASLFILEADD) && defined(SETLFILEADD)
SETLFILEADD
#endif
if (!Fdl || (!nm && num < 0))
return;
fds = ck_fd_status(nm, num);
switch (FdlTy) {
case 0:
if (fds == 2)
Lf->sf |= SELFD;
break;
case 1:
if (fds != 1)
Lf->sf |= SELFD;
}
}
void
alloc_lproc(pid, pgid, ppid, uid, cmd, pss, sf)
int pid;
int pgid;
int ppid;
UID_ARG uid;
char *cmd;
int pss;
int sf;
{
static int sz = 0;
if (!Lproc) {
if (!(Lproc = (struct lproc *)malloc(
(MALLOC_S)(LPROCINCR * sizeof(struct lproc)))))
{
(void) fprintf(stderr,
"%s: no malloc space for %d local proc structures\n",
Pn, LPROCINCR);
Exit(1);
}
sz = LPROCINCR;
} else if ((Nlproc + 1) > sz) {
sz += LPROCINCR;
if (!(Lproc = (struct lproc *)realloc((MALLOC_P *)Lproc,
(MALLOC_S)(sz * sizeof(struct lproc)))))
{
(void) fprintf(stderr,
"%s: no realloc space for %d local proc structures\n",
Pn, sz);
Exit(1);
}
}
Lp = &Lproc[Nlproc++];
Lp->pid = pid;
#if defined(HASTASKS)
Lp->tid = 0;
#endif
Lp->pgid = pgid;
Lp->ppid = ppid;
Lp->file = (struct lfile *)NULL;
Lp->sf = (short)sf;
Lp->pss = (short)pss;
Lp->uid = (uid_t)uid;
if (!(Lp->cmd = mkstrcpy(cmd, (MALLOC_S *)NULL))) {
(void) fprintf(stderr, "%s: PID %d, no space for command name: ",
Pn, pid);
safestrprt(cmd, stderr, 1);
Exit(1);
}
#if defined(HASZONES)
Lp->zn = (char *)NULL;
#endif
#if defined(HASSELINUX)
Lp->cntx = (char *)NULL;
#endif
}
extern int
ck_fd_status(nm, num)
char *nm;
int num;
{
char *cp;
struct fd_lst *fp;
if (!(fp = Fdl) || (!nm && num < 0))
return(0);
if ((cp = nm)) {
while (*cp && *cp == ' ')
cp++;
}
if (FdlTy == 1) {
for (; fp; fp = fp->next) {
if (cp) {
if (fp->nm && strcmp(fp->nm, cp) == 0)
return(1);
continue;
}
if (num >= fp->lo && num <= fp->hi)
return(1);
}
return(0);
}
for (; fp; fp = fp->next) {
if (cp) {
if (fp->nm && strcmp(fp->nm, cp) == 0)
return(2);
continue;
}
if (num >= fp->lo && num <= fp->hi)
return(2);
}
return(0);
}
int
comppid(a1, a2)
COMP_P *a1, *a2;
{
struct lproc **p1 = (struct lproc **)a1;
struct lproc **p2 = (struct lproc **)a2;
if ((*p1)->pid < (*p2)->pid)
return(-1);
if ((*p1)->pid > (*p2)->pid)
return(1);
#if defined(HASTASKS)
if ((*p1)->tid < (*p2)->tid)
return(-1);
if ((*p1)->tid > (*p2)->tid)
return(1);
#endif
return(0);
}
void
ent_inaddr(la, lp, fa, fp, af)
unsigned char *la;
int lp;
unsigned char *fa;
int fp;
int af;
{
int m;
if (la) {
Lf->li[0].af = af;
#if defined(HASIPv6)
if (af == AF_INET6)
Lf->li[0].ia.a6 = *(struct in6_addr *)la;
else
#endif
Lf->li[0].ia.a4 = *(struct in_addr *)la;
Lf->li[0].p = lp;
} else
Lf->li[0].af = 0;
if (fa) {
Lf->li[1].af = af;
#if defined(HASIPv6)
if (af == AF_INET6)
Lf->li[1].ia.a6 = *(struct in6_addr *)fa;
else
#endif
Lf->li[1].ia.a4 = *(struct in_addr *)fa;
Lf->li[1].p = fp;
} else
Lf->li[1].af = 0;
if ((Selflags & SELNA) && Nwad) {
m = (fa && is_nw_addr(fa, fp, af)) ? 1 : 0;
m |= (la && is_nw_addr(la, lp, af)) ? 1 : 0;
if (m)
Lf->sf |= SELNA;
}
}
int
examine_lproc()
{
int sbp = 0;
if (RptTm)
return(0);
if ((Lp->sf & SELPID) && !Selall) {
if ((Selflags == SELPID)
|| (Fand && (Selflags & SELPID))) {
sbp = 1;
Npuns--;
}
}
if (Lp->pss && Npid == 1 && sbp) {
print_init();
(void) print_proc();
PrPass++;
if (PrPass < 2)
(void) print_proc();
Lp->pss = 0;
}
if ( ! Lp->pss) {
(void) free_lproc(Lp);
Nlproc--;
}
return((sbp && Npuns == 0) ? 1 : 0);
}
void
free_lproc(lp)
struct lproc *lp;
{
struct lfile *lf, *nf;
for (lf = lp->file; lf; lf = nf) {
if (lf->dev_ch) {
(void) free((FREE_P *)lf->dev_ch);
lf->dev_ch = (char *)NULL;
}
if (lf->nm) {
(void) free((FREE_P *)lf->nm);
lf->nm = (char *)NULL;
}
if (lf->nma) {
(void) free((FREE_P *)lf->nma);
lf->nma = (char *)NULL;
}
#if defined(HASLFILEADD) && defined(CLRLFILEADD)
CLRLFILEADD(lf)
#endif
nf = lf->next;
(void) free((FREE_P *)lf);
}
lp->file = (struct lfile *)NULL;
if (lp->cmd) {
(void) free((FREE_P *)lp->cmd);
lp->cmd = (char *)NULL;
}
}
int
is_cmd_excl(cmd, pss, sf)
char *cmd;
short *pss;
short *sf;
{
int i;
struct str_lst *sp;
if (Cmdl && Cmdnx) {
for (sp = Cmdl; sp; sp = sp->next) {
if (sp->x && !strncmp(sp->str, cmd, sp->len))
return(1);
}
}
if ((Selflags & SELCMD) == 0)
return(0);
for (sp = Cmdl; sp; sp = sp->next) {
if (!sp->x && !strncmp(sp->str, cmd, sp->len)) {
sp->f = 1;
*pss |= PS_PRI;
*sf |= SELCMD;
return(0);
}
}
for (i = 0; i < NCmdRxU; i++) {
if (!regexec(&CmdRx[i].cx, cmd, 0, NULL, 0)) {
CmdRx[i].mc = 1;
*pss |= PS_PRI;
*sf |= SELCMD;
return(0);
}
}
if (Selflags == SELCMD)
return(1);
return (Fand ? 1 : 0);
}
static int
is_file_sel(lp, lf)
struct lproc *lp;
struct lfile *lf;
{
if (!lf || !lf->sf)
return(0);
if (Lf->sf & SELEXCLF)
return(0);
#if defined(HASSECURITY) && defined(HASNOSOCKSECURITY)
if (Myuid && (Myuid != lp->uid)) {
if (!(lf->sf & (SELNA | SELNET)))
return(0);
}
#endif
if (Selall)
return(1);
if (Fand && ((lf->sf & Selflags) != Selflags))
return(0);
return(1);
}
int
#if defined(HASTASKS)
is_proc_excl(pid, pgid, uid, pss, sf, tid)
#else
is_proc_excl(pid, pgid, uid, pss, sf)
#endif
int pid;
int pgid;
UID_ARG uid;
short *pss;
short *sf;
#if defined(HASTASKS)
int tid;
#endif
{
int i, j;
*pss = *sf = 0;
#if defined(HASSECURITY)
# if !defined(HASNOSOCKSECURITY)
if (Myuid && Myuid != (uid_t)uid)
return(1);
# endif
#endif
if (Nuidexcl) {
for (i = j = 0; (i < Nuid) && (j < Nuidexcl); i++) {
if (!Suid[i].excl)
continue;
if (Suid[i].uid == (uid_t)uid)
return(1);
j++;
}
}
if (Npgidx) {
for (i = j = 0; (i < Npgid) && (j < Npgidx); i++) {
if (!Spgid[i].x)
continue;
if (Spgid[i].i == pgid)
return(1);
j++;
}
}
if (Npidx) {
for (i = j = 0; (i < Npid) && (j < Npidx); i++) {
if (!Spid[i].x)
continue;
if (Spid[i].i == pid)
return(1);
j++;
}
}
if (Selall) {
*pss = PS_PRI;
#if defined(HASSECURITY) && defined(HASNOSOCKSECURITY)
*sf = SELALL & ~(SELNA | SELNET);
#else
*sf = SELALL;
#endif
return(0);
}
if (Npgidi && (Selflags & SELPGID)) {
for (i = j = 0; (i < Npgid) && (j < Npgidi); i++) {
if (Spgid[i].x)
continue;
if (Spgid[i].i == pgid) {
Spgid[i].f = 1;
*pss = PS_PRI;
*sf = SELPGID;
if (Selflags == SELPGID)
return(0);
break;
}
j++;
}
if ((Selflags == SELPGID) && !*sf)
return(1);
}
if (Npidi && (Selflags & SELPID)) {
for (i = j = 0; (i < Npid) && (j < Npidi); i++) {
if (Spid[i].x)
continue;
if (Spid[i].i == pid) {
Spid[i].f = 1;
*pss = PS_PRI;
*sf |= SELPID;
if (Selflags == SELPID)
return(0);
break;
}
j++;
}
if ((Selflags == SELPID) && !*sf)
return(1);
}
if (Nuidincl && (Selflags & SELUID)) {
for (i = j = 0; (i < Nuid) && (j < Nuidincl); i++) {
if (Suid[i].excl)
continue;
if (Suid[i].uid == (uid_t)uid) {
Suid[i].f = 1;
*pss = PS_PRI;
*sf |= SELUID;
if (Selflags == SELUID)
return(0);
break;
}
j++;
}
if (Selflags == SELUID && (*sf & SELUID) == 0)
return(1);
}
#if defined(HASTASKS)
if ((Selflags & SELTASK) && tid) {
*pss = PS_PRI;
*sf |= SELTASK;
if ((Selflags == SELTASK)
|| (Fand && ((*sf & Selflags) == Selflags)))
return(0);
}
#endif
if ( ! *sf)
return((Fand && (Selflags & (SELPGID|SELPID|SELUID|SELTASK)))
? 1 : 0);
if (Selflags & (SELPGID|SELPID|SELUID|SELTASK)) {
if (Fand)
return(((Selflags & (SELPGID|SELPID|SELUID|SELTASK)) != *sf)
? 1 : 0);
return(0);
}
return(Fand ? 1 : 0);
}
void
link_lfile()
{
if (Lf->sf & SELEXCLF)
return;
Lp->pss |= PS_SEC;
if (Plf)
Plf->next = Lf;
else
Lp->file = Lf;
Plf = Lf;
if (Fnet && (Lf->sf & SELNET))
Fnet = 2;
if (Fnfs && (Lf->sf & SELNFS))
Fnfs = 2;
if (Ftask && (Lf->sf & SELTASK))
Ftask = 2;
Lf = (struct lfile *)NULL;
}
#if defined(HASFSTRUCT)
char *
print_fflags(ffg, pof)
long ffg;
long pof;
{
int al, ct, fx;
static int bl = 0;
static char *bp = (char *)NULL;
char *sep;
int sepl;
struct pff_tab *tp;
long wf;
char xbuf[64];
for (ct = fx = 0; fx < 2; fx++) {
if (fx == 0) {
sep = "";
sepl = 0;
tp = Pff_tab;
wf = ffg;
} else {
sep = ";";
sepl = 1;
tp = Pof_tab;
wf = pof;
}
for (; wf && !FsvFlagX; ct += al ) {
while (tp->nm) {
if (wf & tp->val)
break;
tp++;
}
if (!tp->nm)
break;
al = (int)strlen(tp->nm) + sepl;
bp = alloc_fflbuf(&bp, &bl, al + ct);
(void) snpf(bp + ct, al + 1, "%s%s", sep, tp->nm);
sep = ",";
sepl = 1;
wf &= ~(tp->val);
}
if (wf || FsvFlagX) {
(void) snpf(xbuf, sizeof(xbuf), "0x%lx", wf);
al = (int)strlen(xbuf) + sepl;
bp = alloc_fflbuf(&bp, &bl, al + ct);
(void) snpf(bp + ct, al + 1, "%s%s", sep, xbuf);
ct += al;
}
}
if (!bp) {
bp = alloc_fflbuf(&bp, &bl, 0);
*bp = '\0';
}
return(bp);
}
#endif
int
print_proc()
{
char buf[128], *cp;
int lc, len, st, ty;
int rv = 0;
unsigned long ul;
if (!Lp->pss)
return(0);
if (Fterse) {
#if defined(HASTASKS)
if (Lp->tid)
return(0);
#endif
for (Lf = Lp->file; Lf; Lf = Lf->next) {
if (is_file_sel(Lp, Lf)) {
(void) printf("%d\n", Lp->pid);
return(1);
}
}
return(0);
}
if (Ffield) {
for (Lf = Lp->file; Lf; Lf = Lf->next) {
if (is_file_sel(Lp, Lf))
break;
}
if (!Lf)
return(rv);
rv = 1;
(void) printf("%c%d%c", LSOF_FID_PID, Lp->pid, Terminator);
#if defined(HASTASKS)
if (FieldSel[LSOF_FIX_TID].st && Lp->tid)
(void) printf("%c%d%c", LSOF_FID_TID, Lp->tid, Terminator);
#endif
#if defined(HASZONES)
if (FieldSel[LSOF_FIX_ZONE].st && Fzone && Lp->zn)
(void) printf("%c%s%c", LSOF_FID_ZONE, Lp->zn, Terminator);
#endif
#if defined(HASSELINUX)
if (FieldSel[LSOF_FIX_CNTX].st && Fcntx && Lp->cntx && CntxStatus)
(void) printf("%c%s%c", LSOF_FID_CNTX, Lp->cntx, Terminator);
#endif
if (FieldSel[LSOF_FIX_PGID].st && Fpgid)
(void) printf("%c%d%c", LSOF_FID_PGID, Lp->pgid, Terminator);
#if defined(HASPPID)
if (FieldSel[LSOF_FIX_PPID].st && Fppid)
(void) printf("%c%d%c", LSOF_FID_PPID, Lp->ppid, Terminator);
#endif
if (FieldSel[LSOF_FIX_CMD].st) {
putchar(LSOF_FID_CMD);
safestrprt(Lp->cmd ? Lp->cmd : "(unknown)", stdout, 0);
putchar(Terminator);
}
if (FieldSel[LSOF_FIX_UID].st)
(void) printf("%c%d%c", LSOF_FID_UID, (int)Lp->uid, Terminator);
if (FieldSel[LSOF_FIX_LOGIN].st) {
cp = printuid((UID_ARG)Lp->uid, &ty);
if (ty == 0)
(void) printf("%c%s%c", LSOF_FID_LOGIN, cp, Terminator);
}
if (Terminator == '\0')
putchar('\n');
}
for (Lf = Lp->file; Lf; Lf = Lf->next) {
if (!is_file_sel(Lp, Lf))
continue;
rv = 1;
if (!Ffield) {
print_file();
continue;
}
lc = st = 0;
if (FieldSel[LSOF_FIX_FD].st) {
for (cp = Lf->fd; *cp == ' '; cp++)
;
if (*cp) {
(void) printf("%c%s%c", LSOF_FID_FD, cp, Terminator);
lc++;
}
}
if (FieldSel[LSOF_FIX_ACCESS].st) {
(void) printf("%c%c%c",
LSOF_FID_ACCESS, Lf->access, Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_LOCK].st) {
(void) printf("%c%c%c", LSOF_FID_LOCK, Lf->lock, Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_TYPE].st) {
for (cp = Lf->type; *cp == ' '; cp++)
;
if (*cp) {
(void) printf("%c%s%c", LSOF_FID_TYPE, cp, Terminator);
lc++;
}
}
#if defined(HASFSTRUCT)
if (FieldSel[LSOF_FIX_FA].st && (Fsv & FSV_FA)
&& (Lf->fsv & FSV_FA)) {
(void) printf("%c%s%c", LSOF_FID_FA,
print_kptr(Lf->fsa, (char *)NULL, 0), Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_CT].st && (Fsv & FSV_CT)
&& (Lf->fsv & FSV_CT)) {
(void) printf("%c%ld%c", LSOF_FID_CT, Lf->fct, Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_FG].st && (Fsv & FSV_FG)
&& (Lf->fsv & FSV_FG) && (FsvFlagX || Lf->ffg || Lf->pof)) {
(void) printf("%c%s%c", LSOF_FID_FG,
print_fflags(Lf->ffg, Lf->pof), Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_NI].st && (Fsv & FSV_NI)
&& (Lf->fsv & FSV_NI)) {
(void) printf("%c%s%c", LSOF_FID_NI,
print_kptr(Lf->fna, (char *)NULL, 0), Terminator);
lc++;
}
#endif
if (FieldSel[LSOF_FIX_DEVCH].st && Lf->dev_ch && Lf->dev_ch[0]) {
for (cp = Lf->dev_ch; *cp == ' '; cp++)
;
if (*cp) {
(void) printf("%c%s%c", LSOF_FID_DEVCH, cp, Terminator);
lc++;
}
}
if (FieldSel[LSOF_FIX_DEVN].st && Lf->dev_def) {
if (sizeof(unsigned long) > sizeof(dev_t))
ul = (unsigned long)((unsigned int)Lf->dev);
else
ul = (unsigned long)Lf->dev;
(void) printf("%c0x%lx%c", LSOF_FID_DEVN, ul, Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_RDEV].st && Lf->rdev_def) {
if (sizeof(unsigned long) > sizeof(dev_t))
ul = (unsigned long)((unsigned int)Lf->rdev);
else
ul = (unsigned long)Lf->rdev;
(void) printf("%c0x%lx%c", LSOF_FID_RDEV, ul, Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_SIZE].st && Lf->sz_def) {
putchar(LSOF_FID_SIZE);
#if defined(HASPRINTSZ)
cp = HASPRINTSZ(Lf);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_d, Lf->sz);
cp = buf;
#endif
(void) printf("%s", cp);
putchar(Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_OFFSET].st && Lf->off_def) {
putchar(LSOF_FID_OFFSET);
#if defined(HASPRINTOFF)
cp = HASPRINTOFF(Lf, 0);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_0t, Lf->off);
cp = buf;
#endif
len = strlen(cp);
if (OffDecDig && len > (OffDecDig + 2)) {
#if defined(HASPRINTOFF)
cp = HASPRINTOFF(Lf, 1);
#else
(void) snpf(buf, sizeof(buf), SzOffFmt_x, Lf->off);
cp = buf;
#endif
}
(void) printf("%s", cp);
putchar(Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_INODE].st && Lf->inp_ty == 1) {
putchar(LSOF_FID_INODE);
(void) printf(InodeFmt_d, Lf->inode);
putchar(Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_NLINK].st && Lf->nlink_def) {
(void) printf("%c%ld%c", LSOF_FID_NLINK, Lf->nlink, Terminator);
lc++;
}
if (FieldSel[LSOF_FIX_PROTO].st && Lf->inp_ty == 2) {
for (cp = Lf->iproto; *cp == ' '; cp++)
;
if (*cp) {
(void) printf("%c%s%c", LSOF_FID_PROTO, cp, Terminator);
lc++;
}
}
if (FieldSel[LSOF_FIX_STREAM].st && Lf->nm && Lf->is_stream) {
if (strncmp(Lf->nm, "STR:", 4) == 0
|| strcmp(Lf->iproto, "STR") == 0) {
putchar(LSOF_FID_STREAM);
printname(0);
putchar(Terminator);
lc++;
st++;
}
}
if (st == 0 && FieldSel[LSOF_FIX_NAME].st) {
putchar(LSOF_FID_NAME);
printname(0);
putchar(Terminator);
lc++;
}
if (Lf->lts.type >= 0 && FieldSel[LSOF_FIX_TCPTPI].st) {
print_tcptpi(0);
lc++;
}
if (Terminator == '\0' && lc)
putchar('\n');
}
return(rv);
}