diff --git a/Makefile.am b/Makefile.am index 8a23bed5..79335061 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,7 +8,7 @@ EXTRA_DIST += tests/00README tests/TestDB tests/CkTestDB tests/Makefile tests/Ls # Dialect neutral sources lsof_SOURCES = src/arg.c src/main.c lib/node.c src/print.c src/ptti.c src/store.c src/usage.c src/util.c \ lib/ckkv.c lib/cvfs.c lib/dvch.c lib/fino.c lib/isfn.c lib/lkud.c lib/misc.c lib/pdvn.c lib/prfp.c lib/print.c lib/proc.c lib/ptti.c lib/rdev.c lib/rnmt.c lib/rmnt.c lib/rnam.c lib/rnch.c lib/rnmh.c -lsof_SOURCES += lib/common.h include/lsof_fields.h lib/proto.h lib/hash.h +lsof_SOURCES += lib/common.h include/lsof_fields.h lib/proto.h lib/hash.h src/cli.h include_HEADERS = include/lsof.h include/lsof_fields.h DIALECT_ROOT = $(top_srcdir)/lib/dialects DIALECT_PATH = $(DIALECT_ROOT)/$(LSOF_DIALECT_DIR) diff --git a/lib/ckkv.c b/lib/ckkv.c index 2c1b792a..45260489 100644 --- a/lib/ckkv.c +++ b/lib/ckkv.c @@ -39,11 +39,11 @@ * ckkv() - check kernel version */ -void ckkv(d, er, ev, ea) char *d; /* dialect */ -char *er; /* expected revision; NULL, no test */ -char *ev; /* expected version; NULL, no test */ -char *ea; /* expected architecture; NULL, no - * test */ +void ckkv(struct lsof_context *ctx, /* context */ + char *d, /* dialect */ + char *er, /* expected revision; NULL, no test */ + char *ev, /* expected version; NULL, no test */ + char *ea) /* expected architecture; NULL, no test */ { # if defined(HASKERNIDCK) @@ -56,7 +56,7 @@ char *ea; /* expected architecture; NULL, no */ if (uname(&u) < 0) { (void)fprintf(stderr, "%s: uname error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (er && strcmp(er, u.release)) { (void)fprintf(stderr, diff --git a/lib/common.h b/lib/common.h index 28ac7311..14194bcf 100644 --- a/lib/common.h +++ b/lib/common.h @@ -1120,6 +1120,9 @@ typedef struct znhash { extern znhash_t **ZoneArg; # endif /* defined(HASZONES) */ +struct lsof_context { +}; + # include "proto.h" # include "dproto.h" diff --git a/lib/cvfs.c b/lib/cvfs.c index ee079a18..59d01f54 100644 --- a/lib/cvfs.c +++ b/lib/cvfs.c @@ -48,8 +48,9 @@ * completevfs() - complete local vfs structure */ -void completevfs(vfs, dev) struct l_vfs *vfs; /* local vfs structure pointer */ -dev_t *dev; /* device */ +void completevfs(struct lsof_context *ctx, /* context */ + struct l_vfs *vfs, /* local vfs structure pointer */ + dev_t *dev) /* device */ { struct mounts *mp; /* @@ -61,7 +62,7 @@ dev_t *dev; /* device */ /* * Search for a match on device number. */ - for (mp = readmnt(); mp; mp = mp->next) { + for (mp = readmnt(ctx); mp; mp = mp->next) { if (mp->dev == *dev) { # if defined(CVFS_DEVSAVE) diff --git a/lib/dialects/aix/ddev.c b/lib/dialects/aix/ddev.c index ecb9b530..e110d6d2 100644 --- a/lib/dialects/aix/ddev.c +++ b/lib/dialects/aix/ddev.c @@ -46,7 +46,8 @@ static char copyright[] = * Local function prototypes */ -_PROTOTYPE(static int rmdupdev, (struct l_dev * **dp, int n, char *nm)); +static int rmdupdev(struct lsof_context *ctx, struct l_dev ***dp, int n, + char *nm); #if defined(HASDCACHE) && AIXV >= 4140 @@ -54,7 +55,7 @@ _PROTOTYPE(static int rmdupdev, (struct l_dev * **dp, int n, char *nm)); * clr_sect() - clear cached clone and pseudo sections */ -void clr_sect() { +void clr_sect(struct lsof_context *ctx) { struct clone *c, *c1; if (Clone) { @@ -73,8 +74,7 @@ void clr_sect() { * getchan() - get channel from file path name */ -int getchan(p) -char *p; /* file path name */ +int getchan(char *p) /* file path name */ { int ch; char *s; @@ -101,17 +101,17 @@ char *p; /* file path name */ * printdevname() - print device name */ -int printdevname(dev, rdev, f, nty) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ -int f; /* 1 = follow with '\n' */ -int nty; /* node type: N_BLK or N_CHR */ +int printdevname(struct lsof_context *ctx, /* context */ + dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int f, /* 1 = follow with '\n' */ + int nty) /* node type: N_BLK or N_CHR */ { struct l_dev *dp; /* * Search device table for a full match. */ - if ((dp = lkupdev(dev, rdev, 1, 1))) { + if ((dp = lkupdev(ctx, dev, rdev, 1, 1))) { if (Lf->ch < 0) safestrprt(dp->name, stdout, f); else { @@ -123,7 +123,7 @@ int nty; /* node type: N_BLK or N_CHR */ /* * Search device table for a match without inode number and dev. */ - if ((dp = lkupdev(&DevDev, rdev, 0, 1))) { + if ((dp = lkupdev(ctx, &DevDev, rdev, 0, 1))) { /* * A raw device match was found. Record it as a name column addition. @@ -136,10 +136,10 @@ int nty; /* node type: N_BLK or N_CHR */ if (!(cp = (char *)malloc((MALLOC_S)(len + 1)))) { (void)fprintf(stderr, "%s: no nma space for: (%s %s)\n", Pn, ttl, dp->name); - Error(); + Error(ctx); } (void)snpf(cp, len + 1, "(%s %s)", ttl, dp->name); - (void)add_nma(cp, len); + (void)add_nma(ctx, cp, len); (void)free((MALLOC_P *)cp); return (0); } @@ -150,7 +150,8 @@ int nty; /* node type: N_BLK or N_CHR */ * readdev() - read device names, modes and types */ -void readdev(skip) int skip; /* skip device cache read if 1 */ +void readdev(struct lsof_context *ctx, /* context */ + int skip) /* skip device cache read if 1 */ { #if defined(HASDCACHE) @@ -184,7 +185,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ */ if (!skip) { if (DCstate == 2 || DCstate == 3) { - if ((dcrd = read_dcache()) == 0) + if ((dcrd = read_dcache(ctx)) == 0) return; } } else @@ -203,7 +204,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ Dstk = (char **)NULL; Dstkn = Dstkx = 0; - (void)stkdir("/dev"); + (void)stkdir(ctx, "/dev"); /* * Unstack the next /dev or /dev/ directory. */ @@ -229,7 +230,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ mkstrcat(Dstk[Dstkx], -1, "/", 1, (char *)NULL, -1, &pl))) { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(Dstk[Dstkx], stderr, 1); - Error(); + Error(ctx); } (void)free((FREE_P *)Dstk[Dstkx]); Dstk[Dstkx] = (char *)NULL; @@ -251,7 +252,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(path, stderr, 0); safestrprt(dp->d_name, stderr, 1); - Error(); + Error(ctx); } #if defined(USE_STAT) @@ -280,7 +281,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * If it's a subdirectory, stack its name for later processing. */ if ((sb.st_mode & S_IFMT) == S_IFDIR) { - (void)stkdir(fp); + (void)stkdir(ctx, fp); continue; } if ((sb.st_mode & S_IFMT) == S_IFCHR) { @@ -300,7 +301,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!Devtp) { (void)fprintf( stderr, "%s: no space for character device\n", Pn); - Error(); + Error(ctx); } } Devtp[i].rdev = sb.st_rdev; @@ -308,7 +309,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!(Devtp[i].name = mkstrcpy(fp, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } Devtp[i].v = 0; i++; @@ -323,13 +324,13 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for clone device: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } if (!(c->cd.name = mkstrcpy(fp, (MALLOC_S)NULL))) { (void)fprintf(stderr, "%s: no space for clone name: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } c->cd.inode = (INODETYPE)sb.st_ino; c->cd.rdev = sb.st_rdev; @@ -360,7 +361,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!BDevtp) { (void)fprintf(stderr, "%s: no space for block device\n", Pn); - Error(); + Error(ctx); } } BDevtp[j].rdev = sb.st_rdev; @@ -403,14 +404,14 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (MALLOC_S)(sizeof(struct l_dev *) * BNdev)))) { (void)fprintf(stderr, "%s: no space for block device sort pointers\n", Pn); - Error(); + Error(ctx); } for (j = 0; j < BNdev; j++) { BSdev[j] = &BDevtp[j]; } (void)qsort((QSORT_P *)BSdev, (size_t)BNdev, (size_t)sizeof(struct l_dev *), compdev); - BNdev = rmdupdev(&BSdev, BNdev, "block"); + BNdev = rmdupdev(ctx, &BSdev, BNdev, "block"); } else { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: no block devices found\n", Pn); @@ -428,17 +429,17 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for character device sort pointers\n", Pn); - Error(); + Error(ctx); } for (i = 0; i < Ndev; i++) { Sdev[i] = &Devtp[i]; } (void)qsort((QSORT_P *)Sdev, (size_t)Ndev, (size_t)sizeof(struct l_dev *), compdev); - Ndev = rmdupdev(&Sdev, Ndev, "char"); + Ndev = rmdupdev(ctx, &Sdev, Ndev, "char"); } else { (void)fprintf(stderr, "%s: no character devices found\n", Pn); - Error(); + Error(ctx); } #if defined(HASDCACHE) @@ -446,7 +447,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * Write device cache file, as required. */ if (DCstate == 1 || (DCstate == 3 && dcrd)) - write_dcache(); + write_dcache(ctx); #endif /* defined(HASDCACHE) */ } @@ -455,14 +456,14 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * rereaddev() - reread device names, modes and types */ -void rereaddev() { - (void)clr_devtab(); +void rereaddev(struct lsof_context *ctx) { + (void)clr_devtab(ctx); # if defined(DCACHE_CLR) - (void)DCACHE_CLR(); + (void)DCACHE_CLR(ctx); # endif /* defined(DCACHE_CLR) */ - readdev(1); + readdev(ctx, 1); DCunsafe = 0; } #endif /* defined(HASDCACHE) */ @@ -471,10 +472,10 @@ void rereaddev() { * rmdupdev() - remove duplicate (major/minor/inode) devices */ -static int rmdupdev(dp, n, nm) -struct l_dev ***dp; /* device table pointers address */ -int n; /* number of pointers */ -char *nm; /* device table name for error message */ +static int rmdupdev(struct lsof_context *ctx, /* context */ + struct l_dev ***dp, /* device table pointers address */ + int n, /* number of pointers */ + char *nm) /* device table name for error message */ { #if AIXV >= 4140 @@ -519,7 +520,7 @@ char *nm; /* device table name for error message */ if (!(*dp = (struct l_dev **)realloc( (MALLOC_P *)*dp, (MALLOC_S)(j * sizeof(struct l_dev *))))) { (void)fprintf(stderr, "%s: can't realloc %s device pointers\n", Pn, nm); - Error(); + Error(ctx); } return (j); } @@ -529,8 +530,8 @@ char *nm; /* device table name for error message */ * rw_clone_sect() - read/write the device cache file clone section */ -int rw_clone_sect(m) -int m; /* mode: 1 = read; 2 = write */ +int rw_clone_sect(struct lsof_context *ctx, /* context */ + int m) /* mode: 1 = read; 2 = write */ { char buf[MAXPATHLEN * 2], *cp; struct clone *c; @@ -578,7 +579,7 @@ int m; /* mode: 1 = read; 2 = write */ if (!(c = (struct clone *)calloc(1, sizeof(struct clone)))) { (void)fprintf(stderr, "%s: no space for cached clone: ", Pn); safestrprt(buf, stderr, 1); - Error(); + Error(ctx); } /* * Enter the clone device number. @@ -616,7 +617,7 @@ int m; /* mode: 1 = read; 2 = write */ (void)fprintf(stderr, "%s: no space for cached clone path: ", Pn); safestrprt(buf, stderr, 1); - Error(); + Error(ctx); } c->cd.v = 0; c->next = Clone; @@ -650,7 +651,7 @@ int m; /* mode: 1 = read; 2 = write */ * A shouldn't-happen case: mode neither 1 nor 2. */ (void)fprintf(stderr, "%s: internal rw_clone_sect error: %d\n", Pn, m); - Error(); + Error(ctx); } #endif /* defined(HASDCACHE) && AIXV>=4140 */ @@ -661,8 +662,8 @@ int m; /* mode: 1 = read; 2 = write */ * Note: rereads entire device table when an entry can't be verified. */ -int vfy_dev(dp) -struct l_dev *dp; /* device table pointer */ +int vfy_dev(struct lsof_context *ctx, /* context */ + struct l_dev *dp) /* device table pointer */ { struct stat sb; @@ -676,7 +677,7 @@ struct l_dev *dp; /* device table pointer */ # endif /* defined(USE_STAT) */ || dp->rdev != sb.st_rdev || dp->inode != (INODETYPE)sb.st_ino) { - (void)rereaddev(); + (void)rereaddev(ctx); return (0); } dp->v = 1; diff --git a/lib/dialects/aix/dfile.c b/lib/dialects/aix/dfile.c index 97d3f616..0d7cbf12 100644 --- a/lib/dialects/aix/dfile.c +++ b/lib/dialects/aix/dfile.c @@ -101,7 +101,7 @@ static int HbyNmCt = 0; /* HbyNm entry count */ * hashSfile() - hash Sfile entries for use in is_file_named() searches */ -void hashSfile() { +void hashSfile(struct lsof_context *ctx) { static int hs = 0; int i; struct sfile *s; @@ -121,35 +121,35 @@ void hashSfile() { (void)fprintf( stderr, "%s: can't allocate space for %d (dev,ino) hash buckets\n", Pn, SFDIHASH); - Error(); + Error(ctx); } if (!(HbyFrd = (struct hsfile *)calloc((MALLOC_S)SFRDHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d rdev hash buckets\n", Pn, SFRDHASH); - Error(); + Error(ctx); } if (!(HbyFsd = (struct hsfile *)calloc((MALLOC_S)SFFSHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d file sys hash buckets\n", Pn, SFFSHASH); - Error(); + Error(ctx); } if (!(HbyMPC = (struct hsfile *)calloc((MALLOC_S)SFMPCHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d MPC file hash buckets\n", Pn, SFMPCHASH); - Error(); + Error(ctx); } if (!(HbyNm = (struct hsfile *)calloc((MALLOC_S)SFNMHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d name hash buckets\n", Pn, SFNMHASH); - Error(); + Error(ctx); } hs++; /* @@ -203,7 +203,7 @@ void hashSfile() { (void)fprintf(stderr, "%s: can't allocate hsfile bucket for: %s\n", Pn, s->aname); - Error(); + Error(ctx); } sn->s = s; sn->next = sh->next; @@ -217,12 +217,12 @@ void hashSfile() { * is_file_named() - is file named? */ -int is_file_named(p, ty, ch, ic) -char *p; /* path name; NULL = search by device - * and inode (from *Lf) */ -enum vtype ty; /* vnode type */ -chan_t ch; /* gnode channel */ -int ic; /* is clone file (4.1.4 and above) */ +int is_file_named(struct lsof_context *ctx, /* context */ + char *p, /* path name; NULL = search by device + * and inode (from *Lf) */ + enum vtype ty, /* vnode type */ + chan_t ch, /* gnode channel */ + int ic) /* is clone file (4.1.4 and above) */ { int dmaj, dmin, maj, min, rmaj, rmin; static int dsplit = 0; @@ -239,7 +239,7 @@ int ic; /* is clone file (4.1.4 and above) */ * be compared directly, but must be compared by extracting their major and * minor numbers and comparing them. */ - readdev(0); + readdev(ctx, 0); if (!dsplit) { dmaj = GET_MAJ_DEV(DevDev); dmin = GET_MIN_DEV(DevDev); @@ -363,11 +363,11 @@ int ic; /* is clone file (4.1.4 and above) */ */ (void)snpf(Namech, Namechl, "%s", s->name); if (ty == VMPC && s->ch < 0) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d", ch); } if (s->devnm) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, " (%s)", s->devnm); } } @@ -381,10 +381,8 @@ int ic; /* is clone file (4.1.4 and above) */ * print_dev() - print device */ -char *print_dev(lf, dev) -struct lfile *lf; /* file whose device to be printed */ -dev_t *dev; /* pointer to device to be printed */ - +char *print_dev(struct lfile *lf, /* file whose device to be printed */ + dev_t *dev) /* pointer to device to be printed */ { static char buf[128]; int maj = GET_MAJ_DEV(*dev); @@ -405,8 +403,8 @@ dev_t *dev; /* pointer to device to be printed */ * readvfs() - read vfs structure */ -struct l_vfs *readvfs(vn) -struct vnode *vn; /* vnode */ +struct l_vfs *readvfs(struct lsof_context *ctx, /* context */ + struct vnode *vn) /* vnode */ { struct gfs g; void *mp; @@ -424,14 +422,14 @@ struct vnode *vn; /* vnode */ } if (!(vp = (struct l_vfs *)malloc((MALLOC_S)sizeof(struct l_vfs)))) { (void)fprintf(stderr, "%s: PID %d, no space for vfs\n", Pn, Lp->pid); - Error(); + Error(ctx); } vp->dir = (char *)NULL; vp->fsname = (char *)NULL; /* * Read the vfs structure. */ - if (kread((KA_T)vn->v_vfsp, (char *)&v, sizeof(v))) { + if (kread(ctx, (KA_T)vn->v_vfsp, (char *)&v, sizeof(v))) { vfs_exit: (void)free((FREE_P *)vp); @@ -440,18 +438,19 @@ struct vnode *vn; /* vnode */ /* * Locate AIX mount information. */ - if (!v.vfs_gfs || kread((KA_T)v.vfs_gfs, (char *)&g, sizeof(g))) + if (!v.vfs_gfs || kread(ctx, (KA_T)v.vfs_gfs, (char *)&g, sizeof(g))) goto vfs_exit; if (!v.vfs_mdata || - kread((KA_T)((char *)v.vfs_mdata + offsetof(struct vmount, vmt_length)), + kread(ctx, + (KA_T)((char *)v.vfs_mdata + offsetof(struct vmount, vmt_length)), (char *)&ul, sizeof(ul))) goto vfs_exit; if (!(mp = (void *)malloc((MALLOC_S)ul))) { (void)fprintf(stderr, "%s: PID %d, no space for mount data\n", Pn, Lp->pid); - Error(); + Error(ctx); } - if (kread((KA_T)v.vfs_mdata, (char *)mp, (int)ul)) { + if (kread(ctx, (KA_T)v.vfs_mdata, (char *)mp, (int)ul)) { (void)free((FREE_P *)mp); goto vfs_exit; } @@ -507,7 +506,7 @@ struct vnode *vn; /* vnode */ readvfs_aix1: (void)fprintf(stderr, "%s: PID %d, readvfs, no space\n", Pn, Lp->pid); - Error(); + Error(ctx); } } else vp->dir = (char *)NULL; diff --git a/lib/dialects/aix/dmnt.c b/lib/dialects/aix/dmnt.c index a12bc8f3..98e2e877 100644 --- a/lib/dialects/aix/dmnt.c +++ b/lib/dialects/aix/dmnt.c @@ -46,7 +46,7 @@ static int Lmist = 0; /* Lmi status */ * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char *dir, *fs, *h, *ln, *ty; char *dn = (char *)NULL; struct mounts *mtp; @@ -91,7 +91,7 @@ struct mounts *readmnt() { dir = (char *)vmt2dataptr(v, VMT_STUB); fs = (char *)vmt2dataptr(v, VMT_OBJECT); h = (char *)vmt2dataptr(v, VMT_HOST); - if (statsafely(dir, &sb)) { + if (statsafely(ctx, dir, &sb)) { if (!Fwarn) { /* @@ -221,9 +221,9 @@ struct mounts *readmnt() { (void)fprintf(stderr, "%s: no space for mount at %s (%s)\n", Pn, fs, dir); - Error(); + Error(ctx); } - if (!(ln = Readlink(dn))) { + if (!(ln = Readlink(ctx, dn))) { if (!Fwarn) { (void)fprintf(stderr, " Output information may be incomplete.\n"); @@ -267,14 +267,14 @@ struct mounts *readmnt() { goto no_space_for_mount; } mtp->fsname = dn; - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat the file system (mounted-on) device name to get its modes. * Set the modes to zero if the stat fails. Add file system * (mounted-on) device information to the local mountsstructure. */ - if (!ln || statsafely(ln, &sb)) + if (!ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mtp->fsnmres = ln; mtp->fs_mode = sb.st_mode; diff --git a/lib/dialects/aix/dnode.c b/lib/dialects/aix/dnode.c index 80f52710..7e0791fa 100644 --- a/lib/dialects/aix/dnode.c +++ b/lib/dialects/aix/dnode.c @@ -117,8 +117,8 @@ struct rnode { * isglocked() - is a gnode locked */ -char isglocked(ga) -struct gnode *ga; /* local gnode address */ +char isglocked(struct lsof_context *ctx, /* context */ + struct gnode *ga) /* local gnode address */ { struct filock *cfp, f, *ffp; @@ -132,7 +132,7 @@ struct gnode *ga; /* local gnode address */ do { #endif /* AIXV>=4140 */ - if (kread((KA_T)cfp, (char *)&f, sizeof(f))) + if (kread(ctx, (KA_T)cfp, (char *)&f, sizeof(f))) return (' '); #if AIXV >= 4140 @@ -173,7 +173,8 @@ struct gnode *ga; /* local gnode address */ * process_node() - process vnode */ -void process_node(va) KA_T va; /* vnode kernel space address */ +void process_node(struct lsof_context *ctx, /* context */ + KA_T va) /* vnode kernel space address */ { struct cdrnode c; dev_t dev, rdev; @@ -263,7 +264,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * Read the vnode. */ if (!va) { - enter_nm("no vnode address"); + enter_nm(ctx, "no vnode address"); return; } if (!v) { @@ -288,14 +289,14 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HAS_AFS) */ ); - Error(); + Error(ctx); } } /* * Read the vnode. */ - if (readvnode(va, v)) { - enter_nm(Namech); + if (readvnode(ctx, va, v)) { + enter_nm(ctx, Namech); return; } @@ -307,14 +308,14 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Read the gnode. */ - if (!v->v_gnode || readgnode((KA_T)v->v_gnode, &g)) { + if (!v->v_gnode || readgnode(ctx, (KA_T)v->v_gnode, &g)) { if (Selinet) { Lf->sf = SELEXCLF; return; } (void)snpf(Namech, Namechl, "vnode at %s has no gnode\n", print_kptr(va, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } @@ -342,13 +343,14 @@ void process_node(va) KA_T va; /* vnode kernel space address */ default: (void)snpf(Namech, Namechl, "vnode at %s: unknown ISVDEV(%#x)", print_kptr(va, (char *)NULL, 0), g.gn_type); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* * Read the special node. */ - if (!g.gn_data || kread((KA_T)g.gn_data, (char *)&sn, sizeof(sn))) { + if (!g.gn_data || + kread(ctx, (KA_T)g.gn_data, (char *)&sn, sizeof(sn))) { if (Selinet) { Lf->sf = SELEXCLF; return; @@ -356,7 +358,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ (void)snpf(Namech, Namechl, "vnode at %s: can't read specnode (%s)", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)g.gn_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -367,29 +369,29 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->sf = SELEXCLF; return; } - if (readgnode((KA_T)sn.sn_pfsgnode, &g)) { + if (readgnode(ctx, (KA_T)sn.sn_pfsgnode, &g)) { (void)snpf(Namech, Namechl, "vnode at %s: can't read pfsgnode (%s)", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)sn.sn_pfsgnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } - if (!g.gn_data || readlino(&g, &i)) { + if (!g.gn_data || readlino(ctx, &g, &i)) { (void)snpf(Namech, Namechl, "pfsgnode at %s: can't read inode (%s)", print_kptr((KA_T)sn.sn_pfsgnode, tbuf, sizeof(tbuf)), print_kptr((KA_T)g.gn_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } ins = 1; - if (!g.gn_vnode || readvnode((KA_T)g.gn_vnode, v)) { + if (!g.gn_vnode || readvnode(ctx, (KA_T)g.gn_vnode, v)) { (void)snpf(Namech, Namechl, "pfsgnode at %s: can't read vnode (%s)", print_kptr((KA_T)sn.sn_pfsgnode, tbuf, sizeof(tbuf)), print_kptr((KA_T)g.gn_vnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } } else { @@ -404,7 +406,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * and the devnode must have a stream head pointer. */ if (CloneMaj >= 0 && sn.sn_devnode && - kread((KA_T)sn.sn_devnode, (char *)&dn, sizeof(dn)) == 0 && + kread(ctx, (KA_T)sn.sn_devnode, (char *)&dn, sizeof(dn)) == 0 && (ka = (KA_T)dn.dv_pdata)) { # if defined(HASDCACHE) @@ -417,7 +419,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ if (GET_MAJ_DEV(g.gn_rdev) == GET_MIN_DEV(cl->cd.rdev)) { # if defined(HASDCACHE) - if (DCunsafe && !cl->cd.v && !vfy_dev(&cl->cd)) + if (DCunsafe && !cl->cd.v && !vfy_dev(ctx, &cl->cd)) goto process_clone_again; # endif /* defined(HASDCACHE) */ @@ -450,7 +452,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ (void)snpf(Namech, Namechl, "STR:%s", cl->cd.name); nx = (int)strlen(Namech); - if (!kread(ka, (char *)&sh, sizeof(sh))) + if (!kread(ctx, ka, (char *)&sh, sizeof(sh))) qp = (KA_T)sh.sth_wq; else qp = (KA_T)NULL; @@ -470,20 +472,20 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * If the qinfo or module_info structures can't be * read, skip to the next queue structure. */ - if (kread(qp, (char *)&q, sizeof(q))) + if (kread(ctx, qp, (char *)&q, sizeof(q))) break; if (!(ka = (KA_T)q.q_qinfo) || - kread(ka, (char *)&qi, sizeof(qi))) + kread(ctx, ka, (char *)&qi, sizeof(qi))) continue; if (!(ka = (KA_T)qi.qi_minfo) || - kread(ka, (char *)&mi, sizeof(mi))) + kread(ctx, ka, (char *)&mi, sizeof(mi))) continue; if (!(ka = (KA_T)mi.mi_idname) || - kread(ka, mn, sizeof(mn) - 1) || + kread(ctx, ka, mn, sizeof(mn) - 1) || !(ml = (int)strlen(mn)) || !strcmp(mn, "sth")) continue; if (!strcmp(mn, "xtiso") && (xp = (KA_T)q.q_ptr) && - !kread(xp, (char *)&xt, sizeof(xt)) && + !kread(ctx, xp, (char *)&xt, sizeof(xt)) && (ka = (KA_T)xt.xti_so)) { /* @@ -520,12 +522,13 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * If it's a FIFO, read its fifonode. */ if (Ntype == N_FIFO) { - if (!sn.sn_fifonode || readfifonode((KA_T)sn.sn_fifonode, &f)) { + if (!sn.sn_fifonode || + readfifonode(ctx, (KA_T)sn.sn_fifonode, &f)) { (void)snpf(Namech, Namechl, "vnode at %s: can't read fifonode (%s)", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)sn.sn_fifonode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -533,12 +536,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ } else { if (!sn.sn_devnode || - kread((KA_T)sn.sn_devnode, (char *)&dn, sizeof(dn))) { + kread(ctx, (KA_T)sn.sn_devnode, (char *)&dn, sizeof(dn))) { (void)snpf(Namech, Namechl, "vnode at %s: can't read devnode (%s)", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)sn.sn_devnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } g = dn.dv_gnode; @@ -551,13 +554,13 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ if (Ntype != N_AFS && g.gn_rdev == NODEVICE) { vfs = (struct l_vfs *)NULL; - enter_dev_ch(print_kptr(va, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(va, (char *)NULL, 0)); } else { - if (!(vfs = readvfs(v))) { + if (!(vfs = readvfs(ctx, v))) { (void)snpf(Namech, Namechl, "can't read vfs for %s at %s", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_vfsp, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } } @@ -605,7 +608,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Get the lock status. */ - Lf->lock = isglocked(&g); + Lf->lock = isglocked(ctx, &g); switch (Ntype) { #if defined(HAS_NFS) @@ -642,10 +645,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # endif /* AIXA<2 */ if (width > 0) { - if (!g.gn_data || kread((KA_T)g.gn_data, rp, rsz)) { + if (!g.gn_data || kread(ctx, (KA_T)g.gn_data, rp, rsz)) { (void)snpf(Namech, Namechl, "remote gnode at %s has no rnode", print_kptr((KA_T)v->v_gnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } @@ -673,10 +676,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * Read SANFS node and associated structures. */ case N_SANFS: - if (!g.gn_data || kread((KA_T)g.gn_data, &san, sizeof(san))) { + if (!g.gn_data || kread(ctx, (KA_T)g.gn_data, &san, sizeof(san))) { (void)snpf(Namech, Namechl, "gnode at %s has no SANFS node", print_kptr((KA_T)v->v_gnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -698,10 +701,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Read a CD-ROM cdrnode. */ - if (!g.gn_data || readcdrnode((KA_T)g.gn_data, &c)) { + if (!g.gn_data || readcdrnode(ctx, (KA_T)g.gn_data, &c)) { (void)snpf(Namech, Namechl, "gnode at %s has no cdrnode", print_kptr((KA_T)v->v_gnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } (void)zeromem((char *)&i, sizeof(i)); @@ -713,11 +716,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ } else if (g.gn_data) { - if (readlino(&g, &i)) { + if (readlino(ctx, &g, &i)) { (void)snpf(Namech, Namechl, "gnode at %s can't read inode: %s", print_kptr((KA_T)v->v_gnode, tbuf, sizeof(tbuf)), print_kptr((KA_T)g.gn_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } ins = 1; @@ -736,7 +739,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case -1: break; case 0: - if (!hasAFS(v)) { + if (!hasAFS(ctx, v)) { afs = 1; break; } @@ -752,12 +755,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * If this is an AFS node, read the afsnode. */ if (Ntype == N_AFS) { - if (readafsnode(va, v, &an)) + if (readafsnode(ctx, va, v, &an)) return; } else { (void)snpf(Namech, Namechl, "gnode at %s has no inode", print_kptr((KA_T)v->v_gnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } } @@ -766,7 +769,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ else { (void)snpf(Namech, Namechl, "gnode at %s has no inode", print_kptr((KA_T)v->v_gnode, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } #endif /* defined(HAS_AFS) */ @@ -1109,7 +1112,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * supply one. */ if ((Lf->inp_ty == 0) && (type == VBLK)) - find_bl_ino(); + find_bl_ino(ctx); #endif /* defined(HASBLKDEV) */ /* @@ -1117,17 +1120,17 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * supply one. */ if ((Lf->inp_ty == 0) && (type == VCHR)) - find_ch_ino(); + find_ch_ino(ctx); /* * Test for specified file. */ - if (Sfile && is_file_named(NULL, type, g.gn_chan, ic)) + if (Sfile && is_file_named(ctx, NULL, type, g.gn_chan, ic)) Lf->sf |= SELNM; /* * Enter name characters. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } #if defined(HASPRIVFILETYPE) @@ -1135,8 +1138,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * process_shmt() -- process shared memory transport file */ -void process_shmt(sa) KA_T sa; /* shared memory transport node struct - * address ??? */ +void process_shmt(struct lsof_context *ctx, /* context */ + KA_T sa) /* shared memory transport node struct + * address ??? */ { struct shmtnode { /* shared memory transport node * struct ??? */ @@ -1160,13 +1164,13 @@ void process_shmt(sa) KA_T sa; /* shared memory transport node struct * Set type to " SMT" and put shmtnode structure address in device column. */ (void)snpf(Lf->type, sizeof(Lf->type), " SMT"); - if (!sa || kread((KA_T)sa, (char *)&mn, sizeof(mn))) { + if (!sa || kread(ctx, (KA_T)sa, (char *)&mn, sizeof(mn))) { (void)snpf(Namech, Namechl, "can't read shmtnode: %s", print_kptr(sa, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } - enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(sa, (char *)NULL, 0)); /* * If buffer size is less than free bytes, enable offset display. Otherwise * set the file size as buffer size less free bytes. @@ -1181,7 +1185,7 @@ void process_shmt(sa) KA_T sa; /* shared memory transport node struct if (!mn.peer) (void)snpf(Namech, Namechl, "->(unknown)"); else { - if (kread((KA_T)mn.peer, (char *)&pn, sizeof(pn))) + if (kread(ctx, (KA_T)mn.peer, (char *)&pn, sizeof(pn))) (void)snpf(Namech, Namechl, "can't read peer shmtnode: %s", print_kptr((KA_T)mn.peer, (char *)NULL, 0)); else { @@ -1193,7 +1197,7 @@ void process_shmt(sa) KA_T sa; /* shared memory transport node struct print_kptr((KA_T)mn.peer, (char *)NULL, 0)); } } - enter_nm(Namech); + enter_nm(ctx, Namech); } #endif /* AIXV>=4200 */ @@ -1201,9 +1205,9 @@ void process_shmt(sa) KA_T sa; /* shared memory transport node struct * readlino() -- read local inode */ -int readlino(ga, li) -struct gnode *ga; /* gnode address */ -struct l_ino *li; /* local inode receiver */ +int readlino(struct lsof_context *ctx, /* context */ + struct gnode *ga, /* gnode address */ + struct l_ino *li) /* local inode receiver */ { struct inode i; /* "regular" inode */ @@ -1238,13 +1242,13 @@ struct l_ino *li; /* local inode receiver */ * references j2_vnops. */ if (ga->gn_ops && j2va && (ga->gn_ops == j2va)) - return (readj2lino(ga, li)); + return (readj2lino(ctx, ga, li)); #endif /* defined(HAS_JFS2) */ /* * Read a "standard" inode. */ - if (readinode((KA_T)ga->gn_data, &i)) + if (readinode(ctx, (KA_T)ga->gn_data, &i)) return (1); li->dev = i.i_dev; li->nlink = i.i_nlink; diff --git a/lib/dialects/aix/dnode1.c b/lib/dialects/aix/dnode1.c index 3cea072c..11c1a352 100644 --- a/lib/dialects/aix/dnode1.c +++ b/lib/dialects/aix/dnode1.c @@ -34,7 +34,7 @@ static char copyright[] = #endif #if defined(HAS_AFS) -# include "lsof.h" +# include "common.h" /* * This is an emulation of the afs_rwlock_t definition that appears in @@ -63,8 +63,9 @@ typedef struct afs_lock afs_rwlock_t; * Local function prototypes */ -_PROTOTYPE(static struct volume *getvolume, (struct VenusFid * f, int *vols)); -_PROTOTYPE(static int is_rootFid, (struct vcache * vc, int *rfid)); +static struct volume *getvolume(struct lsof_context *ctx, struct VenusFid *f, + int *vols); +static int is_rootFid(struct lsof_context *ctx, struct vcache *vc, int *rfid); /* * alloc_vcache() - allocate space for vcache structure @@ -78,9 +79,9 @@ struct vnode *alloc_vcache() { * getvolume() - get volume structure */ -static struct volume *getvolume(f, vols) -struct VenusFid *f; /* file ID pointer */ -int *vols; /* afs_volumes status return */ +static struct volume *getvolume(struct lsof_context *ctx, /* context */ + struct VenusFid *f, /* file ID pointer */ + int *vols) /* afs_volumes status return */ { int i; static KA_T ka = 0; @@ -107,10 +108,10 @@ int *vols; /* afs_volumes status return */ *vols = 1; i = (NVOLS - 1) & f->Fid.Volume; kh = (KA_T)((char *)ka + (i * sizeof(struct volume *))); - if (kread(kh, (char *)&vp, sizeof(vp))) + if (kread(ctx, kh, (char *)&vp, sizeof(vp))) return ((struct volume *)NULL); while (vp) { - if (kread((KA_T)vp, (char *)&v, sizeof(v))) + if (kread(ctx, (KA_T)vp, (char *)&v, sizeof(v))) return ((struct volume *)NULL); if (v.volume == f->Fid.Volume && v.cell == f->Cell) return (&v); @@ -123,8 +124,8 @@ int *vols; /* afs_volumes status return */ * hasAFS() - test for AFS presence via vfs structure */ -int hasAFS(vp) -struct vnode *vp; /* vnode pointer */ +int hasAFS(struct lsof_context *ctx, /* context */ + struct vnode *vp) /* vnode pointer */ { struct vmount vm; struct vfs v; @@ -143,9 +144,9 @@ struct vnode *vp; /* vnode pointer */ return (1); if (vp->v_data || !vp->v_vfsp) return (0); - if (kread((KA_T)vp->v_vfsp, (char *)&v, sizeof(v))) + if (kread(ctx, (KA_T)vp->v_vfsp, (char *)&v, sizeof(v))) return (0); - if (!v.vfs_mdata || kread((KA_T)v.vfs_mdata, (char *)&vm, sizeof(vm))) + if (!v.vfs_mdata || kread(ctx, (KA_T)v.vfs_mdata, (char *)&vm, sizeof(vm))) return (0); if (vm.vmt_gfstype != MNT_AFS) return (0); @@ -162,9 +163,9 @@ struct vnode *vp; /* vnode pointer */ * 1 if root file ID structure address available */ -static int is_rootFid(vc, rfid) -struct vcache *vc; /* vcache entry */ -int *rfid; /* root file ID pointer status return */ +static int is_rootFid(struct lsof_context *ctx, /* context */ + struct vcache *vc, /* vcache entry */ + int *rfid) /* root file ID pointer status return */ { int err; static int f = 0; /* rootFID structure status: @@ -206,7 +207,7 @@ int *rfid; /* root file ID pointer status return */ *rfid = 0; return (0); } - if (kread((KA_T)AFSnl[X_AFS_FID].n_value, (char *)&r, sizeof(r))) { + if (kread(ctx, (KA_T)AFSnl[X_AFS_FID].n_value, (char *)&r, sizeof(r))) { err = 0; goto rfid_unavailable; } @@ -227,10 +228,10 @@ int *rfid; /* root file ID pointer status return */ * readafsnode() - read AFS node */ -int readafsnode(va, v, an) -KA_T va; /* kernel vnode address */ -struct vnode *v; /* vnode buffer pointer */ -struct afsnode *an; /* afsnode recipient */ +int readafsnode(struct lsof_context *ctx, /* context */ + KA_T va, /* kernel vnode address */ + struct vnode *v, /* vnode buffer pointer */ + struct afsnode *an) /* afsnode recipient */ { char *cp, tbuf[32]; KA_T ka; @@ -241,7 +242,7 @@ struct afsnode *an; /* afsnode recipient */ cp = ((char *)v + sizeof(struct vnode)); ka = (KA_T)((char *)va + sizeof(struct vnode)); len = sizeof(struct vcache) - sizeof(struct vnode); - if (kread(ka, cp, len)) { + if (kread(ctx, ka, cp, len)) { (void)snpf(Namech, Namechl, "vnode at %s: can't read vcache remainder from %s", print_kptr(va, tbuf, sizeof(tbuf)), @@ -258,12 +259,12 @@ struct afsnode *an; /* afsnode recipient */ * Manufacture the "inode" number. */ if (vc->mvstat == 2) { - if ((vp = getvolume(&vc->fid, &vols))) { + if ((vp = getvolume(ctx, &vc->fid, &vols))) { an->inode = (INODETYPE)((vp->mtpoint.Fid.Vnode + (vp->mtpoint.Fid.Volume << 16)) & 0x7fffffff); if (an->inode == (INODETYPE)0) { - if (is_rootFid(vc, &rfid)) + if (is_rootFid(ctx, vc, &rfid)) an->ino_st = 1; else if (rfid) { an->inode = (INODETYPE)2; diff --git a/lib/dialects/aix/dnode2.c b/lib/dialects/aix/dnode2.c index d2c9a09d..2b080d88 100644 --- a/lib/dialects/aix/dnode2.c +++ b/lib/dialects/aix/dnode2.c @@ -52,9 +52,9 @@ static char copyright[] = # include "proto.h" # include "dproto.h" -int readj2lino(ga, li) -struct gnode *ga; /* gnode address */ -struct l_ino *li; /* local inode receiver */ +int readj2lino(struct lsof_context *ctx, /* context */ + struct gnode *ga, /* gnode address */ + struct l_ino *li) /* local inode receiver */ { struct inode i; /* jfs2 inode */ /* @@ -62,7 +62,8 @@ struct l_ino *li; /* local inode receiver */ * * Note: the caller is responsible for initializing *li to zeroes. */ - if (!ga || !ga->gn_data || kread((KA_T)ga->gn_data, (char *)&i, sizeof(i))) + if (!ga || !ga->gn_data || + kread(ctx, (KA_T)ga->gn_data, (char *)&i, sizeof(i))) return (1); li->dev = i.i_dev; li->nlink = i.i_nlink; diff --git a/lib/dialects/aix/dproc.c b/lib/dialects/aix/dproc.c index 37025b9c..ab32831b 100644 --- a/lib/dialects/aix/dproc.c +++ b/lib/dialects/aix/dproc.c @@ -35,30 +35,30 @@ static char copyright[] = #include "common.h" -_PROTOTYPE(static void get_kernel_access, (void)); +static void get_kernel_access(struct lsof_context *ctx); #if AIXA < 2 -_PROTOTYPE(static struct le *getle, (KA_T a, KA_T sid, char **err)); +static struct le *getle(struct lsof_context *ctx, KA_T a, KA_T sid, char **err); #endif /* AIXA<2 */ #if AIXV >= 4110 -_PROTOTYPE(static void getlenm, (struct le * le, KA_T sid)); +static void getlenm(struct lsof_context *ctx, struct le *le, KA_T sid); #endif /* AIXV>=4110 */ -_PROTOTYPE(static int kreadx, (KA_T addr, char *buf, int len, KA_T sid)); +static int kreadx(KA_T addr, char *buf, int len, KA_T sid); #if AIXA < 2 -_PROTOTYPE(static void process_text, (KA_T sid)); +static void process_text(struct lsof_context *ctx, KA_T sid); #else /* AIXA>=2 */ -_PROTOTYPE(static void getsoinfo, (void)); -_PROTOTYPE(static void process_text, (pid_t pid)); +static void getsoinfo(void); +static void process_text(struct lsof_context *ctx, pid_t pid); #endif /* AIXA<2 */ #if defined(SIGDANGER) # if defined(HASINTSIGNAL) -_PROTOTYPE(static int lowpgsp, (int sig)); +static int lowpgsp(struct lsof_context *ctx, int sig); # else /* !defined(HASINTSIGNAL) */ -_PROTOTYPE(static void lowpgsp, (int sig)); +static void lowpgsp(struct lsof_context *ctx, int sig); # endif /* defined(HASINTSIGNAL) */ #endif /* defined(SIGDANGER) */ @@ -221,10 +221,11 @@ static KA_T Uo; /* user area VM offset */ * ckkv() - check kernel version */ -void ckkv(d, er, ev, ea) char *d; /* dialect */ -char *er; /* expected release */ -char *ev; /* expected version */ -char *ea; /* expected architecture */ +void ckkv(struct lsof_context *ctx, /* context */ + char *d, /* dialect */ + char *er, /* expected release */ + char *ev, /* expected version */ + char *ea) /* expected architecture */ { #if defined(HASKERNIDCK) @@ -256,12 +257,12 @@ char *ea; /* expected architecture */ (void)fprintf(stderr, "%s: can't execute %s: %s\n", Pn, OSLEVELPATH, strerror(errno)); - Error(); + Error(ctx); } if ((sb.st_mode & (S_IROTH | S_IXOTH)) != (S_IROTH | S_IXOTH)) { (void)fprintf(stderr, "%s: can't execute %s, modes: %o\n", Pn, OSLEVELPATH, sb.st_mode); - Error(); + Error(ctx); } /* * Open a pipe for receiving the version number from OSLEVEL. Fork a @@ -270,7 +271,7 @@ char *ea; /* expected architecture */ if (pipe(p)) { (void)fprintf(stderr, "%s: can't create pipe to: %s\n", Pn, OSLEVELPATH); - Error(); + Error(ctx); } if ((pid = fork()) == 0) { (void)close(1); @@ -285,7 +286,7 @@ char *ea; /* expected architecture */ if (pid < 0) { (void)fprintf(stderr, "%s: can't fork a child for %s: %s\n", Pn, OSLEVELPATH, strerror(errno)); - Error(); + Error(ctx); } (void)close(p[1]); br = read(p[0], buf, sizeof(buf) - 1); @@ -327,7 +328,7 @@ char *ea; /* expected architecture */ * gather_proc_info() - gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { short cckreg; /* conditional status of regular file * checking: * 0 = unconditionally check @@ -423,7 +424,7 @@ void gather_proc_info() { if (!P) { if (!(P = (struct PROCINFO *)malloc((MALLOC_S)PROCSIZE))) { (void)fprintf(stderr, "%s: can't allocate space for 1 proc\n", Pn); - Error(); + Error(ctx); } Np = 1; } @@ -432,7 +433,7 @@ void gather_proc_info() { if (!(P = (struct PROCINFO *)realloc((MALLOC_P *)P, (size_t)(Np * PROCSIZE)))) { (void)fprintf(stderr, "%s: no space for %d procinfo's\n", Pn, Np); - Error(); + Error(ctx); } } #else /* AIXV>=4300 */ @@ -441,7 +442,7 @@ void gather_proc_info() { if (!(P = (struct PROCINFO *)malloc(msz))) { (void)fprintf(stderr, "%s: can't allocate space for %d procs\n", Pn, PROCINFO_INCR); - Error(); + Error(ctx); } Np = PROCINFO_INCR; } @@ -455,7 +456,7 @@ void gather_proc_info() { if (!(P = (struct PROCINFO *)realloc((MALLOC_P *)P, msz))) { (void)fprintf(stderr, "%s: no more space for proc storage\n", Pn); - Error(); + Error(ctx); } Np += PROCINFO_INCR; } @@ -471,7 +472,7 @@ void gather_proc_info() { for (p = P, Up = &us; np > 0; np--, p++) { if (p->p_stat == 0 || p->p_stat == SZOMB) continue; - if (is_proc_excl(p->p_pid, (int)p->p_pgid, (UID_ARG)p->p_uid, &pss, + if (is_proc_excl(ctx, p->p_pid, (int)p->p_pgid, (UID_ARG)p->p_uid, &pss, &sf)) continue; @@ -515,7 +516,7 @@ void gather_proc_info() { rdir = (KA_T)Up->u_rdir; cmd = Up->u_comm; nf = Up->u_maxofile; - if (is_cmd_excl(cmd, &pss, &sf)) + if (is_cmd_excl(ctx, cmd, &pss, &sf)) continue; if (cckreg) { @@ -535,7 +536,7 @@ void gather_proc_info() { * * If readx is enabled (-X), use it to get the loader_anchor structure. */ - if (is_cmd_excl(p->pi_comm, &pss, &sf)) + if (is_cmd_excl(ctx, p->pi_comm, &pss, &sf)) continue; if (cckreg) { @@ -551,7 +552,7 @@ void gather_proc_info() { (void)fprintf(stderr, "%s: can't allocate fdsinfo struct for PID %d\n", Pn, pid); - Error(); + Error(ctx); } } pid = p->p_pid; @@ -638,26 +639,26 @@ void gather_proc_info() { /* * Allocate a local process structure and start filling it. */ - alloc_lproc(p->p_pid, (int)p->p_pgid, (int)p->p_ppid, (UID_ARG)p->p_uid, - cmd, (int)pss, (int)sf); + alloc_lproc(ctx, p->p_pid, (int)p->p_pgid, (int)p->p_ppid, + (UID_ARG)p->p_uid, cmd, (int)pss, (int)sf); Plf = (struct lfile *)NULL; /* * Save current working directory information. */ if (!ckscko && cdir) { - alloc_lfile(CWD, -1); - process_node(cdir); + alloc_lfile(ctx, CWD, -1); + process_node(ctx, cdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } /* * Save root directory information. */ if (!ckscko && rdir) { - alloc_lfile(RTD, -1); - process_node(rdir); + alloc_lfile(ctx, RTD, -1); + process_node(ctx, rdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } #if AIXV < 4100 @@ -665,10 +666,10 @@ void gather_proc_info() { * Save parent directory information. */ if (!ckscko && pdir) { - alloc_lfile(" pd", -1); - process_node(pdir); + alloc_lfile(ctx, " pd", -1); + process_node(ctx, pdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } #endif /* AIXV<4100 */ @@ -701,11 +702,11 @@ void gather_proc_info() { ck = 0; } if (ck) - process_text(sid); + process_text(ctx, sid); } # endif /* AIXA<1 */ #else /* AIXA>=2 */ - process_text(p->p_pid); + process_text(ctx, p->p_pid); #endif /* AIXA<2 */ } /* @@ -720,8 +721,8 @@ void gather_proc_info() { #endif /* AIXV<4300 */ if (fp) { - alloc_lfile((char *)NULL, i); - process_file(fp); + alloc_lfile(ctx, (char *)NULL, i); + process_file(ctx, fp); if (Lf->sf) { #if defined(HASFSTRUCT) @@ -733,14 +734,14 @@ void gather_proc_info() { # endif /* AIXV<4300 */ #endif /* defined(HASFSTRUCT) */ - link_lfile(); + link_lfile(ctx); } } } /* * Examine results. */ - if (examine_lproc()) + if (examine_lproc(ctx)) return; } } @@ -749,7 +750,7 @@ void gather_proc_info() { * get_kernel_access() - get access to kernel memory */ -static void get_kernel_access() { +static void get_kernel_access(struct lsof_context *ctx) { int oe = 0; #if defined(AIX_KERNBITS) @@ -781,7 +782,7 @@ static void get_kernel_access() { kbb); (void)fprintf(stderr, " The bit size of this kernel is %s.\n", kbr); - Error(); + Error(ctx); } #endif /* defined(AIX_KERNBITS) */ @@ -800,13 +801,13 @@ static void get_kernel_access() { * before attempting to open the (Memory) file. */ if (Memory) - (void)dropgid(); + (void)dropgid(ctx); #else /* !defined(WILLDROPGID) */ /* * See if the non-KMEM memory file is readable. */ - if (Memory && !is_readable(Memory, 1)) - Error(); + if (Memory && !is_readable(ctx, Memory, 1)) + Error(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -818,14 +819,14 @@ static void get_kernel_access() { oe++; } if (oe) - Error(); + Error(ctx); #if defined(WILLDROPGID) /* * Drop setgid permission, if necessary. */ if (!Memory) - (void)dropgid(); + (void)dropgid(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -834,7 +835,7 @@ static void get_kernel_access() { if (knlist(Nl, X_NL_NUM, sizeof(struct nlist)) || !Nl[X_UADDR].n_value) { (void)fprintf(stderr, "%s: can't get kernel's %s address\n", Pn, Nl[X_UADDR].n_name); - Error(); + Error(ctx); } #if defined(HAS_AFS) @@ -876,7 +877,7 @@ static void get_kernel_access() { /* * Check the kernel version number. */ - (void)ckkv("AIX", (char *)NULL, LSOF_VSTR, (char *)NULL); + (void)ckkv(ctx, "AIX", (char *)NULL, LSOF_VSTR, (char *)NULL); #if defined(SIGDANGER) /* @@ -891,10 +892,10 @@ static void get_kernel_access() { * getle() - get loader entry structure */ -static struct le *getle(a, sid, err) -KA_T a; /* loader entry kernel address */ -KA_T sid; /* user structure segment ID */ -char **err; /* error message (if return is NULL) */ +static struct le *getle(struct lsof_context *ctx, /* context */ + KA_T a, /* loader entry kernel address */ + KA_T sid, /* user structure segment ID */ + char **err) /* error message (if return is NULL) */ { static struct le le; @@ -914,7 +915,7 @@ char **err; /* error message (if return is NULL) */ # if AIXV >= 4110 if (!sid) { - if (!kread(a, (char *)&le, sizeof(le))) + if (!kread(ctx, a, (char *)&le, sizeof(le))) return (&le); } else { if (!kreadx((KA_T)(a & RDXMASK), (char *)&le, sizeof(le), (KA_T)sid)) @@ -937,8 +938,9 @@ char **err; /* error message (if return is NULL) */ * getlenm() - get loader entry file name for AIX >= 4.1.1 */ -static void getlenm(le, sid) struct le *le; /* loader entry structure */ -KA_T sid; /* segment ID */ +static void getlenm(struct lsof_context *ctx, /* context */ + struct le *le, /* loader entry structure */ + KA_T sid) /* segment ID */ { char buf[LIBNMLN]; int i; @@ -949,7 +951,7 @@ KA_T sid; /* segment ID */ # else /* AIXV>=4300 */ # if AIXA < 2 if (!sid) { - if (kread((KA_T)le->nm, buf, LIBNMLN)) + if (kread(ctx, (KA_T)le->nm, buf, LIBNMLN)) return; } else { if (!Soff_stat || !le->nm || @@ -959,16 +961,16 @@ KA_T sid; /* segment ID */ buf[LIBNMLN - 1] = '\0'; i = strlen(buf); if (i < (LIBNMLN - 3) && buf[i + 1]) - enter_nm(&buf[i + 1]); + enter_nm(ctx, &buf[i + 1]); else if (buf[0]) - enter_nm(buf); + enter_nm(ctx, buf); # else /* AIXA>=2 */ - if (!le->nm || kread(le->nm, buf, sizeof(buf))) + if (!le->nm || kread(ctx, le->nm, buf, sizeof(buf))) return; buf[LIBNMLN - 1] = '\0'; if (!strlen(buf)) return; - enter_nm(buf); + enter_nm(ctx, buf); # endif /* AIXA<2 */ # endif /* AIXV<4300 */ } @@ -1010,7 +1012,7 @@ static void getsoinfo() { if (!(SoHash = (so_hash_t **)calloc((MALLOC_S)SOHASHBUCKS, sizeof(so_hash_t *)))) { (void)fprintf(stderr, "%s: no space for *.so hash buckets\n", Pn); - Error(); + Error(ctx); } /* * Cache the loader module information, complete with stat(2) results. @@ -1034,7 +1036,7 @@ static void getsoinfo() { if (!(rn = mkstrcpy(lp->mi_name, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for name: %s\n", Pn, lp->mi_name); - Error(); + Error(ctx); } /* * Resolve symbolic links. @@ -1056,7 +1058,7 @@ static void getsoinfo() { if (!(sp = (so_hash_t *)malloc((MALLOC_S)sizeof(so_hash_t)))) { (void)fprintf(stderr, "%s: no space for *.so hash entry: %s\n", Pn, ln); - Error(); + Error(ctx); } sp->dev = sb.st_dev; sp->nlink = (int)sb.st_nlink; @@ -1088,8 +1090,8 @@ static void getsoinfo() { * initialize() - perform all initialization */ -void initialize() { - get_kernel_access(); +void initialize(struct lsof_context *ctx) { + get_kernel_access(ctx); #if AIXA > 1 (void)getsoinfo(); @@ -1100,10 +1102,10 @@ void initialize() { * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, /* context */ + KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { int br; @@ -1122,11 +1124,10 @@ READLEN_T len; /* length to read */ * kreadx() - read kernel segmented memory */ -int kreadx(addr, buf, len, sid) -KA_T addr; /* kernel address */ -char *buf; /* destination buffer */ -int len; /* length */ -KA_T sid; /* segment ID */ +int kreadx(KA_T addr, /* kernel address */ + char *buf, /* destination buffer */ + int len, /* length */ + KA_T sid) /* segment ID */ { int br; @@ -1152,11 +1153,9 @@ static int static void # endif /* defined(HASINTSIGNAL) */ -lowpgsp(sig) -int sig; -{ +lowpgsp(struct lsof_context *ctx, int sig) { (void)fprintf(stderr, "%s: FATAL: system paging space is low.\n", Pn); - Error(); + Error(ctx); } #endif /* defined(SIGDANGER) */ @@ -1165,7 +1164,8 @@ int sig; * process_text() - process text file information for non-ia64 AIX */ -static void process_text(sid) KA_T sid; /* user area segment ID */ +static void process_text(struct lsof_context *ctx, /* context */ + KA_T sid) /* user area segment ID */ { char *err, fd[8]; static struct file **f = (struct file **)NULL; @@ -1191,10 +1191,10 @@ static void process_text(sid) KA_T sid; /* user area segment ID */ # endif /* AIXV<4300 */ { - alloc_lfile(" txt", -1); - if ((le = getle(ll, sid, &err))) { + alloc_lfile(ctx, " txt", -1); + if ((le = getle(ctx, ll, sid, &err))) { if ((xf = le->fp)) { - process_file((KA_T)xf); + process_file(ctx, (KA_T)xf); if (Lf->sf) { # if AIXV >= 4110 && AIXV < 4300 @@ -1202,15 +1202,15 @@ static void process_text(sid) KA_T sid; /* user area segment ID */ getlenm(le, sid); # endif /* AIXV>=4110 && AIXV<4300 */ - link_lfile(); + link_lfile(ctx); } } } else { (void)snpf(Namech, Namechl, "text entry at %s: %s", print_kptr((KA_T)ll, (char *)NULL, 0), err); - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } /* @@ -1226,13 +1226,13 @@ static void process_text(sid) KA_T sid; /* user area segment ID */ ll; ll = (KA_T)le->next) { (void)snpf(fd, sizeof(fd), " L%02d", i); - alloc_lfile(fd, -1); - if (!(le = getle(ll, sid, &err))) { + alloc_lfile(ctx, fd, -1); + if (!(le = getle(ctx, ll, sid, &err))) { (void)snpf(Namech, Namechl, "loader entry at %s: %s", print_kptr((KA_T)ll, (char *)NULL, 0), err); - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); return; } /* @@ -1261,22 +1261,22 @@ static void process_text(sid) KA_T sid; /* user area segment ID */ if (!f) { (void)fprintf(stderr, "%s: no space for text file pointers\n", Pn); - Error(); + Error(ctx); } } f[n++] = le->fp; /* * Save the loader entry. */ - process_file((KA_T)le->fp); + process_file(ctx, (KA_T)le->fp); if (Lf->sf) { # if AIXV >= 4110 if (!Lf->nm || !Lf->nm[0]) - getlenm(le, sid); + getlenm(ctx, le, sid); # endif /* AIXV>=4110 */ - link_lfile(); + link_lfile(ctx); i++; } } @@ -1286,7 +1286,7 @@ static void process_text(sid) KA_T sid; /* user area segment ID */ * process_text() - process text file information for ia64 AIX >= 5 */ -static void process_text(pid) pid_t pid; /* process PID */ +static void process_text(pid_t pid) /* process PID */ { char buf[MAXPATHLEN + 1], fd[8], *nm, *pp; size_t bufl = sizeof(buf); @@ -1305,9 +1305,10 @@ static void process_text(pid) pid_t pid; /* process PID */ /* * Display information on the exec'd entry. */ - if (la->exec && !kread((KA_T)la->exec, (char *)&le, sizeof(le)) && le.fp) { - alloc_lfile(" txt", -1); - process_file((KA_T)le.fp); + if (la->exec && !kread(ctx, (KA_T)la->exec, (char *)&le, sizeof(le)) && + le.fp) { + alloc_lfile(ctx, " txt", -1); + process_file(ctx, (KA_T)le.fp); if (Lf->dev_def && (Lf->inp_ty == 1)) { xdev = Lf->dev; xnode = Lf->inode; @@ -1316,7 +1317,7 @@ static void process_text(pid) pid_t pid; /* process PID */ if (Lf->sf) { if (!Lf->nm || !Lf->nm[0]) getlenm(&le, (KA_T)0); - link_lfile(); + link_lfile(ctx); } } /* @@ -1364,7 +1365,7 @@ static void process_text(pid) pid_t pid; /* process PID */ * Allocate space for a file entry. Set its basic characteristics. */ (void)snpf(fd, sizeof(fd), "L%02d", i++); - alloc_lfile(fd, -1); + alloc_lfile(ctx, fd, -1); Lf->dev_def = Lf->inp_ty = Lf->nlink_def = 1; Lf->dev = sb.st_dev; Lf->inode = (INODETYPE)sb.st_ino; @@ -1416,8 +1417,8 @@ static void process_text(pid) pid_t pid; /* process PID */ * If the file was selected, enter its name and link it to the * other files of the process. */ - enter_nm(nm); - link_lfile(); + enter_nm(ctx, nm); + link_lfile(ctx); } } (void)closedir(dfp); diff --git a/lib/dialects/aix/dproto.h b/lib/dialects/aix/dproto.h index 6f4e160d..70b15685 100644 --- a/lib/dialects/aix/dproto.h +++ b/lib/dialects/aix/dproto.h @@ -38,30 +38,29 @@ # define DPROTO_H # if defined(HAS_AFS) -_PROTOTYPE(extern struct vnode *alloc_vcache, (void)); -_PROTOTYPE(extern int hasAFS, (struct vnode * vp)); -_PROTOTYPE(extern int readafsnode, - (KA_T va, struct vnode *v, struct afsnode *an)); +extern struct vnode *alloc_vcache(void); +extern int hasAFS(struct lsof_context *ctx, struct vnode *vp); +extern int readafsnode(struct lsof_context *ctx, KA_T va, struct vnode *v, + struct afsnode *an); # endif /* defined(HAS_AFS) */ # if defined(HAS_JFS2) -_PROTOTYPE(extern int readj2lino, (struct gnode * ga, struct l_ino *li)); +extern int readj2lino(struct lsof_context *ctx, struct gnode *ga, struct l_ino *li); # endif /* defined(HAS_JFS2) */ -_PROTOTYPE(extern int getchan, (char *p)); -_PROTOTYPE(extern int is_file_named, - (char *p, enum vtype ty, chan_t ch, int ic)); -_PROTOTYPE(extern char isglocked, (struct gnode * ga)); -_PROTOTYPE(extern int readlino, (struct gnode * ga, struct l_ino *li)); -_PROTOTYPE(extern struct l_vfs *readvfs, (struct vnode * vn)); +extern int getchan(char *p); +extern int is_file_named(struct lsof_context *ctx, char *p, enum vtype ty, chan_t ch, int ic); +extern char isglocked(struct lsof_context *ctx, struct gnode *ga); +extern int readlino(struct lsof_context *ctx, struct gnode *ga, struct l_ino *li); +extern struct l_vfs *readvfs(struct lsof_context *ctx, struct vnode *vn); # if AIXV >= 4200 -_PROTOTYPE(extern void process_shmt, (KA_T sa)); +extern void process_shmt(struct lsof_context *ctx, KA_T sa); # endif /* AIV>=4200 */ # if defined(HASDCACHE) && AIXV >= 4140 -_PROTOTYPE(extern void clr_sect, (void)); -_PROTOTYPE(extern int rw_clone_sect, (int m)); +extern void clr_sect(struct lsof_context *ctx); +extern int rw_clone_sect(struct lsof_context *ctx, int m); # endif /* defined(HASDCACHE) && AIXV>=4140 */ #endif /* !defined(DPROTO_H) */ diff --git a/lib/dialects/aix/dsock.c b/lib/dialects/aix/dsock.c index 3a3b7338..e776ddeb 100644 --- a/lib/dialects/aix/dsock.c +++ b/lib/dialects/aix/dsock.c @@ -49,7 +49,8 @@ static char copyright[] = * process_socket() - process socket file */ -void process_socket(sa) KA_T sa; /* socket address in kernel */ +void process_socket(struct lsof_context *ctx, /* context */ + KA_T sa) /* socket address in kernel */ { struct domain d; unsigned char *fa = (unsigned char *)NULL; @@ -79,23 +80,23 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read socket and protocol switch structures. */ if (!sa) { - enter_nm("no socket address"); + enter_nm(ctx, "no socket address"); return; } - if (kread(sa, (char *)&s, sizeof(s))) { + if (kread(ctx, sa, (char *)&s, sizeof(s))) { (void)snpf(Namech, Namechl, "can't read socket struct from %s", print_kptr(sa, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (!s.so_type) { - enter_nm("no socket type"); + enter_nm(ctx, "no socket type"); return; } - if (!s.so_proto || kread((KA_T)s.so_proto, (char *)&p, sizeof(p))) { + if (!s.so_proto || kread(ctx, (KA_T)s.so_proto, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl, "can't read protocol switch from %s", print_kptr((KA_T)s.so_proto, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -134,10 +135,10 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Process socket by the associated domain family. */ - if (!p.pr_domain || kread((KA_T)p.pr_domain, (char *)&d, sizeof(d))) { + if (!p.pr_domain || kread(ctx, (KA_T)p.pr_domain, (char *)&d, sizeof(d))) { (void)snpf(Namech, Namechl, "can't read domain struct from %s", print_kptr((KA_T)p.pr_domain, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } switch ((fam = d.dom_family)) { @@ -153,7 +154,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Read protocol control block. */ - if (!s.so_pcb || kread((KA_T)s.so_pcb, (char *)&inp, sizeof(inp))) { + if (!s.so_pcb || + kread(ctx, (KA_T)s.so_pcb, (char *)&inp, sizeof(inp))) { if (!s.so_pcb) { (void)snpf( Namech, Namechl, "no PCB%s%s", @@ -163,7 +165,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ (void)snpf(Namech, Namechl, "can't read inpcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); } - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (p.pr_protocol == IPPROTO_TCP) { @@ -172,7 +174,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * If this is a TCP socket, read its control block. */ if (inp.inp_ppcb && - !kread((KA_T)inp.inp_ppcb, (char *)&t, sizeof(t))) { + !kread(ctx, (KA_T)inp.inp_ppcb, (char *)&t, sizeof(t))) { ts = 1; tsn = (int)t.t_state; tsnx = tsn + TcpStOff; @@ -224,7 +226,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Save Internet socket information. */ - enter_dev_ch(print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb : s.so_pcb), + enter_dev_ch(ctx, + print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb : s.so_pcb), (char *)NULL, 0)); #if defined(HASIPv6) @@ -276,7 +279,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ #endif /* defined(HASIPv6) */ if (fa || la) - (void)ent_inaddr(la, lp, fa, fp, fam); + (void)ent_inaddr(ctx, la, lp, fa, fp, fam); if (ts) { Lf->lts.type = 0; Lf->lts.state.i = tsn; @@ -298,7 +301,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ case AF_ROUTE: (void)snpf(Lf->type, sizeof(Lf->type), "rte"); if (s.so_pcb) - enter_dev_ch(print_kptr((KA_T)(s.so_pcb), (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)(s.so_pcb), (char *)NULL, 0)); else (void)snpf(Namech, Namechl, "no protocol control block"); break; @@ -312,8 +315,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Read Unix protocol control block and the Unix address structure. */ - enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); - if (kread((KA_T)s.so_pcb, (char *)&unp, sizeof(unp))) { + enter_dev_ch(ctx, print_kptr(sa, (char *)NULL, 0)); + if (kread(ctx, (KA_T)s.so_pcb, (char *)&unp, sizeof(unp))) { (void)snpf(Namech, Namechl, "can't read unpcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); break; @@ -324,7 +327,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ break; } if (unp.unp_addr) { - if (kread((KA_T)unp.unp_addr, (char *)&mb, sizeof(mb))) { + if (kread(ctx, (KA_T)unp.unp_addr, (char *)&mb, sizeof(mb))) { (void)snpf(Namech, Namechl, "can't read unp_addr at %s", print_kptr((KA_T)unp.unp_addr, (char *)NULL, 0)); break; @@ -335,8 +338,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if ((uo + sizeof(struct sockaddr)) <= sizeof(mb)) ua = (struct sockaddr_un *)((char *)&mb + uo); else { - if (mb.m_hdr.mh_data && - !kread((KA_T)mb.m_hdr.mh_data, (char *)&un, sizeof(un))) { + if (mb.m_hdr.mh_data && !kread(ctx, (KA_T)mb.m_hdr.mh_data, + (char *)&un, sizeof(un))) { ua = &un; } } @@ -357,7 +360,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if (ua->sun_family != AF_UNIX) { if (ua->sun_family == AF_UNSPEC) { if (unp.unp_conn) { - if (kread((KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) + if (kread(ctx, (KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) (void)snpf( Namech, Namechl, "can't read unp_conn at %s", print_kptr((KA_T)unp.unp_conn, (char *)NULL, 0)); @@ -376,10 +379,10 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read any associated vnode and then read its gnode and inode. */ g.gn_type = VSOCK; - if (unp.unp_vnode && !readvnode((KA_T)unp.unp_vnode, &v)) { - if (v.v_gnode && !readgnode((KA_T)v.v_gnode, &g)) { - Lf->lock = isglocked(&g); - if (g.gn_type == VSOCK && g.gn_data && !readlino(&g, &i)) + if (unp.unp_vnode && !readvnode(ctx, (KA_T)unp.unp_vnode, &v)) { + if (v.v_gnode && !readgnode(ctx, (KA_T)v.v_gnode, &g)) { + Lf->lock = isglocked(ctx, &g); + if (g.gn_type == VSOCK && g.gn_data && !readlino(ctx, &g, &i)) is = 1; } } @@ -400,7 +403,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if (mb.m_len > sizeof(struct sockaddr_un)) mb.m_len = sizeof(struct sockaddr_un); *((char *)ua + mb.m_len - 1) = '\0'; - if (Sfile && is_file_named(ua->sun_path, VSOCK, 0, 0)) + if (Sfile && is_file_named(ctx, ua->sun_path, VSOCK, 0, 0)) Lf->sf |= SELNM; if (!Namech[0]) (void)snpf(Namech, Namechl, "%s", ua->sun_path); @@ -409,8 +412,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ break; default: - printunkaf(fam, 1); + printunkaf(ctx, fam, 1); } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } diff --git a/lib/dialects/darwin/ddev.c b/lib/dialects/darwin/ddev.c index f14f8694..1615d59a 100644 --- a/lib/dialects/darwin/ddev.c +++ b/lib/dialects/darwin/ddev.c @@ -71,8 +71,9 @@ static int ADevU = 0; /* entries used in ADev[] */ * Local function prototypes */ -_PROTOTYPE(static int rmdupdev, (struct l_dev * **dp, int n, char *nm)); -_PROTOTYPE(static void saveADev, (struct stat * s)); +static int rmdupdev(struct lsof_context *ctx, struct l_dev ***dp, int n, + char *nm); +static void saveADev(struct lsof_context *ctx, struct stat *s); #if defined(HASSPECDEVD) /* @@ -82,8 +83,9 @@ _PROTOTYPE(static void saveADev, (struct stat * s)); * exit: s->st_dev changed to DevDev, as required */ -void HASSPECDEVD(p, s) char *p; /* file path */ -struct stat *s; /* stat(2) result for file */ +void HASSPECDEVD(struct lsof_context *ctx, /* context */ + char *p, /* file path */ + struct stat *s) /* stat(2) result for file */ { int i; @@ -92,7 +94,7 @@ struct stat *s; /* stat(2) result for file */ case S_IFBLK: if (s->st_dev == DevDev) return; - (void)readdev(0); + (void)readdev(ctx, 0); if (!ADev) return; for (i = 0; i < ADevU; i++) { @@ -109,11 +111,11 @@ struct stat *s; /* stat(2) result for file */ * printdevname() -- print character device name */ -int printdevname(dev, rdev, f, nty) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ -int f; /* 1 = follow with '\n' */ -int nty; /* node type: N_BLK or N_chr */ +int printdevname(struct lsof_context *ctx, /* context */ + dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int f, /* 1 = follow with '\n' */ + int nty) /* node type: N_BLK or N_chr */ { char *cp, *ttl; struct l_dev *dp; @@ -124,7 +126,7 @@ int nty; /* node type: N_BLK or N_chr */ */ if (*dev == DevDev) return (0); - readdev(0); + readdev(ctx, 0); for (i = 0; i < ADevU; i++) { if (*dev == ADev[i]) return (0); @@ -138,11 +140,11 @@ int nty; /* node type: N_BLK or N_chr */ #if defined(HASBLKDEV) if (nty == N_BLK) - dp = lkupbdev(&DevDev, rdev, 0, 1); + dp = lkupbdev(ctx, &DevDev, rdev, 0, 1); else #endif /* defined(HASBLKDEV) */ - dp = lkupdev(&DevDev, rdev, 0, 1); + dp = lkupdev(ctx, &DevDev, rdev, 0, 1); if (dp) { /* @@ -153,10 +155,10 @@ int nty; /* node type: N_BLK or N_chr */ if (!(cp = (char *)malloc((MALLOC_S)(len + 1)))) { (void)fprintf(stderr, "%s: no nma space for: (%s %s)\n", Pn, ttl, dp->name); - Error(); + Error(ctx); } (void)snpf(cp, len + 1, "(%s %s)", ttl, dp->name); - (void)add_nma(cp, len); + (void)add_nma(ctx, cp, len); (void)free((MALLOC_P *)cp); } /* @@ -169,9 +171,10 @@ int nty; /* node type: N_BLK or N_chr */ * readdev() -- read device names, modes and types */ -void readdev(skip) int skip; /* skip device cache read if 1 -- - * ignored since device cache not - * used */ +void readdev(struct lsof_context *ctx, /* context */ + int skip) /* skip device cache read if 1 + * -- ignored since device + * cache not used */ { DIR *dfp; int dnamlen; @@ -192,7 +195,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- */ Dstkn = Dstkx = 0; Dstk = (char **)NULL; - (void)stkdir(DDEV_DEVPATH); + (void)stkdir(ctx, DDEV_DEVPATH); /* * Unstack the next directory. */ @@ -218,7 +221,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- mkstrcat(Dstk[Dstkx], -1, "/", 1, (char *)NULL, -1, &pl))) { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(Dstk[Dstkx], stderr, 1); - Error(); + Error(ctx); } (void)free((FREE_P *)Dstk[Dstkx]); Dstk[Dstkx] = (char *)NULL; @@ -241,7 +244,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(path, stderr, 0); safestrprtn(dp->d_name, dnamlen, stderr, 1); - Error(); + Error(ctx); } if (STATFN(fp, &sb) != 0) { if (errno == ENOENT) /* a sym link to nowhere? */ @@ -269,7 +272,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- * Skip /dev/fd. */ if (strcmp(fp, "/dev/fd")) - (void)stkdir(fp); + (void)stkdir(ctx, fp); continue; } if ((sb.st_mode & S_IFMT) == S_IFLNK) { @@ -296,7 +299,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- if (!Devtp) { (void)fprintf( stderr, "%s: no space for character device\n", Pn); - Error(); + Error(ctx); } } Devtp[i].rdev = sb.st_rdev; @@ -304,7 +307,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- if (!(Devtp[i].name = mkstrcpy(fp, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for device name: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } Devtp[i].v = 0; i++; @@ -328,7 +331,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- if (!BDevtp) { (void)fprintf(stderr, "%s: no space for block device\n", Pn); - Error(); + Error(ctx); } } BDevtp[j].name = fp; @@ -344,7 +347,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- * Save a possible new st_dev number within DDEV_DEVPATH. */ if (sb.st_dev != DevDev) - (void)saveADev(&sb); + (void)saveADev(ctx, &sb); } (void)CloseDir(dfp); } @@ -372,7 +375,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- sz = (MALLOC_S)(ADevU * sizeof(dev_t)); if (!(ADev = (dev_t *)realloc((MALLOC_P *)ADev, sz))) { (void)fprintf(stderr, "%s: can't reduce ADev[]\n", Pn); - Error(); + Error(ctx); } } } @@ -401,14 +404,14 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- (MALLOC_S)(sizeof(struct l_dev *) * BNdev)))) { (void)fprintf(stderr, "%s: no space for block device sort pointers\n", Pn); - Error(); + Error(ctx); } for (j = 0; j < BNdev; j++) { BSdev[j] = &BDevtp[j]; } (void)qsort((QSORT_P *)BSdev, (size_t)BNdev, (size_t)sizeof(struct l_dev *), compdev); - BNdev = rmdupdev(&BSdev, BNdev, "block"); + BNdev = rmdupdev(ctx, &BSdev, BNdev, "block"); } # if !defined(NOWARNBLKDEV) @@ -430,17 +433,17 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- (void)fprintf(stderr, "%s: no space for character device sort pointers\n", Pn); - Error(); + Error(ctx); } for (i = 0; i < Ndev; i++) { Sdev[i] = &Devtp[i]; } (void)qsort((QSORT_P *)Sdev, (size_t)Ndev, (size_t)sizeof(struct l_dev *), compdev); - Ndev = rmdupdev(&Sdev, Ndev, "char"); + Ndev = rmdupdev(ctx, &Sdev, Ndev, "char"); } else { (void)fprintf(stderr, "%s: no character devices found\n", Pn); - Error(); + Error(ctx); } } @@ -448,10 +451,10 @@ void readdev(skip) int skip; /* skip device cache read if 1 -- * rmdupdev() - remove duplicate (major/minor/inode) devices */ -static int rmdupdev(dp, n, nm) -struct l_dev ***dp; /* device table pointers address */ -int n; /* number of pointers */ -char *nm; /* device table name for error message */ +static int rmdupdev(struct lsof_context *ctx, /* context */ + struct l_dev ***dp, /* device table pointers address */ + int n, /* number of pointers */ + char *nm) /* device table name for error message */ { int i, j, k; struct l_dev **p; @@ -471,7 +474,7 @@ char *nm; /* device table name for error message */ if (!(*dp = (struct l_dev **)realloc( (MALLOC_P *)*dp, (MALLOC_S)(j * sizeof(struct l_dev *))))) { (void)fprintf(stderr, "%s: can't realloc %s device pointers\n", Pn, nm); - Error(); + Error(ctx); } return (j); } @@ -479,8 +482,8 @@ char *nm; /* device table name for error message */ /* * saveADev() - save additional device number appearing inside DDEV_DEVPATH */ - -static void saveADev(s) struct stat *s; /* stat(2) buffer for file */ +static void saveADev(struct lsof_context *ctx, /* context */ + struct stat *s) /* stat(2) buffer for file */ { int i; MALLOC_S sz; @@ -517,7 +520,7 @@ static void saveADev(s) struct stat *s; /* stat(2) buffer for file */ ADev = (dev_t *)malloc(sz); if (!ADev) { (void)fprintf(stderr, "%s: no space for ADev[]\n", Pn); - Error(); + Error(ctx); } } ADev[ADevU++] = s->st_dev; diff --git a/lib/dialects/darwin/dfile.c b/lib/dialects/darwin/dfile.c index 56cb4e48..f62d745b 100644 --- a/lib/dialects/darwin/dfile.c +++ b/lib/dialects/darwin/dfile.c @@ -47,7 +47,8 @@ extern struct pff_tab Pgf_tab[]; */ void enter_file_info( - pfi) struct proc_fileinfo *pfi; /* pointer to process file info */ + struct lsof_context *ctx, /* context */ + struct proc_fileinfo *pfi) /* pointer to process file info */ { int f; /* @@ -84,7 +85,8 @@ void enter_file_info( */ void enter_vnode_info( - vip) struct vnode_info_path *vip; /* pointer to vnode info with path */ + struct lsof_context *ctx, /* context */ + struct vnode_info_path *vip) /* pointer to vnode info with path */ { char buf[32], *cp; dev_t dev = 0; @@ -169,7 +171,7 @@ void enter_vnode_info( * If a device number is defined, locate file system and save its identity. */ if (devs) { - for (mp = readmnt(); mp; mp = mp->next) { + for (mp = readmnt(ctx); mp; mp = mp->next) { if (dev == mp->dev) { Lf->fsdir = mp->dir; Lf->fsdev = mp->fsname; @@ -194,21 +196,22 @@ void enter_vnode_info( * Test for specified file. */ if (Sfile && - is_file_named(NULL, ((Ntype == N_CHR) || (Ntype == N_BLK) ? 1 : 0))) { + is_file_named(ctx, NULL, + ((Ntype == N_CHR) || (Ntype == N_BLK) ? 1 : 0))) { Lf->sf |= SELNM; } /* * Enter name characters. */ if (!Lf->nm && Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } /* * err2nm() -- convert errno to a message in Namech */ - -void err2nm(pfx) char *pfx; /* Namech message prefix */ +void err2nm(struct lsof_context *ctx, /* context */ + char *pfx) /* Namech message prefix */ { char *sfx; @@ -235,17 +238,16 @@ void err2nm(pfx) char *pfx; /* Namech message prefix */ sfx = strerror(errno); } (void)snpf(Namech, Namechl, "%s: %s", pfx, sfx); - enter_nm(Namech); + enter_nm(ctx, Namech); } /* * print_nm() -- print Name column */ -void print_nm(lf) struct lfile *lf; -{ +void print_nm(struct lsof_context *ctx, struct lfile *lf) { unsigned char extra = 0; - printname(0); + printname(ctx, 0); #if defined(PROC_PIDLISTFILEPORTS) if (lf->fileport) @@ -305,10 +307,7 @@ void print_nm(lf) struct lfile *lf; /* * print_v_path() -- print vnode's path */ - -int print_v_path(lf) -struct lfile *lf; -{ +int print_v_path(struct lsof_context *ctx, struct lfile *lf) { if (lf->V_path) { safestrprt(lf->V_path, stdout, 0); return (1); @@ -319,9 +318,9 @@ struct lfile *lf; /* * process_atalk() -- process an Apple Talk file */ - -void process_atalk(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_atalk(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { (void)snpf(Lf->type, sizeof(Lf->type), "ATALK"); return; @@ -330,17 +329,19 @@ int32_t fd; /* FD */ /* * process_fsevents() -- process a file system events file */ - -void process_fsevents(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ -{ (void)snpf(Lf->type, sizeof(Lf->type), "FSEVENTS"); } +void process_fsevents(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ +{ + (void)snpf(Lf->type, sizeof(Lf->type), "FSEVENTS"); +} /* * process_kqueue() -- process a kernel queue file */ - -void process_kqueue(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_kqueue(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { struct kqueue_fdinfo kq; int nb; @@ -350,7 +351,7 @@ int32_t fd; /* FD */ (void)snpf(Lf->type, sizeof(Lf->type), "KQUEUE"); nb = proc_pidfdinfo(pid, fd, PROC_PIDFDKQUEUEINFO, &kq, sizeof(kq)); if (nb <= 0) { - (void)err2nm("kqueue"); + (void)err2nm(ctx, "kqueue"); return; } else if (nb < sizeof(kq)) { (void)fprintf( @@ -359,27 +360,26 @@ int32_t fd; /* FD */ pid, fd); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(kq), nb); - Error(); + Error(ctx); } /* * Enter the kernel queue file information. */ - enter_file_info(&kq.pfi); + enter_file_info(ctx, &kq.pfi); /* * Enter queue counts as NAME column information. */ (void)snpf(Namech, Namechl, "count=%" SZOFFPSPEC "u, state=%#x", (SZOFFTYPE)kq.kqueueinfo.kq_stat.vst_size, kq.kqueueinfo.kq_state); - enter_nm(Namech); + enter_nm(ctx, Namech); } /* * process_pipe() -- process pipe file */ - -static void process_pipe_common(pi) struct pipe_fdinfo *pi; -{ +static void process_pipe_common(struct lsof_context *ctx, + struct pipe_fdinfo *pi) { char dev_ch[32], *ep; size_t sz; @@ -389,7 +389,7 @@ static void process_pipe_common(pi) struct pipe_fdinfo *pi; */ (void)snpf(dev_ch, sizeof(dev_ch), "%s", print_kptr((KA_T)pi->pipeinfo.pipe_handle, (char *)NULL, 0)); - enter_dev_ch(dev_ch); + enter_dev_ch(ctx, dev_ch); /* * Enable offset or size reporting. */ @@ -402,21 +402,22 @@ static void process_pipe_common(pi) struct pipe_fdinfo *pi; (void)snpf( Namech, Namechl, "->%s", print_kptr((KA_T)pi->pipeinfo.pipe_peerhandle, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); } else Namech[0] = '\0'; /* * If the pipe has a count, add it to the NAME column. */ if (pi->pipeinfo.pipe_stat.vst_size) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", cnt=%" SZOFFPSPEC "u", (SZOFFTYPE)pi->pipeinfo.pipe_stat.vst_size); } } -void process_pipe(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_pipe(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { int nb; struct pipe_fdinfo pi; @@ -425,7 +426,7 @@ int32_t fd; /* FD */ */ nb = proc_pidfdinfo(pid, fd, PROC_PIDFDPIPEINFO, &pi, sizeof(pi)); if (nb <= 0) { - (void)err2nm("pipe"); + (void)err2nm(ctx, "pipe"); return; } else if (nb < sizeof(pi)) { (void)fprintf( @@ -433,15 +434,16 @@ int32_t fd; /* FD */ Pn, pid, fd); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(pi), nb); - Error(); + Error(ctx); } - process_pipe_common(&pi); + process_pipe_common(ctx, &pi); } #if defined(PROC_PIDLISTFILEPORTS) -void process_fileport_pipe(pid, fp) int pid; /* PID */ -uint32_t fp; /* FILEPORT */ +void process_fileport_pipe(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + uint32_t fp) /* FILEPORT */ { int nb; struct pipe_fdinfo pi; @@ -451,7 +453,7 @@ uint32_t fp; /* FILEPORT */ nb = proc_pidfileportinfo(pid, fp, PROC_PIDFILEPORTPIPEINFO, &pi, sizeof(pi)); if (nb <= 0) { - (void)err2nm("pipe"); + (void)err2nm(ctx, "pipe"); return; } else if (nb < sizeof(pi)) { (void)fprintf(stderr, @@ -460,29 +462,29 @@ uint32_t fp; /* FILEPORT */ Pn, pid, fp); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(pi), nb); - Error(); + Error(ctx); } - process_pipe_common(&pi); + process_pipe_common(ctx, &pi); } #endif /* PROC_PIDLISTFILEPORTS */ /* * process_psem() -- process a POSIX semaphore file */ - -void process_psem(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_psem(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { int nb; struct psem_fdinfo ps; /* - * Get the sempaphore file information. + * Get the semaphore file information. */ (void)snpf(Lf->type, sizeof(Lf->type), "PSXSEM"); nb = proc_pidfdinfo(pid, fd, PROC_PIDFDPSEMINFO, &ps, sizeof(ps)); if (nb <= 0) { - (void)err2nm("semaphore"); + (void)err2nm(ctx, "semaphore"); return; } else if (nb < sizeof(ps)) { (void)fprintf( @@ -490,46 +492,45 @@ int32_t fd; /* FD */ Pn, pid, fd); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(ps), nb); - Error(); + Error(ctx); } /* * Enter the semaphore file information. */ - enter_file_info(&ps.pfi); + enter_file_info(ctx, &ps.pfi); /* * If there is a semaphore file name, enter it. */ if (ps.pseminfo.psem_name[0]) { ps.pseminfo.psem_name[sizeof(ps.pseminfo.psem_name) - 1] = '\0'; (void)snpf(Namech, Namechl, "%s", ps.pseminfo.psem_name); - enter_nm(Namech); + enter_nm(ctx, Namech); } } /* * process_pshm() -- process POSIX shared memory file */ - -static void process_pshm_common(ps) struct pshm_fdinfo *ps; -{ +static void process_pshm_common(struct lsof_context *ctx, + struct pshm_fdinfo *ps) { (void)snpf(Lf->type, sizeof(Lf->type), "PSXSHM"); /* * Enter the POSIX shared memory file information. */ - enter_file_info(&ps->pfi); + enter_file_info(ctx, &ps->pfi); /* - * If the POSIX shared memory file has a path name, enter it; otherwise, if - * it has a mapping address, enter that. + * If the POSIX shared memory file has a path name, enter it; otherwise, + * if it has a mapping address, enter that. */ if (ps->pshminfo.pshm_name[0]) { ps->pshminfo.pshm_name[sizeof(ps->pshminfo.pshm_name) - 1] = '\0'; (void)snpf(Namech, Namechl, "%s", ps->pshminfo.pshm_name); - enter_nm(Namech); + enter_nm(ctx, Namech); } else if (ps->pshminfo.pshm_mappaddr) { (void)snpf( Namech, Namechl, "obj=%s", print_kptr((KA_T)ps->pshminfo.pshm_mappaddr, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); } /* * Enable offset or size reporting. @@ -538,8 +539,9 @@ static void process_pshm_common(ps) struct pshm_fdinfo *ps; Lf->sz_def = 1; } -void process_pshm(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_pshm(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { int nb; struct pshm_fdinfo ps; @@ -548,7 +550,7 @@ int32_t fd; /* FD */ */ nb = proc_pidfdinfo(pid, fd, PROC_PIDFDPSHMINFO, &ps, sizeof(ps)); if (nb <= 0) { - (void)err2nm("POSIX shared memory"); + (void)err2nm(ctx, "POSIX shared memory"); return; } else if (nb < sizeof(ps)) { (void)fprintf( @@ -556,15 +558,16 @@ int32_t fd; /* FD */ Pn, pid, fd); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(ps), nb); - Error(); + Error(ctx); } - process_pshm_common(&ps); + process_pshm_common(ctx, &ps); } #if defined(PROC_PIDLISTFILEPORTS) -void process_fileport_pshm(pid, fp) int pid; /* PID */ -uint32_t fp; /* FILEPORT */ +void process_fileport_pshm(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + uint32_t fp) /* FILEPORT */ { int nb; struct pshm_fdinfo ps; @@ -574,7 +577,7 @@ uint32_t fp; /* FILEPORT */ nb = proc_pidfileportinfo(pid, fp, PROC_PIDFILEPORTPSHMINFO, &ps, sizeof(ps)); if (nb <= 0) { - (void)err2nm("POSIX shared memory"); + (void)err2nm(ctx, "POSIX shared memory"); return; } else if (nb < sizeof(ps)) { (void)fprintf(stderr, @@ -583,28 +586,28 @@ uint32_t fp; /* FILEPORT */ Pn, pid, fp); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(ps), nb); - Error(); + Error(ctx); } - process_pshm_common(&ps); + process_pshm_common(ctx, &ps); } #endif /* PROC_PIDLISTFILEPORTS */ /* * process_vnode() -- process a vnode file */ - -static void process_vnode_common(vi) struct vnode_fdinfowithpath *vi; -{ +static void process_vnode_common(struct lsof_context *ctx, + struct vnode_fdinfowithpath *vi) { /* * Enter the file and vnode information. */ - enter_file_info(&vi->pfi); - enter_vnode_info(&vi->pvip); + enter_file_info(ctx, &vi->pfi); + enter_vnode_info(ctx, &vi->pvip); } -void process_vnode(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_vnode(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { int nb; struct vnode_fdinfowithpath vi; @@ -615,13 +618,13 @@ int32_t fd; /* FD */ /* * The file descriptor's vnode may have been revoked. This is a - * bit of a hack, since an ENOENT error might not always mean the - * descriptor's vnode has been revoked. As the libproc API + * bit of a hack, since an ENOENT error might not always mean + * the descriptor's vnode has been revoked. As the libproc API * matures, this code may need to be revisited. */ - enter_nm("(revoked)"); + enter_nm(ctx, "(revoked)"); } else - (void)err2nm("vnode"); + (void)err2nm(ctx, "vnode"); return; } else if (nb < sizeof(vi)) { (void)fprintf( @@ -630,15 +633,16 @@ int32_t fd; /* FD */ pid, fd); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(vi), nb); - Error(); + Error(ctx); } - process_vnode_common(&vi); + process_vnode_common(ctx, &vi); } #if defined(PROC_PIDLISTFILEPORTS) -void process_fileport_vnode(pid, fp) int pid; /* PID */ -uint32_t fp; /* FILEPORT */ +void process_fileport_vnode(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + uint32_t fp) /* FILEPORT */ { int nb; struct vnode_fdinfowithpath vi; @@ -650,13 +654,13 @@ uint32_t fp; /* FILEPORT */ /* * The file descriptor's vnode may have been revoked. This is a - * bit of a hack, since an ENOENT error might not always mean the - * descriptor's vnode has been revoked. As the libproc API + * bit of a hack, since an ENOENT error might not always mean + * the descriptor's vnode has been revoked. As the libproc API * matures, this code may need to be revisited. */ - enter_nm("(revoked)"); + enter_nm(ctx, "(revoked)"); } else - (void)err2nm("vnode"); + (void)err2nm(ctx, "vnode"); return; } else if (nb < sizeof(vi)) { (void)fprintf(stderr, @@ -665,9 +669,9 @@ uint32_t fp; /* FILEPORT */ Pn, pid, fp); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(vi), nb); - Error(); + Error(ctx); } - process_vnode_common(&vi); + process_vnode_common(ctx, &vi); } #endif /* PROC_PIDLISTFILEPORTS */ diff --git a/lib/dialects/darwin/dmnt.c b/lib/dialects/darwin/dmnt.c index e8f1db2b..42af045f 100644 --- a/lib/dialects/darwin/dmnt.c +++ b/lib/dialects/darwin/dmnt.c @@ -50,7 +50,7 @@ static int Lmist = 0; /* Lmi status */ * readmnt() -- read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { #if defined(DIR_MNTSTATUS_TRIGGER) struct { uint32_t length; @@ -115,9 +115,9 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(mb->f_mntfromname, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } - if (!(ln = Readlink(dn))) { + if (!(ln = Readlink(ctx, dn))) { if (!Fwarn) { (void)fprintf(stderr, " Output information may be incomplete.\n"); @@ -133,7 +133,7 @@ struct mounts *readmnt() { /* * Stat() the directory. */ - if (statsafely(dn, &sb)) { + if (statsafely(ctx, dn, &sb)) { if (!Fwarn) { (void)fprintf(stderr, "%s: WARNING: can't stat() ", Pn); @@ -172,13 +172,13 @@ struct mounts *readmnt() { if (!(dn = mkstrcpy(mb->f_mntfromname, (MALLOC_S *)NULL))) goto no_space_for_mount; mtp->fsname = dn; - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat() the file system (mounted-on) name and add file system * information to the local mount table entry. */ - if (!ln || statsafely(ln, &sb)) + if (!ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mtp->fsnmres = ln; mtp->fs_mode = sb.st_mode; diff --git a/lib/dialects/darwin/dproc.c b/lib/dialects/darwin/dproc.c index bb552c29..19bb6709 100644 --- a/lib/dialects/darwin/dproc.c +++ b/lib/dialects/darwin/dproc.c @@ -90,24 +90,26 @@ static int NVips = 0; /* entries allocated to Vips */ /* * Local function prototypes */ -_PROTOTYPE(static void enter_vn_text, (struct vnode_info_path * vip, int *n)); -_PROTOTYPE(static void process_fds, (int pid, uint32_t n, int ckscko)); -_PROTOTYPE(static void process_text, (int pid)); +static void enter_vn_text(struct lsof_context *ctx, struct vnode_info_path *vip, + int *n); +static void process_fds(struct lsof_context *ctx, int pid, uint32_t n, + int ckscko); +static void process_text(struct lsof_context *ctx, int pid); #if DARWINV >= 900 -_PROTOTYPE(static void process_threads, (int pid, uint32_t n)); +static void process_threads(struct lsof_context *ctx, int pid, uint32_t n); #endif /* DARWINV>=900 */ #if defined(PROC_PIDLISTFILEPORTS) -_PROTOTYPE(static void process_fileports, (int pid, int ckscko)); +static void process_fileports(struct lsof_context *ctx, int pid, int ckscko); #endif /* PROC_PIDLISTFILEPORTS */ /* * enter_vn_text() -- enter vnode information text reference */ - -static void enter_vn_text(vip, n) struct vnode_info_path *vip; /* vnode info */ -int *n; /* number of vips[] entries in use */ +static void enter_vn_text(struct lsof_context *ctx, /* context */ + struct vnode_info_path *vip, /* vnode info */ + int *n) /* number of vips[] entries in use */ { int i; /* @@ -122,11 +124,11 @@ int *n; /* number of vips[] entries in use */ /* * Save the text file information. */ - alloc_lfile(" txt", -1); + alloc_lfile(ctx, " txt", -1); Cfp = (struct file *)NULL; - (void)enter_vnode_info(vip); + (void)enter_vnode_info(ctx, vip); if (Lf->sf) - link_lfile(); + link_lfile(ctx); /* * Record the entry of the vnode information. */ @@ -145,7 +147,7 @@ int *n; /* number of vips[] entries in use */ if (!Vips) { (void)fprintf(stderr, "%s: PID %d: no text recording space\n", Pn, Lp->pid); - Error(); + Error(ctx); } } /* @@ -159,8 +161,7 @@ int *n; /* number of vips[] entries in use */ /* * gather_proc_info() -- gather process information */ - -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { short cckreg; /* conditional status of regular file * checking: * 0 = unconditionally check @@ -232,7 +233,7 @@ void gather_proc_info() { if ((nb = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0)) <= 0) { (void)fprintf(stderr, "%s: can't get PID byte count: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (nb > NbPids) { while (nb > NbPids) { @@ -245,7 +246,7 @@ void gather_proc_info() { if (!Pids) { (void)fprintf(stderr, "%s: can't allocate space for %d PIDs\n", Pn, (int)(NbPids / sizeof(int *))); - Error(); + Error(ctx); } } /* @@ -255,7 +256,7 @@ void gather_proc_info() { if ((nb = proc_listpids(PROC_ALL_PIDS, 0, Pids, NbPids)) <= 0) { (void)fprintf(stderr, "%s: can't get list of PIDs: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if ((nb + sizeof(int)) < NbPids) { @@ -275,7 +276,7 @@ void gather_proc_info() { if (!Pids) { (void)fprintf(stderr, "%s: can't allocate space for %d PIDs\n", Pn, (int)(NbPids / sizeof(int *))); - Error(); + Error(ctx); } } } @@ -300,21 +301,21 @@ void gather_proc_info() { Pn, pid); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(tai), nb); - Error(); + Error(ctx); } /* * Check for process or command exclusion. */ - if (is_proc_excl((int)pid, (int)tai.pbsd.pbi_pgid, + if (is_proc_excl(ctx, (int)pid, (int)tai.pbsd.pbi_pgid, (UID_ARG)tai.pbsd.pbi_uid, &pss, &sf)) { continue; } tai.pbsd.pbi_comm[sizeof(tai.pbsd.pbi_comm) - 1] = '\0'; - if (is_cmd_excl(tai.pbsd.pbi_comm, &pss, &sf)) + if (is_cmd_excl(ctx, tai.pbsd.pbi_comm, &pss, &sf)) continue; if (tai.pbsd.pbi_name[0]) { tai.pbsd.pbi_name[sizeof(tai.pbsd.pbi_name) - 1] = '\0'; - if (is_cmd_excl(tai.pbsd.pbi_name, &pss, &sf)) + if (is_cmd_excl(ctx, tai.pbsd.pbi_name, &pss, &sf)) continue; } if (cckreg) { @@ -342,7 +343,7 @@ void gather_proc_info() { (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(vpi), nb); - Error(); + Error(ctx); } else cres = 0; } @@ -352,8 +353,8 @@ void gather_proc_info() { * Caveat: pbi_name can be changed by setprogname(3), while pbi_comm * cannot. Should we allow empty pbi_name here? */ - alloc_lproc((int)pid, (int)tai.pbsd.pbi_pgid, (int)tai.pbsd.pbi_ppid, - (UID_ARG)tai.pbsd.pbi_uid, + alloc_lproc(ctx, (int)pid, (int)tai.pbsd.pbi_pgid, + (int)tai.pbsd.pbi_ppid, (UID_ARG)tai.pbsd.pbi_uid, (tai.pbsd.pbi_name[0] != '\0') ? tai.pbsd.pbi_name : tai.pbsd.pbi_comm, (int)pss, (int)sf); @@ -363,7 +364,7 @@ void gather_proc_info() { */ if (!ckscko) { if (cres || vpi.pvi_cdir.vip_path[0]) { - alloc_lfile(CWD, -1); + alloc_lfile(ctx, CWD, -1); Cfp = (struct file *)NULL; if (cres) { @@ -376,14 +377,14 @@ void gather_proc_info() { (void)snpf(Namech, Namechl, "%s|%s info error: %s", CWD + 1, RTD + 1, strerror(cre)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } else { - (void)enter_vnode_info(&vpi.pvi_cdir); + (void)enter_vnode_info(ctx, &vpi.pvi_cdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } } @@ -392,11 +393,11 @@ void gather_proc_info() { */ if (!ckscko) { if (!cres && vpi.pvi_rdir.vip_path[0]) { - alloc_lfile(RTD, -1); + alloc_lfile(ctx, RTD, -1); Cfp = (struct file *)NULL; - (void)enter_vnode_info(&vpi.pvi_rdir); + (void)enter_vnode_info(ctx, &vpi.pvi_rdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } @@ -406,7 +407,7 @@ void gather_proc_info() { */ if (!ckscko) { if (tai.pbsd.pbi_flags & PROC_FLAG_THCWD) { - (void)process_threads(pid, tai.ptinfo.pti_threadnum); + (void)process_threads(ctx, pid, tai.ptinfo.pti_threadnum); } } #endif /* DARWINV>=900 */ @@ -415,23 +416,23 @@ void gather_proc_info() { * Print text file information. */ if (!ckscko) - (void)process_text(pid); + (void)process_text(ctx, pid); #if defined(PROC_PIDLISTFILEPORTS) /* * Loop through the fileports */ - (void)process_fileports(pid, ckscko); + (void)process_fileports(ctx, pid, ckscko); #endif /* PROC_PIDLISTFILEPORTS */ /* * Loop through the file descriptors. */ - (void)process_fds(pid, tai.pbsd.pbi_nfiles, ckscko); + (void)process_fds(ctx, pid, tai.pbsd.pbi_nfiles, ckscko); /* * Examine results. */ - if (examine_lproc()) + if (examine_lproc(ctx)) return; } } @@ -440,15 +441,15 @@ void gather_proc_info() { * initialize() -- perform all initialization */ -void initialize() {} +void initialize(struct lsof_context *ctx) {} /* * process_fds() -- process file descriptors */ - -static void process_fds(pid, n, ckscko) int pid; /* PID of interest */ -uint32_t n; /* max FDs */ -int ckscko; /* check socket files only */ +static void process_fds(struct lsof_context *ctx, /* context */ + int pid, /* PID of interest */ + uint32_t n, /* max FDs */ + int ckscko) /* check socket files only */ { int i, isock, nb, nf; struct proc_fdinfo *fdp; @@ -469,7 +470,7 @@ int ckscko; /* check socket files only */ if (!Fds) { (void)fprintf(stderr, "%s: PID %d: can't allocate space for %d FDs\n", Pn, pid, (int)(NbFds / sizeof(struct proc_fdinfo))); - Error(); + Error(ctx); } /* * Get FD information for the process. @@ -486,12 +487,12 @@ int ckscko; /* check socket files only */ /* * Make a dummy file entry with an error message in its NAME column. */ - alloc_lfile(" err", -1); + alloc_lfile(ctx, " err", -1); (void)snpf(Namech, Namechl, "FD info error: %s", strerror(errno)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); return; } nf = (int)(nb / sizeof(struct proc_fdinfo)); @@ -500,7 +501,7 @@ int ckscko; /* check socket files only */ */ for (i = 0; i < nf; i++) { fdp = &Fds[i]; - alloc_lfile(NULL, (int)fdp->proc_fd); + alloc_lfile(ctx, NULL, (int)fdp->proc_fd); /* * Process the file by its type. */ @@ -508,44 +509,44 @@ int ckscko; /* check socket files only */ switch (fdp->proc_fdtype) { case PROX_FDTYPE_ATALK: if (!ckscko) - (void)process_atalk(pid, fdp->proc_fd); + (void)process_atalk(ctx, pid, fdp->proc_fd); break; case PROX_FDTYPE_FSEVENTS: if (!ckscko) - (void)process_fsevents(pid, fdp->proc_fd); + (void)process_fsevents(ctx, pid, fdp->proc_fd); break; case PROX_FDTYPE_KQUEUE: if (!ckscko) - (void)process_kqueue(pid, fdp->proc_fd); + (void)process_kqueue(ctx, pid, fdp->proc_fd); break; case PROX_FDTYPE_PIPE: if (!ckscko) - (void)process_pipe(pid, fdp->proc_fd); + (void)process_pipe(ctx, pid, fdp->proc_fd); break; case PROX_FDTYPE_PSEM: if (!ckscko) - (void)process_psem(pid, fdp->proc_fd); + (void)process_psem(ctx, pid, fdp->proc_fd); break; case PROX_FDTYPE_SOCKET: - (void)process_socket(pid, fdp->proc_fd); + (void)process_socket(ctx, pid, fdp->proc_fd); isock = 1; break; case PROX_FDTYPE_PSHM: - (void)process_pshm(pid, fdp->proc_fd); + (void)process_pshm(ctx, pid, fdp->proc_fd); break; case PROX_FDTYPE_VNODE: - (void)process_vnode(pid, fdp->proc_fd); + (void)process_vnode(ctx, pid, fdp->proc_fd); break; default: (void)snpf(Namech, Namechl - 1, "unknown file type: %d", fdp->proc_fdtype); Namech[Namechl - 1] = '\0'; - (void)enter_nm(Namech); + (void)enter_nm(ctx, Namech); break; } if (Lf->sf) { if (!ckscko || isock) - link_lfile(); + link_lfile(ctx); } } } @@ -554,9 +555,9 @@ int ckscko; /* check socket files only */ /* * process_fileports() -- process fileports */ - -static void process_fileports(pid, ckscko) int pid; /* PID of interest */ -int ckscko; /* check socket files only */ +static void process_fileports(struct lsof_context *ctx, /* context */ + int pid, /* PID of interest */ + int ckscko) /* check socket files only */ { int ef, i, isock, nb = 0, nf; struct proc_fileportinfo *fpi; @@ -583,13 +584,13 @@ int ckscko; /* check socket files only */ /* * Make a dummy file entry with an error message in its NAME column. */ - alloc_lfile(" err", -1); + alloc_lfile(ctx, " err", -1); (void)snpf(Namech, Namechl, "FILEPORT info error: %s", strerror(errno)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } if ((nb + sizeof(struct proc_fileportinfo)) < NbFps) { @@ -603,7 +604,7 @@ int ckscko; /* check socket files only */ 0)) <= 0)) { (void)fprintf(stderr, "%s: can't get fileport byte count: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } /* @@ -630,7 +631,7 @@ int ckscko; /* check socket files only */ * fileport reported as "fp." with "(fileport=0xXXXX)" in the Name * column */ - alloc_lfile(" fp.", -1); + alloc_lfile(ctx, " fp.", -1); Lf->fileport = fpi->proc_fileport; /* * Process the file by its type. @@ -639,28 +640,28 @@ int ckscko; /* check socket files only */ switch (fpi->proc_fdtype) { case PROX_FDTYPE_PIPE: if (!ckscko) - (void)process_fileport_pipe(pid, fpi->proc_fileport); + (void)process_fileport_pipe(ctx, pid, fpi->proc_fileport); break; case PROX_FDTYPE_SOCKET: - (void)process_fileport_socket(pid, fpi->proc_fileport); + (void)process_fileport_socket(ctx, pid, fpi->proc_fileport); isock = 1; break; case PROX_FDTYPE_PSHM: - (void)process_fileport_pshm(pid, fpi->proc_fileport); + (void)process_fileport_pshm(ctx, pid, fpi->proc_fileport); break; case PROX_FDTYPE_VNODE: - (void)process_fileport_vnode(pid, fpi->proc_fileport); + (void)process_fileport_vnode(ctx, pid, fpi->proc_fileport); break; default: (void)snpf(Namech, Namechl - 1, "unknown file type: %d", fpi->proc_fileport); Namech[Namechl - 1] = '\0'; - (void)enter_nm(Namech); + (void)enter_nm(ctx, Namech); break; } if (Lf->sf) { if (!ckscko || isock) - link_lfile(); + link_lfile(ctx); } } } @@ -669,8 +670,8 @@ int ckscko; /* check socket files only */ /* * process_text() -- process text information */ - -static void process_text(pid) int pid; /* PID */ +static void process_text(struct lsof_context *ctx, /* context */ + int pid) /* PID */ { uint64_t a; int i, n, nb; @@ -690,14 +691,14 @@ static void process_text(pid) int pid; /* PID */ /* * Warn about all other errors via a NAME column message. */ - alloc_lfile(" txt", -1); + alloc_lfile(ctx, " txt", -1); Cfp = (struct file *)NULL; (void)snpf(Namech, Namechl, "region info error: %s", strerror(errno)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); return; } else if (nb < sizeof(rwpi)) { (void)fprintf(stderr, @@ -705,10 +706,10 @@ static void process_text(pid) int pid; /* PID */ Pn, pid); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(rwpi), nb); - Error(); + Error(ctx); } if (rwpi.prp_vip.vip_path[0]) - enter_vn_text(&rwpi.prp_vip, &n); + enter_vn_text(ctx, &rwpi.prp_vip, &n); a = rwpi.prp_prinfo.pri_address + rwpi.prp_prinfo.pri_size; } } @@ -722,8 +723,9 @@ static void process_text(pid) int pid; /* PID */ " twd" /* per-thread current working directory \ * fd name */ -static void process_threads(pid, n) int pid; /* PID */ -uint32_t n; /* number of threads */ +static void process_threads(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + uint32_t n) /* number of threads */ { int i, nb, nt; /* @@ -742,7 +744,7 @@ uint32_t n; /* number of threads */ if (!Threads) { (void)fprintf(stderr, "%s: can't allocate space for %d Threads\n", Pn, (int)(NbThreads / sizeof(int *))); - Error(); + Error(ctx); } } /* @@ -781,14 +783,14 @@ uint32_t n; /* number of threads */ /* * Warn about all other errors via a NAME column message. */ - alloc_lfile(TWD, -1); + alloc_lfile(ctx, TWD, -1); Cfp = (struct file *)NULL; (void)snpf(Namech, Namechl, "thread info error: %s", strerror(errno)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); return; } else if (nb < sizeof(tpi)) { (void)fprintf(stderr, @@ -796,14 +798,14 @@ uint32_t n; /* number of threads */ Pn, pid); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(tpi), nb); - Error(); + Error(ctx); } if (tpi.pvip.vip_path[0]) { - alloc_lfile(TWD, -1); + alloc_lfile(ctx, TWD, -1); Cfp = (struct file *)NULL; - (void)enter_vnode_info(&tpi.pvip); + (void)enter_vnode_info(ctx, &tpi.pvip); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } } diff --git a/lib/dialects/darwin/dproto.h b/lib/dialects/darwin/dproto.h index 05c6f6f3..1157cec2 100644 --- a/lib/dialects/darwin/dproto.h +++ b/lib/dialects/darwin/dproto.h @@ -38,21 +38,27 @@ * $Id: dproto.h,v 1.6 2012/04/10 16:41:04 abe Exp abe $ */ -_PROTOTYPE(extern void enter_file_info, (struct proc_fileinfo * pfi)); -_PROTOTYPE(extern void enter_vnode_info, (struct vnode_info_path * vip)); -_PROTOTYPE(extern void err2nm, (char *pfx)); -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern void process_atalk, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_fsevents, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_kqueue, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_pipe, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_psem, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_pshm, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_socket, (int pid, int32_t fd)); -_PROTOTYPE(extern void process_vnode, (int pid, int32_t fd)); +extern void enter_file_info(struct lsof_context *ctx, + struct proc_fileinfo *pfi); +extern void enter_vnode_info(struct lsof_context *ctx, + struct vnode_info_path *vip); +extern void err2nm(struct lsof_context *ctx, char *pfx); +extern int is_file_named(struct lsof_context *ctx, char *p, int cd); +extern void process_atalk(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_fsevents(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_kqueue(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_pipe(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_psem(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_pshm(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_socket(struct lsof_context *ctx, int pid, int32_t fd); +extern void process_vnode(struct lsof_context *ctx, int pid, int32_t fd); #if defined(PROC_PIDLISTFILEPORTS) -_PROTOTYPE(extern void process_fileport_pipe, (int pid, uint32_t fileport)); -_PROTOTYPE(extern void process_fileport_pshm, (int pid, uint32_t fileport)); -_PROTOTYPE(extern void process_fileport_socket, (int pid, uint32_t fileport)); -_PROTOTYPE(extern void process_fileport_vnode, (int pid, uint32_t fileport)); +extern void process_fileport_pipe(struct lsof_context *ctx, int pid, + uint32_t fileport); +extern void process_fileport_pshm(struct lsof_context *ctx, int pid, + uint32_t fileport); +extern void process_fileport_socket(struct lsof_context *ctx, int pid, + uint32_t fileport); +extern void process_fileport_vnode(struct lsof_context *ctx, int pid, + uint32_t fileport); #endif /* PROC_PIDLISTFILEPORTS */ diff --git a/lib/dialects/darwin/dsock.c b/lib/dialects/darwin/dsock.c index 2d7b113a..4f6c9eda 100644 --- a/lib/dialects/darwin/dsock.c +++ b/lib/dialects/darwin/dsock.c @@ -50,8 +50,8 @@ static char copyright[] = "@(#) Copyright 2005 Apple Computer, Inc. and Purdue " * process_socket() -- process socket file */ -static void process_socket_common(si) struct socket_fdinfo *si; -{ +static void process_socket_common(struct lsof_context *ctx, + struct socket_fdinfo *si) { unsigned char *fa = (unsigned char *)NULL; int fam, fp, lp, unl; unsigned char *la = (unsigned char *)NULL; @@ -64,7 +64,7 @@ static void process_socket_common(si) struct socket_fdinfo *si; /* * Enter basic file information. */ - enter_file_info(&si->pfi); + enter_file_info(ctx, &si->pfi); /* * Enable size or offset display. */ @@ -157,10 +157,12 @@ static void process_socket_common(si) struct socket_fdinfo *si; printiproto(si->psi.soi_protocol); if ((si->psi.soi_kind == SOCKINFO_TCP) && si->psi.soi_proto.pri_tcp.tcpsi_tp) { - enter_dev_ch(print_kptr((KA_T)si->psi.soi_proto.pri_tcp.tcpsi_tp, + enter_dev_ch(ctx, + print_kptr((KA_T)si->psi.soi_proto.pri_tcp.tcpsi_tp, (char *)NULL, 0)); } else - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, + print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); if (fam == AF_INET) { /* @@ -248,7 +250,7 @@ static void process_socket_common(si) struct socket_fdinfo *si; * Enter local and remote addresses by address family. */ if (fa || la) - (void)ent_inaddr(la, lp, fa, fp, fam); + (void)ent_inaddr(ctx, la, lp, fa, fp, fam); if (si->psi.soi_kind == SOCKINFO_TCP) { /* @@ -282,7 +284,7 @@ static void process_socket_common(si) struct socket_fdinfo *si; break; if (Funix) Lf->sf |= SELUNX; - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); /* * Enter information on a UNIX domain socket that has no address bound * to it, although it may be connected to another UNIX domain socket @@ -317,7 +319,7 @@ static void process_socket_common(si) struct socket_fdinfo *si; if (si->psi.soi_proto.pri_un.unsi_addr.ua_sun.sun_path[0] && Sfile && is_file_named( - si->psi.soi_proto.pri_un.unsi_addr.ua_sun.sun_path, 0)) + ctx, si->psi.soi_proto.pri_un.unsi_addr.ua_sun.sun_path, 0)) Lf->sf |= SELNM; if (si->psi.soi_proto.pri_un.unsi_addr.ua_sun.sun_path[0] && !Namech[0]) @@ -341,7 +343,7 @@ static void process_socket_common(si) struct socket_fdinfo *si; (void)snpf(Lf->type, sizeof(Lf->type), "ndrv"); if (si->psi.soi_kind != SOCKINFO_NDRV) break; - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); si->psi.soi_proto.pri_ndrv .ndrvsi_if_name[sizeof(si->psi.soi_proto.pri_ndrv.ndrvsi_if_name) - 1] = '\0'; @@ -355,7 +357,7 @@ static void process_socket_common(si) struct socket_fdinfo *si; * Process an [internal] key-management function socket. */ (void)snpf(Lf->type, sizeof(Lf->type), "key"); - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); break; case AF_SYSTEM: @@ -365,14 +367,16 @@ static void process_socket_common(si) struct socket_fdinfo *si; (void)snpf(Lf->type, sizeof(Lf->type), "systm"); switch (si->psi.soi_kind) { case SOCKINFO_KERN_EVENT: - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, + print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); (void)snpf(Namech, Namechl, "[event %x:%x:%x]", si->psi.soi_proto.pri_kern_event.kesi_vendor_code_filter, si->psi.soi_proto.pri_kern_event.kesi_class_filter, si->psi.soi_proto.pri_kern_event.kesi_subclass_filter); break; case SOCKINFO_KERN_CTL: - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, + print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); (void)snpf(Namech, Namechl, "[ctl %s id %d unit %d]", si->psi.soi_proto.pri_kern_ctl.kcsi_name, si->psi.soi_proto.pri_kern_ctl.kcsi_id, @@ -386,20 +390,21 @@ static void process_socket_common(si) struct socket_fdinfo *si; * Process a PPP domain socket. */ (void)snpf(Lf->type, sizeof(Lf->type), "ppp"); - enter_dev_ch(print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)si->psi.soi_pcb, (char *)NULL, 0)); break; default: - printunkaf(fam, 1); + printunkaf(ctx, fam, 1); } /* * If there are NAME column characters, enter them. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } -void process_socket(pid, fd) int pid; /* PID */ -int32_t fd; /* FD */ +void process_socket(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + int32_t fd) /* FD */ { int nb; struct socket_fdinfo si; @@ -408,7 +413,7 @@ int32_t fd; /* FD */ */ nb = proc_pidfdinfo(pid, fd, PROC_PIDFDSOCKETINFO, &si, sizeof(si)); if (nb <= 0) { - (void)err2nm("socket"); + (void)err2nm(ctx, "socket"); return; } else if (nb < sizeof(si)) { (void)fprintf( @@ -417,15 +422,16 @@ int32_t fd; /* FD */ pid, fd); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(si), nb); - Error(); + Error(ctx); } - process_socket_common(&si); + process_socket_common(ctx, &si); } #if defined(PROC_PIDLISTFILEPORTS) -void process_fileport_socket(pid, fp) int pid; /* PID */ -uint32_t fp; /* FILEPORT */ +void process_fileport_socket(struct lsof_context *ctx, /* context */ + int pid, /* PID */ + uint32_t fp) /* FILEPORT */ { int nb; struct socket_fdinfo si; @@ -435,7 +441,7 @@ uint32_t fp; /* FILEPORT */ nb = proc_pidfileportinfo(pid, fp, PROC_PIDFILEPORTSOCKETINFO, &si, sizeof(si)); if (nb <= 0) { - (void)err2nm("socket"); + (void)err2nm(ctx, "socket"); return; } else if (nb < sizeof(si)) { (void)fprintf(stderr, @@ -444,9 +450,9 @@ uint32_t fp; /* FILEPORT */ Pn, pid, fp); (void)fprintf(stderr, " too few bytes; expected %ld, got %d\n", sizeof(si), nb); - Error(); + Error(ctx); } - process_socket_common(&si); + process_socket_common(ctx, &si); } #endif /* PROC_PIDLISTFILEPORTS */ diff --git a/lib/dialects/freebsd/dmnt.c b/lib/dialects/freebsd/dmnt.c index 96222718..5144fbc9 100644 --- a/lib/dialects/freebsd/dmnt.c +++ b/lib/dialects/freebsd/dmnt.c @@ -53,7 +53,7 @@ static char *mnt_names[] = INITMOUNTNAMES; * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char *dn = (char *)NULL; char *ln; struct statfs *mb; @@ -97,9 +97,9 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(mb->f_mntfromname, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } - if (!(ln = Readlink(dn))) { + if (!(ln = Readlink(ctx, dn))) { if (!Fwarn) { (void)fprintf(stderr, " Output information may be incomplete.\n"); @@ -115,7 +115,7 @@ struct mounts *readmnt() { /* * Stat() the directory. */ - if (statsafely(dn, &sb)) { + if (statsafely(ctx, dn, &sb)) { if (!Fwarn) { (void)fprintf(stderr, "%s: WARNING: can't stat() ", Pn); @@ -170,13 +170,13 @@ struct mounts *readmnt() { if (!(dn = mkstrcpy(mb->f_mntfromname, (MALLOC_S *)NULL))) goto no_space_for_mount; mtp->fsname = dn; - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat() the file system (mounted-on) name and add file system * information to the local mount table entry. */ - if (!ln || statsafely(ln, &sb)) + if (!ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mtp->fsnmres = ln; mtp->fs_mode = sb.st_mode; @@ -195,7 +195,8 @@ struct mounts *readmnt() { * readvfs() - read vfs structure */ -struct l_vfs *readvfs(uint64_t fsid, const char *path) { +struct l_vfs *readvfs(struct lsof_context *ctx, uint64_t fsid, + const char *path) { struct statfs m; struct l_vfs *vp; /* @@ -226,13 +227,13 @@ struct l_vfs *readvfs(uint64_t fsid, const char *path) { } if (!(vp = (struct l_vfs *)malloc(sizeof(struct l_vfs)))) { (void)fprintf(stderr, "%s: PID %d, no space for vfs\n", Pn, Lp->pid); - Error(); + Error(ctx); } if (!(vp->dir = mkstrcpy(m.f_mntonname, (MALLOC_S *)NULL)) || !(vp->fsname = mkstrcpy(m.f_mntfromname, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: PID %d, no space for mount names\n", Pn, Lp->pid); - Error(); + Error(ctx); } vp->fsid = fsid; @@ -249,7 +250,7 @@ struct l_vfs *readvfs(uint64_t fsid, const char *path) { (char *)NULL, -1, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for fs type name: ", Pn); safestrprt(m.f_fstypename, stderr, 1); - Error(); + Error(ctx); } } else vp->typnm = ""; diff --git a/lib/dialects/freebsd/dnode.c b/lib/dialects/freebsd/dnode.c index 271cd1e6..fc73e643 100644 --- a/lib/dialects/freebsd/dnode.c +++ b/lib/dialects/freebsd/dnode.c @@ -43,7 +43,7 @@ static char copyright[] = # include #endif /* defined(HASPTSFN) && defined(DTYPE_PTS) */ -_PROTOTYPE(static void get_lock_state_kvm, (KA_T f)); +static void get_lock_state_kvm(struct lsof_context *ctx, KA_T f); /* * get_lock_state_*() - get the lock state @@ -70,7 +70,8 @@ static void get_lock_state_sysctl(struct kinfo_file *kf, } #endif /* KERN_LOCKF */ -static void get_lock_state_kvm(f) KA_T f; /* inode's lock pointer */ +static void get_lock_state_kvm(struct lsof_context *ctx, /* context */ + KA_T f) /* inode's lock pointer */ { struct lockf lf; /* lockf structure */ int lt; /* lock type */ @@ -80,15 +81,16 @@ static void get_lock_state_kvm(f) KA_T f; /* inode's lock pointer */ KA_T lef, lep; /* lock_entry pointers */ struct lock_owner lo; /* lock owner structure */ - if (!f || kread(f, (char *)&lf, sizeof(lf))) + if (!f || kread(ctx, f, (char *)&lf, sizeof(lf))) return; if (!(lef = (KA_T)lf.ls_active.lh_first)) return; lep = lef; do { - if (kread(lep, (char *)&le, sizeof(le))) + if (kread(ctx, lep, (char *)&le, sizeof(le))) return; - if (!le.lf_owner || kread((KA_T)le.lf_owner, (char *)&lo, sizeof(lo))) + if (!le.lf_owner || + kread(ctx, (KA_T)le.lf_owner, (char *)&lo, sizeof(lo))) continue; if (lo.lo_pid == (pid_t)Lp->pid) { if (le.lf_start == (off_t)0 && le.lf_end == 0x7fffffffffffffffLL) @@ -113,7 +115,7 @@ static void get_lock_state_kvm(f) KA_T f; /* inode's lock pointer */ * Determine the lock state. */ do { - if (kread(lfp, (char *)&lf, sizeof(lf))) + if (kread(ctx, lfp, (char *)&lf, sizeof(lf))) break; l = 0; switch (lf.lf_flags & (F_FLOCK | F_POSIX)) { @@ -154,43 +156,44 @@ static void get_lock_state_kvm(f) KA_T f; /* inode's lock pointer */ * a file processing function. However, the Net and Open BSD sources don't * require a dfile.c, so this is the next best location for the function. */ - -void process_kf_kqueue(struct kinfo_file *kf, KA_T ka) { +void process_kf_kqueue(struct lsof_context *ctx, /* context */ + struct kinfo_file *kf, /* kernel file*/ + KA_T ka /* kernel address */) { # if __FreeBSD_version < 1400062 struct kqueue kq; /* kqueue structure */ # endif /* __FreeBSD_version < 1400062 */ (void)snpf(Lf->type, sizeof(Lf->type), "KQUEUE"); - enter_dev_ch(print_kptr(ka, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(ka, (char *)NULL, 0)); # if __FreeBSD_version >= 1400062 (void)snpf(Namech, Namechl, "count=%d, state=%#x", kf->kf_un.kf_kqueue.kf_kqueue_count, kf->kf_un.kf_kqueue.kf_kqueue_state); # else /* __FreeBSD_version < 1400062 */ - if (!ka || kread(ka, (char *)&kq, sizeof(kq))) + if (!ka || kread(ctx, ka, (char *)&kq, sizeof(kq))) return; (void)snpf(Namech, Namechl, "count=%d, state=%#x", kq.kq_count, kq.kq_state); # endif /* __FreeBSD_version >= 1400062 */ - enter_nm(Namech); + enter_nm(ctx, Namech); } #endif /* defined(HASKQUEUE) */ #if defined(KF_TYPE_EVENTFD) -void process_eventfd(struct kinfo_file *kf) { +void process_eventfd(struct lsof_context *ctx, struct kinfo_file *kf) { (void)snpf(Lf->type, sizeof(Lf->type), "EVENTFD"); # if __FreeBSD_version >= 1400062 enter_dev_ch( - print_kptr(kf->kf_un.kf_eventfd.kf_eventfd_addr, (char *)NULL, 0)); + ctx, print_kptr(kf->kf_un.kf_eventfd.kf_eventfd_addr, (char *)NULL, 0)); # endif /* __FreeBSD_version >= 1400062 */ (void)snpf(Namech, Namechl, "value=%ju, flags=0x%x", kf->kf_un.kf_eventfd.kf_eventfd_value, kf->kf_un.kf_eventfd.kf_eventfd_flags); - enter_nm(Namech); + enter_nm(ctx, Namech); } #endif /* defined(KF_TYPE_EVENTFD) */ -void process_shm(struct kinfo_file *kf) { +void process_shm(struct lsof_context *ctx, struct kinfo_file *kf) { (void)snpf(Lf->type, sizeof(Lf->type), "SHM"); Lf->sz = kf->kf_un.kf_file.kf_file_size; Lf->sz_def = 1; @@ -201,19 +204,19 @@ void process_shm(struct kinfo_file *kf) { } if (kf->kf_path[0]) { snpf(Namech, Namechl, "%s", kf->kf_path); - enter_nm(Namech); + enter_nm(ctx, Namech); } } -void process_procdesc(struct kinfo_file *kf) { +void process_procdesc(struct lsof_context *ctx, struct kinfo_file *kf) { char pidstr[50]; snpf(Lf->type, sizeof(Lf->type), "PROCDSC"); snpf(pidstr, sizeof(pidstr), "pid=%d", kf->kf_un.kf_proc.kf_pid); - add_nma(pidstr, strlen(pidstr)); + add_nma(ctx, pidstr, strlen(pidstr)); if (kf->kf_path[0]) { snpf(Namech, Namechl, "%s", kf->kf_path); - enter_nm(Namech); + enter_nm(ctx, Namech); } } @@ -269,8 +272,8 @@ static const char *parse_proc_path(struct kinfo_file *kf, int *proc_pid) { * process_vnode() - process vnode */ -void process_vnode(struct kinfo_file *kf, struct xfile *xfile, - struct lock_list *locks) { +void process_vnode(struct lsof_context *ctx, struct kinfo_file *kf, + struct xfile *xfile, struct lock_list *locks) { dev_t dev = 0, rdev = 0; unsigned char devs; unsigned char rdevs; @@ -306,7 +309,7 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, if (++sc > 1024) { (void)snpf(Namech, Namechl, "too many overlaid nodes"); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } #endif /* defined(HASNULLFS) */ @@ -324,7 +327,7 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, v = NULL; if (va) { v = &vb; - if (kread((KA_T)va, (char *)v, sizeof(struct vnode))) + if (kread(ctx, (KA_T)va, (char *)v, sizeof(struct vnode))) v = NULL; } @@ -339,7 +342,7 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, /* * Get the vnode type. */ - vfs = readvfs(fsid, vfs_path); + vfs = readvfs(ctx, fsid, vfs_path); if (vfs) { fsid = vfs->fsid; @@ -385,7 +388,7 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, get_lock_state_sysctl(kf, locks); #elif defined(HAS_V_LOCKF) if (v && v->v_lockf) - (void)get_lock_state_kvm((KA_T)v->v_lockf); + (void)get_lock_state_kvm(ctx, (KA_T)v->v_lockf); #endif /* KERN_LOCKF */ /* @@ -427,7 +430,7 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, np = tbuf; } else np = "(nullfs)"; - (void)add_nma(np, (int)strlen(np)); + (void)add_nma(ctx, np, (int)strlen(np)); } fsid = VNOVAL; /* -------dir-------- @@ -594,7 +597,7 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, * supply one. */ if ((Lf->inp_ty == 0) && (kf_vtype == KF_VTYPE_VCHR)) - find_ch_ino(); + find_ch_ino(ctx); /* * Test for specified file. */ @@ -623,26 +626,27 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, } } } else { - if (Sfile && is_file_named((char *)NULL, ((kf_vtype == KF_VTYPE_VCHR) || - (kf_vtype == KF_VTYPE_VBLK)) - ? 1 - : 0)) + if (Sfile && is_file_named(ctx, (char *)NULL, + ((kf_vtype == KF_VTYPE_VCHR) || + (kf_vtype == KF_VTYPE_VBLK)) + ? 1 + : 0)) Lf->sf |= SELNM; } /* * Enter name characters. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); else if (kf->kf_path[0]) { snpf(Namech, Namechl, "%s", kf->kf_path); if (vfs && vfs->fsname) { char *cp; size_t sz; - cp = endnm(&sz); + cp = endnm(ctx, &sz); snpf(cp, sz, " (%s)", vfs->fsname); } - enter_nm(Namech); + enter_nm(ctx, Namech); } } @@ -650,19 +654,19 @@ void process_vnode(struct kinfo_file *kf, struct xfile *xfile, * process_pipe() - process a file structure whose type is DTYPE_PIPE */ -void process_pipe(struct kinfo_file *kf, KA_T pa) { +void process_pipe(struct lsof_context *ctx, struct kinfo_file *kf, KA_T pa) { char dev_ch[32], *ep; size_t sz; #if __FreeBSD_version < 1400062 struct pipe p; - int have_kpipe = (pa && kread(pa, (char *)&p, sizeof(p)) == 0); + int have_kpipe = (pa && kread(ctx, pa, (char *)&p, sizeof(p)) == 0); #endif (void)snpf(Lf->type, sizeof(Lf->type), "PIPE"); (void)snpf(dev_ch, sizeof(dev_ch), "%s", print_kptr(kf->kf_un.kf_pipe.kf_pipe_addr, (char *)NULL, 0)); - enter_dev_ch(dev_ch); + enter_dev_ch(ctx, dev_ch); #if __FreeBSD_version >= 1400062 Lf->sz = (SZOFFTYPE)kf->kf_un.kf_pipe.kf_pipe_buffer_size; Lf->sz_def = 1; @@ -679,25 +683,25 @@ void process_pipe(struct kinfo_file *kf, KA_T pa) { else Namech[0] = '\0'; if (kf->kf_un.kf_pipe.kf_pipe_buffer_cnt) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", cnt=%d", kf->kf_un.kf_pipe.kf_pipe_buffer_cnt); } #if __FreeBSD_version >= 1400062 if (kf->kf_un.kf_pipe.kf_pipe_buffer_in) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", in=%d", kf->kf_un.kf_pipe.kf_pipe_buffer_in); } if (kf->kf_un.kf_pipe.kf_pipe_buffer_out) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", out=%d", kf->kf_un.kf_pipe.kf_pipe_buffer_out); } #else /* __FreeBSD_version < 1400062 */ if (have_kpipe && p.pipe_buffer.in) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", in=%d", p.pipe_buffer.in); } if (have_kpipe && p.pipe_buffer.out) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", out=%d", p.pipe_buffer.out); } #endif /* __FreeBSD_version >= 1400062 */ @@ -705,7 +709,7 @@ void process_pipe(struct kinfo_file *kf, KA_T pa) { * Enter name characters. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } #if defined(DTYPE_PTS) @@ -713,7 +717,7 @@ void process_pipe(struct kinfo_file *kf, KA_T pa) { * process_pts - process a file structure whose type is DTYPE_PTS */ -void process_pts(struct kinfo_file *kf) { +void process_pts(struct lsof_context *ctx, struct kinfo_file *kf) { (void)snpf(Lf->type, sizeof(Lf->type), "PTS"); /* * Convert the tty's cdev from kernel to user form. diff --git a/lib/dialects/freebsd/dproc.c b/lib/dialects/freebsd/dproc.c index ff913fc0..b8b65c7a 100644 --- a/lib/dialects/freebsd/dproc.c +++ b/lib/dialects/freebsd/dproc.c @@ -35,7 +35,7 @@ static char copyright[] = #include "common.h" -_PROTOTYPE(static void get_kernel_access, (void)); +static void get_kernel_access(struct lsof_context *ctx); /* * Local static values @@ -158,8 +158,8 @@ static int kf_flags_to_fflags(int kf_flags) { } /* Based on process_file() in lib/prfd.c */ -static void process_kinfo_file(struct kinfo_file *kf, struct xfile *xfile, - struct pcb_lists *pcbs, +static void process_kinfo_file(struct lsof_context *ctx, struct kinfo_file *kf, + struct xfile *xfile, struct pcb_lists *pcbs, struct lock_list *locks) { Lf->off = kf->kf_offset; Lf->off_def = 1; @@ -191,42 +191,43 @@ static void process_kinfo_file(struct kinfo_file *kf, struct xfile *xfile, switch (kf->kf_type) { case KF_TYPE_FIFO: case KF_TYPE_VNODE: - process_vnode(kf, xfile, locks); + process_vnode(ctx, kf, xfile, locks); break; case KF_TYPE_SOCKET: - process_socket(kf, pcbs); + process_socket(ctx, kf, pcbs); break; case KF_TYPE_KQUEUE: - process_kf_kqueue(kf, xfile ? xfile->xf_data : 0UL); + process_kf_kqueue(ctx, kf, xfile ? xfile->xf_data : 0UL); break; case KF_TYPE_PIPE: if (!Selinet) - process_pipe(kf, xfile ? xfile->xf_data : 0UL); + process_pipe(ctx, kf, xfile ? xfile->xf_data : 0UL); break; case KF_TYPE_PTS: - process_pts(kf); + process_pts(ctx, kf); break; #if defined(KF_TYPE_EVENTFD) case KF_TYPE_EVENTFD: - process_eventfd(kf); + process_eventfd(ctx, kf); break; #endif /* defined(KF_TYPE_EVENTFD) */ case KF_TYPE_SHM: - process_shm(kf); + process_shm(ctx, kf); break; case KF_TYPE_PROCDESC: - process_procdesc(kf); + process_procdesc(ctx, kf); break; default: /* FIXME: unlike struct file, xfile doesn't have f_ops which should be * printed here */ snpf(Namech, Namechl, "%p file struct, ty=%d", xfile ? (void *)xfile->xf_file : NULL, kf->kf_type); - enter_nm(Namech); + enter_nm(ctx, Namech); } } -static void process_file_descriptors(struct kinfo_proc *p, short ckscko, +static void process_file_descriptors(struct lsof_context *ctx, + struct kinfo_proc *p, short ckscko, struct xfile *xfiles, size_t n_xfiles, struct pcb_lists *pcbs, struct lock_list *locks) { @@ -240,7 +241,8 @@ static void process_file_descriptors(struct kinfo_proc *p, short ckscko, for (i = 0; i < n_kfiles; i++) { if (kfiles[i].kf_fd < 0 || kfiles[i].kf_type == KF_TYPE_FIFO || kfiles[i].kf_type == KF_TYPE_VNODE) - readvfs(kfiles[i].kf_un.kf_file.kf_file_fsid, kfiles[i].kf_path); + readvfs(ctx, kfiles[i].kf_un.kf_file.kf_file_fsid, + kfiles[i].kf_path); } for (i = 0; i < n_kfiles; i++) { struct xfile key, *xfile; @@ -251,39 +253,39 @@ static void process_file_descriptors(struct kinfo_proc *p, short ckscko, bsearch(&key, xfiles, n_xfiles, sizeof(*xfiles), cmp_xfiles_pid_fd); if (!ckscko && kfiles[i].kf_fd == KF_FD_TYPE_CWD) { - alloc_lfile(CWD, -1); - process_vnode(&kfiles[i], xfile, locks); + alloc_lfile(ctx, CWD, -1); + process_vnode(ctx, &kfiles[i], xfile, locks); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } else if (!ckscko && kfiles[i].kf_fd == KF_FD_TYPE_ROOT) { - alloc_lfile(RTD, -1); - process_vnode(&kfiles[i], xfile, locks); + alloc_lfile(ctx, RTD, -1); + process_vnode(ctx, &kfiles[i], xfile, locks); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } else if (!ckscko && kfiles[i].kf_fd == KF_FD_TYPE_JAIL) { - alloc_lfile(" jld", -1); - process_vnode(&kfiles[i], xfile, locks); + alloc_lfile(ctx, " jld", -1); + process_vnode(ctx, &kfiles[i], xfile, locks); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } else if (!ckscko && kfiles[i].kf_fd == KF_FD_TYPE_TEXT) { - alloc_lfile(" txt", -1); - process_vnode(&kfiles[i], xfile, locks); + alloc_lfile(ctx, " txt", -1); + process_vnode(ctx, &kfiles[i], xfile, locks); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } else if (!ckscko && kfiles[i].kf_fd == KF_FD_TYPE_CTTY) { - alloc_lfile("ctty", -1); - process_vnode(&kfiles[i], xfile, locks); + alloc_lfile(ctx, "ctty", -1); + process_vnode(ctx, &kfiles[i], xfile, locks); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } else if (!ckscko && kfiles[i].kf_fd < 0) { if (!Fwarn) fprintf(stderr, "%s: WARNING -- unsupported fd type %d\n", Pn, kfiles[i].kf_fd); } else { - alloc_lfile(NULL, kfiles[i].kf_fd); - process_kinfo_file(&kfiles[i], xfile, pcbs, locks); + alloc_lfile(ctx, NULL, kfiles[i].kf_fd); + process_kinfo_file(ctx, &kfiles[i], xfile, pcbs, locks); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } free(kfiles); @@ -293,7 +295,7 @@ static void process_file_descriptors(struct kinfo_proc *p, short ckscko, * gather_proc_info() -- gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { int mib[3]; size_t len; @@ -399,7 +401,7 @@ void gather_proc_info() { if (P == NULL) { (void)fprintf(stderr, "%s: can't read process table: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } Np = len / sizeof(struct kinfo_proc); if (read_xfiles(&xfiles, &n_xfiles) && !Fwarn) @@ -439,20 +441,20 @@ void gather_proc_info() { * See if process,including its tasks, is excluded. */ tid = Ftask ? (int)p->ki_tid : 0; - if (is_proc_excl(p->P_PID, pgid, (UID_ARG)uid, &pss, &sf, tid)) + if (is_proc_excl(ctx, p->P_PID, pgid, (UID_ARG)uid, &pss, &sf, tid)) continue; #else /* !defined(HASTASKS) */ /* * See if process is excluded. */ - if (is_proc_excl(p->P_PID, pgid, (UID_ARG)uid, &pss, &sf)) + if (is_proc_excl(ctx, p->P_PID, pgid, (UID_ARG)uid, &pss, &sf)) continue; #endif /* defined(HASTASKS) */ /* * Allocate a local process structure. */ - if (is_cmd_excl(p->P_COMM, &pss, &sf)) + if (is_cmd_excl(ctx, p->P_COMM, &pss, &sf)) continue; if (cckreg) { @@ -463,8 +465,8 @@ void gather_proc_info() { */ ckscko = (sf & SelProc) ? 0 : 1; } - alloc_lproc(p->P_PID, pgid, ppid, (UID_ARG)uid, p->P_COMM, (int)pss, - (int)sf); + alloc_lproc(ctx, p->P_PID, pgid, ppid, (UID_ARG)uid, p->P_COMM, + (int)pss, (int)sf); Plf = (struct lfile *)NULL; #if defined(HASTASKS) @@ -481,13 +483,14 @@ void gather_proc_info() { Kpa = (KA_T)p->P_ADDR; #endif /* defined(P_ADDR) */ - process_file_descriptors(p, ckscko, xfiles, n_xfiles, pcbs, &locks); + process_file_descriptors(ctx, p, ckscko, xfiles, n_xfiles, pcbs, + &locks); /* * Unless threads (tasks) are being processed, examine results. */ if (!Ftask) { - if (examine_lproc()) + if (examine_lproc(ctx)) break; } } @@ -503,12 +506,12 @@ void gather_proc_info() { * get_kernel_access() - get access to kernel memory */ -static void get_kernel_access() { +static void get_kernel_access(struct lsof_context *ctx) { /* * Check kernel version. */ - (void)ckkv("FreeBSD", LSOF_VSTR, (char *)NULL, (char *)NULL); + (void)ckkv(ctx, "FreeBSD", LSOF_VSTR, (char *)NULL, (char *)NULL); /* * Set name list file path. */ @@ -518,9 +521,9 @@ static void get_kernel_access() { Nmlst = N_UNIX; #else /* !defined(N_UNIX) */ { - if (!(Nmlst = get_nlist_path(1))) { + if (!(Nmlst = get_nlist_path(ctx, 1))) { (void)fprintf(stderr, "%s: can't get kernel name list path\n", Pn); - Error(); + Error(ctx); } } #endif /* defined(N_UNIX) */ @@ -531,14 +534,14 @@ static void get_kernel_access() { * before attempting to open the (Memory) file. */ if (Memory) - (void)dropgid(); + (void)dropgid(ctx); #else /* !defined(WILLDROPGID) */ /* * See if the non-KMEM memory and the name list files are readable. */ if ((Memory && !is_readable(Memory, 1)) || (Nmlst && !is_readable(Nmlst, 1))) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -565,10 +568,10 @@ static void get_kernel_access() { strerror(errno)); return; } - (void)build_Nl(Drive_Nl); + (void)build_Nl(ctx, Drive_Nl); if (kvm_nlist(Kd, Nl) < 0) { (void)fprintf(stderr, "%s: can't read namelist from %s\n", Pn, Nmlst); - Error(); + Error(ctx); } #if defined(X_BADFILEOPS) @@ -586,7 +589,7 @@ static void get_kernel_access() { * Drop setgid permission, if necessary. */ if (!Memory) - (void)dropgid(); + (void)dropgid(ctx); #endif /* defined(WILLDROPGID) */ } @@ -595,11 +598,11 @@ static void get_kernel_access() { * get_nlist_path() - get kernel name list path */ -char *get_nlist_path(ap) -int ap; /* on success, return an allocated path - * string pointer if 1; return a - * constant character pointer if 0; - * return NULL if failure */ +char *get_nlist_path(struct lsof_context *ctx, + int ap) /* on success, return an allocated path + * string pointer if 1; return a + * constant character pointer if 0; + * return NULL if failure */ { const char *bf; static char *bfc; @@ -615,7 +618,7 @@ int ap; /* on success, return an allocated path (void)fprintf( stderr, "%s: can't allocate %d bytes for boot file path: %s\n", Pn, (int)bfl, bf); - Error(); + Error(ctx); } (void)snpf(bfc, bfl, "%s", bf); return (bfc); @@ -628,9 +631,9 @@ int ap; /* on success, return an allocated path * initialize() - perform all initialization */ -void initialize() { +void initialize(struct lsof_context *ctx) { #if __FreeBSD_version < 1400062 - get_kernel_access(); + get_kernel_access(ctx); #endif /* __FreeBSD_version < 1400062 */ } @@ -638,10 +641,10 @@ void initialize() { * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, /* context */ + KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { int br; diff --git a/lib/dialects/freebsd/dproto.h b/lib/dialects/freebsd/dproto.h index 5966e7d3..a5d970a6 100644 --- a/lib/dialects/freebsd/dproto.h +++ b/lib/dialects/freebsd/dproto.h @@ -35,41 +35,42 @@ */ #if !defined(N_UNIX) -_PROTOTYPE(extern char *get_nlist_path, (int ap)); +extern char *get_nlist_path(struct lsof_context *ctx, int ap); #endif /* !defined(N_UNIX) */ -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern void process_vnode, - (struct kinfo_file * kf, struct xfile *xfile, - struct lock_list *locks)); -_PROTOTYPE(extern void process_socket, - (struct kinfo_file * kf, struct pcb_lists *pcbs)); -_PROTOTYPE(extern struct l_vfs *readvfs, (uint64_t fsid, const char *path)); -_PROTOTYPE(extern struct pcb_lists *read_pcb_lists, (void)); -_PROTOTYPE(extern void free_pcb_lists, (struct pcb_lists * pcb_lists)); -_PROTOTYPE(extern int cmp_kinfo_lockf, (const void *a, const void *b)); +extern int is_file_named(struct lsof_context *ctx, char *p, int cd); +extern void process_vnode(struct lsof_context *ctx, struct kinfo_file *kf, + struct xfile *xfile, struct lock_list *locks); +extern void process_socket(struct lsof_context *ctx, struct kinfo_file *kf, + struct pcb_lists *pcbs); +extern struct l_vfs *readvfs(struct lsof_context *ctx, uint64_t fsid, + const char *path); +extern struct pcb_lists *read_pcb_lists(void); +extern void free_pcb_lists(struct pcb_lists *pcb_lists); +extern int cmp_kinfo_lockf(const void *a, const void *b); -_PROTOTYPE(extern void process_pts, (struct kinfo_file * kf)); +extern void process_pts(struct lsof_context *ctx, struct kinfo_file *kf); #if defined(KF_TYPE_EVENTFD) -_PROTOTYPE(extern void process_eventfd, (struct kinfo_file * kf)); +extern void process_eventfd(struct lsof_context *ctx, struct kinfo_file *kf); #endif /* defined(KF_TYPE_EVENTFD) */ #if defined(HASKQUEUE) -_PROTOTYPE(extern void process_kf_kqueue, (struct kinfo_file * kf, KA_T ka)); +extern void process_kf_kqueue(struct lsof_context *ctx, struct kinfo_file *kf, + KA_T ka); #endif /* defined(HASKQUEUE) */ -_PROTOTYPE(extern void process_pipe, (struct kinfo_file * kf, KA_T pa)); -_PROTOTYPE(extern void process_shm, (struct kinfo_file * kf)); -_PROTOTYPE(extern void process_procdesc, (struct kinfo_file * kf)); +extern void process_pipe(struct lsof_context *ctx, struct kinfo_file *kf, + KA_T pa); +extern void process_shm(struct lsof_context *ctx, struct kinfo_file *kf); +extern void process_procdesc(struct lsof_context *ctx, struct kinfo_file *kf); #if defined(HAS9660FS) -_PROTOTYPE(extern int read_iso_node, (struct vnode * v, dev_t *d, int *dd, - INODETYPE *ino, long *nl, SZOFFTYPE *sz)); +extern int read_iso_node(struct vnode *v, dev_t *d, int *dd, INODETYPE *ino, + long *nl, SZOFFTYPE *sz); #endif /* defined(HAS9660FS) */ #if defined(HASMSDOSFS) -_PROTOTYPE(extern int read_msdos_node, - (struct vnode * v, dev_t *d, int *dd, INODETYPE *ino, long *nl, - SZOFFTYPE *sz)); +extern int read_msdos_node(struct vnode *v, dev_t *d, int *dd, INODETYPE *ino, + long *nl, SZOFFTYPE *sz); #endif /* defined(HASMSDOSFS) */ diff --git a/lib/dialects/freebsd/dsock.c b/lib/dialects/freebsd/dsock.c index d86bd2c6..56bfb37d 100644 --- a/lib/dialects/freebsd/dsock.c +++ b/lib/dialects/freebsd/dsock.c @@ -82,7 +82,7 @@ static char copyright[] = * Local function prototypes */ -_PROTOTYPE(static int ckstate, (struct xtcpcb * pcb, int fam)); +static int ckstate(struct xtcpcb *pcb, int fam); static int cmp_xunpcb_sock_pcb(const void *a, const void *b) { const struct xunpcb *pcb1 = (const struct xunpcb *)a; @@ -367,7 +367,8 @@ static void find_pcb_and_xsocket(struct pcb_lists *pcbs, int domain, int type, * process_socket() - process socket */ -void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { +void process_socket(struct lsof_context *ctx, struct kinfo_file *kf, + struct pcb_lists *pcbs) { unsigned char *fa = (unsigned char *)NULL; int fam; int fp, lp; @@ -459,7 +460,7 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { (void)snpf(Namech, Namechl, "can't read in6pcb at %s", print_kptr((KA_T)kf->kf_un.kf_sock.kf_sock_pcb, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -470,7 +471,8 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { return; } } - enter_dev_ch(print_kptr((KA_T)(kf->kf_un.kf_sock.kf_sock_inpcb + enter_dev_ch(ctx, + print_kptr((KA_T)(kf->kf_un.kf_sock.kf_sock_inpcb ? kf->kf_un.kf_sock.kf_sock_inpcb : kf->kf_un.kf_sock.kf_sock_pcb), (char *)NULL, 0)); @@ -499,14 +501,15 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { (kf->kf_un.kf_sock.kf_sock_rcv_sb_state & SBS_CANTRCVMORE) ? ", CANTRCVMORE" : ""); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (kf->kf_sock_protocol == IPPROTO_TCP) { if ((ts = ckstate((struct xtcpcb *)pcb, fam)) == 1) return; } - enter_dev_ch(print_kptr((KA_T)(kf->kf_un.kf_sock.kf_sock_inpcb + enter_dev_ch(ctx, + print_kptr((KA_T)(kf->kf_un.kf_sock.kf_sock_inpcb ? kf->kf_un.kf_sock.kf_sock_inpcb : kf->kf_un.kf_sock.kf_sock_pcb), (char *)NULL, 0)); @@ -541,7 +544,7 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { * Enter local and remote addresses by address family. */ if (fa || la) - (void)ent_inaddr(la, lp, fa, fp, fam); + (void)ent_inaddr(ctx, la, lp, fa, fp, fam); if (ts == 0) { struct xtcpcb *tcp_pcb = (struct xtcpcb *)pcb; Lf->lts.type = 0; @@ -566,7 +569,7 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { case AF_ROUTE: (void)snpf(Lf->type, sizeof(Lf->type), "rte"); if (s && s->so_pcb) - enter_dev_ch(print_kptr((KA_T)(s->so_pcb), (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)(s->so_pcb), (char *)NULL, 0)); else (void)snpf(Namech, Namechl, "no protocol control block"); break; @@ -584,7 +587,7 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { if (unix_pcb) enter_dev_ch( - print_kptr(unix_pcb->xu_socket.xso_so, (char *)NULL, 0)); + ctx, print_kptr(unix_pcb->xu_socket.xso_so, (char *)NULL, 0)); else { (void)snpf( Namech, Namechl, "can't read unpcb at %s", @@ -600,7 +603,7 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { unl = sizeof(ua->sun_path) - 1; ua->sun_path[unl] = '\0'; - if (ua->sun_path[0] && Sfile && is_file_named(ua->sun_path, 0)) + if (ua->sun_path[0] && Sfile && is_file_named(ctx, ua->sun_path, 0)) Lf->sf |= SELNM; if (ua->sun_path[0] && !Namech[0]) (void)snpf(Namech, Namechl, "%s", ua->sun_path); @@ -623,8 +626,8 @@ void process_socket(struct kinfo_file *kf, struct pcb_lists *pcbs) { break; } default: - printunkaf(fam, 1); + printunkaf(ctx, fam, 1); } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } diff --git a/lib/dialects/hpux/kmem/dfile.c b/lib/dialects/hpux/kmem/dfile.c index 342b6d0a..fd9cf2b3 100644 --- a/lib/dialects/hpux/kmem/dfile.c +++ b/lib/dialects/hpux/kmem/dfile.c @@ -69,9 +69,8 @@ int get_max_fd() { * print_dev() - print device */ -char *print_dev(lf, dev) -struct lfile *lf; /* file whose device is to be printed */ -dev_t *dev; /* device to be printed */ +char *print_dev(struct lfile *lf, /* file whose device is to be printed */ + dev_t *dev) /* device to be printed */ { static char buf[128]; @@ -89,7 +88,7 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ struct file f; int flag; - if (kread((KA_T)fp, (char *)&f, sizeof(f))) { + if (kread(ctx, (KA_T)fp, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "can't read file struct from %s", print_kptr(fp, (char *)NULL, 0)); enter_nm(Namech); @@ -180,7 +179,7 @@ char **pn; /* returned protocol name */ struct qinit qi; size_t sz = Namechl; - if (!sh || kread(sh, (char *)&hd, sizeof(hd))) { + if (!sh || kread(ctx, sh, (char *)&hd, sizeof(hd))) { (void)snpf(Namech, Namechl, "can't read stream head: %s", print_kptr(sh, (char *)NULL, 0)); return (1); @@ -210,13 +209,14 @@ char **pn; /* returned protocol name */ *ip = *pcb = (KA_T)NULL; qa = (KA_T)hd.sth_wq; for (i = 0; i < 20; i++, qa = (KA_T)q.q_next) { - if (!qa || kread(qa, (char *)&q, sizeof(q))) + if (!qa || kread(ctx, qa, (char *)&q, sizeof(q))) break; - if (!(ka = (KA_T)q.q_qinfo) || kread(ka, (char *)&qi, sizeof(qi))) + if (!(ka = (KA_T)q.q_qinfo) || kread(ctx, ka, (char *)&qi, sizeof(qi))) continue; - if (!(ka = (KA_T)qi.qi_minfo) || kread(ka, (char *)&mi, sizeof(mi))) + if (!(ka = (KA_T)qi.qi_minfo) || + kread(ctx, ka, (char *)&mi, sizeof(mi))) continue; - if (!(ka = (KA_T)mi.mi_idname) || kread(ka, mn, ml)) + if (!(ka = (KA_T)mi.mi_idname) || kread(ctx, ka, mn, ml)) continue; if ((len = strlen(mn)) < 1) continue; diff --git a/lib/dialects/hpux/kmem/dmnt.c b/lib/dialects/hpux/kmem/dmnt.c index 35c7b4a7..b5d3d64f 100644 --- a/lib/dialects/hpux/kmem/dmnt.c +++ b/lib/dialects/hpux/kmem/dmnt.c @@ -122,7 +122,7 @@ dev_t *dev; /* device */ if (!(vfs->dir = mkstrcpy(v->vfs_name, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for vfs name: ", Pn); safestrprt(v->vfs_name, stderr, 1); - Error(); + Error(ctx); } if (statsafely(v->vfs_name, &sb) == 0) vfs->dev = sb.st_dev; @@ -140,8 +140,7 @@ dev_t *dev; /* device */ * readvfs() - read vfs structure */ -struct l_vfs *readvfs(lv) -struct vnode *lv; /* local vnode */ +struct l_vfs *readvfs(struct vnode *lv) /* local vnode */ { struct mount m; struct mntinfo mi; @@ -158,7 +157,7 @@ struct vnode *lv; /* local vnode */ } if ((vp = (struct l_vfs *)malloc(sizeof(struct l_vfs))) == NULL) { (void)fprintf(stderr, "%s: PID %d, no space for vfs\n", Pn, Lp->pid); - Error(); + Error(ctx); } vp->dev = 0; vp->dir = (char *)NULL; @@ -168,7 +167,7 @@ struct vnode *lv; /* local vnode */ vp->fs_ino = 0; #endif /* defined(HASFSINO) */ - if (lv->v_vfsp && kread((KA_T)lv->v_vfsp, (char *)&v, sizeof(v))) { + if (lv->v_vfsp && kread(ctx, (KA_T)lv->v_vfsp, (char *)&v, sizeof(v))) { (void)free((FREE_P *)vp); return ((struct l_vfs *)NULL); } @@ -182,7 +181,7 @@ struct vnode *lv; /* local vnode */ * private data pointer to an mntinfo structure. */ if (v.vfs_data && - kread((KA_T)v.vfs_data, (char *)&mi, sizeof(mi)) == 0) { + kread(ctx, (KA_T)v.vfs_data, (char *)&mi, sizeof(mi)) == 0) { #if HPUXV < 1020 td = (dev_t)makedev(255, (int)mi.mi_mntno); @@ -198,7 +197,7 @@ struct vnode *lv; /* local vnode */ } } else { if (v.vfs_data) { - if (kread((KA_T)v.vfs_data, (char *)&m, sizeof(m)) == 0) + if (kread(ctx, (KA_T)v.vfs_data, (char *)&m, sizeof(m)) == 0) ms = 1; else ms = 0; diff --git a/lib/dialects/hpux/kmem/dnode.c b/lib/dialects/hpux/kmem/dnode.c index c9119ca2..a07d0343 100644 --- a/lib/dialects/hpux/kmem/dnode.c +++ b/lib/dialects/hpux/kmem/dnode.c @@ -44,13 +44,13 @@ typedef int time_t; #include #if HPUXV >= 900 -_PROTOTYPE(static void enter_nma, (char *b)); -_PROTOTYPE(static int islocked, (KA_T lp)); +static void enter_nma(char *b); +static int islocked(KA_T lp); #endif /* HPUXV>=900 */ -_PROTOTYPE(static int getnodety, (struct vnode * v)); -_PROTOTYPE(static int readinode, (KA_T ia, struct inode *i)); -_PROTOTYPE(static int read_nmn, (KA_T na, KA_T ia, struct mvfsnode *m)); +static int getnodety(struct vnode *v); +static int readinode(KA_T ia, struct inode *i); +static int read_nmn(KA_T na, KA_T ia, struct mvfsnode *m); #if HPUXV >= 900 /* @@ -107,7 +107,7 @@ KA_T lp; /* local locklist struct pointer */ * Search the locklist chain for this process. */ do { - if (kread(llp, (char *)&ll, sizeof(ll))) + if (kread(ctx, llp, (char *)&ll, sizeof(ll))) return ((int)' '); # if !defined(L_REMOTE) @@ -155,8 +155,7 @@ KA_T lp; /* local locklist struct pointer */ * getnodety() - get node type */ -static int getnodety(v) -struct vnode *v; /* local vnode copy */ +static int getnodety(struct vnode *v) /* local vnode copy */ { #if defined(HAS_AFS) @@ -356,7 +355,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HAS_AFS) */ ); - Error(); + Error(ctx); } } if (readvnode(va, v)) { @@ -437,7 +436,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if HPUXV >= 1000 case N_CDFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&c, sizeof(c))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&c, sizeof(c))) { (void)snpf(Namech, Namechl, "vnode at %s: can't read cdnode (%s)", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_data, (char *)NULL, 0)); @@ -447,7 +446,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ break; case N_FIFO: case N_PIPE: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&f, sizeof(f))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "vnode at %s: can't read fifonode (%s)", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_data, (char *)NULL, 0)); @@ -455,7 +454,8 @@ void process_node(va) KA_T va; /* vnode kernel space address */ return; } fns = 1; - if (f.fn_vap && kread((KA_T)f.fn_vap, (char *)&vat, sizeof(vat)) == 0) + if (f.fn_vap && + kread(ctx, (KA_T)f.fn_vap, (char *)&vat, sizeof(vat)) == 0) vats = 1; break; #endif /* HPUXV>=1000 */ @@ -1025,7 +1025,7 @@ static int readinode(ia, i) KA_T ia; /* inode kernel address */ struct inode *i; /* inode buffer */ { - if (kread((KA_T)ia, (char *)i, sizeof(struct inode))) { + if (kread(ctx, (KA_T)ia, (char *)i, sizeof(struct inode))) { (void)snpf(Namech, Namechl, "can't read inode at %s", print_kptr(ia, (char *)NULL, 0)); return (1); @@ -1044,7 +1044,7 @@ struct mvfsnode *m; /* mvfsnode receiver */ { char tbuf[32]; - if (!ma || kread((KA_T)ma, (char *)m, sizeof(struct mvfsnode))) { + if (!ma || kread(ctx, (KA_T)ma, (char *)m, sizeof(struct mvfsnode))) { (void)snpf(Namech, Namechl, "node at %s: can't read mvfsnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ma, (char *)NULL, 0)); diff --git a/lib/dialects/hpux/kmem/dnode1.c b/lib/dialects/hpux/kmem/dnode1.c index dec34f29..e187c50f 100644 --- a/lib/dialects/hpux/kmem/dnode1.c +++ b/lib/dialects/hpux/kmem/dnode1.c @@ -98,17 +98,16 @@ typedef int time_t; * read_vxnode() - read Veritas file system inode information */ -int read_vxnode(v, vfs, dev, devs, rdev, rdevs) -struct vnode *v; /* local containing vnode */ -struct l_vfs *vfs; /* local vfs structure */ -dev_t *dev; /* device number receiver */ -int *devs; /* device status receiver */ -dev_t *rdev; /* raw device number receiver */ -int *rdevs; /* raw device status receiver */ +int read_vxnode(struct vnode *v, /* local containing vnode */ + struct l_vfs *vfs, /* local vfs structure */ + dev_t *dev, /* device number receiver */ + int *devs, /* device status receiver */ + dev_t *rdev, /* raw device number receiver */ + int *rdevs) /* raw device status receiver */ { struct vx_inode i; - if (!v->v_data || kread((KA_T)v->v_data, (char *)&i, sizeof(i))) + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&i, sizeof(i))) return (1); /* * Return device numbers. diff --git a/lib/dialects/hpux/kmem/dnode2.c b/lib/dialects/hpux/kmem/dnode2.c index 4c014e3f..240fabe4 100644 --- a/lib/dialects/hpux/kmem/dnode2.c +++ b/lib/dialects/hpux/kmem/dnode2.c @@ -73,8 +73,8 @@ typedef struct afs_lock afs_rwlock_t; * Local function prototypes */ -_PROTOTYPE(static struct volume *getvolume, (struct VenusFid * f, int *vols)); -_PROTOTYPE(static int is_rootFid, (struct vcache * vc, int *rfid)); +static struct volume *getvolume(struct VenusFid *f, int *vols); +static int is_rootFid(struct vcache *vc, int *rfid); /* * alloc_vcache() - allocate space for vcache structure @@ -140,9 +140,8 @@ void ckAFSsym(nl) struct nlist *nl; /* copy of Nl[] when empty */ * getvolume() - get volume structure */ -static struct volume *getvolume(f, vols) -struct VenusFid *f; /* file ID pointer */ -int *vols; /* afs_volumes status return */ +static struct volume *getvolume(struct VenusFid *f, /* file ID pointer */ + int *vols) /* afs_volumes status return */ { int i; static KA_T ka = 0; @@ -168,10 +167,10 @@ int *vols; /* afs_volumes status return */ *vols = 1; i = (NVOLS - 1) & f->Fid.Volume; kh = (KA_T)((char *)ka + (i * sizeof(struct volume *))); - if (kread(kh, (char *)&vp, sizeof(vp))) + if (kread(ctx, kh, (char *)&vp, sizeof(vp))) return ((struct volume *)NULL); while (vp) { - if (kread((KA_T)vp, (char *)&v, sizeof(v))) + if (kread(ctx, (KA_T)vp, (char *)&v, sizeof(v))) return ((struct volume *)NULL); if (v.volume == f->Fid.Volume && v.cell == f->Cell) return (&v); @@ -184,8 +183,7 @@ int *vols; /* afs_volumes status return */ * hasAFS() - test for AFS presence via vfs structure */ -int hasAFS(vp) -struct vnode *vp; /* vnode pointer */ +int hasAFS(struct vnode *vp) /* vnode pointer */ { struct vfs v; /* @@ -202,7 +200,7 @@ struct vnode *vp; /* vnode pointer */ if (AFSVfsp && !vp->v_data && vp->v_vfsp == AFSVfsp) return (1); if (vp->v_data || !vp->v_vfsp || - kread((KA_T)vp->v_vfsp, (char *)&v, sizeof(v)) || v.vfs_data || + kread(ctx, (KA_T)vp->v_vfsp, (char *)&v, sizeof(v)) || v.vfs_data || strcmp(v.vfs_name, "AFS") != 0) return (0); AFSVfsp = vp->v_vfsp; @@ -218,9 +216,8 @@ struct vnode *vp; /* vnode pointer */ * 1 if root file ID structure address available */ -static int is_rootFid(vc, rfid) -struct vcache *vc; /* vcache structure */ -int *rfid; /* root file ID pointer status return */ +static int is_rootFid(struct vcache *vc, /* vcache structure */ + int *rfid) /* root file ID pointer status return */ { char *err; static int f = 0; /* rootFID structure status: @@ -261,7 +258,7 @@ int *rfid; /* root file ID pointer status return */ *rfid = 0; return (0); } - if (kread((KA_T)v, (char *)&r, sizeof(r))) { + if (kread(ctx, (KA_T)v, (char *)&r, sizeof(r))) { err = "can't read from kernel"; goto rfid_unavailable; } @@ -296,7 +293,7 @@ struct afsnode *an; /* afsnode recipient */ cp = ((char *)v + sizeof(struct vnode)); ka = (KA_T)((char *)va + sizeof(struct vnode)); len = sizeof(struct vcache) - sizeof(struct vnode); - if (kread(ka, cp, len)) { + if (kread(ctx, ka, cp, len)) { (void)snpf(Namech, Namechl, "vnode at %s: can't read vcache remainder from %s", print_kptr(va, tbuf, sizeof(tbuf)), diff --git a/lib/dialects/hpux/kmem/dproc.c b/lib/dialects/hpux/kmem/dproc.c index ece5a675..0e55bde5 100644 --- a/lib/dialects/hpux/kmem/dproc.c +++ b/lib/dialects/hpux/kmem/dproc.c @@ -128,10 +128,10 @@ static MALLOC_S Nva = 0; /* number of entries allocated to static KA_T *Vp = (KA_T *)NULL; /* vnode address cache */ #endif /* HPUXV>=800 */ -_PROTOTYPE(static void get_kernel_access, (void)); +static void get_kernel_access(void); #if HPUXV >= 800 -_PROTOTYPE(static void process_text, (KA_T vasp)); +static void process_text(KA_T vasp); #endif /* HPUXV>=800 */ /* @@ -221,13 +221,13 @@ void gather_proc_info() { */ if (!oftp) { if ((get_Nl_value("chunksz", Drive_Nl, &v) >= 0) && v) { - if (kread(v, (char *)&oftsz, sizeof(oftsz))) { + if (kread(ctx, v, (char *)&oftsz, sizeof(oftsz))) { (void)fprintf(stderr, "%s: can't get FD chunk size\n", Pn); - Error(); + Error(ctx); } if (!oftsz) { (void)fprintf(stderr, "%s: bad FD chunk size: %d\n", Pn, oftsz); - Error(); + Error(ctx); } } ofasz = (int)(oftsz / SFDCHUNK); @@ -235,11 +235,11 @@ void gather_proc_info() { (void)fprintf(stderr, "%s: FD chunk size (%d) not exact multiple of %d\n", Pn, oftsz, SFDCHUNK); - Error(); + Error(ctx); } if (!(oftp = (char *)malloc((MALLOC_S)oftsz))) { (void)fprintf(stderr, "%s: no space for %d FD bytes\n", Pn, oftsz); - Error(); + Error(ctx); } } #endif /* HPUXV>=1100 */ @@ -258,7 +258,7 @@ void gather_proc_info() { { Kpa = Kp + (KA_T)(px * sizeof(struct proc)); - if (kread(Kpa, (char *)&pbuf, sizeof(pbuf))) + if (kread(ctx, Kpa, (char *)&pbuf, sizeof(pbuf))) continue; if (p->p_stat == 0 || p->p_stat == SZOMB) continue; @@ -341,7 +341,7 @@ void gather_proc_info() { # if defined(hp9000s300) pte_off = (KA_T)&Usrptmap[btokmx(p->p_p0br) + p->p_szpt - 1]; - if (kread(pte_off, (char *)&pte1, sizeof(pte1))) + if (kread(ctx, pte_off, (char *)&pte1, sizeof(pte1))) continue; pte_addr = (KA_T)(ctob(pte1.pg_pfnum + 1) - ((UPAGES + FLOAT) * sizeof(pte2))); @@ -353,7 +353,7 @@ void gather_proc_info() { # endif /* defined(hp9000s300) */ # if defined(hp9000s800) - if (kread((KA_T)uvadd((struct proc *)Kpa), (char *)u, + if (kread(ctx, (KA_T)uvadd((struct proc *)Kpa), (char *)u, sizeof(struct user))) continue; } @@ -409,8 +409,8 @@ void gather_proc_info() { #if HPUXV >= 800 if (j >= SFDCHUNK) { - if (!pfp || kread((KA_T)pfp, (char *)&ofp, sizeof(ofp)) || - !ofp || kread((KA_T)ofp, oftp, oftsz)) + if (!pfp || kread(ctx, (KA_T)pfp, (char *)&ofp, sizeof(ofp)) || + !ofp || kread(ctx, (KA_T)ofp, oftp, oftsz)) break; j = 0; pfp += sizeof(KA_T); @@ -446,7 +446,7 @@ void gather_proc_info() { ; if (k >= NFDCHUNKS) break; - if (kread((KA_T)u->u_ofilep[k], (char *)&u->u_ofile, + if (kread(ctx, (KA_T)u->u_ofilep[k], (char *)&u->u_ofile, sizeof(struct ofile_t))) { break; } @@ -502,7 +502,7 @@ static void get_kernel_access() { if ((rv = sysconf(_SC_KERNEL_BITS)) < 0) { (void)fprintf(stderr, "%s: sysconf(_SC_KERNEL_BITS) returns: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (rv != (long)HPUXKERNBITS) { (void)fprintf( @@ -510,7 +510,7 @@ static void get_kernel_access() { "%s: FATAL: %s was built for a %d bit kernel, but this\n", Pn, Pn, HPUXKERNBITS); (void)fprintf(stderr, " is a %ld bit kernel.\n", rv); - Error(); + Error(ctx); } } #endif /* HPUXV>=1030 */ @@ -548,7 +548,7 @@ static void get_kernel_access() { * See if the non-KMEM memory file is readable. */ if (Memory && !is_readable(Memory, 1)) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -560,7 +560,7 @@ static void get_kernel_access() { (void)fprintf(stderr, "%s: can't open ", Pn); safestrprt(Memory ? Memory : KMEM, stderr, 0); (void)fprintf(stderr, ": %s\n", strerror(errno_save)); - Error(); + Error(ctx); } #if defined(WILLDROPGID) @@ -574,7 +574,7 @@ static void get_kernel_access() { * See if the name list file is readable. */ if (Nmlst && !is_readable(Nmlst, 1)) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ (void)build_Nl(Drive_Nl); @@ -589,7 +589,7 @@ static void get_kernel_access() { */ if (!(nl = (struct NLIST_TYPE *)malloc(Nll))) { (void)fprintf(stderr, "%s: no space (%d) for Nl[] copy\n", Pn, Nll); - Error(); + Error(ctx); } (void)memcpy((void *)nl, (void *)Nl, (size_t)Nll); } @@ -601,14 +601,14 @@ static void get_kernel_access() { if (NLIST_TYPE(Nmlst ? Nmlst : N_UNIX, Nl) < 0) { (void)fprintf(stderr, "%s: can't read namelist from: ", Pn); safestrprt(Nmlst ? Nmlst : N_UNIX, stderr, 1); - Error(); + Error(ctx); } if (get_Nl_value("proc", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&Kp, sizeof(Kp)) || + kread(ctx, (KA_T)v, (char *)&Kp, sizeof(Kp)) || get_Nl_value("nproc", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&Np, sizeof(Np)) || !Kp || Np < 1) { + kread(ctx, (KA_T)v, (char *)&Np, sizeof(Np)) || !Kp || Np < 1) { (void)fprintf(stderr, "%s: can't read proc table info\n", Pn); - Error(); + Error(ctx); } if (get_Nl_value("vfops", Drive_Nl, (KA_T *)&Vnfops) < 0) Vnfops = (KA_T)NULL; @@ -616,11 +616,11 @@ static void get_kernel_access() { #if HPUXV < 800 && defined(hp9000s300) if (get_Nl_value("upmap", Drive_Nl, (unsigned long *)&Usrptmap) < 0) { (void)fprintf(stderr, "%s: can't get kernel's Usrptmap\n", Pn); - Error(); + Error(ctx); } if (get_Nl_value("upt", Drive_Nl, (unsigned long *)&usrpt) < 0) { (void)fprintf(stderr, "%s: can't get kernel's usrpt\n", Pn); - Error(); + Error(ctx); } #endif /* HPUXV<800 && defined(hp9000s300) */ @@ -628,18 +628,18 @@ static void get_kernel_access() { proc = (struct proc *)Kp; if (get_Nl_value("ubase", Drive_Nl, (unsigned long *)&ubase) < 0) { (void)fprintf(stderr, "%s: can't get kernel's ubase\n", Pn); - Error(); + Error(ctx); } if (get_Nl_value("npids", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&npids, sizeof(npids))) { + kread(ctx, (KA_T)v, (char *)&npids, sizeof(npids))) { (void)fprintf(stderr, "%s: can't get kernel's npids\n", Pn); - Error(); + Error(ctx); } #endif /* HPUXV<800 && defined(hp9000s800) */ #if HPUXV >= 1030 if (get_Nl_value("clmaj", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&CloneMaj, sizeof(CloneMaj))) + kread(ctx, (KA_T)v, (char *)&CloneMaj, sizeof(CloneMaj))) HaveCloneMaj = 0; else HaveCloneMaj = 1; @@ -673,10 +673,10 @@ void initialize() { get_kernel_access(); } * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, /* context */ + KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { int br; @@ -724,7 +724,7 @@ static void process_text(vasp) KA_T vasp; /* kernel's virtual address space /* * Read virtual address space pointer. */ - if (kread(vasp, (char *)&v, sizeof(v))) + if (kread(ctx, vasp, (char *)&v, sizeof(v))) return; /* * Follow the virtual address space pregion structure chain. @@ -745,9 +745,9 @@ static void process_text(vasp) KA_T vasp; /* kernel's virtual address space /* * Read the pregion and region. */ - if (kread(prp, (char *)&p, sizeof(p))) + if (kread(ctx, prp, (char *)&p, sizeof(p))) return; - if (kread((KA_T)p.p_reg, (char *)&r, sizeof(r))) + if (kread(ctx, (KA_T)p.p_reg, (char *)&r, sizeof(r))) return; /* * Skip file entries with no file pointers. @@ -775,7 +775,7 @@ static void process_text(vasp) KA_T vasp; /* kernel's virtual address space if (!Vp) { (void)fprintf( stderr, "%s: no more space for text vnode pointers\n", Pn); - Error(); + Error(ctx); } } Vp[i++] = va; diff --git a/lib/dialects/hpux/kmem/dproto.h b/lib/dialects/hpux/kmem/dproto.h index fe0b9ab7..5dbff4fe 100644 --- a/lib/dialects/hpux/kmem/dproto.h +++ b/lib/dialects/hpux/kmem/dproto.h @@ -35,37 +35,33 @@ */ #if HPUXV >= 800 -_PROTOTYPE(extern void completevfs, - (struct l_vfs * vfs, dev_t *dev, struct vfs *v)); +extern void completevfs(struct l_vfs *vfs, dev_t *dev, struct vfs *v); #else -_PROTOTYPE(extern void completevfs, (struct l_vfs * vfs, dev_t *dev)); +extern void completevfs(struct l_vfs *vfs, dev_t *dev); #endif /* HPUXV>=800 */ -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern int get_max_fd, (void)); +extern int is_file_named(char *p, int cd); +extern int get_max_fd(void); #if defined(DTYPE_LLA) -_PROTOTYPE(extern void process_lla, (KA_T la)); +extern void process_lla(KA_T la); #endif -_PROTOTYPE(extern struct l_vfs *readvfs, (struct vnode * lv)); +extern struct l_vfs *readvfs(struct vnode *lv); #if HPUXV >= 1030 -_PROTOTYPE(extern void process_stream_sock, - (KA_T ip, KA_T pcb, char *pn, enum vtype vt)); -_PROTOTYPE(extern int read_mi, (KA_T sh, KA_T *ip, KA_T *pcb, char **pn)); +extern void process_stream_sock(KA_T ip, KA_T pcb, char *pn, enum vtype vt); +extern int read_mi(KA_T sh, KA_T *ip, KA_T *pcb, char **pn); #endif /* HPUXV>=1030 */ #if defined(HAS_AFS) -_PROTOTYPE(extern struct vnode *alloc_vcache, (void)); -_PROTOTYPE(extern void ckAFSsym, (struct nlist * nl)); -_PROTOTYPE(extern int hasAFS, (struct vnode * vp)); -_PROTOTYPE(extern int readafsnode, - (KA_T va, struct vnode *v, struct afsnode *an)); +extern struct vnode *alloc_vcache(void); +extern void ckAFSsym(struct nlist *nl); +extern int hasAFS(struct vnode *vp); +extern int readafsnode(KA_T va, struct vnode *v, struct afsnode *an); #endif /* defined(HAS_AFS) */ #if defined(HASVXFS) -_PROTOTYPE(extern int read_vxnode, - (struct vnode * v, struct l_vfs *vfs, dev_t *dev, int *devs, - dev_t *rdev, int *rdevs)); +extern int read_vxnode(struct vnode *v, struct l_vfs *vfs, dev_t *dev, + int *devs, dev_t *rdev, int *rdevs); #endif /* defined(HASVXFS) */ diff --git a/lib/dialects/hpux/kmem/dsock.c b/lib/dialects/hpux/kmem/dsock.c index d04a1022..e9457a44 100644 --- a/lib/dialects/hpux/kmem/dsock.c +++ b/lib/dialects/hpux/kmem/dsock.c @@ -419,7 +419,7 @@ void process_lla(la) KA_T la; /* link level CB address in kernel */ /* * Read link level access control block. */ - if (!la || kread((KA_T)la, (char *)&lcb, sizeof(lcb))) { + if (!la || kread(ctx, (KA_T)la, (char *)&lcb, sizeof(lcb))) { (void)snpf(Namech, Namechl, "can't read LLA CB (%s)", print_kptr(la, (char *)NULL, 0)); enter_nm(Namech); @@ -509,7 +509,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ enter_nm("no socket address"); return; } - if (kread((KA_T)sa, (char *)&s, sizeof(s))) { + if (kread(ctx, (KA_T)sa, (char *)&s, sizeof(s))) { (void)snpf(Namech, Namechl, "can't read socket struct from %s", print_kptr(sa, (char *)NULL, 0)); enter_nm(Namech); @@ -523,14 +523,14 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ enter_nm(Namech); return; } - if (!s.so_proto || kread((KA_T)s.so_proto, (char *)&p, sizeof(p))) { + if (!s.so_proto || kread(ctx, (KA_T)s.so_proto, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl, "no protocol switch"); enter_nm(Namech); return; } #if HPUXV >= 800 - if (kread((KA_T)p.pr_domain, (char *)&d, sizeof(d))) { + if (kread(ctx, (KA_T)p.pr_domain, (char *)&d, sizeof(d))) { (void)snpf(Namech, Namechl, "can't read domain struct from %s", print_kptr((KA_T)p.pr_domain, (char *)NULL, 0)); enter_nm(Namech); @@ -581,7 +581,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Get the X25 PCB and its extension. */ - if (!s.so_pcb || kread((KA_T)s.so_pcb, (char *)&xp, sizeof(xp))) { + if (!s.so_pcb || kread(ctx, (KA_T)s.so_pcb, (char *)&xp, sizeof(xp))) { (void)snpf(Namech, Namechl, "can't read x.25 pcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); enter_nm(Namech); @@ -589,7 +589,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ } enter_dev_ch(print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); if (!xp.x25pcb_extend || - kread((KA_T)xp.x25pcb_extend, (char *)&xpe, sizeof(xpe))) { + kread(ctx, (KA_T)xp.x25pcb_extend, (char *)&xpe, sizeof(xpe))) { (void)snpf(Namech, Namechl, "can't read x.25 pcb (%s) extension at %s", print_kptr((KA_T)s.so_pcb, tbuf, sizeof(tbuf)), @@ -704,7 +704,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Print raw socket information. */ - if (kread((KA_T)s.so_pcb, (char *)&raw, sizeof(raw)) || + if (kread(ctx, (KA_T)s.so_pcb, (char *)&raw, sizeof(raw)) || (struct socket *)sa != (struct socket *)raw.rcb_socket) { (void)snpf(Namech, Namechl, "can't read rawcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); @@ -731,7 +731,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Print Internet socket information. */ - if (kread((KA_T)s.so_pcb, (char *)&inp, sizeof(inp))) { + if (kread(ctx, (KA_T)s.so_pcb, (char *)&inp, sizeof(inp))) { (void)snpf(Namech, Namechl, "can't read inpcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); enter_nm(Namech); @@ -749,7 +749,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if (fa || la) (void)ent_inaddr(la, lp, fa, fp, AF_INET); if (p.pr_protocol == IPPROTO_TCP && inp.inp_ppcb && - kread((KA_T)inp.inp_ppcb, (char *)&t, sizeof(t)) == 0) { + kread(ctx, (KA_T)inp.inp_ppcb, (char *)&t, sizeof(t)) == 0) { Lf->lts.type = 0; Lf->lts.state.i = (int)t.t_state; } @@ -769,9 +769,9 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Save size information for HP-UX 10.30 and above. */ - if (!s.so_rcv || kread((KA_T)s.so_rcv, (char *)&rb, sizeof(rb))) + if (!s.so_rcv || kread(ctx, (KA_T)s.so_rcv, (char *)&rb, sizeof(rb))) rb.sb_cc = 0; - if (!s.so_snd || kread((KA_T)s.so_snd, (char *)&sb, sizeof(sb))) + if (!s.so_snd || kread(ctx, (KA_T)s.so_snd, (char *)&sb, sizeof(sb))) sb.sb_cc = 0; if (Lf->access == LSOF_FILE_ACCESS_READ) Lf->sz = (SZOFFTYPE)rb.sb_cc; @@ -786,7 +786,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read Unix protocol control block and the Unix address structure. */ enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); - if (kread((KA_T)s.so_pcb, (char *)&unp, sizeof(unp))) { + if (kread(ctx, (KA_T)s.so_pcb, (char *)&unp, sizeof(unp))) { (void)snpf(Namech, Namechl, "can't read unpcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); break; @@ -802,7 +802,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read UNIX domain socket address information for HP-UX below 10.30. */ if (unp.unp_addr) { - if (kread((KA_T)unp.unp_addr, (char *)&mb, sizeof(mb))) { + if (kread(ctx, (KA_T)unp.unp_addr, (char *)&mb, sizeof(mb))) { (void)snpf(Namech, Namechl, "can't read unp_addr at %s", print_kptr((KA_T)unp.unp_addr, (char *)NULL, 0)); break; @@ -822,9 +822,9 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ ua = (struct sockaddr_un *)NULL; mbl = 0; if (unp.unp_addr && - kread((KA_T)unp.unp_addr, (char *)&mb, sizeof(mb)) == 0 && + kread(ctx, (KA_T)unp.unp_addr, (char *)&mb, sizeof(mb)) == 0 && mb.b_datap && - kread((KA_T)mb.b_datap, (char *)&db, sizeof(db)) == 0) { + kread(ctx, (KA_T)mb.b_datap, (char *)&db, sizeof(db)) == 0) { if (db.db_base) { if (dbl < (db.db_size + 1)) { dbl = db.db_size + 1; @@ -837,10 +837,10 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ stderr, "%s: no space (%d) for UNIX socket address\n", Pn, dbl); - Error(); + Error(ctx); } } - if (kread((KA_T)db.db_base, dbf, db.db_size) == 0) { + if (kread(ctx, (KA_T)db.db_base, dbf, db.db_size) == 0) { mbl = db.db_size; dbf[mbl] = '\0'; ua = (struct sockaddr_un *)dbf; @@ -862,7 +862,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if (ua->sun_family != AF_UNIX) { if (ua->sun_family == AF_UNSPEC) { if (unp.unp_conn) { - if (kread((KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) + if (kread(ctx, (KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) (void)snpf( Namech, Namechl, "can't read unp_conn at %s", print_kptr((KA_T)unp.unp_conn, (char *)NULL, 0)); @@ -939,7 +939,7 @@ enum vtype vt; /* vnode type */ * Get IP structure. */ *Namech = '\0'; - if (!ip || kread(ip, (char *)&ic, sizeof(ic))) { + if (!ip || kread(ctx, ip, (char *)&ic, sizeof(ic))) { ep = endnm(&sz); (void)snpf(ep, sz, "%scan't read IP control structure from %s", sz ? " " : "", print_kptr(ip, (char *)NULL, 0)); @@ -967,7 +967,7 @@ enum vtype vt; /* vnode type */ /* * Process TCP socket. */ - if (kread(pcb, (char *)&tc, sizeof(tc))) { + if (kread(ctx, pcb, (char *)&tc, sizeof(tc))) { ep = endnm(&sz); (void)snpf(ep, sz, "%scan't read TCP PCB from %s", sz ? " " : "", print_kptr(pcb, (char *)NULL, 0)); @@ -988,7 +988,7 @@ enum vtype vt; /* vnode type */ */ la = (unsigned char *)&tc.tcp_u.tcp_u_iph.iph_src[0]; if (tc.tcp_hdr_len && tc.tcp_tcph && - kread((KA_T)tc.tcp_tcph, (char *)&th, sizeof(th)) == 0) + kread(ctx, (KA_T)tc.tcp_tcph, (char *)&th, sizeof(th)) == 0) pt = (u_short)th.th_lport; } lp = (int)ntohs(pt); @@ -1084,7 +1084,7 @@ enum vtype vt; /* vnode type */ /* * Process UDP socket. */ - if (kread(pcb, (char *)&ud, sizeof(ud))) { + if (kread(ctx, pcb, (char *)&ud, sizeof(ud))) { ep = endnm(&sz); (void)snpf(ep, sz, "%scan't read UDP PCB from %s", sz ? " " : "", print_kptr(pcb, (char *)NULL, 0)); diff --git a/lib/dialects/hpux/pstat/dfile.c b/lib/dialects/hpux/pstat/dfile.c index 0c1acbd5..27afe35a 100644 --- a/lib/dialects/hpux/pstat/dfile.c +++ b/lib/dialects/hpux/pstat/dfile.c @@ -119,10 +119,10 @@ static int Nzpss = 0; /* Nzps status: 1 = zeroed */ * Local function prototypes */ -_PROTOTYPE(static struct l_nc *ncache_addr, (struct psfileid * ps)); -_PROTOTYPE(static void ncache_free, (void)); -_PROTOTYPE(static int ncache_isroot, (struct psfileid * ps)); -_PROTOTYPE(static void ncache_size, (void)); +static struct l_nc *ncache_addr(struct psfileid *ps); +static void ncache_free(void); +static int ncache_isroot(struct psfileid *ps); +static void ncache_size(void); #endif /* defined(HASNCACHE) */ #if defined(HASIPv6) @@ -133,9 +133,9 @@ _PROTOTYPE(static void ncache_size, (void)); * getipnodebyname() functions */ -extern struct hostent *gethostbyname2(nm, prot) -char *nm; /* host name */ -int prot; /* protocol -- AF_INET or AF_INET6 */ +extern struct hostent * +gethostbyname2(char *nm, /* host name */ + int prot) /* protocol -- AF_INET or AF_INET6 */ { int err; @@ -170,8 +170,7 @@ int get_max_fd() { * ncache_addr() -- get ncache entry address */ -static struct l_nc *ncache_addr(ps) -struct psfileid *ps; /* parent's psfileid */ +static struct l_nc *ncache_addr(struct psfileid *ps) /* parent's psfileid */ { struct l_nc **hp, *lc; @@ -194,7 +193,7 @@ static void ncache_alloc() { (void)fprintf(stderr, "%s: can't allocate %d local name cache entries\n", Pn, Nceh); - Error(); + Error(ctx); } if (Ncfsid) return; @@ -202,7 +201,7 @@ static void ncache_alloc() { (void)fprintf(stderr, "%s: can't allocate %d local file system cache entries\n", Pn, NFSIDH); - Error(); + Error(ctx); } } @@ -250,8 +249,7 @@ static void ncache_free() { * ncache_isroot() -- does psfileid represent the root of a file system? */ -static int ncache_isroot(ps) -struct psfileid *ps; /* psfileid */ +static int ncache_isroot(struct psfileid *ps) /* psfileid */ { if (!ps->psf_fsid.psfs_id && !ps->psf_fsid.psfs_type && ps->psf_fileid == -1) @@ -290,9 +288,8 @@ void ncache_load() { * ncache_loadfs() -- load the name cache for a file system */ -struct l_fic *ncache_loadfs(fsid, fh) -struct psfsid *fsid; /* ID of file system to add */ -struct l_fic **fh; /* Ncfsid hash bucket */ +struct l_fic *ncache_loadfs(struct psfsid *fsid, /* ID of file system to add */ + struct l_fic **fh) /* Ncfsid hash bucket */ { char *cp; struct l_fic *f; @@ -305,7 +302,7 @@ struct l_fic **fh; /* Ncfsid hash bucket */ */ if (!(f = (struct l_fic *)malloc(sizeof(struct l_fic)))) { (void)fprintf(stderr, "%s: no fsid structure space\n", Pn); - Error(); + Error(ctx); } f->fsid = *fsid; f->nc = 0; @@ -330,13 +327,13 @@ struct l_fic **fh; /* Ncfsid hash bucket */ if (!(cp = (char *)malloc((MALLOC_S)(nl + 1)))) { (void)fprintf(stderr, "%s: no name entry space (%d) for:%s\n", Pn, nl + 1, mp[i].psr_name); - Error(); + Error(ctx); } if (!(nn = (struct l_nc *)malloc(sizeof(struct l_nc)))) { (void)fprintf(stderr, "%s: no name cache entry space (%d) for: %s\n", Pn, (int)sizeof(struct l_nc), mp[i].psr_name); - Error(); + Error(ctx); } /* * Fill in name cache entry, complete with name and name length. @@ -393,10 +390,9 @@ struct l_fic **fh; /* Ncfsid hash bucket */ * ncache_lookup() -- look up a node's name in the kernel's name cache */ -char *ncache_lookup(buf, blen, fp) -char *buf; /* receiving name buffer */ -int blen; /* receiving buffer length */ -int *fp; /* full path reply */ +char *ncache_lookup(char *buf, /* receiving name buffer */ + int blen, /* receiving buffer length */ + int *fp) /* full path reply */ { char *cp = buf; int ef; @@ -568,7 +564,7 @@ static void ncache_size() { if (pstat_getdynamic(&pd, sizeof(pd), 1, 0) != 1) { (void)fprintf(stderr, "%s: can't get dynamic status\n", Pn); - Error(); + Error(ctx); } Ndnlc = (int)pd.psd_dnlc_size; for (Nceh = 1; Nceh < (Ndnlc + Ndnlc); Nceh <<= 1) @@ -581,9 +577,8 @@ static void ncache_size() { * print_dev() -- print device */ -char *print_dev(lf, dev) -struct lfile *lf; /* file whose device is to be printed */ -dev_t *dev; /* device to be printed */ +char *print_dev(struct lfile *lf, /* file whose device is to be printed */ + dev_t *dev) /* device to be printed */ { static char buf[128]; diff --git a/lib/dialects/hpux/pstat/dproc.c b/lib/dialects/hpux/pstat/dproc.c index 75657dbc..31ab3201 100644 --- a/lib/dialects/hpux/pstat/dproc.c +++ b/lib/dialects/hpux/pstat/dproc.c @@ -110,13 +110,11 @@ static struct psfileid RtPsfid; /* "/" psfileid */ * Local function prototypes */ -_PROTOTYPE(static void get_kernel_access, (void)); -_PROTOTYPE(static void process_text, (struct pst_status * p)); -_PROTOTYPE(static struct pst_fileinfo2 *read_files, - (struct pst_status * p, int *n)); -_PROTOTYPE(static struct pst_status *read_proc, (int *n)); -_PROTOTYPE(static struct pst_vm_status *read_vmreg, - (struct pst_status * p, int *n)); +static void get_kernel_access(void); +static void process_text(struct pst_status *p); +static struct pst_fileinfo2 *read_files(struct pst_status *p, int *n); +static struct pst_status *read_proc(int *n); +static struct pst_vm_status *read_vmreg(struct pst_status *p, int *n); /* * gather_proc_info() -- gather process information @@ -153,7 +151,7 @@ void gather_proc_info() { if (!(fds = (int *)malloc(nb))) { (void)fprintf(stderr, "%s: can't allocate %d FD status entries\n", Pn, FDS_ALLOC_INIT); - Error(); + Error(ctx); } for (fdsa = 0; fdsa < FDS_ALLOC_INIT; fdsa++) { if (Fand && Fdl) @@ -310,7 +308,7 @@ void gather_proc_info() { stderr, "%s: can't reallocate %d FD status entries\n", Pn, l); - Error(); + Error(ctx); } while (fdsa < l) { fds[fdsa] = (ck_fd_status(NULL, fdsa) == 2) ? 1 : 0; @@ -443,12 +441,12 @@ static void get_kernel_access() { (void)fprintf(stderr, "%s: FATAL: can't determine PSTAT static size: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (pstat_getstatic(&pst, (size_t)pst.pst_static_size, 1, 0) != 1) { (void)fprintf(stderr, "%s: FATAL: can't read %ld bytes of pst_static\n", Pn, (long)pst.pst_static_size); - Error(); + Error(ctx); } /* * Check all the pst_static members defined in PstatCk[]. @@ -480,7 +478,7 @@ static void get_kernel_access() { } if (!err) return; - Error(); + Error(ctx); } /* @@ -541,7 +539,7 @@ static void process_text(p) struct pst_status *p; /* pst_status for process */ (void)fprintf(stderr, "%s: no memory for text and VM info array; PID: %d\n", Pn, (int)p->pst_pid); - Error(); + Error(ctx); } } /* @@ -630,13 +628,12 @@ static void process_text(p) struct pst_status *p; /* pst_status for process */ * read_det() -- read the pst_filedetails structure */ -KA_T read_det(ki, hf, lf, hn, ln, pd) -struct pst_fid *ki; /* kernel file ID */ -uint32_t hf; /* high file ID bits */ -uint32_t lf; /* low file ID bits */ -uint32_t hn; /* high node ID bits */ -uint32_t ln; /* low node ID bits */ -struct pst_filedetails *pd; /* details receiver */ +KA_T read_det(struct pst_fid *ki, /* kernel file ID */ + uint32_t hf, /* high file ID bits */ + uint32_t lf, /* low file ID bits */ + uint32_t hn, /* high node ID bits */ + uint32_t ln, /* low node ID bits */ + struct pst_filedetails *pd) /* details receiver */ { KA_T na; @@ -653,9 +650,9 @@ struct pst_filedetails *pd; /* details receiver */ * read_files() -- read the file descriptor information for a process */ -static struct pst_fileinfo2 *read_files(p, n) -struct pst_status *p; /* pst_status for the process */ -int *n; /* returned fi[] entry count */ +static struct pst_fileinfo2 * +read_files(struct pst_status *p, /* pst_status for the process */ + int *n) /* returned fi[] entry count */ { size_t ec; static struct pst_fileinfo2 *fi = (struct pst_fileinfo2 *)NULL; @@ -684,7 +681,7 @@ int *n; /* returned fi[] entry count */ (void)fprintf(stderr, "%s: can't allocate %d bytes for pst_filinfo\n", Pn, nb); - Error(); + Error(ctx); } } /* @@ -705,8 +702,7 @@ int *n; /* returned fi[] entry count */ * read_proc() -- read process table status information */ -static struct pst_status *read_proc(n) -int *n; /* returned ps[] entry count */ +static struct pst_status *read_proc(int *n) /* returned ps[] entry count */ { size_t el; int i = 0; @@ -738,7 +734,7 @@ int *n; /* returned ps[] entry count */ stderr, "%s: can't allocate %d bytes for pst_status table\n", Pn, nb); - Error(); + Error(ctx); } } /* @@ -768,9 +764,9 @@ int *n; /* returned ps[] entry count */ * read_vmreg() -- read info about the VM regions of a process */ -static struct pst_vm_status *read_vmreg(p, n) -struct pst_status *p; /* pst_status for process */ -int *n; /* returned region count */ +static struct pst_vm_status * +read_vmreg(struct pst_status *p, /* pst_status for process */ + int *n) /* returned region count */ { size_t ec = (size_t)p->pst_pid; MALLOC_S nb; @@ -798,7 +794,7 @@ int *n; /* returned region count */ (void)fprintf(stderr, "%s: can't allocate %d bytes for pst_vm_status\n", Pn, nb); - Error(); + Error(ctx); } } /* diff --git a/lib/dialects/hpux/pstat/dproto.h b/lib/dialects/hpux/pstat/dproto.h index 74cf53c8..6e17a1fa 100644 --- a/lib/dialects/hpux/pstat/dproto.h +++ b/lib/dialects/hpux/pstat/dproto.h @@ -34,26 +34,22 @@ * $Id: dproto.h,v 1.5 2008/10/21 16:17:50 abe Exp $ */ -_PROTOTYPE(extern int get_max_fd, (void)); -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern void process_finfo, - (struct pst_filedetails * pd, struct pst_fid *opfid, - struct psfileid *psfid, KA_T na)); -_PROTOTYPE(extern void process_socket, - (struct pst_fileinfo2 * f, struct pst_socket *s)); -_PROTOTYPE(extern void process_stream, (struct pst_fileinfo2 * f, int ckscko)); -_PROTOTYPE(extern KA_T read_det, - (struct pst_fid * ki, uint32_t hf, uint32_t lf, uint32_t hn, - uint32_t ln, struct pst_filedetails *pd)); -_PROTOTYPE(extern struct pst_socket *read_sock, (struct pst_fileinfo2 * f)); +extern int get_max_fd(void); +extern int is_file_named(char *p, int cd); +extern void process_finfo(struct pst_filedetails *pd, struct pst_fid *opfid, + struct psfileid *psfid, KA_T na); +extern void process_socket(struct pst_fileinfo2 *f, struct pst_socket *s); +extern void process_stream(struct pst_fileinfo2 *f, int ckscko); +extern KA_T read_det(struct pst_fid *ki, uint32_t hf, uint32_t lf, uint32_t hn, + uint32_t ln, struct pst_filedetails *pd); +extern struct pst_socket *read_sock(struct pst_fileinfo2 *f); #if defined(HASIPv6) -_PROTOTYPE(extern struct hostent *gethostbyname2, (char *nm, int proto)); +extern struct hostent *gethostbyname2(char *nm, int proto); #endif /* defined(HASIPv6) */ #if defined(HASVXFS) -_PROTOTYPE(extern int read_vxnode, - (struct vnode * v, struct l_vfs *vfs, dev_t *dev)); +extern int read_vxnode(struct vnode *v, struct l_vfs *vfs, dev_t *dev); #endif /* defined(HASVXFS) */ -_PROTOTYPE(extern void scanmnttab, (void)); +extern void scanmnttab(void); diff --git a/lib/dialects/hpux/pstat/dsock.c b/lib/dialects/hpux/pstat/dsock.c index 3814abdc..557c827f 100644 --- a/lib/dialects/hpux/pstat/dsock.c +++ b/lib/dialects/hpux/pstat/dsock.c @@ -40,12 +40,11 @@ static char copyright[] = */ #if defined(PS_STR_XPORT_DATA) -_PROTOTYPE(static void make_sock, - (struct pst_fileinfo2 * f, struct pst_stream *sh, - struct pst_socket *s)); +static void make_sock(struct pst_fileinfo2 *f, struct pst_stream *sh, + struct pst_socket *s); #endif /* defined(PS_STR_XPORT_DATA) */ -_PROTOTYPE(static void printpsproto, (uint32_t p)); +static void printpsproto(uint32_t p); /* * Local macros @@ -1399,7 +1398,7 @@ int ckscko; /* socket file only checking if (!s) { (void)fprintf(stderr, "%s: no space for %ld pst_stream bytes\n", Pn, (long)nb); - Error(); + Error(ctx); } nsa = nsn; } @@ -1582,8 +1581,7 @@ int ckscko; /* socket file only checking * read_sock() -- read pst_socket info for file */ -struct pst_socket *read_sock(f) -struct pst_fileinfo2 *f; /* file information */ +struct pst_socket *read_sock(struct pst_fileinfo2 *f) /* file information */ { static struct pst_socket s; diff --git a/lib/dialects/linux/dfile.c b/lib/dialects/linux/dfile.c index be74bb09..78ecde9c 100644 --- a/lib/dialects/linux/dfile.c +++ b/lib/dialects/linux/dfile.c @@ -91,7 +91,7 @@ static int HbyNmCt = 0; /* HbyNm entry count */ /* * hashSfile() - hash Sfile entries for use in is_file_named() searches */ -void hashSfile() { +void hashSfile(struct lsof_context *ctx) { static int hs = 0; int i; struct sfile *s; @@ -111,28 +111,28 @@ void hashSfile() { (void)fprintf( stderr, "%s: can't allocate space for %d (dev,ino) hash buckets\n", Pn, SFDIHASH); - Error(); + Error(ctx); } if (!(HbyFrd = (struct hsfile *)calloc((MALLOC_S)SFRDHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d rdev hash buckets\n", Pn, SFRDHASH); - Error(); + Error(ctx); } if (!(HbyFsd = (struct hsfile *)calloc((MALLOC_S)SFFSHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d file sys hash buckets\n", Pn, SFFSHASH); - Error(); + Error(ctx); } if (!(HbyNm = (struct hsfile *)calloc((MALLOC_S)SFNMHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d name hash buckets\n", Pn, SFNMHASH); - Error(); + Error(ctx); } hs++; /* @@ -185,7 +185,7 @@ void hashSfile() { (void)fprintf(stderr, "%s: can't allocate hsfile bucket for: %s\n", Pn, s->aname); - Error(); + Error(ctx); } sn->s = s; sn->next = sh->next; @@ -199,6 +199,8 @@ void hashSfile() { * is_file_named() - is this file named? */ int is_file_named( + /* context */ + struct lsof_context *ctx, /* search type: 0 = only by device * and inode * 1 = by device and @@ -325,7 +327,7 @@ int is_file_named( */ (void)snpf(Namech, Namechl, "%s", s->name); if (s->devnm) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, " (%s)", s->devnm); } } @@ -346,10 +348,11 @@ int is_file_named( * since it is called by printname() in print.c, an ersatz one * is provided here. */ -int printdevname(dev_t *dev, /* device */ - dev_t *rdev, /* raw device */ - int newline, /* 1 = follow with '\n' */ - int node_type) /* node type: N_BLK or N_chr */ +int printdevname(struct lsof_context *ctx, /* context */ + dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int newline, /* 1 = follow with '\n' */ + int node_type) /* node type: N_BLK or N_chr */ { char buf[128]; diff --git a/lib/dialects/linux/dmnt.c b/lib/dialects/linux/dmnt.c index 4ae54214..892dc3e0 100644 --- a/lib/dialects/linux/dmnt.c +++ b/lib/dialects/linux/dmnt.c @@ -44,12 +44,12 @@ * Local function prototypes */ -_PROTOTYPE(static char *convert_octal_escaped, (char *orig_str)); +static char *convert_octal_escaped(struct lsof_context *ctx, char *orig_str); #if defined(HASMNTSUP) -_PROTOTYPE(static int getmntdev, - (char *dir_name, size_t dir_name_len, struct stat *s, int *ss)); -_PROTOTYPE(static int hash_mnt, (char *dir_name)); +static int getmntdev(struct lsof_context *ctx, char *dir_name, + size_t dir_name_len, struct stat *s, int *ss); +static int hash_mnt(char *dir_name); #endif /* defined(HASMNTSUP) */ /* @@ -78,7 +78,8 @@ static mntsup_t **MSHash = (mntsup_t **)NULL; /* mount supplement /* * convert_octal_escaped() -- convert octal-escaped characters in string */ -static char *convert_octal_escaped(char *orig_str /* original string */) { +static char *convert_octal_escaped(struct lsof_context *ctx, /* context */ + char *orig_str /* original string */) { int cur_ch, cvt_len, cvt_idx, orig_len, orig_idx, temp_idx; char *cvt_str; int temp_ch; @@ -93,7 +94,7 @@ static char *convert_octal_escaped(char *orig_str /* original string */) { (void)fprintf(stderr, "%s: can't allocate %d bytes for octal-escaping.\n", Pn, orig_len + 1); - Error(); + Error(ctx); } /* * Copy the string, replacing octal-escaped characters as they are found. @@ -146,7 +147,7 @@ static char *convert_octal_escaped(char *orig_str /* original string */) { (void)fprintf( stderr, "%s: can't realloc %d bytes for octal-escaping.\n", Pn, cvt_len + 1); - Error(); + Error(ctx); } } @@ -168,12 +169,12 @@ static char *convert_octal_escaped(char *orig_str /* original string */) { * getmntdev() - get mount device from mount supplement */ static int -getmntdev( - char *dir_name, /* mounted directory name */ - size_t dir_name_len, /* strlen(dir_name) */ - struct stat *s, /* stat(2) buffer receptor */ - int *ss /* stat(2) status result -- i.e., SB_* - * values */) +getmntdev(struct lsof_context *ctx, /* context */ + char *dir_name, /* mounted directory name */ + size_t dir_name_len, /* strlen(dir_name) */ + struct stat *s, /* stat(2) buffer receptor */ + int *ss /* stat(2) status result -- i.e., SB_* + * values */) { static int err = 0; int h; @@ -205,7 +206,7 @@ getmntdev( err = 1; return (0); } - if (!(fs = open_proc_stream(MntSupP, "r", &vbuf, &vsz, 0))) { + if (!(fs = open_proc_stream(ctx, MntSupP, "r", &vbuf, &vsz, 0))) { /* * The mount supplement file can't be opened for reading. @@ -285,7 +286,7 @@ getmntdev( (void)fprintf( stderr, "%s: no space for mount supplement hash buckets\n", Pn); - Error(); + Error(ctx); } } h = hash_mnt(path); @@ -317,14 +318,14 @@ getmntdev( stderr, "%s: no space for mount supplement entry: %d \"%s\"\n", Pn, ln, buf); - Error(); + Error(ctx); } if (!(mpn->dir_name = (char *)malloc(sz + 1))) { (void)fprintf( stderr, "%s: no space for mount supplement path: %d \"%s\"\n", Pn, ln, buf); - Error(); + Error(ctx); } (void)strcpy(mpn->dir_name, path); mpn->dir_name_len = sz; @@ -396,7 +397,7 @@ static int hash_mnt(char *dir_name /* mount point directory name */) { /* * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char buf[MAXPATHLEN], *cp, **fp; char *dn = (char *)NULL; size_t dnl; @@ -419,13 +420,13 @@ struct mounts *readmnt() { * Open access to /proc/mounts, assigning a page size buffer to its stream. */ (void)snpf(buf, sizeof(buf), "%s/mounts", PROCFS); - ms = open_proc_stream(buf, "r", &vbuf, &vsz, 1); + ms = open_proc_stream(ctx, buf, "r", &vbuf, &vsz, 1); /* * Read mount table entries. */ while (fgets(buf, sizeof(buf), ms)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 3 || !fp[0] || - !fp[1] || !fp[2]) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 3 || + !fp[0] || !fp[1] || !fp[2]) continue; /* * Convert octal-escaped characters in the device name and mounted-on @@ -439,8 +440,8 @@ struct mounts *readmnt() { (void)free((FREE_P *)fp1); fp1 = (char *)NULL; } - if (!(fp0 = convert_octal_escaped(fp[0])) || - !(fp1 = convert_octal_escaped(fp[1]))) + if (!(fp0 = convert_octal_escaped(ctx, fp[0])) || + !(fp1 = convert_octal_escaped(ctx, fp[1]))) continue; /* * Locate any colon (':') in the device name. @@ -491,7 +492,7 @@ struct mounts *readmnt() { * Avoid Readlink() when requested. */ if (!ignrdl) { - if (!(ln = Readlink(dn))) { + if (!(ln = Readlink(ctx, dn))) { if (!Fwarn) { (void)fprintf( stderr, @@ -547,7 +548,7 @@ struct mounts *readmnt() { if (ignstat) fr = 1; else { - if ((fr = statsafely(dn, &sb))) { + if ((fr = statsafely(ctx, dn, &sb))) { if (!Fwarn) { (void)fprintf(stderr, "%s: WARNING: can't stat() ", Pn); safestrprt(fp[2], stderr, 0); @@ -570,7 +571,7 @@ struct mounts *readmnt() { */ if ((MntSup == 2) && MntSupP) { ds = 0; - if (getmntdev(dn, dnl, &sb, &ds) || !(ds & SB_DEV)) { + if (getmntdev(ctx, dn, dnl, &sb, &ds) || !(ds & SB_DEV)) { (void)fprintf(stderr, "%s: assuming dev=%#lx for %s from %s\n", Pn, (long)sb.st_dev, dn, MntSupP); @@ -609,7 +610,7 @@ struct mounts *readmnt() { (void)fprintf(stderr, "%s: can't allocate mounts struct for: ", Pn); safestrprt(dn, stderr, 1); - Error(); + Error(ctx); } } mp->dir = dn; @@ -662,18 +663,18 @@ struct mounts *readmnt() { if (!(ln = mkstrcpy(dn, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: can't allocate space for: ", Pn); safestrprt(dn, stderr, 1); - Error(); + Error(ctx); } ignstat = 1; } else - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat() the file system (mounted-on) name and add file system * information to the local mount table entry. */ - if (ignstat || !ln || statsafely(ln, &sb)) + if (ignstat || !ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mp->fsnmres = ln; mp->fs_mode = sb.st_mode; diff --git a/lib/dialects/linux/dnode.c b/lib/dialects/linux/dnode.c index 28583b0b..dde55bb1 100644 --- a/lib/dialects/linux/dnode.c +++ b/lib/dialects/linux/dnode.c @@ -69,10 +69,10 @@ struct llock **LckH = (struct llock **)NULL; /* PID-hashed locks */ * Local function prototypes */ -_PROTOTYPE(static void check_lock, (void)); +static void check_lock(struct lsof_context *ctx); #if defined(HASEPTOPTS) -_PROTOTYPE(static void enter_pinfo, (void)); +static void enter_pinfo(struct lsof_context *ctx); #endif /* defined(HASEPTOPTS) */ /* @@ -95,7 +95,7 @@ static pxinfo_t **EvtFDinfo = * check_lock() - check lock for file *Lf, process *Lp */ -static void check_lock() { +static void check_lock(struct lsof_context *ctx) { int h; struct llock *lp; @@ -129,8 +129,8 @@ static void endpoint_pxinfo_hash(pxinfo_t **pinfo_hash, const size_t nbuckets, } } -static void endpoint_enter(pxinfo_t **pinfo_hash, const char *table_name, - int id) { +static void endpoint_enter(struct lsof_context *ctx, pxinfo_t **pinfo_hash, + const char *table_name, int id) { int h; struct lfile *lf; /* local file structure pointer */ struct lproc *lp; /* local proc structure pointer */ @@ -156,7 +156,7 @@ static void endpoint_enter(pxinfo_t **pinfo_hash, const char *table_name, (void)fprintf(stderr, "%s: no space for pipeinfo for %s, PID %d, FD %s\n", table_name, Pn, Lp->pid, Lf->fd); - Error(); + Error(ctx); } np->ino = id; np->lf = Lf; @@ -169,9 +169,10 @@ static void endpoint_enter(pxinfo_t **pinfo_hash, const char *table_name, } static pxinfo_t * -endpoint_find(pxinfo_t **pinfo_hash, - int (*is_acceptable)(pxinfo_t *, int, struct lfile *), int pid, - struct lfile *lf, int id, pxinfo_t *pp) { +endpoint_find(struct lsof_context *ctx, pxinfo_t **pinfo_hash, + int (*is_acceptable)(struct lsof_context *, pxinfo_t *, int, + struct lfile *), + int pid, struct lfile *lf, int id, pxinfo_t *pp) { int h; /* hash result */ pxinfo_t *pi; /* pipe info pointer */ @@ -183,7 +184,7 @@ endpoint_find(pxinfo_t **pinfo_hash, pi = pinfo_hash[h]; } while (pi) { - if (pi->ino == id && is_acceptable(pi, pid, lf)) + if (pi->ino == id && is_acceptable(ctx, pi, pid, lf)) return (pi); pi = pi->next; } @@ -196,7 +197,8 @@ endpoint_find(pxinfo_t **pinfo_hash, * fd associated with pi is not the same as fd associated with lf. */ -static int endpoint_accept_other_than_self(pxinfo_t *pi, int pid, +static int endpoint_accept_other_than_self(struct lsof_context *ctx, + pxinfo_t *pi, int pid, struct lfile *lf) { struct lfile *ef = pi->lf; struct lproc *ep = &Lproc[pi->lpx]; @@ -207,7 +209,9 @@ static int endpoint_accept_other_than_self(pxinfo_t *pi, int pid, * clear_pinfo() -- clear allocated pipe info */ -void clear_pinfo() { endpoint_pxinfo_hash(Pinfo, PINFOBUCKS, free); } +void clear_pinfo(struct lsof_context *ctx) { + endpoint_pxinfo_hash(Pinfo, PINFOBUCKS, free); +} /* * enter_pinfo() -- enter pipe info @@ -216,7 +220,7 @@ void clear_pinfo() { endpoint_pxinfo_hash(Pinfo, PINFOBUCKS, free); } * Lp = local process structure pointer */ -static void enter_pinfo() { +static void enter_pinfo(struct lsof_context *ctx) { if (!Pinfo) { /* * Allocate pipe info hash buckets. @@ -224,22 +228,22 @@ static void enter_pinfo() { if (!(Pinfo = (pxinfo_t **)calloc(PINFOBUCKS, sizeof(pxinfo_t *)))) { (void)fprintf(stderr, "%s: no space for %d pipe info buckets\n", Pn, PINFOBUCKS); - Error(); + Error(ctx); } } - endpoint_enter(Pinfo, "pipeinfo", Lf->inode); + endpoint_enter(ctx, Pinfo, "pipeinfo", Lf->inode); } /* * find_pepti() -- find pipe end point info */ -pxinfo_t *find_pepti(pid, lf, pp) -int pid; /* pid of the process owning lf */ -struct lfile *lf; /* pipe's lfile */ -pxinfo_t *pp; /* previous pipe info (NULL == none) */ +pxinfo_t *find_pepti(struct lsof_context *ctx, /* context */ + int pid, /* pid of the process owning lf */ + struct lfile *lf, /* pipe's lfile */ + pxinfo_t *pp) /* previous pipe info (NULL == none) */ { - return endpoint_find(Pinfo, endpoint_accept_other_than_self, pid, lf, + return endpoint_find(ctx, Pinfo, endpoint_accept_other_than_self, pid, lf, lf->inode, pp); } @@ -249,7 +253,9 @@ pxinfo_t *pp; /* previous pipe info (NULL == none) */ * clear_ptyinfo() -- clear allocated pseudoterminal info */ -void clear_ptyinfo() { endpoint_pxinfo_hash(PtyInfo, PINFOBUCKS, free); } +void clear_ptyinfo(struct lsof_context *ctx) { + endpoint_pxinfo_hash(PtyInfo, PINFOBUCKS, free); +} /* * enter_ptmxi() -- enter pty info @@ -258,7 +264,8 @@ void clear_ptyinfo() { endpoint_pxinfo_hash(PtyInfo, PINFOBUCKS, free); } * Lp = local process structure pointer */ -void enter_ptmxi(mn) int mn; /* minor number of device */ +void enter_ptmxi(struct lsof_context *ctx, /* context */ + int mn) /* minor number of device */ { /* * Allocate pipe info hash buckets (but used for pty). @@ -267,10 +274,10 @@ void enter_ptmxi(mn) int mn; /* minor number of device */ if (!(PtyInfo = (pxinfo_t **)calloc(PINFOBUCKS, sizeof(pxinfo_t *)))) { (void)fprintf(stderr, "%s: no space for %d pty info buckets\n", Pn, PINFOBUCKS); - Error(); + Error(ctx); } } - endpoint_enter(PtyInfo, "pty", mn); + endpoint_enter(ctx, PtyInfo, "pty", mn); } /* @@ -278,7 +285,8 @@ void enter_ptmxi(mn) int mn; /* minor number of device */ * or not */ -static int ptyepti_accept_ptmx(pxinfo_t *pi, int pid, struct lfile *lf) { +static int ptyepti_accept_ptmx(struct lsof_context *ctx, pxinfo_t *pi, int pid, + struct lfile *lf) { struct lfile *ef = pi->lf; return is_pty_ptmx(ef->rdev); } @@ -288,7 +296,8 @@ static int ptyepti_accept_ptmx(pxinfo_t *pi, int pid, struct lfile *lf) { * slave or not */ -static int ptyepti_accept_slave(pxinfo_t *pi, int pid, struct lfile *lf) { +static int ptyepti_accept_slave(struct lsof_context *ctx, pxinfo_t *pi, int pid, + struct lfile *lf) { struct lfile *ef = pi->lf; return is_pty_slave(GET_MAJ_DEV(ef->rdev)); } @@ -297,16 +306,16 @@ static int ptyepti_accept_slave(pxinfo_t *pi, int pid, struct lfile *lf) { * find_ptyepti() -- find pseudoterminal end point info */ -pxinfo_t *find_ptyepti(pid, lf, m, pp) -int pid; -struct lfile *lf; /* pseudoterminal's lfile */ -int m; /* minor number type: - * 0 == use tty_index - * 1 == use minor device */ -pxinfo_t *pp; /* previous pseudoterminal info - * (NULL == none) */ +pxinfo_t *find_ptyepti(struct lsof_context *ctx, /* context */ + int pid, /* PID*/ + struct lfile *lf, /* pseudoterminal's lfile */ + int m, /* minor number type: + * 0 == use tty_index + * 1 == use minor device */ + pxinfo_t *pp) /* previous pseudoterminal info + * (NULL == none) */ { - return endpoint_find(PtyInfo, + return endpoint_find(ctx, PtyInfo, m ? ptyepti_accept_ptmx : ptyepti_accept_slave, pid, lf, m ? GET_MIN_DEV(lf->rdev) : lf->tty_index, pp); } @@ -315,8 +324,7 @@ pxinfo_t *pp; /* previous pseudoterminal info * is_pty_slave() -- is a pseudoterminal a slave device */ -int is_pty_slave(sm) -int sm; /* slave major device number */ +int is_pty_slave(int sm) /* slave major device number */ { /* linux/Documentation/admin-guide/devices.txt ------------------------------------------- @@ -342,8 +350,7 @@ int sm; /* slave major device number */ * is_pty_ptmx() -- is a pseudoterminal a master clone device */ -int is_pty_ptmx(dev) -dev_t dev; /* device number */ +int is_pty_ptmx(dev_t dev) /* device number */ { if ((GET_MAJ_DEV(dev) == TTYAUX_MAJOR) && (GET_MIN_DEV(dev) == 2)) return 1; @@ -355,7 +362,9 @@ dev_t dev; /* device number */ * clear_psxmqinfo -- clear allocate posix mq info */ -void clear_psxmqinfo() { endpoint_pxinfo_hash(PSXMQinfo, PINFOBUCKS, free); } +void clear_psxmqinfo(struct lsof_context *ctx) { + endpoint_pxinfo_hash(PSXMQinfo, PINFOBUCKS, free); +} /* * enter_psxmqinfo() -- enter posix mq info @@ -364,7 +373,7 @@ void clear_psxmqinfo() { endpoint_pxinfo_hash(PSXMQinfo, PINFOBUCKS, free); } * Lp = local process structure pointer */ -void enter_psxmqinfo() { +void enter_psxmqinfo(struct lsof_context *ctx) { if (!PSXMQinfo) { /* * Allocate posix mq info hash buckets. @@ -373,30 +382,33 @@ void enter_psxmqinfo() { (pxinfo_t **)calloc(PINFOBUCKS, sizeof(pxinfo_t *)))) { (void)fprintf(stderr, "%s: no space for %d posix mq info buckets\n", Pn, PINFOBUCKS); - Error(); + Error(ctx); } } - endpoint_enter(PSXMQinfo, "psxmqinfo", Lf->inode); + endpoint_enter(ctx, PSXMQinfo, "psxmqinfo", Lf->inode); } /* * find_psxmqinfo() -- find posix mq end point info */ -pxinfo_t *find_psxmqinfo(pid, lf, pp) -int pid; /* pid of the process owning lf */ -struct lfile *lf; /* posix mq's lfile */ -pxinfo_t *pp; /* previous posix mq info (NULL == none) */ +pxinfo_t * +find_psxmqinfo(struct lsof_context *ctx, /* context */ + int pid, /* pid of the process owning lf */ + struct lfile *lf, /* posix mq's lfile */ + pxinfo_t *pp) /* previous posix mq info (NULL == none) */ { - return endpoint_find(PSXMQinfo, endpoint_accept_other_than_self, pid, lf, - lf->inode, pp); + return endpoint_find(ctx, PSXMQinfo, endpoint_accept_other_than_self, pid, + lf, lf->inode, pp); } /* * clear_evtfdinfo -- clear allocate eventfd info */ -void clear_evtfdinfo() { endpoint_pxinfo_hash(EvtFDinfo, PINFOBUCKS, free); } +void clear_evtfdinfo(struct lsof_context *ctx) { + endpoint_pxinfo_hash(EvtFDinfo, PINFOBUCKS, free); +} /* * enter_evtfdinfo() -- enter eventfd info @@ -405,7 +417,7 @@ void clear_evtfdinfo() { endpoint_pxinfo_hash(EvtFDinfo, PINFOBUCKS, free); } * Lp = local process structure pointer */ -void enter_evtfdinfo(int id) { +void enter_evtfdinfo(struct lsof_context *ctx, int id) { if (!EvtFDinfo) { /* * Allocate eventfd info hash buckets. @@ -414,23 +426,24 @@ void enter_evtfdinfo(int id) { (pxinfo_t **)calloc(PINFOBUCKS, sizeof(pxinfo_t *)))) { (void)fprintf(stderr, "%s: no space for %d envet fd info buckets\n", Pn, PINFOBUCKS); - Error(); + Error(ctx); } } - endpoint_enter(EvtFDinfo, "evtfdinfo", id); + endpoint_enter(ctx, EvtFDinfo, "evtfdinfo", id); } /* * find_evtfdinfo() -- find eventfd end point info */ -pxinfo_t *find_evtfdinfo(pid, lf, pp) -int pid; /* pid of the process owning lf */ -struct lfile *lf; /* eventfd's lfile */ -pxinfo_t *pp; /* previous eventfd info (NULL == none) */ +pxinfo_t * +find_evtfdinfo(struct lsof_context *ctx, /* context */ + int pid, /* pid of the process owning lf */ + struct lfile *lf, /* eventfd's lfile */ + pxinfo_t *pp) /* previous eventfd info (NULL == none) */ { - void *r = endpoint_find(EvtFDinfo, endpoint_accept_other_than_self, pid, lf, - lf->eventfd_id, pp); + void *r = endpoint_find(ctx, EvtFDinfo, endpoint_accept_other_than_self, + pid, lf, lf->eventfd_id, pp); return r; } #endif /* defined(HASEPTOPTS) */ @@ -439,16 +452,16 @@ pxinfo_t *pp; /* previous eventfd info (NULL == none) */ * get_fields() - separate a line into fields */ -int get_fields(ln, sep, fr, eb, en) -char *ln; /* input line */ -char *sep; /* separator list */ -char ***fr; /* field pointer return address */ -int *eb; /* indexes of fields where blank or an - * entry from the separator list may be - * embedded and are not separators - * (may be NULL) */ -int en; /* number of entries in eb[] (may be - * zero) */ +int get_fields(struct lsof_context *ctx, /* context */ + char *ln, /* input line */ + char *sep, /* separator list */ + char ***fr, /* field pointer return address */ + int *eb, /* indexes of fields where blank or an + * entry from the separator list may be + * embedded and are not separators + * (may be NULL) */ + int en) /* number of entries in eb[] (may be + * zero) */ { char *bp, *cp, *sp; int i, j, n; @@ -529,7 +542,7 @@ int en; /* number of entries in eb[] (may be (void)fprintf( stderr, "%s: can't allocate %d bytes for field pointers.\n", Pn, (int)len); - Error(); + Error(ctx); } } fp[n++] = bp; @@ -542,7 +555,8 @@ int en; /* number of entries in eb[] (may be * get_locks() - get lock information from /proc/locks */ -void get_locks(p) char *p; /* /proc lock path */ +void get_locks(struct lsof_context *ctx, /* context */ + char *p) /* /proc lock path */ { unsigned long bp, ep; char buf[MAXPATHLEN], *ec, **fp; @@ -576,17 +590,17 @@ void get_locks(p) char *p; /* /proc lock path */ if (!LckH) { (void)fprintf(stderr, "%s: can't allocate %d lock hash bytes\n", Pn, (int)(sizeof(struct llock *) * PIDBUCKS)); - Error(); + Error(ctx); } } /* * Open the /proc lock file, assign a page size buffer to its stream, * and read it. */ - if (!(ls = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(ls = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf), ls)) { - if (get_fields(buf, ":", &fp, (int *)NULL, 0) < 10) + if (get_fields(ctx, buf, ":", &fp, (int *)NULL, 0) < 10) continue; if (!fp[1] || strcmp(fp[1], "->") == 0) continue; @@ -665,7 +679,7 @@ void get_locks(p) char *p; /* /proc lock path */ (void)fprintf( stderr, "%s: can't allocate llock: PID %d; dev %x; inode %s\n", Pn, pid, (int)dev, buf); - Error(); + Error(ctx); } lp->pid = pid; lp->dev = dev; @@ -681,14 +695,14 @@ void get_locks(p) char *p; /* /proc lock path */ * process_proc_node() - process file node */ -void process_proc_node(p, pbr, s, ss, l, - ls) char *p; /* node's readlink() path */ -char *pbr; /* node's path before readlink() */ -struct stat *s; /* stat() result for path */ -int ss; /* *s status -- i.e., SB_* values */ -struct stat *l; /* lstat() result for FD (NULL for - * others) */ -int ls; /* *l status -- i.e., SB_* values */ +void process_proc_node(struct lsof_context *ctx, /* context */ + char *p, /* node's readlink() path */ + char *pbr, /* node's path before readlink() */ + struct stat *s, /* stat() result for path */ + int ss, /* *s status -- i.e., SB_* values */ + struct stat *l, /* lstat() result for FD (NULL for + * others) */ + int ls) /* *l status -- i.e., SB_* values */ { mode_t access; mode_t type = 0; @@ -724,7 +738,7 @@ int ls; /* *l status -- i.e., SB_* values */ break; case S_IFSOCK: /* Lf->ntype = Ntype = N_REGLR; by alloc_lfile() */ - process_proc_sock(p, pbr, s, ss, l, ls); + process_proc_sock(ctx, p, pbr, s, ss, l, ls); return; case 0: if (!strcmp(p, "anon_inode")) @@ -749,14 +763,14 @@ int ls; /* *l status -- i.e., SB_* values */ #if defined(HASEPTOPTS) && defined(HASPTYEPT) if (FeptE && (Ntype == N_CHR) && is_pty_slave(GET_MAJ_DEV(Lf->rdev))) { - enter_ptmxi(GET_MIN_DEV(Lf->rdev)); + enter_ptmxi(ctx, GET_MIN_DEV(Lf->rdev)); Lf->sf |= SELPTYINFO; } #endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ } } if (Ntype == N_REGLR && (HasNFS == 2)) { - for (mp = readmnt(); mp; mp = mp->next) { + for (mp = readmnt(ctx); mp; mp = mp->next) { if ((mp->ty == N_NFS) && (mp->ds & SB_DEV) && Lf->dev_def && (Lf->dev == mp->dev) && (mp->dir && mp->dirl && !strncmp(mp->dir, p, mp->dirl))) { @@ -774,10 +788,10 @@ int ls; /* *l status -- i.e., SB_* values */ #if defined(HASEPTOPTS) if ((Lf->ntype == N_FIFO) && FeptE) { - (void)enter_pinfo(); + (void)enter_pinfo(ctx); Lf->sf |= SELPINFO; } else if ((Lf->dev == MqueueDev) && FeptE) { - (void)enter_psxmqinfo(); + (void)enter_psxmqinfo(ctx); Lf->sf |= SELPSXMQINFO; } #endif /* defined(HASEPTOPTS) */ @@ -786,7 +800,7 @@ int ls; /* *l status -- i.e., SB_* values */ * Check for a lock. */ if (Lf->dev_def && (Lf->inp_ty == 1)) - (void)check_lock(); + (void)check_lock(ctx); /* * Save the file size. */ @@ -869,7 +883,7 @@ int ls; /* *l status -- i.e., SB_* values */ * Test for specified file. */ if (Sfile && - is_file_named(1, p, mp, + is_file_named(ctx, 1, p, mp, ((type == S_IFCHR) || (type == S_IFBLK)) ? 1 : 0)) Lf->sf |= SELNM; /* @@ -880,10 +894,10 @@ int ls; /* *l status -- i.e., SB_* values */ if (!Namech[0]) { (void)snpf(Namech, Namechl, "%s", p); if ((Ntype == N_NFS) && mp && mp->fsname) { - cp = endnm(&sz); + cp = endnm(ctx, &sz); (void)snpf(cp, sz, " (%s)", mp->fsname); } } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } diff --git a/lib/dialects/linux/dproc.c b/lib/dialects/linux/dproc.c index 440da75a..b6af36e0 100644 --- a/lib/dialects/linux/dproc.c +++ b/lib/dialects/linux/dproc.c @@ -113,26 +113,27 @@ static short Ckscko; /* socket file only checking status: * Local function prototypes */ -_PROTOTYPE(static MALLOC_S alloc_cbf, - (MALLOC_S len, char **cbf, MALLOC_S cbfa)); -_PROTOTYPE(static int get_fdinfo, (char *p, int msk, struct l_fdinfo *fi)); -_PROTOTYPE(static int getlinksrc, (char *ln, char *src, int srcl, char **rest)); -_PROTOTYPE(static int isefsys, (char *path, char *type, int l, - efsys_list_t **rep, struct lfile **lfr)); -_PROTOTYPE(static int nm2id, (char *nm, int *id, int *idl)); -_PROTOTYPE(static int read_id_stat, - (char *p, int id, char **cmd, int *ppid, int *pgid)); -_PROTOTYPE(static void process_proc_map, (char *p, struct stat *s, int ss)); -_PROTOTYPE(static int process_id, - (char *idp, int idpl, char *cmd, UID_ARG uid, int pid, int ppid, - int pgid, int tid, char *tcmd)); -_PROTOTYPE(static int statEx, (char *p, struct stat *s, int *ss)); - -_PROTOTYPE(static void snp_eventpoll, - (char *p, int len, int *tfds, int tfd_count)); +static MALLOC_S alloc_cbf(struct lsof_context *ctx, MALLOC_S len, char **cbf, + MALLOC_S cbfa); +static int get_fdinfo(struct lsof_context *ctx, char *p, int msk, + struct l_fdinfo *fi); +static int getlinksrc(char *ln, char *src, int srcl, char **rest); +static int isefsys(struct lsof_context *ctx, char *path, char *type, int l, + efsys_list_t **rep, struct lfile **lfr); +static int nm2id(char *nm, int *id, int *idl); +static int read_id_stat(struct lsof_context *ctx, char *p, int id, char **cmd, + int *ppid, int *pgid); +static void process_proc_map(struct lsof_context *ctx, char *p, struct stat *s, + int ss); +static int process_id(struct lsof_context *ctx, char *idp, int idpl, char *cmd, + UID_ARG uid, int pid, int ppid, int pgid, int tid, + char *tcmd); +static int statEx(struct lsof_context *ctx, char *p, struct stat *s, int *ss); + +static void snp_eventpoll(char *p, int len, int *tfds, int tfd_count); #if defined(HASSELINUX) -_PROTOTYPE(static int cmp_cntx_eq, (char *pcntx, char *ucntx)); +static int cmp_cntx_eq(char *pcntx, char *ucntx); # include @@ -140,17 +141,18 @@ _PROTOTYPE(static int cmp_cntx_eq, (char *pcntx, char *ucntx)); * cmp_cntx_eq -- compare program and user security contexts */ -static int cmp_cntx_eq(pcntx, ucntx) -char *pcntx; /* program context */ -char *ucntx; /* user supplied context */ -{ return !fnmatch(ucntx, pcntx, 0); } +static int cmp_cntx_eq(char *pcntx, /* program context */ + char *ucntx) /* user supplied context */ +{ + return !fnmatch(ucntx, pcntx, 0); +} /* * enter_cntx_arg() - enter name ecurity context argument */ -int enter_cntx_arg(cntx) -char *cntx; /* context */ +int enter_cntx_arg(struct lsof_context *ctx, /* context */ + char *cntx) /* context */ { cntxlist_t *cntxp; /* @@ -169,7 +171,7 @@ char *cntx; /* context */ */ if (!(cntxp = (cntxlist_t *)malloc((MALLOC_S)sizeof(cntxlist_t)))) { (void)fprintf(stderr, "%s: no space for context: %s\n", Pn, cntx); - Error(); + Error(ctx); } cntxp->f = 0; cntxp->cntx = cntx; @@ -183,10 +185,10 @@ char *cntx; /* context */ * alloc_cbf() -- allocate a command buffer */ -static MALLOC_S alloc_cbf(len, cbf, cbfa) -MALLOC_S len; /* required length */ -char **cbf; /* current buffer */ -MALLOC_S cbfa; /* current buffer allocation */ +static MALLOC_S alloc_cbf(struct lsof_context *ctx, /* context */ + MALLOC_S len, /* required length */ + char **cbf, /* current buffer */ + MALLOC_S cbfa) /* current buffer allocation */ { if (*cbf) *cbf = (char *)realloc((MALLOC_P *)*cbf, len); @@ -195,7 +197,7 @@ MALLOC_S cbfa; /* current buffer allocation */ if (!*cbf) { (void)fprintf(stderr, "%s: can't allocate command %d bytes\n", Pn, (int)len); - Error(); + Error(ctx); } return (len); } @@ -204,7 +206,7 @@ MALLOC_S cbfa; /* current buffer allocation */ * gather_proc_info() -- gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { char *cmd, *tcmd; char cmdbuf[MAXPATHLEN]; struct dirent *dp; @@ -234,17 +236,17 @@ void gather_proc_info() { (void)fprintf(stderr, "%s: can't allocate %d bytes for \"%s/\"\n", Pn, (int)pidpathl, PROCFS); - Error(); + Error(ctx); } (void)snpf(pidpath, pidpathl, "%s/", PROCFS); } /* * Get lock and net information. */ - (void)make_proc_path(pidpath, pidx, &path, &pathl, "locks"); - (void)get_locks(path); - (void)make_proc_path(pidpath, pidx, &path, &pathl, "net/"); - (void)set_net_paths(path, strlen(path)); + (void)make_proc_path(ctx, pidpath, pidx, &path, &pathl, "locks"); + (void)get_locks(ctx, path); + (void)make_proc_path(ctx, pidpath, pidx, &path, &pathl, "net/"); + (void)set_net_paths(ctx, path, strlen(path)); /* * If only socket files have been selected, or socket files have been * selected ANDed with other selection options, enable the skipping of @@ -298,7 +300,7 @@ void gather_proc_info() { if (!ps) { if (!(ps = opendir(PROCFS))) { (void)fprintf(stderr, "%s: can't open %s\n", Pn, PROCFS); - Error(); + Error(ctx); } } else (void)rewinddir(ps); @@ -314,7 +316,7 @@ void gather_proc_info() { (void)fprintf(stderr, "%s: can't allocate %d bytes for \"%s/%s/\"\n", Pn, (int)pidpathl, PROCFS, dp->d_name); - Error(); + Error(ctx); } } (void)snpf(pidpath + pidx, pidpathl - pidx, "%s/", dp->d_name); @@ -329,8 +331,8 @@ void gather_proc_info() { /* * Get the PID's command name. */ - (void)make_proc_path(pidpath, n, &path, &pathl, "stat"); - if ((prv = read_id_stat(path, pid, &cmd, &ppid, &pgid)) < 0) + (void)make_proc_path(ctx, pidpath, n, &path, &pathl, "stat"); + if ((prv = read_id_stat(ctx, path, pid, &cmd, &ppid, &pgid)) < 0) cmd = NULL; /* NULL means failure to get command name */ #if defined(HASTASKS) @@ -353,7 +355,8 @@ void gather_proc_info() { cmd = cmdbuf; } - (void)make_proc_path(pidpath, n, &taskpath, &taskpathl, "task"); + (void)make_proc_path(ctx, pidpath, n, &taskpath, &taskpathl, + "task"); tx = n + 4; if ((ts = opendir(taskpath))) { @@ -390,7 +393,7 @@ void gather_proc_info() { Pn, tidpathl); (void)fprintf(stderr, " for \"%s/%s/stat\"\n", taskpath, dp->d_name); - Error(); + Error(ctx); } } (void)snpf(tidpath, tidpathl, "%s/%s/stat", taskpath, @@ -398,14 +401,14 @@ void gather_proc_info() { /* * Check the task state. */ - rv = read_id_stat(tidpath, tid, &tcmd, &tppid, &tpgid); + rv = read_id_stat(ctx, tidpath, tid, &tcmd, &tppid, &tpgid); if ((rv < 0) || (rv == 1)) continue; /* * Attempt to record the task. */ - if (!process_id(tidpath, (tx + 1 + nl + 1), cmd, uid, pid, - tppid, tpgid, tid, tcmd)) { + if (!process_id(ctx, tidpath, (tx + 1 + nl + 1), cmd, uid, + pid, tppid, tpgid, tid, tcmd)) { ht = 1; } } @@ -424,7 +427,7 @@ void gather_proc_info() { tid = (Fand && ht && pidts && !IgnTasks && (Selflags & SELTASK)) ? pid : 0; - if ((!process_id(pidpath, n, cmd, uid, pid, ppid, pgid, tid, + if ((!process_id(ctx, pidpath, n, cmd, uid, pid, ppid, pgid, tid, (char *)NULL)) && tid) { Lp->tid = 0; @@ -437,12 +440,12 @@ void gather_proc_info() { * get_fdinfo() - get values from /proc/fdinfo/FD */ -static int get_fdinfo(p, msk, fi) -char *p; /* path to fdinfo file */ -int msk; /* mask for information type: e.g., - * the FDINFO_* definition */ -struct l_fdinfo *fi; /* pointer to local fdinfo values - * return structure */ +static int get_fdinfo(struct lsof_context *ctx, /* context */ + char *p, /* path to fdinfo file */ + int msk, /* mask for information type: e.g., + * the FDINFO_* definition */ + struct l_fdinfo *fi) /* pointer to local fdinfo values + * return structure */ { char buf[MAXPATHLEN + 1], *ep, **fp; FILE *fs; @@ -472,7 +475,7 @@ struct l_fdinfo *fi; /* pointer to local fdinfo values */ while (fgets(buf, sizeof(buf), fs)) { int opt_flg = 0; - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 2) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 2) continue; if (!fp[0] || !*fp[0] || !fp[1] || !*fp[1]) continue; @@ -577,13 +580,12 @@ struct l_fdinfo *fi; /* pointer to local fdinfo values * getlinksrc() - get the source path name for the /proc//fd/ link */ -static int getlinksrc(ln, src, srcl, rest) -char *ln; /* link path */ -char *src; /* link source path return address */ -int srcl; /* length of src[] */ -char **rest; /* pointer to what follows the ':' in - * the link source path (NULL if no - * return requested) */ +static int getlinksrc(char *ln, /* link path */ + char *src, /* link source path return address */ + int srcl, /* length of src[] */ + char **rest) /* pointer to what follows the ':' in + * the link source path (NULL if no + * return requested) */ { char *cp; int ll; @@ -608,7 +610,7 @@ char **rest; /* pointer to what follows the ':' in * initialize() - perform all initialization */ -void initialize() { +void initialize(struct lsof_context *ctx) { int fd; struct l_fdinfo fi; char path[MAXPATHLEN]; @@ -618,7 +620,7 @@ void initialize() { */ if (Fxopt && (Fnet || Nwad)) { (void)fprintf(stderr, "%s: -i is useless when -X is specified.\n", Pn); - usage(1, 0, 0); + usage(ctx, 1, 0, 0); } /* * Open LSTAT_TEST_FILE and seek to byte LSTAT_TEST_SEEK, then lstat the @@ -641,7 +643,7 @@ void initialize() { if (OffType == OFFSET_UNKNOWN) { (void)snpf(path, sizeof(path), "%s/%d/fdinfo/%d", PROCFS, Mypid, fd); - if (get_fdinfo(path, FDINFO_POS, &fi) & FDINFO_POS) { + if (get_fdinfo(ctx, path, FDINFO_POS, &fi) & FDINFO_POS) { if (fi.pos == (off_t)LSTAT_TEST_SEEK) OffType = OFFSET_FDINFO; } @@ -669,7 +671,7 @@ void initialize() { * local mount table.) */ if (Selinet == 0) - (void)readmnt(); + (void)readmnt(ctx); } /* @@ -686,12 +688,12 @@ void initialize() { * np = updated with new path * nl = updated with new buffer size */ -int make_proc_path(pp, pl, np, nl, sf) -char *pp; /* path prefix -- e.g., /proc// */ -int pl; /* strlen(pp) */ -char **np; /* malloc'd receiving buffer */ -int *nl; /* malloc'd size */ -char *sf; /* suffix of new path */ +int make_proc_path(struct lsof_context *ctx, /* context */ + char *pp, /* path prefix -- e.g., /proc// */ + int pl, /* strlen(pp) */ + char **np, /* malloc'd receiving buffer */ + int *nl, /* malloc'd size */ + char *sf) /* suffix of new path */ { char *cp; MALLOC_S rl, sl; @@ -705,7 +707,7 @@ char *sf; /* suffix of new path */ if (!cp) { (void)fprintf(stderr, "%s: can't allocate %d bytes for %s%s\n", Pn, (int)rl, pp, sf); - Error(); + Error(ctx); } *nl = rl; *np = cp; @@ -721,14 +723,14 @@ char *sf; /* suffix of new path */ * Note: alloc_lfile() must have been called in advance. */ -static int isefsys(path, type, l, rep, lfr) -char *path; /* path to file */ -char *type; /* unknown file type */ -int l; /* link request: 0 = report - * 1 = link */ -efsys_list_t **rep; /* returned Efsysl pointer, if not - * NULL */ -struct lfile **lfr; /* allocated struct lfile pointer */ +static int isefsys(struct lsof_context *ctx, /* context */ + char *path, /* path to file */ + char *type, /* unknown file type */ + int l, /* link request: 0 = report + * 1 = link */ + efsys_list_t **rep, /* returned Efsysl pointer, if not + * NULL */ + struct lfile **lfr) /* allocated struct lfile pointer */ { efsys_list_t *ep; int ds, len; @@ -769,18 +771,18 @@ struct lfile **lfr; /* allocated struct lfile pointer */ } } if (!ds) - (void)enter_dev_ch("UNKNOWN"); + (void)enter_dev_ch(ctx, "UNKNOWN"); Lf->ntype = N_UNKN; (void)snpf(Lf->type, sizeof(Lf->type), "%s", (type ? type : "UNKN")); - (void)enter_nm(path); + (void)enter_nm(ctx, path); (void)snpf(nmabuf, sizeof(nmabuf), "(%ce %s)", ep->rdlnk ? '+' : '-', ep->path); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); if (Lf->sf) { if (lfr) *lfr = Lf; - link_lfile(); + link_lfile(ctx); } else if (lfr) *lfr = (struct lfile *)NULL; return (0); @@ -792,10 +794,9 @@ struct lfile **lfr; /* allocated struct lfile pointer */ * nm2id() - convert a name to an integer ID */ -static int nm2id(nm, id, idl) -char *nm; /* pointer to name */ -int *id; /* pointer to ID receiver */ -int *idl; /* pointer to ID length receiver */ +static int nm2id(char *nm, /* pointer to name */ + int *id, /* pointer to ID receiver */ + int *idl) /* pointer to ID length receiver */ { int tid, tidl; int invalid; @@ -822,18 +823,18 @@ int *idl; /* pointer to ID length receiver */ * open_proc_stream() -- open a /proc stream */ -FILE *open_proc_stream(p, m, buf, sz, act) -char *p; /* pointer to path to open */ -char *m; /* pointer to mode -- e.g., "r" */ -char **buf; /* pointer tp setvbuf() address - * (NULL if none) */ -size_t *sz; /* setvbuf() size (0 if none or if - * getpagesize() desired */ -int act; /* fopen() failure action: - * 0 : return (FILE *)NULL - * <>0 : fprintf() an error message - * and Error() - */ +FILE *open_proc_stream(struct lsof_context *ctx, /* context */ + char *p, /* pointer to path to open */ + char *m, /* pointer to mode -- e.g., "r" */ + char **buf, /* pointer tp setvbuf() address + * (NULL if none) */ + size_t *sz, /* setvbuf() size (0 if none or if + * getpagesize() desired */ + int act) /* fopen() failure action: + * 0 : return (FILE *)NULL + * <>0 : fprintf() an error message + * and Error() + */ { FILE *fs; /* opened stream */ static size_t psz = (size_t)0; /* page size */ @@ -846,7 +847,7 @@ int act; /* fopen() failure action: return ((FILE *)NULL); (void)fprintf(stderr, "%s: can't fopen(%s, \"%s\"): %s\n", Pn, p, m, strerror(errno)); - Error(); + Error(ctx); } /* * Return the stream if no buffer change is required. @@ -869,7 +870,7 @@ int act; /* fopen() failure action: (void)fprintf(stderr, "%s: can't allocate %d bytes for %s stream buffer\n", Pn, (int)tsz, p); - Error(); + Error(ctx); } *sz = tsz; } @@ -879,7 +880,7 @@ int act; /* fopen() failure action: if (setvbuf(fs, *buf, _IOFBF, tsz)) { (void)fprintf(stderr, "%s: setvbuf(%s)=%d failure: %s\n", Pn, p, (int)tsz, strerror(errno)); - Error(); + Error(ctx); } return (fs); } @@ -891,16 +892,16 @@ int act; /* fopen() failure action: * 1 == ID not processed */ -static int process_id(idp, idpl, cmd, uid, pid, ppid, pgid, tid, tcmd) -char *idp; /* pointer to ID's path */ -int idpl; /* pointer to ID's path length */ -char *cmd; /* pointer to ID's command */ -UID_ARG uid; /* ID's UID */ -int pid; /* ID's PID */ -int ppid; /* parent PID */ -int pgid; /* parent GID */ -int tid; /* task ID, if non-zero */ -char *tcmd; /* task command, if non-NULL) */ +static int process_id(struct lsof_context *ctx, /* context */ + char *idp, /* pointer to ID's path */ + int idpl, /* pointer to ID's path length */ + char *cmd, /* pointer to ID's command */ + UID_ARG uid, /* ID's UID */ + int pid, /* ID's PID */ + int ppid, /* parent PID */ + int pgid, /* parent GID */ + int tid, /* task ID, if non-zero */ + char *tcmd) /* task command, if non-NULL) */ { int av = 0; static char *dpath = (char *)NULL; @@ -930,8 +931,8 @@ char *tcmd; /* task command, if non-NULL) */ /* * See if process is excluded. */ - if (is_proc_excl(pid, pgid, uid, &pss, &sf, tid) || - is_cmd_excl(cmd, &pss, &sf)) { + if (is_proc_excl(ctx, pid, pgid, uid, &pss, &sf, tid) || + is_cmd_excl(ctx, cmd, &pss, &sf)) { #if defined(HASEPTOPTS) if (!FeptE) @@ -949,7 +950,7 @@ char *tcmd; /* task command, if non-NULL) */ */ Ckscko = (sf & SelProc) ? 0 : 1; } - alloc_lproc(pid, pgid, ppid, uid, cmd, (int)pss, (int)sf); + alloc_lproc(ctx, pid, pgid, ppid, uid, cmd, (int)pss, (int)sf); Plf = (struct lfile *)NULL; #if defined(HASTASKS) @@ -963,7 +964,7 @@ char *tcmd; /* task command, if non-NULL) */ "%s: PID %d, TID %d, no space for task name: ", Pn, pid, tid); safestrprt(tcmd, stderr, 1); - Error(); + Error(ctx); } } #endif /* defined(HASTASKS) */ @@ -973,8 +974,8 @@ char *tcmd; /* task command, if non-NULL) */ */ efs = 0; if (!Ckscko) { - (void)make_proc_path(idp, idpl, &path, &pathl, "cwd"); - alloc_lfile(CWD, -1); + (void)make_proc_path(ctx, idp, idpl, &path, &pathl, "cwd"); + alloc_lfile(ctx, CWD, -1); if (getlinksrc(path, pbuf, sizeof(pbuf), (char **)NULL) < 1) { if (!Fwarn) { zeromem((char *)&sb, sizeof(sb)); @@ -982,20 +983,20 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "(readlink: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); pn = 1; } else pn = 0; } else { lnk = pn = 1; - if (Efsysl && !isefsys(pbuf, "UNKNcwd", 1, NULL, &lfr)) { + if (Efsysl && !isefsys(ctx, pbuf, "UNKNcwd", 1, NULL, &lfr)) { efs = 1; pn = 0; } else { ss = SB_ALL; if (HasNFS) { - if ((sv = statsafely(path, &sb))) - sv = statEx(pbuf, &sb, &ss); + if ((sv = statsafely(ctx, path, &sb))) + sv = statEx(ctx, pbuf, &sb, &ss); } else sv = stat(path, &sb); if (sv) { @@ -1004,16 +1005,16 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "(stat: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } } } } if (pn) { - (void)process_proc_node(lnk ? pbuf : path, path, &sb, ss, + (void)process_proc_node(ctx, lnk ? pbuf : path, path, &sb, ss, (struct stat *)NULL, 0); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } /* @@ -1021,27 +1022,27 @@ char *tcmd; /* task command, if non-NULL) */ */ lnk = ss = 0; if (!Ckscko) { - (void)make_proc_path(idp, idpl, &path, &pathl, "root"); - alloc_lfile(RTD, -1); + (void)make_proc_path(ctx, idp, idpl, &path, &pathl, "root"); + alloc_lfile(ctx, RTD, -1); if (getlinksrc(path, pbuf, sizeof(pbuf), (char **)NULL) < 1) { if (!Fwarn) { zeromem((char *)&sb, sizeof(sb)); (void)snpf(nmabuf, sizeof(nmabuf), "(readlink: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); pn = 1; } else pn = 0; } else { lnk = pn = 1; - if (Efsysl && !isefsys(pbuf, "UNKNrtd", 1, NULL, NULL)) + if (Efsysl && !isefsys(ctx, pbuf, "UNKNrtd", 1, NULL, NULL)) pn = 0; else { ss = SB_ALL; if (HasNFS) { - if ((sv = statsafely(path, &sb))) - sv = statEx(pbuf, &sb, &ss); + if ((sv = statsafely(ctx, path, &sb))) + sv = statEx(ctx, pbuf, &sb, &ss); } else sv = stat(path, &sb); if (sv) { @@ -1050,16 +1051,16 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "(stat: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } } } } if (pn) { - (void)process_proc_node(lnk ? pbuf : path, path, &sb, ss, + (void)process_proc_node(ctx, lnk ? pbuf : path, path, &sb, ss, (struct stat *)NULL, 0); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } /* @@ -1067,8 +1068,8 @@ char *tcmd; /* task command, if non-NULL) */ */ lnk = ss = txts = 0; if (!Ckscko) { - (void)make_proc_path(idp, idpl, &path, &pathl, "exe"); - alloc_lfile("txt", -1); + (void)make_proc_path(ctx, idp, idpl, &path, &pathl, "exe"); + alloc_lfile(ctx, "txt", -1); if (getlinksrc(path, pbuf, sizeof(pbuf), (char **)NULL) < 1) { zeromem((void *)&sb, sizeof(sb)); if (!Fwarn) { @@ -1076,20 +1077,20 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "(readlink: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } pn = 1; } else pn = 0; } else { lnk = pn = 1; - if (Efsysl && !isefsys(pbuf, "UNKNtxt", 1, NULL, NULL)) + if (Efsysl && !isefsys(ctx, pbuf, "UNKNtxt", 1, NULL, NULL)) pn = 0; else { ss = SB_ALL; if (HasNFS) { - if ((sv = statsafely(path, &sb))) { - sv = statEx(pbuf, &sb, &ss); + if ((sv = statsafely(ctx, path, &sb))) { + sv = statEx(ctx, pbuf, &sb, &ss); if (!sv && (ss & SB_DEV) && (ss & SB_INO)) txts = 1; } @@ -1101,25 +1102,25 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "(stat: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } } else txts = 1; } } if (pn) { - (void)process_proc_node(lnk ? pbuf : path, path, &sb, ss, + (void)process_proc_node(ctx, lnk ? pbuf : path, path, &sb, ss, (struct stat *)NULL, 0); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } /* * Process the ID's memory map info. */ if (!Ckscko) { - (void)make_proc_path(idp, idpl, &path, &pathl, "maps"); - (void)process_proc_map(path, txts ? &sb : (struct stat *)NULL, + (void)make_proc_path(ctx, idp, idpl, &path, &pathl, "maps"); + (void)process_proc_map(ctx, path, txts ? &sb : (struct stat *)NULL, txts ? ss : 0); } @@ -1141,7 +1142,7 @@ char *tcmd; /* task command, if non-NULL) */ if (!(Lp->cntx = strdup(nmabuf))) { (void)fprintf(stderr, "%s: no context error space: PID %ld", Pn, (long)Lp->pid); - Error(); + Error(ctx); } } } else if (CntxArg) { @@ -1164,11 +1165,11 @@ char *tcmd; /* task command, if non-NULL) */ /* * Process the ID's file descriptor directory. */ - if ((i = make_proc_path(idp, idpl, &dpath, &dpathl, "fd/")) < 3) + if ((i = make_proc_path(ctx, idp, idpl, &dpath, &dpathl, "fd/")) < 3) return (0); dpath[i - 1] = '\0'; if ((OffType == OFFSET_FDINFO) && - ((j = make_proc_path(idp, idpl, &ipath, &ipathl, "fdinfo/")) >= 7)) + ((j = make_proc_path(ctx, idp, idpl, &ipath, &ipathl, "fdinfo/")) >= 7)) oty = 1; else oty = 0; @@ -1176,10 +1177,10 @@ char *tcmd; /* task command, if non-NULL) */ if (!Fwarn) { (void)snpf(nmabuf, sizeof(nmabuf), "%s (opendir: %s)", dpath, strerror(errno)); - alloc_lfile("NOFD", -1); + alloc_lfile(ctx, "NOFD", -1); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); - link_lfile(); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); + link_lfile(ctx); } return (0); } @@ -1187,8 +1188,8 @@ char *tcmd; /* task command, if non-NULL) */ while ((fp = readdir(fdp))) { if (nm2id(fp->d_name, &fd, &n)) continue; - (void)make_proc_path(dpath, i, &path, &pathl, fp->d_name); - (void)alloc_lfile((char *)NULL, fd); + (void)make_proc_path(ctx, dpath, i, &path, &pathl, fp->d_name); + (void)alloc_lfile(ctx, (char *)NULL, fd); if (getlinksrc(path, pbuf, sizeof(pbuf), &rest) < 1) { zeromem((char *)&sb, sizeof(sb)); lnk = ss = 0; @@ -1197,26 +1198,26 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "(readlink: %s)", strerror(errno)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); pn = 1; } else pn = 0; } else { lnk = 1; - if (Efsysl && !isefsys(pbuf, "UNKNfd", 1, NULL, &lfr)) { + if (Efsysl && !isefsys(ctx, pbuf, "UNKNfd", 1, NULL, &lfr)) { efs = 1; pn = 0; } else { if (HasNFS) { - if (lstatsafely(path, &lsb)) { - (void)statEx(pbuf, &lsb, &ls); + if (lstatsafely(ctx, path, &lsb)) { + (void)statEx(ctx, pbuf, &lsb, &ls); enls = errno; } else { enls = 0; ls = SB_ALL; } - if (statsafely(path, &sb)) { - (void)statEx(pbuf, &sb, &ss); + if (statsafely(ctx, path, &sb)) { + (void)statEx(ctx, pbuf, &sb, &ss); enss = errno; } else { enss = 0; @@ -1232,13 +1233,13 @@ char *tcmd; /* task command, if non-NULL) */ (void)snpf(nmabuf, sizeof(nmabuf), "lstat: %s)", strerror(enls)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } if (!ss && !Fwarn) { (void)snpf(nmabuf, sizeof(nmabuf), "(stat: %s)", strerror(enss)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } if (Ckscko) { if ((ss & SB_MODE) && ((sb.st_mode & S_IFMT) == S_IFSOCK)) { @@ -1257,7 +1258,8 @@ char *tcmd; /* task command, if non-NULL) */ if (oty) { int fdinfo_mask = FDINFO_BASE; - (void)make_proc_path(ipath, j, &pathi, &pathil, fp->d_name); + (void)make_proc_path(ctx, ipath, j, &pathi, &pathil, + fp->d_name); if (rest && rest[0] == '[' && rest[1] == 'e' && rest[2] == 'v' && rest[3] == 'e' && rest[4] == 'n' && @@ -1277,7 +1279,8 @@ char *tcmd; /* task command, if non-NULL) */ if (rest && rest[0] == '[' && rest[1] == 'p') fdinfo_mask |= FDINFO_PID; - if ((av = get_fdinfo(pathi, fdinfo_mask, &fi)) & FDINFO_POS) { + if ((av = get_fdinfo(ctx, pathi, fdinfo_mask, &fi)) & + FDINFO_POS) { if (efs) { lfr->off = (SZOFFTYPE)fi.pos; lfr->off_def = 1; @@ -1301,7 +1304,8 @@ char *tcmd; /* task command, if non-NULL) */ #endif /* !defined(HASNOFSFLAGS) */ } if (pn) { - process_proc_node(lnk ? pbuf : path, path, &sb, ss, &lsb, ls); + process_proc_node(ctx, lnk ? pbuf : path, path, &sb, ss, &lsb, + ls); if (Lf->ntype == N_ANON_INODE) { if (rest && *rest) { #if defined(HASEPTOPTS) @@ -1321,11 +1325,11 @@ char *tcmd; /* task command, if non-NULL) */ fi.tfds, fi.tfd_count); } - enter_nm(rest); + enter_nm(ctx, rest); } #if defined(HASEPTOPTS) if (FeptE && fi.eventfd_id != -1) { - enter_evtfdinfo(fi.eventfd_id); + enter_evtfdinfo(ctx, fi.eventfd_id); Lf->eventfd_id = fi.eventfd_id; Lf->sf |= SELEVTFDINFO; } @@ -1334,14 +1338,14 @@ char *tcmd; /* task command, if non-NULL) */ #if defined(HASEPTOPTS) && defined(HASPTYEPT) else if (FeptE && Lf->rdev_def && is_pty_ptmx(Lf->rdev) && (av & FDINFO_TTY_INDEX)) { - enter_ptmxi(fi.tty_index); + enter_ptmxi(ctx, fi.tty_index); Lf->tty_index = fi.tty_index; Lf->sf |= SELPTYINFO; } #endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } } @@ -1351,8 +1355,7 @@ char *tcmd; /* task command, if non-NULL) */ /* compare mount namespace of this lsof process and the target process */ -static int compare_mntns(pid) -int pid; /* pid of the target process */ +static int compare_mntns(int pid) /* pid of the target process */ { char nspath[NS_PATH_LENGTH]; struct stat sb_self, sb_target; @@ -1379,7 +1382,8 @@ int pid; /* pid of the target process */ */ static void -process_proc_map(char *p, /* path to process maps file */ +process_proc_map(struct lsof_context *ctx, /* context */ + char *p, /* path to process maps file */ struct stat *s, /* executing text file state buffer */ int ss) /* *s status -- i.e., SB_* values */ { @@ -1407,7 +1411,7 @@ process_proc_map(char *p, /* path to process maps file */ * Open the /proc//maps file, assign a page size buffer to its stream, * and read it/ */ - if (!(ms = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(ms = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; /* target process in a different mount namespace from lsof process. */ @@ -1415,7 +1419,7 @@ process_proc_map(char *p, /* path to process maps file */ diff_mntns = 1; while (fgets(buf, sizeof(buf), ms)) { - if (get_fields(buf, ":", &fp, &eb, 1) < 7) + if (get_fields(ctx, buf, ":", &fp, &eb, 1) < 7) continue; /* not enough fields */ if (!fp[6] || !*fp[6]) continue; /* no path name */ @@ -1483,7 +1487,7 @@ process_proc_map(char *p, /* path to process maps file */ stderr, "%s: can't allocate %d bytes for saved maps, PID %d\n", Pn, (int)len, Lp->pid); - Error(); + Error(ctx); } } sm[ns].dev = dev; @@ -1493,8 +1497,8 @@ process_proc_map(char *p, /* path to process maps file */ * for it. Skip the stat(2) operation if this is on an exempt file * system. */ - alloc_lfile("mem", -1); - if (Efsysl && !isefsys(fp[6], (char *)NULL, 0, &rep, NULL)) + alloc_lfile(ctx, "mem", -1); + if (Efsysl && !isefsys(ctx, fp[6], (char *)NULL, 0, &rep, NULL)) efs = sv = 1; else efs = 0; @@ -1524,7 +1528,7 @@ process_proc_map(char *p, /* path to process maps file */ if (!efs) { if (HasNFS) - sv = statsafely(path, &sb); + sv = statsafely(ctx, path, &sb); else sv = stat(path, &sb); } @@ -1532,7 +1536,7 @@ process_proc_map(char *p, /* path to process maps file */ stat_directly: if (!efs) { if (HasNFS) - sv = statsafely(fp[6], &sb); + sv = statsafely(ctx, fp[6], &sb); else sv = stat(fp[6], &sb); } @@ -1553,11 +1557,11 @@ process_proc_map(char *p, /* path to process maps file */ sb.st_mode = S_IFREG; mss = SB_DEV | SB_INO | SB_MODE; if (ds) - alloc_lfile("DEL", -1); + alloc_lfile(ctx, "DEL", -1); else if (!efs && !Fwarn) { (void)snpf(nmabuf, sizeof(nmabuf), "(stat: %s)", strerror(en)); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } } else if (diff_mntns) { mss = SB_ALL; @@ -1574,7 +1578,7 @@ process_proc_map(char *p, /* path to process maps file */ * information. */ if (ds) - alloc_lfile("DEL", -1); + alloc_lfile(ctx, "DEL", -1); else if (!Fwarn) { char *sep; @@ -1583,7 +1587,7 @@ process_proc_map(char *p, /* path to process maps file */ GET_MAJ_DEV(sb.st_dev), GET_MIN_DEV(sb.st_dev), ((INODETYPE)sb.st_ino == inode) ? ")" : ","); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); sep = ""; } else sep = "(path "; @@ -1593,7 +1597,7 @@ process_proc_map(char *p, /* path to process maps file */ (void)snpf(nmabuf, sizeof(nmabuf), fmtbuf, sep, (INODETYPE)sb.st_ino); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } } zeromem((char *)&sb, sizeof(sb)); @@ -1607,7 +1611,8 @@ process_proc_map(char *p, /* path to process maps file */ * Record the file's information. */ if (!efs) - process_proc_node(fp[6], fp[6], &sb, mss, (struct stat *)NULL, 0); + process_proc_node(ctx, fp[6], fp[6], &sb, mss, (struct stat *)NULL, + 0); else { /* @@ -1618,16 +1623,16 @@ process_proc_map(char *p, /* path to process maps file */ Lf->dev = sb.st_dev; Lf->inode = (ino_t)sb.st_ino; Lf->dev_def = Lf->inp_ty = 1; - (void)enter_nm(fp[6]); + (void)enter_nm(ctx, fp[6]); (void)snpf(Lf->type, sizeof(Lf->type), "%s", (ds ? "UNKNdel" : "UNKNmem")); (void)snpf(nmabuf, sizeof(nmabuf), "(%ce %s)", rep->rdlnk ? '+' : '-', rep->path); nmabuf[sizeof(nmabuf) - 1] = '\0'; - (void)add_nma(nmabuf, strlen(nmabuf)); + (void)add_nma(ctx, nmabuf, strlen(nmabuf)); } if (Lf->sf) - link_lfile(); + link_lfile(ctx); } (void)fclose(ms); } @@ -1640,12 +1645,13 @@ process_proc_map(char *p, /* path to process maps file */ * 1 == ID is a zombie * 2 == ID is a thread */ -static int read_id_stat(char *p, /* path to status file */ - int id, /* ID: PID or LWP */ - char **cmd, /* malloc'd command name */ - int *ppid, /* returned parent PID for PID type */ - int *pgid) /* returned process group ID for PID - * type */ +static int read_id_stat(struct lsof_context *ctx, /* context */ + char *p, /* path to status file */ + int id, /* ID: PID or LWP */ + char **cmd, /* malloc'd command name */ + int *ppid, /* returned parent PID for PID type */ + int *pgid) /* returned process group ID for PID + * type */ { char buf[MAXPATHLEN], *cp, *cp1, **fp; int ch, cx, es, pc; @@ -1658,7 +1664,7 @@ static int read_id_stat(char *p, /* path to status file */ * Open the stat file path, assign a page size buffer to its stream, * and read the file's first line. */ - if (!(fs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(fs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return (-1); if (!(cp = fgets(buf, sizeof(buf), fs))) { @@ -1726,7 +1732,7 @@ static int read_id_stat(char *p, /* path to status file */ break; } if ((cx + 2) > cbfa) - cbfa = alloc_cbf((cx + 2), &cbf, cbfa); + cbfa = alloc_cbf(ctx, (cx + 2), &cbf, cbfa); cbf[cx] = ch; cx++; cbf[cx] = '\0'; @@ -1745,7 +1751,7 @@ static int read_id_stat(char *p, /* path to status file */ (void)fclose(fs); if (!cp || !*cp) return (-1); - if (get_fields(cp, (char *)NULL, &fp, (int *)NULL, 0) < 3) + if (get_fields(ctx, cp, (char *)NULL, &fp, (int *)NULL, 0) < 3) return (-1); /* * Convert and return parent process (fourth field) and process group (fifth @@ -1782,10 +1788,11 @@ static int read_id_stat(char *p, /* path to status file */ * This function should be used only when links have been successfully * resolved in the /proc path by getlinksrc(). */ -static int statEx(char *p, /* file path */ - struct stat *s, /* stat() result -- NULL if none - * wanted */ - int *ss) /* stat() status -- SB_* values */ +static int statEx(struct lsof_context *ctx, /* context */ + char *p, /* file path */ + struct stat *s, /* stat() result -- NULL if none + * wanted */ + int *ss) /* stat() status -- SB_* values */ { static size_t ca = 0; static char *cb = NULL; @@ -1806,7 +1813,7 @@ static int statEx(char *p, /* file path */ if (!cb) { (void)fprintf(stderr, "%s: PID %ld: no statEx path space: %s\n", Pn, (long)Lp->pid, p); - Error(); + Error(ctx); } ca = sz + 1; } @@ -1818,7 +1825,7 @@ static int statEx(char *p, /* file path */ */ for (cp = strrchr(cb, '/'); cp && (cp != cb);) { *cp = '\0'; - if (!statsafely(cb, &sb)) { + if (!statsafely(ctx, cb, &sb)) { st = 1; break; } diff --git a/lib/dialects/linux/dproto.h b/lib/dialects/linux/dproto.h index f35e4350..defa7b81 100644 --- a/lib/dialects/linux/dproto.h +++ b/lib/dialects/linux/dproto.h @@ -35,20 +35,35 @@ */ #if defined(HASSELINUX) -_PROTOTYPE(extern int enter_cntx_arg, (char *cnxt)); +extern int enter_cntx_arg(struct lsof_context *ctx, char *cnxt); #endif /* defined(HASSELINUX) */ -_PROTOTYPE(extern int get_fields, - (char *ln, char *sep, char ***fr, int *eb, int en)); -_PROTOTYPE(extern void get_locks, (char *p)); -_PROTOTYPE(extern int is_file_named, - (int ty, char *p, struct mounts *mp, int cd)); -_PROTOTYPE(extern int make_proc_path, - (char *pp, int lp, char **np, int *npl, char *sf)); -_PROTOTYPE(extern FILE *open_proc_stream, - (char *p, char *mode, char **buf, size_t *sz, int act)); -_PROTOTYPE(extern void process_proc_node, (char *p, char *pbr, struct stat *s, - int ss, struct stat *l, int ls)); -_PROTOTYPE(extern void process_proc_sock, (char *p, char *pbr, struct stat *s, - int ss, struct stat *l, int ls)); -_PROTOTYPE(extern void set_net_paths, (char *p, int pl)); +extern int get_fields(struct lsof_context *ctx, char *ln, char *sep, char ***fr, + int *eb, int en); +extern void get_locks(struct lsof_context *ctx, char *p); +extern void clean_locks(struct lsof_context *ctx); +extern void clean_ax25(struct lsof_context *ctx); +extern void clean_icmp(struct lsof_context *ctx); +extern void clean_ipx(struct lsof_context *ctx); +extern void clean_netlink(struct lsof_context *ctx); +extern void clean_pack(struct lsof_context *ctx); +extern void clean_raw(struct lsof_context *ctx); +extern void clean_sctp(struct lsof_context *ctx); +extern void clean_unix(struct lsof_context *ctx); +extern void clean_tcpudp(struct lsof_context *ctx, int free_array); +#if defined(HASIPv6) +extern void clean_raw6(struct lsof_context *ctx); +extern void clean_tcpudp6(struct lsof_context *ctx, int free_array); +#endif +extern int is_file_named(struct lsof_context *ctx, int ty, char *p, + struct mounts *mp, int cd); +extern int make_proc_path(struct lsof_context *ctx, char *pp, int lp, char **np, + int *npl, char *sf); +extern FILE *open_proc_stream(struct lsof_context *ctx, char *p, char *mode, + char **buf, size_t *sz, int act); +extern void process_proc_node(struct lsof_context *ctx, char *p, char *pbr, + struct stat *s, int ss, struct stat *l, int ls); +extern void process_proc_sock(struct lsof_context *ctx, char *p, char *pbr, + struct stat *s, int ss, struct stat *l, int ls); +extern void set_net_paths(struct lsof_context *ctx, char *p, int pl); +extern void refresh_socket_info(struct lsof_context *ctx); \ No newline at end of file diff --git a/lib/dialects/linux/dsock.c b/lib/dialects/linux/dsock.c index 1d7efa1a..c5c84c52 100644 --- a/lib/dialects/linux/dsock.c +++ b/lib/dialects/linux/dsock.c @@ -319,91 +319,95 @@ static uxsin_t **Uxsin = (uxsin_t **)NULL; * Local function prototypes */ -_PROTOTYPE(static struct ax25sin *check_ax25, (INODETYPE i)); +static struct ax25sin *check_ax25(struct lsof_context *ctx, INODETYPE i); #if defined(HASEPTOPTS) && defined(HASUXSOCKEPT) -_PROTOTYPE(static void enter_uxsinfo, (uxsin_t * up)); -_PROTOTYPE(static void fill_uxicino, (INODETYPE si, INODETYPE sc)); -_PROTOTYPE(static void fill_uxpino, (INODETYPE si, INODETYPE pi)); -_PROTOTYPE(static int get_diagmsg, (int sockfd)); -_PROTOTYPE(static void get_uxpeeri, (void)); -_PROTOTYPE(static void parse_diag, (struct unix_diag_msg * dm, int len)); -_PROTOTYPE(static void prt_uxs, (uxsin_t * p, int mk)); +static void enter_uxsinfo(struct lsof_context *ctx, uxsin_t *up); +static void fill_uxicino(struct lsof_context *ctx, INODETYPE si, INODETYPE sc); +static void fill_uxpino(struct lsof_context *ctx, INODETYPE si, INODETYPE pi); +static int get_diagmsg(int sockfd); +static void get_uxpeeri(struct lsof_context *ctx); +static void parse_diag(struct lsof_context *ctx, struct unix_diag_msg *dm, + int len); +static void prt_uxs(struct lsof_context *ctx, uxsin_t *p, int mk); #endif /* defined(HASEPTOPTS) && defined(HASUXSOCKEPT) */ #if defined(HASEPTOPTS) -_PROTOTYPE(static void enter_netsinfo, (struct tcp_udp * tp)); -_PROTOTYPE(static void get_netpeeri, (void)); +static void enter_netsinfo(struct lsof_context *ctx, struct tcp_udp *tp); +static void get_netpeeri(struct lsof_context *ctx); #endif /* defined(HASEPTOPTS) */ #if defined(HASIPv6) # if defined(HASEPTOPTS) -_PROTOTYPE(static void enter_nets6info, (struct tcp_udp6 * tp)); -_PROTOTYPE(static void get_net6peeri, (void)); +static void enter_nets6info(struct lsof_context *ctx, struct tcp_udp6 *tp); +static void get_net6peeri(struct lsof_context *ctx); # endif /* defined(HASEPTOPTS) */ #endif /* defined(HASIPv6) */ -_PROTOTYPE(static struct icmpin *check_icmp, (INODETYPE i)); -_PROTOTYPE(static struct ipxsin *check_ipx, (INODETYPE i)); -_PROTOTYPE(static struct nlksin *check_netlink, (INODETYPE i)); -_PROTOTYPE(static struct packin *check_pack, (INODETYPE i)); -_PROTOTYPE(static struct rawsin *check_raw, (INODETYPE i)); -_PROTOTYPE(static struct sctpsin *check_sctp, (INODETYPE i)); -_PROTOTYPE(static struct tcp_udp *check_tcpudp, (INODETYPE i, char **p)); -_PROTOTYPE(static uxsin_t *check_unix, (INODETYPE i)); -_PROTOTYPE(static void get_ax25, (char *p)); -_PROTOTYPE(static void get_icmp, (char *p)); -_PROTOTYPE(static void get_ipx, (char *p)); -_PROTOTYPE(static void get_netlink, (char *p)); -_PROTOTYPE(static void get_pack, (char *p)); -_PROTOTYPE(static void get_raw, (char *p)); -_PROTOTYPE(static void get_sctp, (void)); -_PROTOTYPE(static char *get_sctpaddrs, (char **fp, int i, int nf, int *x)); -_PROTOTYPE(static void get_tcpudp, (char *p, int pr, int clr)); -_PROTOTYPE(static void get_unix, (char *p)); -_PROTOTYPE(static int isainb, (char *a, char *b)); -_PROTOTYPE(static void print_ax25info, (struct ax25sin * ap)); -_PROTOTYPE(static void print_ipxinfo, (struct ipxsin * ip)); -_PROTOTYPE(static char *socket_type_to_str, (uint32_t ty, int *rf)); -_PROTOTYPE(static char *netlink_proto_to_str, (unsigned int pr)); +static struct icmpin *check_icmp(struct lsof_context *ctx, INODETYPE i); +static struct ipxsin *check_ipx(struct lsof_context *ctx, INODETYPE i); +static struct nlksin *check_netlink(struct lsof_context *ctx, INODETYPE i); +static struct packin *check_pack(struct lsof_context *ctx, INODETYPE i); +static struct rawsin *check_raw(struct lsof_context *ctx, INODETYPE i); +static struct sctpsin *check_sctp(struct lsof_context *ctx, INODETYPE i); +static struct tcp_udp *check_tcpudp(struct lsof_context *ctx, INODETYPE i, + char **p); +static uxsin_t *check_unix(struct lsof_context *ctx, INODETYPE i); +static void get_ax25(struct lsof_context *ctx, char *p); +static void get_icmp(struct lsof_context *ctx, char *p); +static void get_ipx(struct lsof_context *ctx, char *p); +static void get_netlink(struct lsof_context *ctx, char *p); +static void get_pack(struct lsof_context *ctx, char *p); +static void get_raw(struct lsof_context *ctx, char *p); +static void get_sctp(struct lsof_context *ctx); +static char *get_sctpaddrs(char **fp, int i, int nf, int *x); +static void get_tcpudp(struct lsof_context *ctx, char *p, int pr, int clr); +static void get_unix(struct lsof_context *ctx, char *p); +static int isainb(char *a, char *b); +static void print_ax25info(struct lsof_context *ctx, struct ax25sin *ap); +static void print_ipxinfo(struct lsof_context *ctx, struct ipxsin *ip); +static char *socket_type_to_str(uint32_t ty, int *rf); +static char *netlink_proto_to_str(unsigned int pr); #if defined(HASSOSTATE) -_PROTOTYPE(static char *socket_state_to_str, (unsigned int ss)); +static char *socket_state_to_str(unsigned int ss); #endif /* defined(HASSOSTATE) */ -_PROTOTYPE(static char *ethernet_proto_to_str, (unsigned int pr)); +static char *ethernet_proto_to_str(unsigned int pr); #if defined(HASIPv6) -_PROTOTYPE(static struct rawsin *check_raw6, (INODETYPE i)); -_PROTOTYPE(static struct tcp_udp6 *check_tcpudp6, (INODETYPE i, char **p)); -_PROTOTYPE(static void get_raw6, (char *p)); -_PROTOTYPE(static void get_tcpudp6, (char *p, int pr, int clr)); -_PROTOTYPE(static int hex_ipv6_to_in6, (char *as, struct in6_addr *ad)); +static struct rawsin *check_raw6(struct lsof_context *ctx, INODETYPE i); +static struct tcp_udp6 *check_tcpudp6(struct lsof_context *ctx, INODETYPE i, + char **p); +static void get_raw6(struct lsof_context *ctx, char *p); +static void get_tcpudp6(struct lsof_context *ctx, char *p, int pr, int clr); +static int hex_ipv6_to_in6(char *as, struct in6_addr *ad); #endif /* defined(HASIPv6) */ /* * build_IPstates() -- build the TCP and UDP state tables */ -void build_IPstates() { +void build_IPstates(struct lsof_context *ctx) { if (!TcpSt) { - (void)enter_IPstate("TCP", "ESTABLISHED", TCP_ESTABLISHED); - (void)enter_IPstate("TCP", "SYN_SENT", TCP_SYN_SENT); - (void)enter_IPstate("TCP", "SYN_RECV", TCP_SYN_RECV); - (void)enter_IPstate("TCP", "FIN_WAIT1", TCP_FIN_WAIT1); - (void)enter_IPstate("TCP", "FIN_WAIT2", TCP_FIN_WAIT2); - (void)enter_IPstate("TCP", "TIME_WAIT", TCP_TIME_WAIT); - (void)enter_IPstate("TCP", "CLOSE", TCP_CLOSE); - (void)enter_IPstate("TCP", "CLOSE_WAIT", TCP_CLOSE_WAIT); - (void)enter_IPstate("TCP", "LAST_ACK", TCP_LAST_ACK); - (void)enter_IPstate("TCP", "LISTEN", TCP_LISTEN); - (void)enter_IPstate("TCP", "CLOSING", TCP_CLOSING); - (void)enter_IPstate("TCP", "CLOSED", 0); - (void)enter_IPstate("TCP", (char *)NULL, 0); + (void)enter_IPstate(ctx, "TCP", "ESTABLISHED", TCP_ESTABLISHED); + (void)enter_IPstate(ctx, "TCP", "SYN_SENT", TCP_SYN_SENT); + (void)enter_IPstate(ctx, "TCP", "SYN_RECV", TCP_SYN_RECV); + (void)enter_IPstate(ctx, "TCP", "FIN_WAIT1", TCP_FIN_WAIT1); + (void)enter_IPstate(ctx, "TCP", "FIN_WAIT2", TCP_FIN_WAIT2); + (void)enter_IPstate(ctx, "TCP", "TIME_WAIT", TCP_TIME_WAIT); + (void)enter_IPstate(ctx, "TCP", "CLOSE", TCP_CLOSE); + (void)enter_IPstate(ctx, "TCP", "CLOSE_WAIT", TCP_CLOSE_WAIT); + (void)enter_IPstate(ctx, "TCP", "LAST_ACK", TCP_LAST_ACK); + (void)enter_IPstate(ctx, "TCP", "LISTEN", TCP_LISTEN); + (void)enter_IPstate(ctx, "TCP", "CLOSING", TCP_CLOSING); + (void)enter_IPstate(ctx, "TCP", "CLOSED", 0); + (void)enter_IPstate(ctx, "TCP", (char *)NULL, 0); } } /* * check_ax25() - check for AX25 socket file */ -static struct ax25sin *check_ax25(INODETYPE i) /* socket file's inode number */ +static struct ax25sin *check_ax25(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(AX25sin, INOHASH, struct ax25sin, inode, i); } @@ -411,7 +415,8 @@ static struct ax25sin *check_ax25(INODETYPE i) /* socket file's inode number */ /* * check_icmp() - check for ICMP socket */ -static struct icmpin *check_icmp(INODETYPE i) /* socket file's inode number */ +static struct icmpin *check_icmp(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(Icmpin, INOHASH, struct icmpin, inode, i); } @@ -419,7 +424,8 @@ static struct icmpin *check_icmp(INODETYPE i) /* socket file's inode number */ /* * check_ipx() - check for IPX socket file */ -static struct ipxsin *check_ipx(INODETYPE i) /* socket file's inode number */ +static struct ipxsin *check_ipx(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(Ipxsin, INOHASH, struct ipxsin, inode, i); } @@ -428,7 +434,8 @@ static struct ipxsin *check_ipx(INODETYPE i) /* socket file's inode number */ * check_netlink() - check for Netlink socket file */ static struct nlksin * -check_netlink(INODETYPE i) /* socket file's inode number */ +check_netlink(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(Nlksin, INOHASH, struct nlksin, inode, i); } @@ -436,7 +443,8 @@ check_netlink(INODETYPE i) /* socket file's inode number */ /* * check_pack() - check for packet file */ -static struct packin *check_pack(INODETYPE i) /* packet file's inode number */ +static struct packin *check_pack(struct lsof_context *ctx, + INODETYPE i) /* packet file's inode number */ { return HASH_FIND_ELEMENT(Packin, INOHASH, struct packin, inode, i); } @@ -445,7 +453,8 @@ static struct packin *check_pack(INODETYPE i) /* packet file's inode number */ * check_raw() - check for raw socket file */ -static struct rawsin *check_raw(INODETYPE i) /* socket file's inode number */ +static struct rawsin *check_raw(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(Rawsin, INOHASH, struct rawsin, inode, i); } @@ -453,7 +462,8 @@ static struct rawsin *check_raw(INODETYPE i) /* socket file's inode number */ /* * check_sctp() - check for SCTP socket file */ -static struct sctpsin *check_sctp(INODETYPE i) /* socket file's inode number */ +static struct sctpsin *check_sctp(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(SCTPsin, INOHASH, struct sctpsin, inode, i); } @@ -462,7 +472,8 @@ static struct sctpsin *check_sctp(INODETYPE i) /* socket file's inode number */ * check_tcpudp() - check for IPv4 TCP or UDP socket file */ static struct tcp_udp * -check_tcpudp(INODETYPE i, /* socket file's inode number */ +check_tcpudp(struct lsof_context *ctx, + INODETYPE i, /* socket file's inode number */ char **p) /* protocol return */ { struct tcp_udp *tp; @@ -489,7 +500,8 @@ check_tcpudp(INODETYPE i, /* socket file's inode number */ /* * check_inet() - check for locally used INET domain socket */ -static struct tcp_udp *check_inet(INODETYPE i) /* socket file's inode number */ +static struct tcp_udp *check_inet(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(TcpUdp, TCPUDPHASH, struct tcp_udp, inode, i); } @@ -497,7 +509,7 @@ static struct tcp_udp *check_inet(INODETYPE i) /* socket file's inode number */ /* * clear_netsinfo -- clear allocated INET socket info */ -void clear_netsinfo() { +void clear_netsinfo(struct lsof_context *ctx) { int h; /* hash index */ struct tcp_udp *ti, *tp; /* temporary pointers */ @@ -535,7 +547,8 @@ void clear_netsinfo() { /* * check_raw6() - check for raw IPv6 socket file */ -static struct rawsin *check_raw6(INODETYPE i) /* socket file's inode number */ +static struct rawsin *check_raw6(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(Rawsin6, INOHASH, struct rawsin, inode, i); } @@ -544,7 +557,8 @@ static struct rawsin *check_raw6(INODETYPE i) /* socket file's inode number */ * check_tcpudp6() - check for IPv6 TCP or UDP socket file */ static struct tcp_udp6 * -check_tcpudp6(INODETYPE i, /* socket file's inode number */ +check_tcpudp6(struct lsof_context *ctx, + INODETYPE i, /* socket file's inode number */ char **p) /* protocol return */ { struct tcp_udp6 *tp6; @@ -572,7 +586,8 @@ check_tcpudp6(INODETYPE i, /* socket file's inode number */ * check_inet6() - check for locally used INET6 domain socket */ static struct tcp_udp6 * -check_inet6(INODETYPE i) /* socket file's inode number */ +check_inet6(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(TcpUdp6, TCPUDP6HASH, struct tcp_udp6, inode, i); } @@ -580,7 +595,7 @@ check_inet6(INODETYPE i) /* socket file's inode number */ /* * clear_nets6info -- clear allocated INET6 socket info */ -void clear_nets6info() { +void clear_nets6info(struct lsof_context *ctx) { int h; /* hash index */ struct tcp_udp6 *ti, *tp; /* temporary pointers */ @@ -619,7 +634,8 @@ void clear_nets6info() { /* * check_unix() - check for UNIX domain socket */ -static uxsin_t *check_unix(INODETYPE i) /* socket file's inode number */ +static uxsin_t *check_unix(struct lsof_context *ctx, + INODETYPE i) /* socket file's inode number */ { return HASH_FIND_ELEMENT(Uxsin, INOHASH, uxsin_t, inode, i); } @@ -627,7 +643,7 @@ static uxsin_t *check_unix(INODETYPE i) /* socket file's inode number */ /* * clear_uxsinfo -- clear allocated UNIX socket info */ -void clear_uxsinfo() { +void clear_uxsinfo(struct lsof_context *ctx) { int h; /* hash index */ uxsin_t *ui, *up; /* remporary pointers */ @@ -664,7 +680,8 @@ void clear_uxsinfo() { /* * get_ax25() - get /proc/net/ax25 info */ -static void get_ax25(char *p) /* /proc/net/ax25 path */ +static void get_ax25(struct lsof_context *ctx, + char *p) /* /proc/net/ax25 path */ { struct ax25sin *ap, *np; FILE *as; @@ -699,17 +716,17 @@ static void get_ax25(char *p) /* /proc/net/ax25 path */ (void)fprintf(stderr, "%s: can't allocate %d AX25 hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct ax25sin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/ax25 file, assign a page size buffer to the stream, * and read it. Store AX25 socket info in the AX25sin[] hash buckets. */ - if (!(as = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(as = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, as)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 24) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 24) continue; /* * /proc/net/ax25 has no title line, a very poor deficiency in its @@ -765,7 +782,7 @@ static void get_ax25(char *p) /* /proc/net/ax25 path */ stderr, "%s: can't allocate %d destination AX25 addr bytes: %s\n", Pn, (int)(len + 1), fp[3]); - Error(); + Error(ctx); } (void)snpf(da, len + 1, "%s", fp[3]); } else @@ -781,7 +798,7 @@ static void get_ax25(char *p) /* /proc/net/ax25 path */ stderr, "%s: can't allocate %d source AX25 address bytes: %s\n", Pn, (int)(len + 1), fp[2]); - Error(); + Error(ctx); } (void)snpf(sa, len + 1, "%s", fp[2]); } else @@ -797,7 +814,7 @@ static void get_ax25(char *p) /* /proc/net/ax25 path */ stderr, "%s: can't allocate %d destination AX25 dev bytes: %s\n", Pn, (int)(len + 1), fp[1]); - Error(); + Error(ctx); } (void)snpf(dev_ch, len + 1, "%s", fp[1]); } else @@ -810,7 +827,7 @@ static void get_ax25(char *p) /* /proc/net/ax25 path */ (void)fprintf(stderr, "%s: can't allocate %d byte ax25sin structure\n", Pn, (int)sizeof(struct ax25sin)); - Error(); + Error(ctx); } ap->da = da; ap->dev_ch = dev_ch; @@ -832,7 +849,7 @@ static void get_ax25(char *p) /* /proc/net/ax25 path */ * entry Lf = local file structure pointer * Lp = local process structure pointer */ -static void enter_uxsinfo(uxsin_t *up) { +static void enter_uxsinfo(struct lsof_context *ctx, uxsin_t *up) { pxinfo_t *pi; /* pxinfo_t structure pointer */ struct lfile *lf; /* local file structure pointer */ struct lproc *lp; /* local proc structure pointer */ @@ -849,7 +866,7 @@ static void enter_uxsinfo(uxsin_t *up) { if (!(np = (pxinfo_t *)malloc(sizeof(pxinfo_t)))) { (void)fprintf(stderr, "%s: no space for pipeinfo in uxsinfo, PID %d\n", Pn, Lp->pid); - Error(); + Error(ctx); } np->ino = Lf->inode; np->lf = Lf; @@ -861,7 +878,8 @@ static void enter_uxsinfo(uxsin_t *up) { /* * fill_uxicino() -- fill incoming connection inode number */ -static void fill_uxicino(INODETYPE si, /* UNIX socket inode number */ +static void fill_uxicino(struct lsof_context *ctx, + INODETYPE si, /* UNIX socket inode number */ INODETYPE ic) /* incoming UNIX socket connection * inode number */ { @@ -869,10 +887,10 @@ static void fill_uxicino(INODETYPE si, /* UNIX socket inode number */ uxsin_t *pic; /* pointer to incoming connection's * information */ - if ((psi = check_unix(si))) { + if ((psi = check_unix(ctx, si))) { if (psi->icstat || psi->icons) return; - if ((pic = check_unix(ic))) { + if ((pic = check_unix(ctx, ic))) { psi->icstat = 1; psi->icons = pic; } @@ -882,14 +900,15 @@ static void fill_uxicino(INODETYPE si, /* UNIX socket inode number */ /* * fill_uxpino() -- fill in UNIX socket's peer inode number */ -static void fill_uxpino(INODETYPE si, /* UNIX socket inode number */ +static void fill_uxpino(struct lsof_context *ctx, + INODETYPE si, /* UNIX socket inode number */ INODETYPE pi) /* UNIX socket peer's inode number */ { uxsin_t *pp, *up; - if ((up = check_unix(si))) { + if ((up = check_unix(ctx, si))) { if (!up->peer) { - if ((pp = check_unix(pi))) + if ((pp = check_unix(ctx, pi))) up->peer = pp; } } @@ -898,11 +917,12 @@ static void fill_uxpino(INODETYPE si, /* UNIX socket inode number */ /* * find_uxepti(lf) -- find UNIX socket endpoint info */ -uxsin_t *find_uxepti(struct lfile *lf) /* pipe's lfile */ +uxsin_t *find_uxepti(struct lsof_context *ctx, + struct lfile *lf) /* pipe's lfile */ { uxsin_t *up; - up = check_unix(lf->inode); + up = check_unix(ctx, lf->inode); return (up ? up->peer : (uxsin_t *)NULL); } @@ -948,7 +968,7 @@ static int get_diagmsg(int sockfd) /* socket's file descriptor */ /* * get_uxpeeri() - get UNIX socket peer inode information */ -static void get_uxpeeri() { +static void get_uxpeeri(struct lsof_context *ctx) { struct unix_diag_msg *dm; /* pointer to diag message */ struct nlmsghdr *hp; /* netlink structure header pointer */ int nb = 0; /* number of bytes */ @@ -961,7 +981,7 @@ static void get_uxpeeri() { if ((ns = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_SOCK_DIAG)) == -1) { (void)fprintf(stderr, "%s: netlink socket error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } /* * Request peer information. @@ -989,7 +1009,7 @@ static void get_uxpeeri() { } dm = (struct unix_diag_msg *)NLMSG_DATA(hp); rl = hp->nlmsg_len - NLMSG_LENGTH(sizeof(*dm)); - parse_diag(dm, rl); + parse_diag(ctx, dm, rl); hp = NLMSG_NEXT(hp, nb); } } @@ -1002,7 +1022,8 @@ static void get_uxpeeri() { /* * parse_diag() -- parse UNIX diag message */ -static void parse_diag(struct unix_diag_msg *dm, /* pointer to diag message */ +static void parse_diag(struct lsof_context *ctx, + struct unix_diag_msg *dm, /* pointer to diag message */ int len) /* message length */ { struct rtattr *rp; /* route info pointer */ @@ -1028,15 +1049,15 @@ static void parse_diag(struct unix_diag_msg *dm, /* pointer to diag message */ return; } if ((inoc = *(uint32_t *)RTA_DATA(rp))) { - fill_uxpino((INODETYPE)inop, (INODETYPE)inoc); - fill_uxpino((INODETYPE)inoc, (INODETYPE)inop); + fill_uxpino(ctx, (INODETYPE)inop, (INODETYPE)inoc); + fill_uxpino(ctx, (INODETYPE)inoc, (INODETYPE)inop); } break; case UNIX_DIAG_ICONS: icct = RTA_PAYLOAD(rp), icp = (uint32_t *)RTA_DATA(rp); for (i = 0; i < icct; i += sizeof(uint32_t), icp++) { - fill_uxicino((INODETYPE)inop, (INODETYPE)*icp); + fill_uxicino(ctx, (INODETYPE)inop, (INODETYPE)*icp); } } rp = RTA_NEXT(rp, len); @@ -1046,8 +1067,8 @@ static void parse_diag(struct unix_diag_msg *dm, /* pointer to diag message */ /* * prt_uxs() -- print UNIX socket information */ -static void prt_uxs(uxsin_t *p, /* peer info */ - int mk) /* 1 == mark for later processing */ +static void prt_uxs(struct lsof_context *ctx, uxsin_t *p, /* peer info */ + int mk) /* 1 == mark for later processing */ { struct lproc *ep; /* socket endpoint process */ struct lfile *ef; /* socket endpoint file */ @@ -1059,7 +1080,7 @@ static void prt_uxs(uxsin_t *p, /* peer info */ (void)strcpy(nma, "->INO="); len = (int)strlen(nma); (void)snpf(&nma[len], sizeof(nma) - len - 1, InodeFmt_d, p->inode); - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); for (pp = p->pxinfo; pp; pp = pp->next) { /* @@ -1074,7 +1095,7 @@ static void prt_uxs(uxsin_t *p, /* peer info */ } (void)snpf(nma, sizeof(nma) - 1, "%d,%.*s,%s%c", ep->pid, CmdLim, ep->cmd, &ef->fd[i], access_to_char(ef->access)); - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); if (mk && FeptE == 2) { /* @@ -1092,7 +1113,8 @@ static void prt_uxs(uxsin_t *p, /* peer info */ * UNIX socket files and selecting UNIX socket end point * files (if requested) */ -void process_uxsinfo(int f) /* function: +void process_uxsinfo(struct lsof_context *ctx, + int f) /* function: * 0 == process selected socket * 1 == process socket end point */ @@ -1117,23 +1139,23 @@ void process_uxsinfo(int f) /* function: * This file has been selected by some criterion other than its * being a socket. Look up the socket's endpoints. */ - p = find_uxepti(Lf); + p = find_uxepti(ctx, Lf); if (p && p->inode) - prt_uxs(p, 1); - if ((tp = check_unix(Lf->inode))) { + prt_uxs(ctx, p, 1); + if ((tp = check_unix(ctx, Lf->inode))) { if (tp->icons) { if (tp->icstat) { p = tp->icons; while (p && p != tp) { if (p->inode) - prt_uxs(p, 1); + prt_uxs(ctx, p, 1); p = p->icons; } } else { for (p = tp->icons; p && !p->icstat; p = p->icons) ; /* DO NOTHING */ if (p && p->inode) - prt_uxs(p, 1); + prt_uxs(ctx, p, 1); } } } @@ -1149,23 +1171,23 @@ void process_uxsinfo(int f) /* function: */ Lf->sf = Selflags; Lp->pss |= PS_SEC; - p = find_uxepti(Lf); + p = find_uxepti(ctx, Lf); if (p && p->inode) - prt_uxs(p, 0); - else if ((tp = check_unix(Lf->inode))) { + prt_uxs(ctx, p, 0); + else if ((tp = check_unix(ctx, Lf->inode))) { if (tp->icons) { if (tp->icstat) { p = tp->icons; while (p && p != tp) { if (p->inode) - prt_uxs(p, 0); + prt_uxs(ctx, p, 0); p = p->icons; } } else { for (p = tp->icons; p && !p->icstat; p = p->icons) ; /* DO NOTHING */ if (p && p->inode) - prt_uxs(p, 0); + prt_uxs(ctx, p, 0); } } } @@ -1181,7 +1203,8 @@ void process_uxsinfo(int f) /* function: * enter_netsinfo_common() -- enter inet or inet6 socket info * tp = tcp/udp on ipv4 or ipv4 socket pointer */ -static void enter_netsinfo_common(void *tp, pxinfo_t *(*get_pxinfo)(void *), +static void enter_netsinfo_common(struct lsof_context *ctx, void *tp, + pxinfo_t *(*get_pxinfo)(void *), void (*set_pxinfo)(void *, pxinfo_t *)) { pxinfo_t *pi; /* pxinfo_t structure pointer */ struct lfile *lf; /* local file structure pointer */ @@ -1199,7 +1222,7 @@ static void enter_netsinfo_common(void *tp, pxinfo_t *(*get_pxinfo)(void *), if (!(np = (pxinfo_t *)malloc(sizeof(pxinfo_t)))) { (void)fprintf(stderr, "%s: no space for pipeinfo in netsinfo, PID %d\n", Pn, Lp->pid); - Error(); + Error(ctx); } np->ino = Lf->inode; np->lf = Lf; @@ -1211,9 +1234,9 @@ static void enter_netsinfo_common(void *tp, pxinfo_t *(*get_pxinfo)(void *), /* * prt_nets_common() -- print locally used INET or INET6 socket information */ -static void prt_nets_common(void *p, /* peer info */ - int mk, /* 1 == mark for later - * processing */ +static void prt_nets_common(struct lsof_context *ctx, void *p, /* peer info */ + int mk, /* 1 == mark for later + * processing */ pxinfo_t *(*get_pxinfo)(void *), unsigned char chend, short ept_flag) { struct lproc *ep; /* socket endpoint process */ @@ -1236,7 +1259,7 @@ static void prt_nets_common(void *p, /* peer info */ } (void)snpf(nma, sizeof(nma) - 1, "%d,%.*s,%s%c", ep->pid, CmdLim, ep->cmd, &ef->fd[i], access_to_char(ef->access)); - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); if (mk && FeptE == 2) { /* @@ -1263,25 +1286,26 @@ static void tcp_udp_set_pxinfo(void *vp, pxinfo_t *np) { tp->pxinfo = np; } -static void enter_netsinfo(struct tcp_udp *tp) { - enter_netsinfo_common(tp, tcp_udp_get_pxinfo, tcp_udp_set_pxinfo); +static void enter_netsinfo(struct lsof_context *ctx, struct tcp_udp *tp) { + enter_netsinfo_common(ctx, tp, tcp_udp_get_pxinfo, tcp_udp_set_pxinfo); } /* * find_netsepti(lf) -- find locally used INET socket endpoint info */ -static struct tcp_udp *find_netsepti(struct lfile *lf) /* socket's lfile */ +static struct tcp_udp *find_netsepti(struct lsof_context *ctx, /* context */ + struct lfile *lf) /* socket's lfile */ { struct tcp_udp *tp; - tp = check_inet(lf->inode); + tp = check_inet(ctx, lf->inode); return (tp ? tp->ipc_peer : (struct tcp_udp *)NULL); } /* * get_netpeeri() - get INET socket peer inode information */ -static void get_netpeeri() { +static void get_netpeeri(struct lsof_context *ctx) { int h; struct tcp_udp *np, *tp; @@ -1307,10 +1331,11 @@ static void get_netpeeri() { /* * prt_nets() -- print locally used INET socket information */ -static void prt_nets(struct tcp_udp *p, /* peer info */ - int mk) /* 1 == mark for later processing */ +static void prt_nets(struct lsof_context *ctx, /* context */ + struct tcp_udp *p, /* peer info */ + int mk) /* 1 == mark for later processing */ { - prt_nets_common(p, mk, tcp_udp_get_pxinfo, CHEND_NETS, EPT_NETS_END); + prt_nets_common(ctx, p, mk, tcp_udp_get_pxinfo, CHEND_NETS, EPT_NETS_END); } /* @@ -1318,10 +1343,11 @@ static void prt_nets(struct tcp_udp *p, /* peer info */ * it to selected INET socket files and selecting INET * socket end point files (if requested) */ -void process_netsinfo(int f) /* function: - * 0 == process selected socket - * 1 == process socket end point - */ +void process_netsinfo(struct lsof_context *ctx, /* context */ + int f) /* function: + * 0 == process selected socket + * 1 == process socket end point + */ { struct tcp_udp *p; /* peer INET socket info pointer */ @@ -1347,9 +1373,9 @@ void process_netsinfo(int f) /* function: * This file has been selected by some criterion other than its * being a socket. Look up the socket's endpoints. */ - p = find_netsepti(Lf); + p = find_netsepti(ctx, Lf); if (p && p->inode) - prt_nets(p, 1); + prt_nets(ctx, p, 1); } break; case 1: @@ -1362,9 +1388,9 @@ void process_netsinfo(int f) /* function: */ Lf->sf = Selflags; Lp->pss |= PS_SEC; - p = find_netsepti(Lf); + p = find_netsepti(ctx, Lf); if (p && p->inode) - prt_nets(p, 0); + prt_nets(ctx, p, 0); } break; } @@ -1388,25 +1414,26 @@ static void tcp_udp6_set_pxinfo(void *vp, pxinfo_t *np) { tp->pxinfo = np; } -static void enter_nets6info(struct tcp_udp6 *tp) { - enter_netsinfo_common(tp, tcp_udp6_get_pxinfo, tcp_udp6_set_pxinfo); +static void enter_nets6info(struct lsof_context *ctx, struct tcp_udp6 *tp) { + enter_netsinfo_common(ctx, tp, tcp_udp6_get_pxinfo, tcp_udp6_set_pxinfo); } /* * find_nets6epti(lf) -- find locally used INET6 socket endpoint info */ -static struct tcp_udp6 *find_nets6epti(struct lfile *lf) /* socket's lfile */ +static struct tcp_udp6 *find_nets6epti(struct lsof_context *ctx, /* context */ + struct lfile *lf) /* socket's lfile */ { struct tcp_udp6 *tp; - tp = check_inet6(lf->inode); + tp = check_inet6(ctx, lf->inode); return (tp ? tp->ipc_peer : (struct tcp_udp6 *)NULL); } /* * get_net6peeri() - get INET6 socket peer inode information */ -static void get_net6peeri() { +static void get_net6peeri(struct lsof_context *ctx) { int h; struct tcp_udp6 *np, *tp; @@ -1433,10 +1460,12 @@ static void get_net6peeri() { /* * prt_nets6() -- print locally used INET6 socket information */ -static void prt_nets6(struct tcp_udp6 *p, /* peer info */ - int mk) /* 1 == mark for later processing */ +static void prt_nets6(struct lsof_context *ctx, /* context */ + struct tcp_udp6 *p, /* peer info */ + int mk) /* 1 == mark for later processing */ { - prt_nets_common(p, mk, tcp_udp6_get_pxinfo, CHEND_NETS6, EPT_NETS6_END); + prt_nets_common(ctx, p, mk, tcp_udp6_get_pxinfo, CHEND_NETS6, + EPT_NETS6_END); } /* @@ -1444,10 +1473,11 @@ static void prt_nets6(struct tcp_udp6 *p, /* peer info */ * it to selected INET6 socket files and selecting INET6 * socket end point files (if requested) */ -void process_nets6info(int f) /* function: - * 0 == process selected socket - * 1 == process socket end point - */ +void process_nets6info(struct lsof_context *ctx, /* context */ + int f) /* function: + * 0 == process selected socket + * 1 == process socket end point + */ { struct tcp_udp6 *p; /* peer INET6 socket info pointer */ @@ -1467,9 +1497,9 @@ void process_nets6info(int f) /* function: * This file has been selected by some criterion other than its * being a socket. Look up the socket's endpoints. */ - p = find_nets6epti(Lf); + p = find_nets6epti(ctx, Lf); if (p && p->inode) - prt_nets6(p, 1); + prt_nets6(ctx, p, 1); } break; case 1: @@ -1482,9 +1512,9 @@ void process_nets6info(int f) /* function: */ Lf->sf = Selflags; Lp->pss |= PS_SEC; - p = find_nets6epti(Lf); + p = find_nets6epti(ctx, Lf); if (p && p->inode) - prt_nets6(p, 0); + prt_nets6(ctx, p, 0); } break; } @@ -1496,7 +1526,8 @@ void process_nets6info(int f) /* function: /* * get_icmp() - get ICMP net info */ -static void get_icmp(char *p) /* /proc/net/icmp path */ +static void get_icmp(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/icmp path */ { char buf[MAXPATHLEN], *ep, **fp, *la, *ra; int fl = 1; @@ -1524,17 +1555,17 @@ static void get_icmp(char *p) /* /proc/net/icmp path */ (void)fprintf(stderr, "%s: can't allocate %d icmp hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct icmpin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/icmp file, assign a page size buffer to its stream, * and read the file. Store icmp info in the Icmpin[] hash buckets. */ - if (!(xs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(xs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, xs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 11) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 11) continue; if (fl) { @@ -1584,7 +1615,7 @@ static void get_icmp(char *p) /* /proc/net/icmp path */ stderr, "%s: can't allocate %d local icmp address bytes: %s\n", Pn, (int)(lal + 1), fp[1]); - Error(); + Error(ctx); } (void)snpf(la, lal + 1, "%s", fp[1]); } @@ -1597,7 +1628,7 @@ static void get_icmp(char *p) /* /proc/net/icmp path */ stderr, "%s: can't allocate %d remote icmp address bytes: %s\n", Pn, (int)(ral + 1), fp[2]); - Error(); + Error(ctx); } (void)snpf(ra, ral + 1, "%s", fp[2]); } @@ -1608,7 +1639,7 @@ static void get_icmp(char *p) /* /proc/net/icmp path */ if (!(icmpp = (struct icmpin *)malloc(sizeof(struct icmpin)))) { (void)fprintf(stderr, "%s: can't allocate %d byte icmp structure\n", Pn, (int)sizeof(struct icmpin)); - Error(); + Error(ctx); } icmpp->inode = inode; icmpp->la = la; @@ -1623,7 +1654,8 @@ static void get_icmp(char *p) /* /proc/net/icmp path */ /* * get_ipx() - get /proc/net/ipx info */ -static void get_ipx(char *p) /* /proc/net/ipx path */ +static void get_ipx(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/ipx path */ { char buf[MAXPATHLEN], *ep, **fp, *la, *ra; int fl = 1; @@ -1656,17 +1688,17 @@ static void get_ipx(char *p) /* /proc/net/ipx path */ (void)fprintf(stderr, "%s: can't allocate %d IPX hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct ipxsin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/ipx file, assign a page size buffer to the stream, * and read it. Store IPX socket info in the Ipxsin[] hash buckets. */ - if (!(xs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(xs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, xs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 7) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 7) continue; if (fl) { @@ -1725,7 +1757,7 @@ static void get_ipx(char *p) /* /proc/net/ipx path */ stderr, "%s: can't allocate %d local IPX address bytes: %s\n", Pn, (int)(len + 1), fp[0]); - Error(); + Error(ctx); } (void)snpf(la, len + 1, "%s", fp[0]); } else @@ -1741,7 +1773,7 @@ static void get_ipx(char *p) /* /proc/net/ipx path */ stderr, "%s: can't allocate %d remote IPX address bytes: %s\n", Pn, (int)(len + 1), fp[1]); - Error(); + Error(ctx); } (void)snpf(ra, len + 1, "%s", fp[1]); } else @@ -1754,7 +1786,7 @@ static void get_ipx(char *p) /* /proc/net/ipx path */ (void)fprintf(stderr, "%s: can't allocate %d byte ipxsin structure\n", Pn, (int)sizeof(struct ipxsin)); - Error(); + Error(ctx); } ip->inode = inode; ip->la = la; @@ -1770,7 +1802,8 @@ static void get_ipx(char *p) /* /proc/net/ipx path */ /* * get_netlink() - get /proc/net/netlink info */ -static void get_netlink(char *p) /* /proc/net/netlink path */ +static void get_netlink(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/netlink path */ { char buf[MAXPATHLEN], *ep, **fp; int fr = 1; @@ -1797,17 +1830,17 @@ static void get_netlink(char *p) /* /proc/net/netlink path */ (void)fprintf(stderr, "%s: can't allocate %d netlink hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct nlksin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/netlink file, assign a page size buffer to its stream, * and read the file. Store Netlink info in the Nlksin[] hash buckets. */ - if (!(xs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(xs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, xs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 10) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 10) continue; if (fr) { @@ -1850,7 +1883,7 @@ static void get_netlink(char *p) /* /proc/net/netlink path */ (void)fprintf(stderr, "%s: can't allocate %d byte Netlink structure\n", Pn, (int)sizeof(struct nlksin)); - Error(); + Error(ctx); } lp->inode = inode; lp->pr = pr; @@ -1862,7 +1895,8 @@ static void get_netlink(char *p) /* /proc/net/netlink path */ /* * get_pack() - get /proc/net/packet info */ -static void get_pack(char *p) /* /proc/net/raw path */ +static void get_pack(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/raw path */ { char buf[MAXPATHLEN], *ep, **fp; int fl = 1; @@ -1890,17 +1924,17 @@ static void get_pack(char *p) /* /proc/net/raw path */ (void)fprintf(stderr, "%s: can't allocate %d packet hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct packin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/packet file, assign a page size buffer to its stream, * and read the file. Store packet info in the Packin[] hash buckets. */ - if (!(xs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(xs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, xs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < 9) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < 9) continue; if (fl) { @@ -1947,7 +1981,7 @@ static void get_pack(char *p) /* /proc/net/raw path */ (void)fprintf(stderr, "%s: can't allocate %d byte packet structure\n", Pn, (int)sizeof(struct packin)); - Error(); + Error(ctx); } pp->inode = inode; pp->pr = (int)pr; @@ -1960,7 +1994,8 @@ static void get_pack(char *p) /* /proc/net/raw path */ /* * get_raw() - get /proc/net/raw info */ -static void get_raw(char *p) /* /proc/net/raw path */ +static void get_raw(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/raw path */ { char buf[MAXPATHLEN], *ep, **fp, *la, *ra, *sp; int h; @@ -1992,17 +2027,17 @@ static void get_raw(char *p) /* /proc/net/raw path */ (void)fprintf(stderr, "%s: can't allocate %d raw hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct rawsin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/raw file, assign a page size buffer to its stream, * and read the file. Store raw socket info in the Rawsin[] hash buckets. */ - if (!(xs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(xs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, xs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < nf) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < nf) continue; if (nf == 12) { @@ -2044,7 +2079,7 @@ static void get_raw(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d local raw address bytes: %s\n", Pn, (int)(lal + 1), fp[1]); - Error(); + Error(ctx); } (void)snpf(la, lal + 1, "%s", fp[1]); } @@ -2057,7 +2092,7 @@ static void get_raw(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d remote raw address bytes: %s\n", Pn, (int)(ral + 1), fp[2]); - Error(); + Error(ctx); } (void)snpf(ra, ral + 1, "%s", fp[2]); } @@ -2070,7 +2105,7 @@ static void get_raw(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d remote raw state bytes: %s\n", Pn, (int)(spl + 1), fp[2]); - Error(); + Error(ctx); } (void)snpf(sp, spl + 1, "%s", fp[3]); } @@ -2082,7 +2117,7 @@ static void get_raw(char *p) /* /proc/net/raw path */ (void)fprintf(stderr, "%s: can't allocate %d byte rawsin structure\n", Pn, (int)sizeof(struct rawsin)); - Error(); + Error(ctx); } rp->inode = inode; rp->la = la; @@ -2099,7 +2134,7 @@ static void get_raw(char *p) /* /proc/net/raw path */ /* * get_sctp() - get /proc/net/sctp/assocs info */ -static void get_sctp() { +static void get_sctp(struct lsof_context *ctx) { char buf[MAXPATHLEN], *a, *ep, **fp, *id, *la, *lp, *ra, *rp, *ta; int d, err, fl, h, i, j, nf, ty, x; INODETYPE inode; @@ -2137,7 +2172,7 @@ static void get_sctp() { (void)fprintf(stderr, "%s: can't allocate %d SCTP hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct sctpsin *))); - Error(); + Error(ctx); } } /* @@ -2145,11 +2180,11 @@ static void get_sctp() { * and read them. Store SCTP socket info in the SCTPsin[] hash buckets. */ for (i = 0; i < NSCTPPATHS; i++) { - if (!(ss = open_proc_stream(SCTPPath[i], "r", &vbuf, &vsz, 0))) + if (!(ss = open_proc_stream(ctx, SCTPPath[i], "r", &vbuf, &vsz, 0))) continue; fl = 1; while (fgets(buf, sizeof(buf) - 1, ss)) { - if ((nf = get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0)) < + if ((nf = get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0)) < (i ? 9 : 16)) { continue; } @@ -2231,7 +2266,7 @@ static void get_sctp() { (void)fprintf( stderr, "%s: can't allocate %d SCTP ASSOC bytes: %s\n", Pn, (int)(len + 1), fp[0]); - Error(); + Error(ctx); } if (!d) { if (plen) @@ -2262,7 +2297,7 @@ static void get_sctp() { stderr, "%s: can't allocate %d SCTP ASSOC-ID bytes: %s\n", Pn, (int)(len + 1), fp[6]); - Error(); + Error(ctx); } if (!d) { if (plen) @@ -2293,7 +2328,7 @@ static void get_sctp() { (void)fprintf( stderr, "%s: can't allocate %d SCTP LPORT bytes: %s\n", Pn, (int)(len + 1), fp[j]); - Error(); + Error(ctx); } if (!d) { if (plen) @@ -2323,7 +2358,7 @@ static void get_sctp() { (void)fprintf( stderr, "%s: can't allocate %d SCTP RPORT bytes: %s\n", Pn, (int)(len + 1), fp[12]); - Error(); + Error(ctx); } if (!d) { if (plen) @@ -2344,7 +2379,7 @@ static void get_sctp() { (void)fprintf(stderr, "%s: can't allocate %d SCTP LADDRS bytes\n", Pn, (int)len); - Error(); + Error(ctx); } if (la) { if (isainb(ta, la)) { @@ -2356,7 +2391,7 @@ static void get_sctp() { stderr, "%s: can't reallocate %d SCTP LADDRS bytes\n", Pn, (int)len); - Error(); + Error(ctx); } (void)snpf(la + plen, len + 2, ",%s", ta); (void)free((FREE_P *)ta); @@ -2375,7 +2410,7 @@ static void get_sctp() { (void)fprintf(stderr, "%s: can't allocate %d SCTP RADDRS bytes\n", Pn, (int)len); - Error(); + Error(ctx); } if (ra) { if (isainb(ta, ra)) { @@ -2387,7 +2422,7 @@ static void get_sctp() { stderr, "%s: can't reallocate %d SCTP RADDRS bytes\n", Pn, (int)len); - Error(); + Error(ctx); } (void)snpf(ra + plen, len + 2, ",%s", ta); (void)free((FREE_P *)ta); @@ -2406,7 +2441,7 @@ static void get_sctp() { stderr, "%s: can't allocate %d byte sctpsin structure\n", Pn, (int)sizeof(struct sctpsin)); - Error(); + Error(ctx); } sp->inode = inode; HASH_INSERT_ELEMENT(SCTPsin, INOHASH, sp, inode); @@ -2460,10 +2495,11 @@ static char *get_sctpaddrs(char **fp, /* field pointers */ /* * get_tcpudp() - get IPv4 TCP, UDP or UDPLITE net info */ -static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ - int pr, /* protocol: 0 = TCP, 1 = UDP, - * 2 = UDPLITE */ - int clr) /* 1 == clear the table */ +static void get_tcpudp(struct lsof_context *ctx, /* context */ + char *p, /* /proc/net/{tcp,udp} path */ + int pr, /* protocol: 0 = TCP, 1 = UDP, + * 2 = UDPLITE */ + int clr) /* 1 == clear the table */ { char buf[MAXPATHLEN], *ep, **fp; unsigned long faddr, fport, laddr, lport, rxq, state, txq; @@ -2516,7 +2552,8 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ TcpUdp_bucks = INOBUCKS; if ((fs = fopen(SockStatPath, "r"))) { while (fgets(buf, sizeof(buf) - 1, fs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) != 3) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) != + 3) continue; if (!fp[0] || strcmp(fp[0], "sockets:") || !fp[1] || strcmp(fp[1], "used") || !fp[2] || !*fp[2]) @@ -2535,7 +2572,7 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ stderr, "%s: can't allocate %d bytes for TCP&UDP hash buckets\n", Pn, (int)(TcpUdp_bucks * sizeof(struct tcp_udp *))); - Error(); + Error(ctx); } #if defined(HASEPTOPTS) if (FeptE && (!(TcpUdpIPC = (struct tcp_udp **)calloc( @@ -2544,7 +2581,7 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ "%s: can't allocate %d bytes for TCP&UDP local IPC " "hash buckets\n", Pn, (int)(IPCBUCKS * sizeof(struct tcp_udp *))); - Error(); + Error(ctx); } #endif /* defined(HASEPTOPTS) */ } @@ -2552,12 +2589,12 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ * Open the /proc/net file, assign a page size buffer to the stream, and * read it. */ - if (!(fs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(fs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; nf = 12; while (fgets(buf, sizeof(buf) - 1, fs)) { - if (get_fields(buf, (nf == 12) ? (char *)NULL : ":", &fp, (int *)NULL, - 0) < nf) + if (get_fields(ctx, buf, (nf == 12) ? (char *)NULL : ":", &fp, + (int *)NULL, 0) < nf) continue; if (nf == 12) { if (!fp[1] || strcmp(fp[1], "local_address") || !fp[2] || @@ -2624,7 +2661,7 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ (void)fprintf(stderr, "%s: can't allocate %d bytes for tcp_udp struct\n", Pn, (int)sizeof(struct tcp_udp)); - Error(); + Error(ctx); } tp->inode = inode; tp->faddr = faddr; @@ -2654,7 +2691,7 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ * If endpoint info has been requested, link INET socket peer info. */ if (FeptE) - get_netpeeri(); + get_netpeeri(ctx); #endif /* defined(HASEPTOPTS) */ (void)fclose(fs); @@ -2664,7 +2701,8 @@ static void get_tcpudp(char *p, /* /proc/net/{tcp,udp} path */ /* * get_raw6() - get /proc/net/raw6 info */ -static void get_raw6(char *p) /* /proc/net/raw path */ +static void get_raw6(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/raw path */ { char buf[MAXPATHLEN], *ep, **fp, *la, *ra, *sp; int h; @@ -2698,17 +2736,17 @@ static void get_raw6(char *p) /* /proc/net/raw path */ (void)fprintf(stderr, "%s: can't allocate %d raw6 hash pointer bytes\n", Pn, (int)(INOBUCKS * sizeof(struct rawsin *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/raw6 file, assign a page size buffer to the stream, * and read it. Store raw6 socket info in the Rawsin6[] hash buckets. */ - if (!(xs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(xs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, xs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) < nf) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) < nf) continue; if (nf == 12) { @@ -2750,7 +2788,7 @@ static void get_raw6(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d local raw6 address bytes: %s\n", Pn, (int)(lal + 1), fp[1]); - Error(); + Error(ctx); } (void)snpf(la, lal + 1, "%s", fp[1]); } @@ -2763,7 +2801,7 @@ static void get_raw6(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d remote raw6 address bytes: %s\n", Pn, (int)(ral + 1), fp[2]); - Error(); + Error(ctx); } (void)snpf(ra, ral + 1, "%s", fp[2]); } @@ -2776,7 +2814,7 @@ static void get_raw6(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d remote raw6 state bytes: %s\n", Pn, (int)(spl + 1), fp[2]); - Error(); + Error(ctx); } (void)snpf(sp, spl + 1, "%s", fp[3]); } @@ -2789,7 +2827,7 @@ static void get_raw6(char *p) /* /proc/net/raw path */ stderr, "%s: can't allocate %d byte rawsin structure for IPv6\n", Pn, (int)sizeof(struct rawsin)); - Error(); + Error(ctx); } rp->inode = inode; rp->la = la; @@ -2806,7 +2844,8 @@ static void get_raw6(char *p) /* /proc/net/raw path */ /* * get_tcpudp6() - get IPv6 TCP, UDP or UDPLITE net info */ -static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ +static void get_tcpudp6(struct lsof_context *ctx, /* context */ + char *p, /* /proc/net/{tcp,udp} path */ int pr, /* protocol: 0 = TCP, 1 = UDP */ int clr) /* 1 == clear the table */ { @@ -2860,7 +2899,8 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ i = nf = 0; if ((fs = fopen(SockStatPath6, "r"))) { while (fgets(buf, sizeof(buf) - 1, fs)) { - if (get_fields(buf, (char *)NULL, &fp, (int *)NULL, 0) != 3) + if (get_fields(ctx, buf, (char *)NULL, &fp, (int *)NULL, 0) != + 3) continue; if (!fp[0] || !fp[1] || strcmp(fp[1], "inuse") || !fp[2] || !*fp[2]) @@ -2891,7 +2931,7 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ stderr, "%s: can't allocate %d bytes for TCP6&UDP6 hash buckets\n", Pn, (int)(TcpUdp6_bucks * sizeof(struct tcp_udp6 *))); - Error(); + Error(ctx); } # if defined(HASEPTOPTS) if (FeptE && (!(TcpUdp6IPC = (struct tcp_udp6 **)calloc( @@ -2900,7 +2940,7 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ "%s: can't allocate %d bytes for TCP6&UDP6 local IPC " "hash buckets\n", Pn, (int)(IPCBUCKS * sizeof(struct tcp_udp6 *))); - Error(); + Error(ctx); } # endif /* defined(HASEPTOPTS) */ } @@ -2908,12 +2948,12 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ * Open the /proc/net file, assign a page size buffer to the stream, * and read it. */ - if (!(fs = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(fs = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; nf = 12; while (fgets(buf, sizeof(buf) - 1, fs)) { - if (get_fields(buf, (nf == 12) ? (char *)NULL : ":", &fp, (int *)NULL, - 0) < nf) + if (get_fields(ctx, buf, (nf == 12) ? (char *)NULL : ":", &fp, + (int *)NULL, 0) < nf) continue; if (nf == 12) { if (!fp[1] || strcmp(fp[1], "local_address") || !fp[2] || @@ -2977,7 +3017,7 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ (void)fprintf(stderr, "%s: can't allocate %d bytes for tcp_udp6 struct\n", Pn, (int)sizeof(struct tcp_udp6)); - Error(); + Error(ctx); } tp6->inode = inode; tp6->faddr = faddr; @@ -3006,7 +3046,7 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ * If endpoint info has been requested, link INET6 socket peer info. */ if (FeptE) - get_net6peeri(); + get_net6peeri(ctx); # endif /* defined(HASEPTOPTS) */ (void)fclose(fs); @@ -3016,7 +3056,8 @@ static void get_tcpudp6(char *p, /* /proc/net/{tcp,udp} path */ /* * get_unix() - get UNIX net info */ -static void get_unix(char *p) /* /proc/net/unix path */ +static void get_unix(struct lsof_context *ctx, /* context */ + char *p) /* /proc/net/unix path */ { char buf[MAXPATHLEN], *ep, **fp, *path, *pcb; int fl = 1; /* First line */ @@ -3062,17 +3103,17 @@ static void get_unix(char *p) /* /proc/net/unix path */ (void)fprintf(stderr, "%s: can't allocate %d bytes for Unix socket info\n", Pn, (int)(INOBUCKS * sizeof(uxsin_t *))); - Error(); + Error(ctx); } } /* * Open the /proc/net/unix file, assign a page size buffer to the stream, * read the file's contents, and add them to the Uxsin hash buckets. */ - if (!(us = open_proc_stream(p, "r", &vbuf, &vsz, 0))) + if (!(us = open_proc_stream(ctx, p, "r", &vbuf, &vsz, 0))) return; while (fgets(buf, sizeof(buf) - 1, us)) { - if ((nf = get_fields(buf, ":", &fp, (int *)NULL, 0)) < 7) + if ((nf = get_fields(ctx, buf, ":", &fp, (int *)NULL, 0)) < 7) continue; if (fl) { @@ -3113,7 +3154,7 @@ static void get_unix(char *p) /* /proc/net/unix path */ (void)fprintf(stderr, "%s: can't allocate %d bytes for UNIX PCB: %s\n", Pn, (int)(len + 1), fp[0]); - Error(); + Error(ctx); } (void)snpf(pcb, len + 1, "0x%s", fp[0]); } @@ -3123,7 +3164,7 @@ static void get_unix(char *p) /* /proc/net/unix path */ stderr, "%s: can't allocate %d bytes for UNIX path \"%s\"\n", Pn, (int)(len + 1), fp[7]); - Error(); + Error(ctx); } (void)snpf(path, len + 1, "%s", fp[7]); } else @@ -3160,7 +3201,7 @@ static void get_unix(char *p) /* /proc/net/unix path */ (void)fprintf(stderr, "%s: can't allocate %d bytes for uxsin struct\n", Pn, (int)sizeof(uxsin_t)); - Error(); + Error(ctx); } up->inode = inode; up->next = (uxsin_t *)NULL; @@ -3180,7 +3221,7 @@ static void get_unix(char *p) /* /proc/net/unix path */ int sr; if (HasNFS) - sr = statsafely(path, &sb); + sr = statsafely(ctx, path, &sb); else sr = stat(path, &sb); if (sr == 0 && ((sb.st_mode & S_IFMT) == S_IFSOCK)) { @@ -3208,7 +3249,7 @@ static void get_unix(char *p) /* /proc/net/unix path */ * If endpoint info has been requested, get UNIX socket peer info. */ if (FeptE) - get_uxpeeri(); + get_uxpeeri(ctx); #endif /* defined(HASEPTOPTS) && defined(HASUXSOCKEPT) */ (void)fclose(us); @@ -3303,7 +3344,8 @@ static int isainb(char *a, /*string a */ /* * print_ax25info() - print AX25 socket info */ -static void print_ax25info(struct ax25sin *ap) /* AX25 socket info */ +static void print_ax25info(struct lsof_context *ctx, /* context */ + struct ax25sin *ap) /* AX25 socket info */ { char *cp, pbuf[1024]; int ds; @@ -3342,7 +3384,7 @@ static void print_ax25info(struct ax25sin *ap) /* AX25 socket info */ stderr, "%s: can't allocate %d bytes for AX25 sock state, PID: %d\n", Pn, (int)(pl + 1), Lp->pid); - Error(); + Error(ctx); } (void)snpf(cp, pl + 1, "%s", pbuf); Lf->nma = cp; @@ -3351,7 +3393,8 @@ static void print_ax25info(struct ax25sin *ap) /* AX25 socket info */ /* * print_ipxinfo() - print IPX socket info */ -static void print_ipxinfo(struct ipxsin *ip) /* IPX socket info */ +static void print_ipxinfo(struct lsof_context *ctx, /* context */ + struct ipxsin *ip) /* IPX socket info */ { char *cp, pbuf[256]; MALLOC_S pl; @@ -3365,7 +3408,7 @@ static void print_ipxinfo(struct ipxsin *ip) /* IPX socket info */ (void)fprintf( stderr, "%s: can't allocate %d bytes for IPX sock state, PID: %d\n", Pn, (int)(pl + 1), Lp->pid); - Error(); + Error(ctx); } (void)snpf(cp, pl + 1, "%s", pbuf); Lf->nma = cp; @@ -3397,7 +3440,8 @@ static void print_unix(int nl) { /* * print_tcptpi() - print TCP/TPI state e.g. ESTBALISHED */ -void print_tcptpi(int nl) /* 1 == '\n' required */ +void print_tcptpi(struct lsof_context *ctx, /* context */ + int nl) /* 1 == '\n' required */ { char buf[128]; char *cp = (char *)NULL; @@ -3410,7 +3454,7 @@ void print_tcptpi(int nl) /* 1 == '\n' required */ } if ((Ftcptpi & TCPTPI_STATE) && Lf->lts.type == 0) { if (!TcpSt) - (void)build_IPstates(); + (void)build_IPstates(ctx); if ((s = Lf->lts.state.i + TcpStOff) < 0 || s >= TcpNstates) { (void)snpf(buf, sizeof(buf), "UNKNOWN_TCP_STATE_%d", Lf->lts.state.i); @@ -3503,7 +3547,8 @@ void print_tcptpi(int nl) /* 1 == '\n' required */ /* * process_proc_sock() - process /proc-based socket */ -void process_proc_sock(char *p, /* node's readlink() path */ +void process_proc_sock(struct lsof_context *ctx, /* context */ + char *p, /* node's readlink() path */ char *pbr, /* node's path before readlink() */ struct stat *s, /* stat() result for path */ int ss, /* *s status -- i.e, SB_* values */ @@ -3545,11 +3590,11 @@ void process_proc_sock(char *p, /* node's readlink() path */ * Check for socket's inode presence in the protocol info caches. */ if (AX25path) { - (void)get_ax25(AX25path); + (void)get_ax25(ctx, AX25path); (void)free((FREE_P *)AX25path); AX25path = (char *)NULL; } - if ((ss & SB_INO) && (ap = check_ax25((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (ap = check_ax25(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to an AX25 /proc record. @@ -3560,19 +3605,19 @@ void process_proc_sock(char *p, /* node's readlink() path */ */ (void)snpf(Lf->type, sizeof(Lf->type), "ax25"); if (ap->dev_ch) - (void)enter_dev_ch(ap->dev_ch); + (void)enter_dev_ch(ctx, ap->dev_ch); Lf->inode = ap->inode; Lf->inp_ty = 1; - print_ax25info(ap); + print_ax25info(ctx, ap); return; } if (Ipxpath) { - (void)get_ipx(Ipxpath); + (void)get_ipx(ctx, Ipxpath); (void)free((FREE_P *)Ipxpath); Ipxpath = (char *)NULL; } - if ((ss & SB_INO) && (ip = check_ipx((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (ip = check_ipx(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to an IPX /proc record. * @@ -3619,18 +3664,18 @@ void process_proc_sock(char *p, /* node's readlink() path */ nl -= len; } } - (void)print_ipxinfo(ip); + (void)print_ipxinfo(ctx, ip); if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (Rawpath) { - (void)get_raw(Rawpath); + (void)get_raw(ctx, Rawpath); (void)free((FREE_P *)Rawpath); Rawpath = (char *)NULL; } - if ((ss & SB_INO) && (rp = check_raw((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (rp = check_raw(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to a raw /proc record. * @@ -3681,16 +3726,16 @@ void process_proc_sock(char *p, /* node's readlink() path */ } } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (Nlkpath) { - (void)get_netlink(Nlkpath); + (void)get_netlink(ctx, Nlkpath); (void)free((FREE_P *)Nlkpath); Nlkpath = (char *)NULL; } - if ((ss & SB_INO) && (np = check_netlink((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (np = check_netlink(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to a Netlink /proc record. * @@ -3708,16 +3753,16 @@ void process_proc_sock(char *p, /* node's readlink() path */ Lf->inode = (INODETYPE)s->st_ino; Lf->inp_ty = 1; if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (Packpath) { - (void)get_pack(Packpath); + (void)get_pack(ctx, Packpath); (void)free((FREE_P *)Packpath); Packpath = (char *)NULL; } - if ((ss & SB_INO) && (pp = check_pack((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (pp = check_pack(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to a packet /proc record. * @@ -3740,19 +3785,19 @@ void process_proc_sock(char *p, /* node's readlink() path */ if (ss & SB_INO) { (void)snpf(tbuf, sizeof(tbuf), InodeFmt_d, (INODETYPE)s->st_ino); tbuf[sizeof(tbuf) - 1] = '\0'; - enter_dev_ch(tbuf); + enter_dev_ch(ctx, tbuf); } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (UNIXpath) { - (void)get_unix(UNIXpath); + (void)get_unix(ctx, UNIXpath); (void)free((FREE_P *)UNIXpath); UNIXpath = (char *)NULL; } - if ((ss & SB_INO) && (up = check_unix((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (up = check_unix(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to a UNIX /proc record. @@ -3764,7 +3809,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ Lf->sf |= SELUNX; (void)snpf(Lf->type, sizeof(Lf->type), "unix"); if (up->pcb) - enter_dev_ch(up->pcb); + enter_dev_ch(ctx, up->pcb); Lf->inode = (INODETYPE)s->st_ino; Lf->inp_ty = 1; @@ -3777,7 +3822,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ #endif /* defined(HASSOSTATE) */ #if defined(HASEPTOPTS) && defined(HASUXSOCKEPT) if (FeptE) { - (void)enter_uxsinfo(up); + (void)enter_uxsinfo(ctx, up); Lf->sf |= SELUXSINFO; } #endif /* defined(HASEPTOPTS) && defined(HASUXSOCKEPT) */ @@ -3786,7 +3831,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ (void)snpf(Namech, Namechl - 1, "%s%stype=%s", up->path ? up->path : "", up->path ? " " : "", cp); Namech[Namechl - 1] = '\0'; - (void)enter_nm(Namech); + (void)enter_nm(ctx, Namech); if (Sfile) { /* @@ -3824,7 +3869,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ Lf->dev = up->sb_dev; Lf->inode = up->sb_ino; Lf->rdev = up->sb_rdev; - if (is_file_named(0, path, (struct mounts *)NULL, 0)) { + if (is_file_named(ctx, 0, path, (struct mounts *)NULL, 0)) { f = 1; Lf->sf |= SELNM; } @@ -3841,7 +3886,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ * If the file has not yet been found and the stat buffer has * st_mode, search for the file by full path. */ - if (is_file_named(2, up->path ? up->path : p, + if (is_file_named(ctx, 2, up->path ? up->path : p, (struct mounts *)NULL, ((s->st_mode & S_IFMT) == S_IFCHR)) ? 1 @@ -3856,11 +3901,12 @@ void process_proc_sock(char *p, /* node's readlink() path */ #if defined(HASIPv6) if (Raw6path) { if (!Fxopt) - (void)get_raw6(Raw6path); + (void)get_raw6(ctx, Raw6path); (void)free((FREE_P *)Raw6path); Raw6path = (char *)NULL; } - if (!Fxopt && (ss & SB_INO) && (rp = check_raw6((INODETYPE)s->st_ino))) { + if (!Fxopt && (ss & SB_INO) && + (rp = check_raw6(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to a raw IPv6 /proc record. @@ -3913,33 +3959,33 @@ void process_proc_sock(char *p, /* node's readlink() path */ } } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (TCP6path) { if (!Fxopt) - (void)get_tcpudp6(TCP6path, 0, 1); + (void)get_tcpudp6(ctx, TCP6path, 0, 1); (void)free((FREE_P *)TCP6path); TCP6path = (char *)NULL; } if (UDP6path) { if (!Fxopt) - (void)get_tcpudp6(UDP6path, 1, 0); + (void)get_tcpudp6(ctx, UDP6path, 1, 0); (void)free((FREE_P *)UDP6path); UDP6path = (char *)NULL; } if (UDPLITE6path) { if (!Fxopt) - (void)get_tcpudp6(UDPLITE6path, 2, 0); + (void)get_tcpudp6(ctx, UDPLITE6path, 2, 0); (void)free((FREE_P *)UDPLITE6path); UDPLITE6path = (char *)NULL; } if (!Fxopt && (ss & SB_INO) && - (tp6 = check_tcpudp6((INODETYPE)s->st_ino, &pr))) { + (tp6 = check_tcpudp6(ctx, (INODETYPE)s->st_ino, &pr))) { /* * The inode is connected to an IPv6 TCP or UDP /proc record. @@ -3984,7 +4030,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ if (ss & SB_INO) { (void)snpf(tbuf, sizeof(tbuf), InodeFmt_d, (INODETYPE)s->st_ino); tbuf[sizeof(tbuf) - 1] = '\0'; - enter_dev_ch(tbuf); + enter_dev_ch(ctx, tbuf); Lf->inode = (INODETYPE)s->st_ino; } af = AF_INET6; @@ -4004,7 +4050,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ if (la) la += 12; } - ent_inaddr(la, tp6->lport, fa, tp6->fport, af); + ent_inaddr(ctx, la, tp6->lport, fa, tp6->fport, af); Lf->lts.type = tp6->proto; Lf->lts.state.i = tp6->state; @@ -4016,7 +4062,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ # if defined(HASEPTOPTS) if (FeptE && tp6->ipc_peer) { - (void)enter_nets6info(tp6); + (void)enter_nets6info(ctx, tp6); Lf->sf |= SELNETS6INFO; } # endif /* defined(HASEPTOPTS) */ @@ -4026,27 +4072,27 @@ void process_proc_sock(char *p, /* node's readlink() path */ if (TCPpath) { if (!Fxopt) - (void)get_tcpudp(TCPpath, 0, 1); + (void)get_tcpudp(ctx, TCPpath, 0, 1); (void)free((FREE_P *)TCPpath); TCPpath = (char *)NULL; } if (UDPpath) { if (!Fxopt) - (void)get_tcpudp(UDPpath, 1, 0); + (void)get_tcpudp(ctx, UDPpath, 1, 0); (void)free((FREE_P *)UDPpath); UDPpath = (char *)NULL; } if (UDPLITEpath) { if (!Fxopt) - (void)get_tcpudp(UDPLITEpath, 2, 0); + (void)get_tcpudp(ctx, UDPLITEpath, 2, 0); (void)free((FREE_P *)UDPLITEpath); UDPLITEpath = (char *)NULL; } if (!Fxopt && (ss & SB_INO) && - (tp = check_tcpudp((INODETYPE)s->st_ino, &pr))) { + (tp = check_tcpudp(ctx, (INODETYPE)s->st_ino, &pr))) { /* * The inode is connected to an IPv4 TCP or UDP /proc record. @@ -4097,7 +4143,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ if (ss & SB_INO) { (void)snpf(tbuf, sizeof(tbuf), InodeFmt_d, (INODETYPE)s->st_ino); tbuf[sizeof(tbuf) - 1] = '\0'; - enter_dev_ch(tbuf); + enter_dev_ch(ctx, tbuf); Lf->inode = (INODETYPE)s->st_ino; } if (tp->faddr || tp->fport) { @@ -4110,7 +4156,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ la = (unsigned char *)&ls; } else la = (unsigned char *)NULL; - ent_inaddr(la, tp->lport, fa, tp->fport, AF_INET); + ent_inaddr(ctx, la, tp->lport, fa, tp->fport, AF_INET); Lf->lts.type = tp->proto; Lf->lts.state.i = tp->state; @@ -4122,7 +4168,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ #if defined(HASEPTOPTS) if (FeptE && tp->ipc_peer) { - (void)enter_netsinfo(tp); + (void)enter_netsinfo(ctx, tp); Lf->sf |= SELNETSINFO; } #endif /* defined(HASEPTOPTS) */ @@ -4131,13 +4177,13 @@ void process_proc_sock(char *p, /* node's readlink() path */ } if (SCTPPath[0]) { - (void)get_sctp(); + (void)get_sctp(ctx); for (i = 0; i < NSCTPPATHS; i++) { (void)free((FREE_P *)SCTPPath[i]); SCTPPath[i] = (char *)NULL; } } - if ((ss & SB_INO) && (sp = check_sctp((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (sp = check_sctp(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to an SCTP /proc record. @@ -4151,7 +4197,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ Lf->inp_ty = 2; (void)snpf(tbuf, sizeof(tbuf), InodeFmt_d, (INODETYPE)s->st_ino); tbuf[sizeof(tbuf) - 1] = '\0'; - enter_dev_ch(tbuf); + enter_dev_ch(ctx, tbuf); Namech[0] = '\0'; if (sp->type == 1) { @@ -4181,16 +4227,16 @@ void process_proc_sock(char *p, /* node's readlink() path */ sp->rport ? sp->rport : "", sp->rport ? "]" : ""); } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (ICMPpath) { - (void)get_icmp(ICMPpath); + (void)get_icmp(ctx, ICMPpath); (void)free((FREE_P *)ICMPpath); ICMPpath = (char *)NULL; } - if ((ss & SB_INO) && (icmpp = check_icmp((INODETYPE)s->st_ino))) { + if ((ss & SB_INO) && (icmpp = check_icmp(ctx, (INODETYPE)s->st_ino))) { /* * The inode is connected to an ICMP /proc record. @@ -4229,7 +4275,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ } } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); return; } @@ -4246,7 +4292,7 @@ void process_proc_sock(char *p, /* node's readlink() path */ Lf->dev_def = 1; } if (Fxopt) - enter_nm("can't identify protocol (-X specified)"); + enter_nm(ctx, "can't identify protocol (-X specified)"); else { (void)snpf(Namech, Namechl, "protocol: "); if (!prp) { @@ -4255,61 +4301,62 @@ void process_proc_sock(char *p, /* node's readlink() path */ sz = (ssize_t)(Namechl - i - 1); } if ((getxattr(pbr, "system.sockprotoname", prp, sz)) < 0) - enter_nm("can't identify protocol"); + enter_nm(ctx, "can't identify protocol"); else - enter_nm(Namech); + enter_nm(ctx, Namech); } } /* * set_net_paths() - set /proc/net paths */ -void set_net_paths(char *p, /* path to /proc/net/ */ - int pl) /* strlen(p) */ +void set_net_paths(struct lsof_context *ctx, /* context */ + char *p, /* path to /proc/net/ */ + int pl) /* strlen(p) */ { int i; int pathl; pathl = 0; - (void)make_proc_path(p, pl, &AX25path, &pathl, "ax25"); + (void)make_proc_path(ctx, p, pl, &AX25path, &pathl, "ax25"); pathl = 0; - (void)make_proc_path(p, pl, &ICMPpath, &pathl, "icmp"); + (void)make_proc_path(ctx, p, pl, &ICMPpath, &pathl, "icmp"); pathl = 0; - (void)make_proc_path(p, pl, &Ipxpath, &pathl, "ipx"); + (void)make_proc_path(ctx, p, pl, &Ipxpath, &pathl, "ipx"); pathl = 0; - (void)make_proc_path(p, pl, &Nlkpath, &pathl, "netlink"); + (void)make_proc_path(ctx, p, pl, &Nlkpath, &pathl, "netlink"); pathl = 0; - (void)make_proc_path(p, pl, &Packpath, &pathl, "packet"); + (void)make_proc_path(ctx, p, pl, &Packpath, &pathl, "packet"); pathl = 0; - (void)make_proc_path(p, pl, &Rawpath, &pathl, "raw"); + (void)make_proc_path(ctx, p, pl, &Rawpath, &pathl, "raw"); for (i = 0; i < NSCTPPATHS; i++) { pathl = 0; - (void)make_proc_path(p, pl, &SCTPPath[i], &pathl, SCTPSfx[i]); + (void)make_proc_path(ctx, p, pl, &SCTPPath[i], &pathl, SCTPSfx[i]); } pathl = 0; - (void)make_proc_path(p, pl, &SockStatPath, &pathl, "sockstat"); + (void)make_proc_path(ctx, p, pl, &SockStatPath, &pathl, "sockstat"); pathl = 0; - (void)make_proc_path(p, pl, &TCPpath, &pathl, "tcp"); + (void)make_proc_path(ctx, p, pl, &TCPpath, &pathl, "tcp"); pathl = 0; - (void)make_proc_path(p, pl, &UDPpath, &pathl, "udp"); + (void)make_proc_path(ctx, p, pl, &UDPpath, &pathl, "udp"); pathl = 0; - (void)make_proc_path(p, pl, &UDPLITEpath, &pathl, "udplite"); + (void)make_proc_path(ctx, p, pl, &UDPLITEpath, &pathl, "udplite"); #if defined(HASIPv6) pathl = 0; - (void)make_proc_path(p, pl, &Raw6path, &pathl, "raw6"); + (void)make_proc_path(ctx, p, pl, &Raw6path, &pathl, "raw6"); pathl = 0; - (void)make_proc_path(p, pl, &SockStatPath6, &pathl, "sockstat6"); + (void)make_proc_path(ctx, p, pl, &SockStatPath6, &pathl, "sockstat6"); pathl = 0; - (void)make_proc_path(p, pl, &TCP6path, &pathl, "tcp6"); + (void)make_proc_path(ctx, p, pl, &TCP6path, &pathl, "tcp6"); pathl = 0; - (void)make_proc_path(p, pl, &UDP6path, &pathl, "udp6"); + (void)make_proc_path(ctx, p, pl, &UDP6path, &pathl, "udp6"); pathl = 0; - (void)make_proc_path(p, pl, &UDPLITE6path, &pathl, "udplite6"); + (void)make_proc_path(ctx, p, pl, &UDPLITE6path, &pathl, "udplite6"); #endif /* defined(HASIPv6) */ pathl = 0; - (void)make_proc_path(p, pl, &UNIXpath, &pathl, "unix"); + (void)make_proc_path(ctx, p, pl, &UNIXpath, &pathl, "unix"); } /* diff --git a/lib/dialects/netbsd/dmnt.c b/lib/dialects/netbsd/dmnt.c index de4e3351..7ff0e024 100644 --- a/lib/dialects/netbsd/dmnt.c +++ b/lib/dialects/netbsd/dmnt.c @@ -67,7 +67,7 @@ static int Lmist = 0; /* Lmi status */ * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char *dn = (char *)NULL; char *ln; struct mounts *mtp; @@ -119,9 +119,9 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(mb->f_mntfromname, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } - if ((ln = Readlink(dn)) == NULL) { + if ((ln = Readlink(ctx, dn)) == NULL) { if (!Fwarn) { (void)fprintf(stderr, " Output information may be incomplete.\n"); @@ -137,7 +137,7 @@ struct mounts *readmnt() { /* * Stat() the directory. */ - if (statsafely(dn, &sb)) { + if (statsafely(ctx, dn, &sb)) { if (!Fwarn) { (void)fprintf(stderr, "%s: WARNING: can't stat() ", Pn); safestrprt(mb->f_fstypename, stderr, 0); @@ -195,13 +195,13 @@ struct mounts *readmnt() { if (!(dn = mkstrcpy(mb->f_mntfromname, (MALLOC_S *)NULL))) goto no_space_for_mount; mtp->fsname = dn; - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat() the file system (mounted-on) name and add file system * information to the local mount table entry. */ - if (!ln || statsafely(ln, &sb)) + if (!ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mtp->fsnmres = ln; mtp->fs_mode = sb.st_mode; @@ -220,8 +220,8 @@ struct mounts *readmnt() { * readvfs() - read vfs structure */ -struct l_vfs *readvfs(vm) -KA_T vm; /* kernel mount address from vnode */ +struct l_vfs *readvfs(struct lsof_context *ctx, /* context */ + KA_T vm) /* kernel mount address from vnode */ { struct mount m; struct l_vfs *vp; @@ -235,17 +235,17 @@ KA_T vm; /* kernel mount address from vnode */ /* * Read the (new) mount structure, allocate a local entry, and fill it. */ - if (kread(vm, (char *)&m, sizeof(m)) != 0) + if (kread(ctx, vm, (char *)&m, sizeof(m)) != 0) return ((struct l_vfs *)NULL); if (!(vp = (struct l_vfs *)malloc(sizeof(struct l_vfs)))) { (void)fprintf(stderr, "%s: PID %d, no space for vfs\n", Pn, Lp->pid); - Error(); + Error(ctx); } if (!(vp->dir = mkstrcpy(m.m_stat.f_mntonname, (MALLOC_S *)NULL)) || !(vp->fsname = mkstrcpy(m.m_stat.f_mntfromname, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: PID %d, no space for mount names\n", Pn, Lp->pid); - Error(); + Error(ctx); } vp->addr = vm; diff --git a/lib/dialects/netbsd/dnode.c b/lib/dialects/netbsd/dnode.c index d5f51863..bb6c0ac5 100644 --- a/lib/dialects/netbsd/dnode.c +++ b/lib/dialects/netbsd/dnode.c @@ -46,7 +46,7 @@ static char copyright[] = #endif /* defined(HAS_DINODE_U) */ #if defined(HASFDESCFS) && HASFDESCFS == 1 -_PROTOTYPE(static int lkup_dev_tty, (dev_t * dr, INODETYPE *ir)); +static int lkup_dev_tty(struct lsof_context *ctx, dev_t *dr, INODETYPE *ir); #endif /* defined(HASFDESCFS) && HASFDESCFS==1 */ #if defined(HAS_UM_UFS) @@ -55,7 +55,7 @@ _PROTOTYPE(static int lkup_dev_tty, (dev_t * dr, INODETYPE *ir)); #endif /* defined(HAS_UM_UFS) */ #if defined(HASPROCFS) -_PROTOTYPE(static void getmemsz, (pid_t pid)); +static void getmemsz(struct lsof_context *ctx, pid_t pid); # if !defined(PGSHIFT) # define PGSHIFT pgshift @@ -65,7 +65,7 @@ _PROTOTYPE(static void getmemsz, (pid_t pid)); * getmemsz() - get memory size of a /proc//mem entry */ -static void getmemsz(pid) pid_t pid; +static void getmemsz(struct lsof_context *ctx, pid_t pid) { int n; struct vmspace vm; @@ -79,7 +79,7 @@ static void getmemsz(pid) pid_t pid; for (n = 0, p = P; n < Np; n++, p++) { if (p->P_PID == pid) { if (!p->P_VMSPACE || - kread((KA_T)p->P_VMSPACE, (char *)&vm, sizeof(vm))) + kread(ctx, (KA_T)p->P_VMSPACE, (char *)&vm, sizeof(vm))) return; Lf->sz = (SZOFFTYPE)ctob(vm.vm_tsize + vm.vm_dsize + vm.vm_ssize); Lf->sz_def = 1; @@ -95,13 +95,13 @@ static void getmemsz(pid) pid_t pid; * lkup_dev_tty() - look up /dev/tty */ -static int lkup_dev_tty(dr, ir) -dev_t *dr; /* place to return device number */ -INODETYPE *ir; /* place to return inode number */ +static int lkup_dev_tty(struct lsof_context *ctx, /* context */ + dev_t *dr, /* place to return device number */ + INODETYPE *ir) /* place to return inode number */ { int i; - readdev(0); + readdev(ctx, 0); # if defined(HASDCACHE) @@ -113,7 +113,7 @@ INODETYPE *ir; /* place to return inode number */ if (strcmp(Devtp[i].name, "/dev/tty") == 0) { # if defined(HASDCACHE) - if (DCunsafe && !Devtp[i].v && !vfy_dev(&Devtp[i])) + if (DCunsafe && !Devtp[i].v && !vfy_dev(ctx, &Devtp[i])) goto lkup_dev_tty_again; # endif /* defined(HASDCACHE) */ @@ -125,7 +125,7 @@ INODETYPE *ir; /* place to return inode number */ # if defined(HASDCACHE) if (DCunsafe) { - (void)rereaddev(); + (void)rereaddev(ctx); goto lkup_dev_tty_again; } # endif /* defined(HASDCACHE) */ @@ -143,11 +143,12 @@ INODETYPE *ir; /* place to return inode number */ * require a dfile.c, so this is the next best location for the function. */ -void process_kqueue(ka) KA_T ka; /* kqueue file structure address */ +void process_kqueue(struct lsof_context *ctx, /* context */ + KA_T ka) /* kqueue file structure address */ { (void)snpf(Lf->type, sizeof(Lf->type), "KQUEUE"); - enter_dev_ch(print_kptr(ka, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(ka, (char *)NULL, 0)); } #endif /* defined(HASKQUEUE) */ @@ -155,7 +156,8 @@ void process_kqueue(ka) KA_T ka; /* kqueue file structure address */ * process_node() - process vnode */ -void process_node(va) KA_T va; /* vnode kernel space address */ +void process_node(struct lsof_context *ctx, /* context */ + KA_T va) /* vnode kernel space address */ { dev_t dev, rdev; unsigned char devs; @@ -276,7 +278,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ if (++sc > 1024) { (void)snpf(Namech, Namechl, "too many overlaid nodes"); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } #endif /* defined(HASNULLFS) */ @@ -309,12 +311,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * Read the vnode. */ if (!va) { - enter_nm("no vnode address"); + enter_nm(ctx, "no vnode address"); return; } v = &vb; - if (readvnode(va, v)) { - enter_nm(Namech); + if (readvnode(ctx, va, v)) { + enter_nm(ctx, Namech); return; } @@ -336,7 +338,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ if (!v->v_mount) vfs = (struct l_vfs *)NULL; else { - vfs = readvfs((KA_T)v->v_mount); + vfs = readvfs(ctx, (KA_T)v->v_mount); if (vfs) { if (strcmp(vfs->type, MOUNT_NFS) == 0) Ntype = N_NFS; @@ -371,10 +373,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HAS9660FS) case VT_ISOFS: - if (read_iso_node(v, &iso_dev, &iso_ino, &iso_nlink, &iso_sz)) { + if (read_iso_node(ctx, v, &iso_dev, &iso_ino, &iso_nlink, &iso_sz)) { (void)snpf(Namech, Namechl, "can't read iso_node at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } iso_stat = 1; @@ -384,10 +386,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASFDESCFS) case VT_FDESC: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&f, sizeof(f))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "can't read fdescnode at: %x", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } nty = FDESCNODE; @@ -400,11 +402,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Read the kernfs_node. */ - if (!v->v_data || kread((KA_T)v->v_data, (char *)&kn, sizeof(kn))) { + if (!v->v_data || + kread(ctx, (KA_T)v->v_data, (char *)&kn, sizeof(kn))) { if (v->v_type != VDIR || !(v->VNODE_VFLAG && NCACHE_VROOT)) { (void)snpf(Namech, Namechl, "can't read kernfs_node at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } else kn.kf_kt = (struct kern_target *)NULL; @@ -413,11 +416,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * Generate the /kern file name by reading the kern_target to which * the kernfs_node points. */ - if (kn.kf_kt && kread((KA_T)kn.kf_kt, (char *)&kt, sizeof(kt)) == 0 && + if (kn.kf_kt && + kread(ctx, (KA_T)kn.kf_kt, (char *)&kt, sizeof(kt)) == 0 && (ktnl = (int)kt.kt_namlen) > 0 && kt.kt_name) { if (ktnl > (sizeof(ktnm) - 1)) ktnl = sizeof(ktnm) - 1; - if (!kread((KA_T)kt.kt_name, ktnm, ktnl)) { + if (!kread(ctx, (KA_T)kt.kt_name, ktnm, ktnl)) { ktnm[ktnl] = 0; ktnl = strlen(ktnm); if (ktnl > (MAXPATHLEN - strlen(_PATH_KERNFS) - 2)) { @@ -444,10 +448,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HASKERNFS) */ case VT_MFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&m, sizeof(m))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&m, sizeof(m))) { (void)snpf(Namech, Namechl, "can't read mfsnode at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } nty = MFSNODE; @@ -455,10 +459,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASTMPFS) case VT_TMPFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&tmp, sizeof(tmp))) { + if (!v->v_data || + kread(ctx, (KA_T)v->v_data, (char *)&tmp, sizeof(tmp))) { (void)snpf(Namech, Namechl, "can't read tmpfs_node at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } nty = TMPFSNODE; @@ -467,10 +472,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASMSDOSFS) case VT_MSDOSFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&d, sizeof(d))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&d, sizeof(d))) { (void)snpf(Namech, Namechl, "can't read denode at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } nty = DOSNODE; @@ -478,18 +483,19 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HASMSDOSFS) */ case VT_NFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&n, sizeof(n))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&n, sizeof(n))) { (void)snpf(Namech, Namechl, "can't read nfsnode at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } #if defined(HASNFSVATTRP) - if (!n.n_vattr || kread((KA_T)n.n_vattr, (char *)&nv, sizeof(nv))) { + if (!n.n_vattr || + kread(ctx, (KA_T)n.n_vattr, (char *)&nv, sizeof(nv))) { (void)snpf(Namech, Namechl, "can't read n_vattr at: %x", print_kptr((KA_T)n.n_vattr, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } #endif /* defined(HASNFSVATTRP) */ @@ -501,15 +507,16 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case VT_NULL: if ((sc == 1) && vfs) nvfs = vfs; - if (!v->v_data || kread((KA_T)v->v_data, (char *)&nu, sizeof(nu))) { + if (!v->v_data || + kread(ctx, (KA_T)v->v_data, (char *)&nu, sizeof(nu))) { (void)snpf(Namech, Namechl, "can't read null_node at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (!nu.null_lowervp) { (void)snpf(Namech, Namechl, "null_node overlays nothing"); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } va = (KA_T)nu.null_lowervp; @@ -518,10 +525,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASPROCFS) case VT_PROCFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&p, sizeof(p))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl, "can't read pfsnode at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } nty = PFSNODE; @@ -530,10 +537,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASPTYFS) case VT_PTYFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&pt, sizeof(pt))) { + if (!v->v_data || + kread(ctx, (KA_T)v->v_data, (char *)&pt, sizeof(pt))) { (void)snpf(Namech, Namechl, "can't read ptyfsnode at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } nty = PTYFSNODE; @@ -549,10 +557,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HASLFS) */ case VT_UFS: - if (!v->v_data || kread((KA_T)v->v_data, (char *)&i, sizeof(i))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&i, sizeof(i))) { (void)snpf(Namech, Namechl, "can't read inode at: %s", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } @@ -562,7 +570,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # if defined(HASI_E2FS_PTR) if (i.DINODE_U.e2fs_din && - !kread((KA_T)i.DINODE_U.e2fs_din, (char *)&ed, sizeof(ed))) + !kread(ctx, (KA_T)i.DINODE_U.e2fs_din, (char *)&ed, sizeof(ed))) edp = &ed; # else /* !defined(HASI_E2FS_PTR) */ # if HASEXT2FS < 2 @@ -582,18 +590,19 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * If there are multiple FFS's, read the relevant structures. */ - if (i.i_ump && !kread((KA_T)i.i_ump, (char *)&um, sizeof(um))) { + if (i.i_ump && + !kread(ctx, (KA_T)i.i_ump, (char *)&um, sizeof(um))) { if (um.um_fstype == UFS1) { ffs = 1; if (i.DINODE_U.ffs1_din && - !kread((KA_T)i.DINODE_U.ffs1_din, (char *)&u1, + !kread(ctx, (KA_T)i.DINODE_U.ffs1_din, (char *)&u1, sizeof(u1))) { u1s = 1; } } else if (um.um_fstype == UFS2) { ffs = 2; if (i.DINODE_U.ffs2_din && - !kread((KA_T)i.DINODE_U.ffs2_din, (char *)&u2, + !kread(ctx, (KA_T)i.DINODE_U.ffs2_din, (char *)&u2, sizeof(u2))) { u2s = 1; } @@ -610,7 +619,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ lfp = lff; do { - if (kread((KA_T)lfp, (char *)&lf, sizeof(lf))) + if (kread(ctx, (KA_T)lfp, (char *)&lf, sizeof(lf))) break; lt = 0; switch (lf.lf_flags & (F_FLOCK | F_POSIX)) { @@ -627,7 +636,8 @@ void process_node(va) KA_T va; /* vnode kernel space address */ struct lwp lw; - if (!kread((KA_T)lf.lf_id, (char *)&lw, sizeof(lw)) && + if (!kread(ctx, (KA_T)lf.lf_id, (char *)&lw, + sizeof(lw)) && (KA_T)lw.l_proc == Kpa) lt = 1; } @@ -657,7 +667,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ if (v->v_type == VBAD || v->v_type == VNON) break; (void)snpf(Namech, Namechl, "unknown file system type: %d", v->v_tag); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -677,7 +687,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case FDESCNODE: # if defined(HASFDLINK) - if (f.fd_link && !kread((KA_T)f.fd_link, Namech, Namechl - 1)) { + if (f.fd_link && !kread(ctx, (KA_T)f.fd_link, Namech, Namechl - 1)) { Namech[Namechl - 1] = '\0'; break; } @@ -686,7 +696,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # if HASFDESCFS == 1 if (f.fd_type == Fctty) { if (f_tty_s == 0) - f_tty_s = lkup_dev_tty(&f_tty_dev, &f_tty_ino); + f_tty_s = lkup_dev_tty(ctx, &f_tty_dev, &f_tty_ino); if (f_tty_s == 1) { dev = DevDev; rdev = f_tty_dev; @@ -783,7 +793,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASPTYFS) case PTYFSNODE: if (v->v_un.vu_specinfo && - !kread((KA_T)v->v_un.vu_specinfo, (char *)&si, sizeof(si))) { + !kread(ctx, (KA_T)v->v_un.vu_specinfo, (char *)&si, sizeof(si))) { rdev = si.si_rdev; rdevs = 1; } @@ -822,7 +832,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASMSDOSFS) case DOSNODE: - if (d.de_pmp && !kread((KA_T)d.de_pmp, (char *)&pm, sizeof(pm))) { + if (d.de_pmp && !kread(ctx, (KA_T)d.de_pmp, (char *)&pm, sizeof(pm))) { dpb = (u_long)(pm.pm_BytesPerSec / sizeof(struct direntry)); if (d.de_Attributes & ATTR_DIRECTORY) { if (d.de_StartCluster == MSDOSFSROOT) @@ -948,7 +958,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->sz_def = 1; break; case Pmem: - (void)getmemsz(p.pfs_pid); + (void)getmemsz(ctx, p.pfs_pid); break; case Pregs: Lf->sz = (SZOFFTYPE)sizeof(struct reg); @@ -1213,7 +1223,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ else if (nty == MFSNODE) { Lf->dev_def = Lf->rdev_def = 0; (void)snpf(Namech, Namechl, "%#x", m.mfs_baseoff); - enter_dev_ch("memory"); + enter_dev_ch(ctx, "memory"); } #if defined(HASPROCFS) @@ -1226,63 +1236,63 @@ void process_node(va) KA_T va; /* vnode kernel space address */ ty = "PDIR"; break; case Pcurproc: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/curproc"); ty = "PCUR"; break; case Pproc: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d", p.pfs_pid); ty = "PDIR"; break; case Pfile: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/file", p.pfs_pid); ty = "PFIL"; break; case Pmem: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/mem", p.pfs_pid); ty = "PMEM"; break; case Pregs: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/regs", p.pfs_pid); ty = "PREG"; break; case Pfpregs: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/fpregs", p.pfs_pid); ty = "PFPR"; break; # if defined(Pctl) case Pctl: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/ctl", p.pfs_pid); ty = "PCTL"; break; # endif /* defined(Pctl) */ case Pstatus: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/status", p.pfs_pid); ty = "PSTA"; break; case Pnote: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/note", p.pfs_pid); ty = "PNTF"; break; case Pnotepg: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/notepg", p.pfs_pid); ty = "PGID"; break; # if defined(Pfd) case Pfd: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/fd", p.pfs_pid); ty = "PFD"; break; @@ -1290,7 +1300,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # if defined(Pmap) case Pmap: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/map", p.pfs_pid); ty = "PMAP"; break; @@ -1298,7 +1308,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # if defined(Pmaps) case Pmaps: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%d/maps", p.pfs_pid); ty = "PMPS"; break; @@ -1316,11 +1326,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->nlink_def = 1; switch (pt.ptyfs_type) { case PTYFSpts: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%lu", (unsigned long)pt.ptyfs_pty); break; case PTYFSptc: - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "/%lu (master)", (unsigned long)pt.ptyfs_pty); break; case PTYFSroot: @@ -1339,7 +1349,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * supply one. */ if ((Lf->inp_ty == 0) && (type == VBLK)) - find_bl_ino(); + find_bl_ino(ctx); #endif /* defined(HASBLKDEV) */ /* @@ -1347,7 +1357,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * supply one. */ if ((Lf->inp_ty == 0) && (type == VCHR)) - find_ch_ino(); + find_ch_ino(ctx); /* * Test for specified file. */ @@ -1379,12 +1389,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ { if (Namech[0]) { - enter_nm(Namech); + enter_nm(ctx, Namech); ns = 1; } else ns = 0; if (Sfile && - is_file_named((char *)NULL, + is_file_named(ctx, (char *)NULL, ((type == VCHR) || (type == VBLK)) ? 1 : 0)) { Lf->sf |= SELNM; } @@ -1395,7 +1405,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * Enter name characters. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } #if defined(HAS_SYS_PIPEH) @@ -1403,20 +1413,21 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * process_pipe() - process a file structure whose type is DTYPE_PIPE */ -void process_pipe(pa) KA_T pa; /* pipe structure kernel address */ +void process_pipe(struct lsof_context *ctx, /* context */ + KA_T pa) /* pipe structure kernel address */ { char *ep; struct pipe p; size_t sz; - if (!pa || kread((KA_T)pa, (char *)&p, sizeof(p))) { + if (!pa || kread(ctx, (KA_T)pa, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl, "can't read DTYPE_PIPE pipe struct: %#s", print_kptr(pa, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } (void)snpf(Lf->type, sizeof(Lf->type), "PIPE"); - enter_dev_ch(print_kptr(pa, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(pa, (char *)NULL, 0)); Lf->sz = (SZOFFTYPE)p.pipe_buffer.size; Lf->sz_def = 1; if (p.pipe_peer) @@ -1425,21 +1436,21 @@ void process_pipe(pa) KA_T pa; /* pipe structure kernel address */ else Namech[0] = '\0'; if (p.pipe_buffer.cnt) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", cnt=%d", p.pipe_buffer.cnt); } if (p.pipe_buffer.in) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", in=%d", p.pipe_buffer.in); } if (p.pipe_buffer.out) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", out=%d", p.pipe_buffer.out); } /* * Enter name characters. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } #endif /* defined(HAS_SYS_PIPEH) */ diff --git a/lib/dialects/netbsd/dnode1.c b/lib/dialects/netbsd/dnode1.c index d184bc83..71825309 100644 --- a/lib/dialects/netbsd/dnode1.c +++ b/lib/dialects/netbsd/dnode1.c @@ -71,16 +71,16 @@ static char copyright[] = * read_iso_node() -- read CD 9660 iso_node */ -int read_iso_node(v, d, ino, nl, sz) -struct vnode *v; /* containing vnode */ -dev_t *d; /* returned device number */ -INODETYPE *ino; /* returned inode number */ -long *nl; /* returned link count */ -SZOFFTYPE *sz; /* returned size */ +int read_iso_node(struct lsof_context *ctx, /* context */ + struct vnode *v, /* containing vnode */ + dev_t *d, /* returned device number */ + INODETYPE *ino, /* returned inode number */ + long *nl, /* returned link count */ + SZOFFTYPE *sz) /* returned size */ { struct iso_node i; - if (!v->v_data || kread((KA_T)v->v_data, (char *)&i, sizeof(i))) + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&i, sizeof(i))) return (1); *d = i.i_dev; *ino = (INODETYPE)i.i_number; diff --git a/lib/dialects/netbsd/dproc.c b/lib/dialects/netbsd/dproc.c index c0c9f597..07fc0693 100644 --- a/lib/dialects/netbsd/dproc.c +++ b/lib/dialects/netbsd/dproc.c @@ -63,9 +63,9 @@ static char copyright[] = # define OFILES(fd, dt) ((fd).fd_ofiles) #endif -_PROTOTYPE(static void enter_vn_text, (KA_T va, int *n)); -_PROTOTYPE(static void get_kernel_access, (void)); -_PROTOTYPE(static void process_text, (KA_T vm)); +static void enter_vn_text(struct lsof_context *ctx, KA_T va, int *n); +static void get_kernel_access(struct lsof_context *ctx); +static void process_text(struct lsof_context *ctx, KA_T vm); /* * Local static values @@ -78,10 +78,11 @@ static KA_T *Vp = NULL; /* vnode address cache */ * ckkv - check kernel version */ -void ckkv(d, er, ev, ea) char *d; /* dialect */ -char *er; /* expected release */ -char *ev; /* expected version */ -char *ea; /* expected architecture */ +void ckkv(struct lsof_context *ctx, /* context */ + char *d, /* dialect */ + char *er, /* expected release */ + char *ev, /* expected version */ + char *ea) /* expected architecture */ { #if defined(HASKERNIDCK) @@ -100,7 +101,7 @@ char *ea; /* expected architecture */ if (sysctl(m, 2, v, &l, NULL, 0) < 0) { (void)fprintf(stderr, "%s: CTL_KERN, KERN_OSRELEASE: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } /* * Warn if the actual and expected releases don't match. @@ -116,8 +117,9 @@ char *ea; /* expected architecture */ * enter_vn_text() - enter a vnode text reference */ -static void enter_vn_text(va, n) KA_T va; /* vnode address */ -int *n; /* Vp[] entries in use */ +static void enter_vn_text(struct lsof_context *ctx, /* context */ + KA_T va, /* vnode address */ + int *n) /* Vp[] entries in use */ { int i; /* @@ -130,11 +132,11 @@ int *n; /* Vp[] entries in use */ /* * Save the text file information. */ - alloc_lfile(" txt", -1); + alloc_lfile(ctx, " txt", -1); Cfp = (struct file *)NULL; - process_node((KA_T)va); + process_node(ctx, (KA_T)va); if (Lf->sf) - link_lfile(); + link_lfile(ctx); if (i >= Nv) { /* @@ -148,7 +150,7 @@ int *n; /* Vp[] entries in use */ if (!Vp) { (void)fprintf(stderr, "%s: no txt ptr space, PID %d\n", Pn, Lp->pid); - Error(); + Error(ctx); } } /* @@ -162,7 +164,7 @@ int *n; /* Vp[] entries in use */ * gather_proc_info() -- gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { struct filedesc fd; int i, nf; MALLOC_S nb; @@ -210,7 +212,7 @@ void gather_proc_info() { if (!P) { (void)fprintf(stderr, "%s: can't read process table: %s\n", Pn, kvm_geterr(Kd)); - Error(); + Error(ctx); } /* * Examine proc structures and their associated information. @@ -228,61 +230,61 @@ void gather_proc_info() { * Read file structure pointers. */ uid = p->P_UID; - if (is_proc_excl((int)p->P_PID, (int)p->P_PGID, (UID_ARG)uid, &pss, + if (is_proc_excl(ctx, (int)p->P_PID, (int)p->P_PGID, (UID_ARG)uid, &pss, &sf)) { continue; } - if (!p->P_FD || kread((KA_T)p->P_FD, (char *)&fd, sizeof(fd))) + if (!p->P_FD || kread(ctx, (KA_T)p->P_FD, (char *)&fd, sizeof(fd))) continue; if (!fd.fd_refcnt) continue; #if HAVE_STRUCT_FDTAB - if (!fd.fd_dt || kread((KA_T)fd.fd_dt, (char *)&dt, sizeof(dt))) + if (!fd.fd_dt || kread(ctx, (KA_T)fd.fd_dt, (char *)&dt, sizeof(dt))) continue; #endif /* ! HAVE_STRUCT_FDTAB */ if (fd.fd_lastfile > NFILES(fd, dt)) continue; #if defined(HASCWDINFO) - if (!p->P_CWDI || kread((KA_T)p->P_CWDI, (char *)&cw, sizeof(cw))) + if (!p->P_CWDI || kread(ctx, (KA_T)p->P_CWDI, (char *)&cw, sizeof(cw))) CDIR = RDIR = (struct vnode *)NULL; #endif /* defined(HASCWDINFO) */ /* * Allocate a local process structure. */ - if (is_cmd_excl(p->P_COMM, &pss, &sf)) + if (is_cmd_excl(ctx, p->P_COMM, &pss, &sf)) continue; - alloc_lproc((int)p->P_PID, (int)p->P_PGID, (int)p->P_PPID, (UID_ARG)uid, - p->P_COMM, (int)pss, (int)sf); + alloc_lproc(ctx, (int)p->P_PID, (int)p->P_PGID, (int)p->P_PPID, + (UID_ARG)uid, p->P_COMM, (int)pss, (int)sf); Plf = (struct lfile *)NULL; Kpa = (KA_T)p->P_ADDR; /* * Save current working directory information. */ if (CDIR) { - alloc_lfile(CWD, -1); + alloc_lfile(ctx, CWD, -1); Cfp = (struct file *)NULL; - process_node((KA_T)CDIR); + process_node(ctx, (KA_T)CDIR); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } /* * Save root directory information. */ if (RDIR) { - alloc_lfile(RTD, -1); + alloc_lfile(ctx, RTD, -1); Cfp = (struct file *)NULL; - process_node((KA_T)RDIR); + process_node(ctx, (KA_T)RDIR); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } /* * Save information on the text file. */ if (p->P_VMSPACE) - process_text((KA_T)p->P_VMSPACE); + process_text(ctx, (KA_T)p->P_VMSPACE); /* * Read open file structure pointers. */ @@ -297,11 +299,11 @@ void gather_proc_info() { if (!ofb) { (void)fprintf(stderr, "%s: PID %d, no file * space\n", Pn, p->P_PID); - Error(); + Error(ctx); } ofbb = nb; } - if (kread((KA_T)OFILES(fd, dt), (char *)ofb, nb)) + if (kread(ctx, (KA_T)OFILES(fd, dt), (char *)ofb, nb)) continue; #if defined(HASFSTRUCT) @@ -314,12 +316,12 @@ void gather_proc_info() { if (!pof) { (void)fprintf(stderr, "%s: PID %d, no file flag space\n", Pn, p->P_PID); - Error(); + Error(ctx); } pofb = nb; } # if !HAVE_STRUCT_FDFILE - if (!fd.fd_ofileflags || kread((KA_T)fd.fd_ofileflags, pof, nb)) + if (!fd.fd_ofileflags || kread(ctx, (KA_T)fd.fd_ofileflags, pof, nb)) zeromem(pof, nb); # endif /* ! HAVE_STRUCT_FDFILE */ #endif /* defined(HASFSTRUCT) */ @@ -331,7 +333,7 @@ void gather_proc_info() { if (ofb[i]) { #if HAVE_STRUCT_FDFILE struct fdfile fdf; - if (kread((KA_T)ofb[i], (char *)&fdf, sizeof(fdf))) + if (kread(ctx, (KA_T)ofb[i], (char *)&fdf, sizeof(fdf))) continue; Cfp = fdf.ff_file; if (Cfp == NULL) @@ -341,22 +343,22 @@ void gather_proc_info() { #else /* ! HAVE_STRUCT_FDFILE */ Cfp = ofb[i]; #endif /* ! HAVE_STRUCT_FDFILE */ - alloc_lfile(NULL, i); - process_file((KA_T)Cfp); + alloc_lfile(ctx, NULL, i); + process_file(ctx, (KA_T)Cfp); if (Lf->sf) { #if defined(HASFSTRUCT) Lf->pof = (long)pof[i]; #endif /* defined(HASFSTRUCT) */ - link_lfile(); + link_lfile(ctx); } } } /* * Examine results. */ - if (examine_lproc()) + if (examine_lproc(ctx)) return; } } @@ -365,12 +367,12 @@ void gather_proc_info() { * get_kernel_access() - get access to kernel memory */ -static void get_kernel_access() { +static void get_kernel_access(struct lsof_context *ctx) { KA_T v; /* * Check kernel version. */ - (void)ckkv("NetBSD", LSOF_VSTR, (char *)NULL, (char *)NULL); + (void)ckkv(ctx, "NetBSD", LSOF_VSTR, (char *)NULL, (char *)NULL); /* * Set name list file path. */ @@ -380,9 +382,9 @@ static void get_kernel_access() { Nmlst = N_UNIX; #else /* !defined(N_UNIX) */ { - if (!(Nmlst = get_nlist_path(1))) { + if (!(Nmlst = get_nlist_path(ctx, 1))) { (void)fprintf(stderr, "%s: can't get kernel name list path\n", Pn); - Error(); + Error(ctx); } } #endif /* defined(N_UNIX) */ @@ -393,14 +395,14 @@ static void get_kernel_access() { * before attempting to open the (Memory) file. */ if (Memory) - (void)dropgid(); + (void)dropgid(ctx); #else /* !defined(WILLDROPGID) */ /* * See if the non-KMEM memory and name list files are readable. */ if ((Memory && !is_readable(Memory, 1)) || (Nmlst && !is_readable(Nmlst, 1))) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -419,12 +421,12 @@ static void get_kernel_access() { #endif /* defined(_PATH_MEM) */ strerror(errno)); - Error(); + Error(ctx); } - (void)build_Nl(Drive_Nl); + (void)build_Nl(ctx, Drive_Nl); if (kvm_nlist(Kd, Nl) < 0) { (void)fprintf(stderr, "%s: can't read namelist from %s\n", Pn, Nmlst); - Error(); + Error(ctx); } #if defined(WILLDROPGID) @@ -432,14 +434,14 @@ static void get_kernel_access() { * Drop setgid permission, if necessary. */ if (!Memory) - (void)dropgid(); + (void)dropgid(ctx); #endif /* defined(WILLDROPGID) */ /* * Read the kernel's page shift amount, if possible. */ if (get_Nl_value("pgshift", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&pgshift, sizeof(pgshift))) + kread(ctx, (KA_T)v, (char *)&pgshift, sizeof(pgshift))) pgshift = 0; } @@ -448,11 +450,11 @@ static void get_kernel_access() { * get_nlist_path() - get kernel name list path */ -char *get_nlist_path(ap) -int ap; /* on success, return an allocated path - * string pointer if 1; return a - * constant character pointer if 0; - * return NULL if failure */ +char *get_nlist_path(struct lsof_context *ctx, /* context */ + int ap) /* on success, return an allocated path + * string pointer if 1; return a + * constant character pointer if 0; + * return NULL if failure */ { const char *bf; static char *bfc; @@ -468,7 +470,7 @@ int ap; /* on success, return an allocated path (void)fprintf( stderr, "%s: can't allocate %d bytes for boot file path: %s\n", Pn, bfl, bf); - Error(); + Error(ctx); } (void)snpf(bfc, bfl, "%s", bf); return (bfc); @@ -481,16 +483,16 @@ int ap; /* on success, return an allocated path * initialize() - perform all initialization */ -void initialize() { get_kernel_access(); } +void initialize(struct lsof_context *ctx) { get_kernel_access(ctx); } /* * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, /* context */ + KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { int br; @@ -501,7 +503,8 @@ READLEN_T len; /* length to read */ /* * process_text() - process text information */ -void process_text(vm) KA_T vm; /* kernel vm space pointer */ +void process_text(struct lsof_context *ctx, /* context */ + KA_T vm) /* kernel vm space pointer */ { int i, j; KA_T ka; @@ -517,7 +520,7 @@ void process_text(vm) KA_T vm; /* kernel vm space pointer */ /* * Read the vmspace structure for the process. */ - if (kread(vm, (char *)&vmsp, sizeof(vmsp))) + if (kread(ctx, vm, (char *)&vmsp, sizeof(vmsp))) return; /* * Read the vm_map structure. Search its vm_map_entry structure list. @@ -539,7 +542,7 @@ void process_text(vm) KA_T vm; /* kernel vm space pointer */ if (!(ka = (KA_T)e->next)) return; e = &vmme; - if (kread(ka, (char *)e, sizeof(vmme))) + if (kread(ctx, ka, (char *)e, sizeof(vmme))) return; } @@ -549,7 +552,7 @@ void process_text(vm) KA_T vm; /* kernel vm space pointer */ * type as a vnode pointer. */ if ((e->etype > UVM_ET_OBJ) && e->object.uvm_obj) - (void)enter_vn_text((KA_T)e->object.uvm_obj, &n); + (void)enter_vn_text(ctx, (KA_T)e->object.uvm_obj, &n); #else /* !defined(UVM) */ /* * Read the map entry's object and the object's shadow. @@ -559,9 +562,10 @@ void process_text(vm) KA_T vm; /* kernel vm space pointer */ continue; for (j = 0, ka = (KA_T)e->object.vm_object; j < 2 && ka; j++, ka = (KA_T)vmo.shadow) { - if (kread(ka, (char *)&vmo, sizeof(vmo))) + if (kread(ctx, ka, (char *)&vmo, sizeof(vmo))) break; - if (!(ka = (KA_T)vmo.pager) || kread(ka, (char *)&pg, sizeof(pg))) + if (!(ka = (KA_T)vmo.pager) || + kread(ctx, ka, (char *)&pg, sizeof(pg))) continue; if (!pg.pg_handle || pg.pg_type != PG_VNODE) continue; diff --git a/lib/dialects/netbsd/dproto.h b/lib/dialects/netbsd/dproto.h index f48e72c3..897b1559 100644 --- a/lib/dialects/netbsd/dproto.h +++ b/lib/dialects/netbsd/dproto.h @@ -35,19 +35,19 @@ */ #if !defined(N_UNIX) -_PROTOTYPE(extern char *get_nlist_path, (int ap)); +extern char *get_nlist_path(struct lsof_context *ctx, int ap); #endif /* !defined(N_UNIX) */ -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern struct l_vfs *readvfs, (KA_T vm)); +extern int is_file_named(struct lsof_context *ctx, char *p, int cd); +extern struct l_vfs *readvfs(struct lsof_context *ctx, KA_T vm); #if defined(HAS_SYS_PIPEH) -_PROTOTYPE(extern void process_pipe, (KA_T pa)); +extern void process_pipe(struct lsof_context *ctx, KA_T pa); #endif /* defined(HAS_SYS_PIPEH) */ #if defined(HAS9660FS) -_PROTOTYPE(extern int read_iso_node, (struct vnode * v, dev_t *d, - INODETYPE *ino, long *nl, SZOFFTYPE *sz)); +extern int read_iso_node(struct lsof_context *ctx, struct vnode *v, dev_t *d, + INODETYPE *ino, long *nl, SZOFFTYPE *sz); #endif /* defined(HAS9660FS) */ -_PROTOTYPE(extern void process_socket, (KA_T sa)); +extern void process_socket(struct lsof_context *ctx, KA_T sa); diff --git a/lib/dialects/netbsd/dsock.c b/lib/dialects/netbsd/dsock.c index 0faeb636..79977c45 100644 --- a/lib/dialects/netbsd/dsock.c +++ b/lib/dialects/netbsd/dsock.c @@ -49,7 +49,8 @@ static char copyright[] = * process_socket() - process socket */ -void process_socket(sa) KA_T sa; /* socket address in kernel */ +void process_socket(struct lsof_context *ctx, /* context */ + KA_T sa) /* socket address in kernel */ { #if NETBSDV >= 9099104 # define NETBSD_MERGED_INPCB @@ -97,29 +98,29 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read the socket, protocol, and domain structures. */ if (!sa) { - enter_nm("no socket address"); + enter_nm(ctx, "no socket address"); return; } - if (kread(sa, (char *)&s, sizeof(s))) { + if (kread(ctx, sa, (char *)&s, sizeof(s))) { (void)snpf(Namech, Namechl, "can't read socket struct from %s", print_kptr(sa, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } if (!s.so_type) { - enter_nm("no socket type"); + enter_nm(ctx, "no socket type"); return; } - if (!s.so_proto || kread((KA_T)s.so_proto, (char *)&p, sizeof(p))) { + if (!s.so_proto || kread(ctx, (KA_T)s.so_proto, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl, "can't read protocol switch from %s", print_kptr((KA_T)s.so_proto, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } - if (!p.pr_domain || kread((KA_T)p.pr_domain, (char *)&d, sizeof(d))) { + if (!p.pr_domain || kread(ctx, (KA_T)p.pr_domain, (char *)&d, sizeof(d))) { (void)snpf(Namech, Namechl, "can't read domain struct from %s", print_kptr((KA_T)p.pr_domain, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -194,18 +195,18 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read IPv6 protocol control block. */ if (!s.so_pcb || - kread((KA_T)s.so_pcb, (char *)&in6p, sizeof(in6p))) { + kread(ctx, (KA_T)s.so_pcb, (char *)&in6p, sizeof(in6p))) { (void)snpf(Namech, Namechl, "can't read in6pcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* * Save IPv6 address information. */ - enter_dev_ch( - print_kptr((KA_T)(in6p.in6p_ppcb ? in6p.in6p_ppcb : s.so_pcb), - (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)(in6p.in6p_ppcb ? in6p.in6p_ppcb + : s.so_pcb), + (char *)NULL, 0)); if (p.pr_protocol == IPPROTO_TCP) ta = (KA_T)in6p.in6p_ppcb; # ifdef NETBSD_MERGED_INPCB @@ -232,7 +233,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ /* * Read IPv4 or IPv6 (NetBSD) protocol control block. */ - if (!s.so_pcb || kread((KA_T)s.so_pcb, (char *)&inp, sizeof(inp))) { + if (!s.so_pcb || + kread(ctx, (KA_T)s.so_pcb, (char *)&inp, sizeof(inp))) { if (!s.so_pcb) { (void)snpf( Namech, Namechl, "no PCB%s%s", @@ -242,7 +244,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ (void)snpf(Namech, Namechl, "can't read inpcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); } - enter_nm(Namech); + enter_nm(ctx, Namech); return; } #ifdef NETBSD_MERGED_INPCB @@ -250,8 +252,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ # define inp_lport in4p_pcb.inp_lport #endif enter_dev_ch( - print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb : s.so_pcb), - (char *)NULL, 0)); + ctx, print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb : s.so_pcb), + (char *)NULL, 0)); if (p.pr_protocol == IPPROTO_TCP) ta = (KA_T)inp.inp_ppcb; lp = (int)ntohs(inp.inp_lport); @@ -312,12 +314,12 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Enter local and remote addresses by address family. */ if (fa || la) - (void)ent_inaddr(la, lp, fa, fp, fam); + (void)ent_inaddr(ctx, la, lp, fa, fp, fam); /* * If the protocol is TCP, and its address is available, read the * TCP protocol control block and save its state. */ - if (ta && !kread(ta, (char *)&t, sizeof(t))) { + if (ta && !kread(ctx, ta, (char *)&t, sizeof(t))) { Lf->lts.type = 0; Lf->lts.state.i = (int)t.t_state; @@ -335,7 +337,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ case AF_ROUTE: (void)snpf(Lf->type, sizeof(Lf->type), "rte"); if (s.so_pcb) - enter_dev_ch(print_kptr((KA_T)(s.so_pcb), (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)(s.so_pcb), (char *)NULL, 0)); else (void)snpf(Namech, Namechl, "no protocol control block"); break; @@ -350,8 +352,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ * Read Unix protocol control block and the Unix address structure. */ - enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); - if (kread((KA_T)s.so_pcb, (char *)&unp, sizeof(unp))) { + enter_dev_ch(ctx, print_kptr(sa, (char *)NULL, 0)); + if (kread(ctx, (KA_T)s.so_pcb, (char *)&unp, sizeof(unp))) { (void)snpf(Namech, Namechl, "can't read unpcb at %s", print_kptr((KA_T)s.so_pcb, (char *)NULL, 0)); break; @@ -364,9 +366,9 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if (unp.unp_addr) { #if defined(UNPADDR_IN_MBUF) - if (kread((KA_T)unp.unp_addr, (char *)&mb, sizeof(mb))) + if (kread(ctx, (KA_T)unp.unp_addr, (char *)&mb, sizeof(mb))) #else /* !defined(UNPADDR_IN_MBUF) */ - if (kread((KA_T)unp.unp_addr, (char *)&un, sizeof(un))) + if (kread(ctx, (KA_T)unp.unp_addr, (char *)&un, sizeof(un))) #endif /* defined(UNPADDR_IN_MBUF) */ { @@ -397,7 +399,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ if (ua->sun_family != AF_UNIX) { if (ua->sun_family == AF_UNSPEC) { if (unp.unp_conn) { - if (kread((KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) + if (kread(ctx, (KA_T)unp.unp_conn, (char *)&uc, sizeof(uc))) (void)snpf( Namech, Namechl, "can't read unp_conn at %s", print_kptr((KA_T)unp.unp_conn, (char *)NULL, 0)); @@ -422,7 +424,7 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ ua->sun_path[sizeof(ua->sun_path) - 1] = '\0'; #endif /* defined(UNPADDR_IN_MBUF) */ - if (Sfile && is_file_named(ua->sun_path, 0)) + if (Sfile && is_file_named(ctx, ua->sun_path, 0)) Lf->sf |= SELNM; if (!Namech[0]) (void)snpf(Namech, Namechl, "%s", ua->sun_path); @@ -430,8 +432,8 @@ void process_socket(sa) KA_T sa; /* socket address in kernel */ (void)snpf(Namech, Namechl, "no address"); break; default: - printunkaf(fam, 1); + printunkaf(ctx, fam, 1); } if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } diff --git a/lib/dialects/openbsd/dfile.c b/lib/dialects/openbsd/dfile.c index d2b728b8..8ccd83a3 100644 --- a/lib/dialects/openbsd/dfile.c +++ b/lib/dialects/openbsd/dfile.c @@ -38,12 +38,12 @@ static char copyright[] = /* * process_kqueue() -- process kqueue file */ -void process_kqueue_file(struct kinfo_file *file) { +void process_kqueue_file(struct lsof_context *ctx, struct kinfo_file *file) { char buf[64]; int flag; /* Alloc Lf and set fd */ - alloc_lfile(NULL, file->fd_fd); + alloc_lfile(ctx, NULL, file->fd_fd); /* Fill type name*/ (void)snpf(Lf->type, sizeof(Lf->type), "KQUEUE"); @@ -51,7 +51,7 @@ void process_kqueue_file(struct kinfo_file *file) { /* Fill dev with f_data if available */ if (file->f_data) { (void)snpf(buf, sizeof(buf), "0x%" PRIx64, file->f_data); - enter_dev_ch(buf); + enter_dev_ch(ctx, buf); } /* @@ -66,10 +66,10 @@ void process_kqueue_file(struct kinfo_file *file) { /* Finish */ if (Lf->sf) - link_lfile(); + link_lfile(ctx); } /* * process_pipe() - process a file structure whose type is DTYPE_PIPE */ -void process_pipe(struct kinfo_file *file) {} \ No newline at end of file +void process_pipe(struct lsof_context *ctx, struct kinfo_file *file) {} \ No newline at end of file diff --git a/lib/dialects/openbsd/dmnt.c b/lib/dialects/openbsd/dmnt.c index 9574eca5..50949865 100644 --- a/lib/dialects/openbsd/dmnt.c +++ b/lib/dialects/openbsd/dmnt.c @@ -45,7 +45,7 @@ static int Lmist = 0; /* Lmi status */ /* * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char *dn = (char *)NULL; char *ln; struct mounts *mtp; @@ -84,9 +84,9 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(mb->f_mntfromname, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } - if ((ln = Readlink(dn)) == NULL) { + if ((ln = Readlink(ctx, dn)) == NULL) { if (!Fwarn) { (void)fprintf(stderr, " Output information may be incomplete.\n"); @@ -102,7 +102,7 @@ struct mounts *readmnt() { /* * Stat() the directory. */ - if (statsafely(dn, &sb)) { + if (statsafely(ctx, dn, &sb)) { if (!Fwarn) { (void)fprintf(stderr, "%s: WARNING: can't stat() ", Pn); safestrprt(mb->f_fstypename, stderr, 0); @@ -141,13 +141,13 @@ struct mounts *readmnt() { if (!(dn = mkstrcpy(mb->f_mntfromname, (MALLOC_S *)NULL))) goto no_space_for_mount; mtp->fsname = dn; - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat() the file system (mounted-on) name and add file system * information to the local mount table entry. */ - if (!ln || statsafely(ln, &sb)) + if (!ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mtp->fsnmres = ln; mtp->fs_mode = sb.st_mode; diff --git a/lib/dialects/openbsd/dnode.c b/lib/dialects/openbsd/dnode.c index 5f220629..8ac05afd 100644 --- a/lib/dialects/openbsd/dnode.c +++ b/lib/dialects/openbsd/dnode.c @@ -38,7 +38,7 @@ static char copyright[] = /* * process_vnode() - process vnode */ -void process_vnode(struct kinfo_file *file) { +void process_vnode(struct lsof_context *ctx, struct kinfo_file *file) { char *nm = NULL; int num = -1; uint32_t flag; @@ -63,7 +63,7 @@ void process_vnode(struct kinfo_file *file) { num = file->fd_fd; break; } - alloc_lfile(nm, num); + alloc_lfile(ctx, nm, num); if (file->fd_fd == KERN_FILE_CDIR) { /* @@ -76,7 +76,7 @@ void process_vnode(struct kinfo_file *file) { size = sizeof(path); if (sysctl(mib, 3, path, &size, NULL, 0) >= 0) { (void)snpf(Namech, Namechl, "%s", path); - enter_nm(Namech); + enter_nm(ctx, Namech); } } @@ -152,11 +152,11 @@ void process_vnode(struct kinfo_file *file) { /* Handle name match, must be done late, because if_file_named checks * Lf->dev etc. */ - if (is_file_named(nm, 0)) { + if (is_file_named(ctx, nm, 0)) { Lf->sf |= SELNM; } /* Finish */ if (Lf->sf) - link_lfile(); + link_lfile(ctx); } diff --git a/lib/dialects/openbsd/dproc.c b/lib/dialects/openbsd/dproc.c index 76959078..5038f796 100644 --- a/lib/dialects/openbsd/dproc.c +++ b/lib/dialects/openbsd/dproc.c @@ -35,7 +35,8 @@ static char copyright[] = #include "common.h" -_PROTOTYPE(static void process_kinfo_file, (struct kinfo_file * file)); +static void process_kinfo_file(struct lsof_context *ctx, + struct kinfo_file *file); /* * Local static values @@ -44,7 +45,7 @@ _PROTOTYPE(static void process_kinfo_file, (struct kinfo_file * file)); /* * gather_proc_info() -- gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { short pss, sf; uid_t uid; struct stat st; @@ -85,7 +86,7 @@ void gather_proc_info() { if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) { (void)fprintf(stderr, "%s: can't read process table: %d\n", Pn, errno); - Error(); + Error(ctx); } /* Alloc more to handle new processes in the meantime */ @@ -99,7 +100,7 @@ void gather_proc_info() { } if (!procs) { (void)fprintf(stderr, "%s: no kinfo_proc * space\n", Pn); - Error(); + Error(ctx); } mib[5] = size / sizeof(struct kinfo_proc); /* elem_count */ @@ -110,7 +111,7 @@ void gather_proc_info() { } else if (res < 0 && errno != ENOMEM) { (void)fprintf(stderr, "%s: can't read process table: %d\n", Pn, errno); - Error(); + Error(ctx); } }; @@ -130,18 +131,19 @@ void gather_proc_info() { * Read file structure pointers. */ uid = proc->p_uid; - if (is_proc_excl((int)proc->p_pid, (int)proc->p__pgid, (UID_ARG)uid, - &pss, &sf)) { + if (is_proc_excl(ctx, (int)proc->p_pid, (int)proc->p__pgid, + (UID_ARG)uid, &pss, &sf)) { continue; } /* * Allocate a local process structure. */ - if (is_cmd_excl(proc->p_comm, &pss, &sf)) + if (is_cmd_excl(ctx, proc->p_comm, &pss, &sf)) continue; - alloc_lproc((int)proc->p_pid, (int)proc->p__pgid, (int)proc->p_ppid, - (UID_ARG)uid, proc->p_comm, (int)pss, (int)sf); + alloc_lproc(ctx, (int)proc->p_pid, (int)proc->p__pgid, + (int)proc->p_ppid, (UID_ARG)uid, proc->p_comm, (int)pss, + (int)sf); Plf = (struct lfile *)NULL; /* Empty list head */ /* @@ -164,7 +166,7 @@ void gather_proc_info() { if (sysctl(mib, 6, NULL, &size, NULL, 0) < 0) { (void)fprintf(stderr, "%s: can't read file table: %d\n", Pn, errno); - Error(); + Error(ctx); } /* Alloc more to handle new processes in the meantime */ @@ -178,7 +180,7 @@ void gather_proc_info() { } if (!files) { (void)fprintf(stderr, "%s: no kinfo_file * space\n", Pn); - Error(); + Error(ctx); } mib[5] = size / sizeof(struct kinfo_file); /* elem_count */ @@ -189,18 +191,18 @@ void gather_proc_info() { } else if (res < 0 && errno != ENOMEM) { (void)fprintf(stderr, "%s: can't read file table: %d\n", Pn, errno); - Error(); + Error(ctx); } }; for (file = files, fx = 0; fx < num_files; fx++, file++) { - process_kinfo_file(file); + process_kinfo_file(ctx, file); } /* * Examine results. */ - if (examine_lproc()) + if (examine_lproc(ctx)) return; } } @@ -208,24 +210,24 @@ void gather_proc_info() { /* * initialize() - perform all initialization */ -void initialize() {} +void initialize(struct lsof_context *ctx) {} /* * process_kinfo_file() - process kinfo_file */ -void process_kinfo_file(struct kinfo_file *file) { +void process_kinfo_file(struct lsof_context *ctx, struct kinfo_file *file) { switch (file->f_type) { case DTYPE_VNODE: /* file */ - process_vnode(file); + process_vnode(ctx, file); break; case DTYPE_SOCKET: - process_socket(file); + process_socket(ctx, file); break; case DTYPE_PIPE: - process_pipe(file); + process_pipe(ctx, file); break; case DTYPE_KQUEUE: - process_kqueue_file(file); + process_kqueue_file(ctx, file); break; } } \ No newline at end of file diff --git a/lib/dialects/openbsd/dproto.h b/lib/dialects/openbsd/dproto.h index 19f070e6..138ca13a 100644 --- a/lib/dialects/openbsd/dproto.h +++ b/lib/dialects/openbsd/dproto.h @@ -34,9 +34,10 @@ * $Id: dproto.h,v 1.11 2005/08/08 19:53:24 abe Exp $ */ -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); +extern int is_file_named(struct lsof_context *ctx, char *p, int cd); -_PROTOTYPE(extern void process_vnode, (struct kinfo_file * file)); -_PROTOTYPE(extern void process_socket, (struct kinfo_file * file)); -_PROTOTYPE(extern void process_pipe, (struct kinfo_file * file)); -_PROTOTYPE(extern void process_kqueue_file, (struct kinfo_file * file)); +extern void process_vnode(struct lsof_context *ctx, struct kinfo_file *file); +extern void process_socket(struct lsof_context *ctx, struct kinfo_file *file); +extern void process_pipe(struct lsof_context *ctx, struct kinfo_file *file); +extern void process_kqueue_file(struct lsof_context *ctx, + struct kinfo_file *file); diff --git a/lib/dialects/openbsd/dsock.c b/lib/dialects/openbsd/dsock.c index e27d1e89..f43ff9f9 100644 --- a/lib/dialects/openbsd/dsock.c +++ b/lib/dialects/openbsd/dsock.c @@ -38,7 +38,7 @@ static char copyright[] = /* * process_socket() - process socket */ -void process_socket(struct kinfo_file *file) { +void process_socket(struct lsof_context *ctx, struct kinfo_file *file) { char *type_name = NULL; char *proto = NULL; char *type = NULL; @@ -47,7 +47,7 @@ void process_socket(struct kinfo_file *file) { uint32_t lport, fport; /* Alloc Lf and set fd */ - alloc_lfile(NULL, file->fd_fd); + alloc_lfile(ctx, NULL, file->fd_fd); /* Type name */ switch (file->so_family) { @@ -113,12 +113,12 @@ void process_socket(struct kinfo_file *file) { lport = ntohs(file->inp_lport); fport = ntohs(file->inp_fport); if (file->inp_fport) { - ent_inaddr((unsigned char *)file->inp_laddru, lport, + ent_inaddr(ctx, (unsigned char *)file->inp_laddru, lport, (unsigned char *)file->inp_faddru, fport, file->so_family); } else { /* No foreign address on LISTEN sockets */ - ent_inaddr((unsigned char *)file->inp_laddru, lport, NULL, 0, + ent_inaddr(ctx, (unsigned char *)file->inp_laddru, lport, NULL, 0, file->so_family); } @@ -131,11 +131,11 @@ void process_socket(struct kinfo_file *file) { /* Fill dev with pcb if available */ if (file->inp_ppcb) { (void)snpf(buf, sizeof(buf), "0x%" PRIx64, file->inp_ppcb); - enter_dev_ch(buf); + enter_dev_ch(ctx, buf); } else if (file->so_pcb && file->so_pcb != (uint64_t)(-1)) { /* when running as non-root, -1 means not NULL */ (void)snpf(buf, sizeof(buf), "0x%" PRIx64, file->so_pcb); - enter_dev_ch(buf); + enter_dev_ch(ctx, buf); } } else if (file->so_family == AF_UNIX) { /* Show this entry if requested */ @@ -143,7 +143,7 @@ void process_socket(struct kinfo_file *file) { if (Funix) Lf->sf |= SELUNX; /* Name matches */ - if (is_file_named(file->unp_path, 0)) { + if (is_file_named(ctx, file->unp_path, 0)) { Lf->sf |= SELNM; } @@ -163,7 +163,7 @@ void process_socket(struct kinfo_file *file) { (void)snpf(Namech, Namechl, "%s%stype=%s", file->unp_path[0] ? file->unp_path : "", file->unp_path[0] ? " " : "", type); - (void)enter_nm(Namech); + (void)enter_nm(ctx, Namech); /* Fill TCP state */ if (file->so_type == SOCK_STREAM) { @@ -174,17 +174,17 @@ void process_socket(struct kinfo_file *file) { /* Fill dev with so_pcb if available */ if (file->so_pcb && file->so_pcb != (uint64_t)(-1)) { (void)snpf(buf, sizeof(buf), "0x%" PRIx64, file->so_pcb); - enter_dev_ch(buf); + enter_dev_ch(ctx, buf); } } else if (file->so_family == AF_ROUTE) { /* Fill dev with f_data if available */ if (file->f_data) { (void)snpf(buf, sizeof(buf), "0x%" PRIx64, file->f_data); - enter_dev_ch(buf); + enter_dev_ch(ctx, buf); } } /* Finish */ if (Lf->sf) - link_lfile(); + link_lfile(ctx); } diff --git a/lib/dialects/osr/dfile.c b/lib/dialects/osr/dfile.c index 1f86f50a..8169f345 100644 --- a/lib/dialects/osr/dfile.c +++ b/lib/dialects/osr/dfile.c @@ -62,9 +62,8 @@ int get_max_fd() { * print_dev() - print dev */ -char *print_dev(lf, dev) -struct lfile *lf; /* file whose device is to be printed */ -dev_t *dev; /* device to be printed */ +char *print_dev(struct lfile *lf, /* file whose device is to be printed */ + dev_t *dev) /* device to be printed */ { static char buf[128]; @@ -78,8 +77,7 @@ dev_t *dev; /* device to be printed */ * print_ino() - print inode */ -char *print_ino(lf) -struct lfile *lf; /* file whose device is to be printed */ +char *print_ino(struct lfile *lf) /* file whose device is to be printed */ { static char buf[128]; @@ -97,7 +95,7 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ struct file f; int flag; - if (kread(fp, (char *)&f, sizeof(f))) { + if (kread(ctx, fp, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "can't read file struct from %s", print_kptr(fp, (char *)NULL, 0)); enter_nm(Namech); diff --git a/lib/dialects/osr/dmnt.c b/lib/dialects/osr/dmnt.c index 95288566..202aa7b2 100644 --- a/lib/dialects/osr/dmnt.c +++ b/lib/dialects/osr/dmnt.c @@ -65,7 +65,7 @@ struct mounts *readmnt() { */ if ((fd = open(MNTTAB, O_RDONLY, 0)) < 0) { (void)fprintf(stderr, "%s: can't open %s\n", Pn, MNTTAB); - Error(); + Error(ctx); } /* * Read the first mount table entry. @@ -154,7 +154,7 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(dvnm, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } } /* diff --git a/lib/dialects/osr/dnode.c b/lib/dialects/osr/dnode.c index 30ff6c4b..3abe346f 100644 --- a/lib/dialects/osr/dnode.c +++ b/lib/dialects/osr/dnode.c @@ -35,17 +35,15 @@ static char copyright[] = #include "common.h" -_PROTOTYPE(static struct l_dev *finddev, - (dev_t * dev, dev_t *rdev, int stream)); +static struct l_dev *finddev(dev_t *dev, dev_t *rdev, int stream); /* * finddev() - look up device by device number */ -static struct l_dev *finddev(dev, rdev, stream) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ -int stream; /* stream if 1 */ +static struct l_dev *finddev(dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int stream) /* stream if 1 */ { struct clone *c; struct l_dev *dp; @@ -231,7 +229,7 @@ void process_node(na) KA_T na; /* inode kernel space address */ if ((flf = (KA_T)i.i_filocks)) { flp = flf; do { - if ((kread(flp, (char *)&fl, sizeof(fl)))) + if ((kread(ctx, flp, (char *)&fl, sizeof(fl)))) break; if (fl.set.l_pid != (pid_t)Lp->pid) continue; @@ -266,7 +264,7 @@ void process_node(na) KA_T na; /* inode kernel space address */ hpps = 1; if (i.i_fsptr) { enter_dev_ch(print_kptr((KA_T)i.i_fsptr, (char)NULL, 0)); - if (kread((KA_T)i.i_fsptr, (char *)&pi, sizeof(pi)) == 0) + if (kread(ctx, (KA_T)i.i_fsptr, (char *)&pi, sizeof(pi)) == 0) hpps = 2; } } @@ -327,20 +325,20 @@ void process_node(na) KA_T na; /* inode kernel space address */ * cdevsw[].d_name. */ p = (KA_T)NULL; - if (!kread((KA_T)i.i_sptr, (char *)&sd, sizeof(sd))) { + if (!kread(ctx, (KA_T)i.i_sptr, (char *)&sd, sizeof(sd))) { dl = sizeof(tbuf) - 1; tbuf[dl] = '\0'; qp = (KA_T)sd.sd_wrq; for (j = 0; qp && j < 20; j++, qp = (KA_T)q.q_next) { - if (kread(qp, (char *)&q, sizeof(q))) + if (kread(ctx, qp, (char *)&q, sizeof(q))) break; if (!(ka = (KA_T)q.q_qinfo) || - kread(ka, (char *)&qi, sizeof(qi))) + kread(ctx, ka, (char *)&qi, sizeof(qi))) continue; if (!(ka = (KA_T)qi.qi_minfo) || - kread(ka, (char *)&mi, sizeof(mi))) + kread(ctx, ka, (char *)&mi, sizeof(mi))) continue; - if (!(ka = (KA_T)mi.mi_idname) || kread(ka, tbuf, dl)) + if (!(ka = (KA_T)mi.mi_idname) || kread(ctx, ka, tbuf, dl)) continue; if ((l = strlen(tbuf)) < 1) continue; @@ -388,7 +386,7 @@ void process_node(na) KA_T na; /* inode kernel space address */ * If the stream has a TCP or UDP module with a PCB pointer, * print any associated local and foreign Internet addresses. */ - if (kread(p, (char *)&pcb, sizeof(pcb))) + if (kread(ctx, p, (char *)&pcb, sizeof(pcb))) break; if (Fnet) Lf->sf |= SELNET; @@ -400,8 +398,8 @@ void process_node(na) KA_T na; /* inode kernel space address */ * If this is a UDP stream, get the udpdev structure at the * PCB's per-protocol address. It may contain addresses. */ - if (kread((KA_T)pcb.inp_ppcb, (char *)&udp, sizeof(udp)) == - 0) { + if (kread(ctx, (KA_T)pcb.inp_ppcb, (char *)&udp, + sizeof(udp)) == 0) { #if OSRV >= 500 if (udp.ud_lsin.sin_addr.s_addr != INADDR_ANY || diff --git a/lib/dialects/osr/dproc.c b/lib/dialects/osr/dproc.c index ba0e6e6f..157fa613 100644 --- a/lib/dialects/osr/dproc.c +++ b/lib/dialects/osr/dproc.c @@ -52,16 +52,16 @@ static int Prsz = 0; /* size of Pr */ static struct var Var; /* kernel variables */ -_PROTOTYPE(static void get_cdevsw, (void)); -_PROTOTYPE(static void get_kernel_access, (void)); +static void get_cdevsw(void); +static void get_kernel_access(void); #if !defined(N_UNIX) -_PROTOTYPE(static int is_boot, (char *p)); +static int is_boot(char *p); #endif /* !defined(N_UNIX) */ -_PROTOTYPE(static int open_kmem, (int nx)); -_PROTOTYPE(static void process_text, (KA_T prp)); -_PROTOTYPE(static void readfsinfo, (void)); +static int open_kmem(int nx); +static void process_text(KA_T prp); +static void readfsinfo(void); /* * Ckkv - check kernel version @@ -84,7 +84,7 @@ char *ea; /* expected architecture */ if (__scoinfo(&s, sizeof(s)) < 0) { (void)fprintf(stderr, "%s: can't get __scoinfo: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } /* * Warn if the actual and expected releases don't match. @@ -126,7 +126,7 @@ void gather_proc_info() { (void)fprintf(stderr, "%s: no space for %d byte user structure buffer\n", Pn, ual); - Error(); + Error(ctx); } u = (struct user *)ua; } @@ -137,7 +137,7 @@ void gather_proc_info() { if (!(pb = (char *)malloc(sizeof(struct proc) * PROCBFRD))) { (void)fprintf(stderr, "%s: no space for %d proc structures\n", Pn, PROCBFRD); - Error(); + Error(ctx); } } /* @@ -152,7 +152,7 @@ void gather_proc_info() { i = Var.v_proc - px; if (i > PROCBFRD) i = PROCBFRD; - j = kread((KA_T)(Kp + (px * sizeof(struct proc))), pb, + j = kread(ctx, (KA_T)(Kp + (px * sizeof(struct proc))), pb, sizeof(struct proc) * i); pbc = px + i; p = (struct proc *)pb; @@ -242,7 +242,7 @@ void gather_proc_info() { } npofb = nf; } - if (kread((KA_T)u->u_pofile, pofb, nf)) + if (kread(ctx, (KA_T)u->u_pofile, pofb, nf)) pof = (char *)NULL; else pof = pofb; @@ -289,7 +289,7 @@ void get_cdevsw() { */ if (get_Nl_value("cdev", Drive_Nl, &v[0]) < 0 || get_Nl_value("ncdev", Drive_Nl, &v[1]) < 0 || !v[0] || !v[1] || - kread(v[1], (char *)&Cdevcnt, sizeof(Cdevcnt)) || Cdevcnt < 1) + kread(ctx, v[1], (char *)&Cdevcnt, sizeof(Cdevcnt)) || Cdevcnt < 1) return; /* * Allocate cache space. @@ -297,7 +297,7 @@ void get_cdevsw() { if (!(Cdevsw = (char **)malloc(Cdevcnt * sizeof(char *)))) { (void)fprintf(stderr, "%s: no space for %d cdevsw[] names\n", Pn, Cdevcnt); - Error(); + Error(ctx); } /* * Allocate temporary space for a copy of cdevsw[] and read it. @@ -306,9 +306,9 @@ void get_cdevsw() { if (!(tmp = (struct cdevsw *)malloc(i))) { (void)fprintf(stderr, "%s: no space for %d cdevsw[] entries\n", Pn, Cdevcnt); - Error(); + Error(ctx); } - if (kread((KA_T)v[0], (char *)tmp, i)) { + if (kread(ctx, (KA_T)v[0], (char *)tmp, i)) { (void)free((FREE_P *)Cdevsw); Cdevsw = (char **)NULL; Cdevcnt = 0; @@ -325,7 +325,7 @@ void get_cdevsw() { Cdevsw[i] = (char *)NULL; if (!c->d_name) continue; - if (kread((KA_T)c->d_name, buf, j)) { + if (kread(ctx, (KA_T)c->d_name, buf, j)) { (void)fprintf(stderr, "%s: WARNING: can't read name for cdevsw[%d]: %#x\n", Pn, i, c->d_name); @@ -337,7 +337,7 @@ void get_cdevsw() { if (!(Cdevsw[i] = (char *)malloc(len))) { (void)fprintf(stderr, "%s: no space for cdevsw[%d] name: %s\n", Pn, i, buf); - Error(); + Error(ctx); } (void)snpf(Cdevsw[i], len, "%s", buf); if (!HaveCloneMajor && strcmp(buf, "clone") == 0) { @@ -371,7 +371,7 @@ static void get_kernel_access() { * See if the name list file is readable. */ if (Nmlst && !is_readable(Nmlst, 1)) - Error(); + Error(ctx); /* * Access kernel symbols. */ @@ -385,7 +385,7 @@ static void get_kernel_access() { { (void)fprintf(stderr, "%s: can't read kernel name list.\n", Pn); - Error(); + Error(ctx); } /* * Open access to kernel memory. @@ -404,7 +404,7 @@ static void get_kernel_access() { */ if (get_Nl_value("proc", Drive_Nl, &Kp) < 0 || !Kp) { (void)fprintf(stderr, "%s: no proc table pointer\n", Pn); - Error(); + Error(ctx); } #if OSRV < 500 @@ -413,16 +413,16 @@ static void get_kernel_access() { */ v = (KA_T)0; if (get_Nl_value("pregpp", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&Npp, sizeof(Npp)) || Npp < 1) { + kread(ctx, v, (char *)&Npp, sizeof(Npp)) || Npp < 1) { (void)fprintf(stderr, "%s: can't read pregion count (%d) from %s\n", Pn, Npp, print_kptr(v, (char *)NULL, 0)); - Error(); + Error(ctx); } Prsz = (MALLOC_S)(Npp * sizeof(struct pregion)); if (!(Pr = (struct pregion *)malloc(Prsz))) { (void)fprintf(stderr, "%s: can't allocate space for %d pregions\n", Pn, Npp); - Error(); + Error(ctx); } #endif /* OSRV< 500 */ @@ -430,23 +430,23 @@ static void get_kernel_access() { * Read system configuration information. */ if (get_Nl_value("var", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&Var, sizeof(Var))) { + kread(ctx, (KA_T)v, (char *)&Var, sizeof(Var))) { (void)fprintf(stderr, "%s: can't read system configuration info\n", Pn); - Error(); + Error(ctx); } /* * Read system clock values -- Hz and lightning bolt timer. */ v = (KA_T)0; if (get_Nl_value("hz", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&Hz, sizeof(Hz))) { + kread(ctx, v, (char *)&Hz, sizeof(Hz))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read Hz from %s\n", Pn, print_kptr(v, (char *)NULL, 0)); Hz = -1; } if (get_Nl_value("lbolt", Drive_Nl, &Lbolt) < 0 || !v || - kread((KA_T)v, (char *)&lbolt, sizeof(lbolt))) { + kread(ctx, (KA_T)v, (char *)&lbolt, sizeof(lbolt))) { if (!Fwarn) (void)fprintf( stderr, @@ -458,7 +458,7 @@ static void get_kernel_access() { * Get socket device number and socket table address. */ if (get_Nl_value("sockd", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&Sockdev, sizeof(Sockdev))) { + kread(ctx, v, (char *)&Sockdev, sizeof(Sockdev))) { (void)fprintf(stderr, "%s: WARNING: can't identify socket device.\n", Pn); (void)fprintf(stderr, " Socket output may be incomplete.\n"); @@ -480,24 +480,24 @@ static void get_kernel_access() { */ v = (KA_T)0; if (get_Nl_value("nxdm", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&nxdevmaps, sizeof(nxdevmaps)) || nxdevmaps < 0) { + kread(ctx, v, (char *)&nxdevmaps, sizeof(nxdevmaps)) || nxdevmaps < 0) { (void)fprintf(stderr, "%s: bad extended device table size (%d) at %s.\n", Pn, nxdevmaps, print_kptr(v, (char *)NULL, 0)); - Error(); + Error(ctx); } len = (MALLOC_S)((nxdevmaps + 1) * sizeof(struct XDEVMAP)); if (!(Xdevmap = (struct XDEVMAP *)malloc(len))) { (void)fprintf(stderr, "%s: no space for %d byte xdevmap table\n", Pn, len); - Error(); + Error(ctx); } v = (KA_T)0; if (get_Nl_value("xdm", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)Xdevmap, len)) { + kread(ctx, (KA_T)v, (char *)Xdevmap, len)) { (void)fprintf(stderr, "%s: can't read %d byte xdevmap table at #x\n", Pn, len, v); - Error(); + Error(ctx); } #endif /* OSRV>=40 */ @@ -512,11 +512,10 @@ static void get_kernel_access() { * boot path's name list will have been loaded into Nl[]. */ -char *get_nlist_path(ap) -int ap; /* on success, return an allocated path - * string pointer if 1; return a - * constant character pointer if 0; - * return NULL if failure */ +char *get_nlist_path(int ap) /* on success, return an allocated path + * string pointer if 1; return a + * constant character pointer if 0; + * return NULL if failure */ { FILE *bf; char *bfp, b1[MAXPATHLEN + 1], b2[MAXPATHLEN + 1], *pp, *tp; @@ -601,7 +600,7 @@ int ap; /* on success, return an allocated path (void)fprintf(stderr, "%s: can't allocate %d bytes for: %s\n", Pn, len, pp); - Error(); + Error(ctx); } (void)snpf(tp, len, "%s", pp); return (tp); @@ -641,7 +640,7 @@ is_boot(p) char *p; /* specified path */ } s1, s2; /* * Get the scoutsname structure via __scoinfo() to use as a reference - * against the one obtained via kread()'ing from the + * against the one obtained via kread(ctx, )'ing from the * nlist() address. If __scoinfo() fails, return the * default boot path. */ @@ -665,7 +664,7 @@ is_boot(p) char *p; /* specified path */ if (open_kmem(1)) return (0); } - if (kread(ka, (char *)&s2.s, sizeof(s2.s))) + if (kread(ctx, ka, (char *)&s2.s, sizeof(s2.s))) return (0); for (i = 0; i < sizeof(struct scoutsname); i++) { if (s1.sc[i] != s2.sc[i]) @@ -679,10 +678,10 @@ is_boot(p) char *p; /* specified path */ * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, /* context */ + KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { int br; @@ -697,8 +696,7 @@ READLEN_T len; /* length to read */ * open_kmem() - open kernel memory access */ -static int open_kmem(nx) -int nx; /* no Error() if 1 */ +static int open_kmem(int nx) /* no Error(ctx) if 1 */ { if (Kd >= 0) return (0); @@ -708,7 +706,7 @@ int nx; /* no Error() if 1 */ if (Memory && !is_readable(Memory, 1)) { if (nx) return (1); - Error(); + Error(ctx); } /* * Open kernel memory access. @@ -718,7 +716,7 @@ int nx; /* no Error() if 1 */ return (1); (void)fprintf(stderr, "%s: can't open %s: %s\n", Pn, Memory ? Memory : KMEM, strerror(errno)); - Error(); + Error(ctx); } return (0); } @@ -745,7 +743,7 @@ static void process_text(prp) KA_T prp; /* process region pointer */ */ #if OSRV < 500 - if (kread(prp, (char *)Pr, Prsz)) + if (kread(ctx, prp, (char *)Pr, Prsz)) return; for (i = j = 0, p = Pr; i < Npp; i++, p++) #else /* OSRV>=500 */ @@ -765,7 +763,7 @@ static void process_text(prp) KA_T prp; /* process region pointer */ Pn, Lp->pid); return; } - if ((i && pc == prp) || kread((KA_T)pc, (char *)p, sizeof(ps))) + if ((i && pc == prp) || kread(ctx, (KA_T)pc, (char *)p, sizeof(ps))) return; #endif /* OSRV>=500 */ @@ -775,7 +773,7 @@ static void process_text(prp) KA_T prp; /* process region pointer */ * Read the region. * Skip entries with no node pointers and duplicate node addresses. */ - if (kread((KA_T)p->p_reg, (char *)&r, sizeof(r))) + if (kread(ctx, (KA_T)p->p_reg, (char *)&r, sizeof(r))) continue; if (!(na = (KA_T)r.r_iptr)) continue; @@ -792,7 +790,7 @@ static void process_text(prp) KA_T prp; /* process region pointer */ if (!(Nc = (KA_T *)malloc((MALLOC_S)(sizeof(KA_T) * 10)))) { (void)fprintf(stderr, "%s: no txt ptr space, PID %d\n", Pn, Lp->pid); - Error(); + Error(ctx); } Nn = 10; } else if (j >= Nn) { @@ -801,7 +799,7 @@ static void process_text(prp) KA_T prp; /* process region pointer */ (MALLOC_S)(Nn * sizeof(KA_T))))) { (void)fprintf(stderr, "%s: no more txt ptr space, PID %d\n", Pn, Lp->pid); - Error(); + Error(ctx); } } Nc[j++] = na; @@ -850,26 +848,26 @@ static void readfsinfo() { if ((Fsinfomax = sysfs(GETNFSTYP)) == -1) { (void)fprintf(stderr, "%s: sysfs(GETNFSTYP) error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (Fsinfomax == 0) return; if (!(Fsinfo = (char **)malloc((MALLOC_S)(Fsinfomax * sizeof(char *))))) { (void)fprintf(stderr, "%s: no space for sysfs info\n", Pn); - Error(); + Error(ctx); } for (i = 1; i <= Fsinfomax; i++) { if (sysfs(GETFSTYP, i, buf) == -1) { (void)fprintf(stderr, "%s: sysfs(GETFSTYP) error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } buf[FSTYPSZ] = '\0'; len = strlen(buf) + 1; if (!(Fsinfo[i - 1] = (char *)malloc((MALLOC_S)len))) { (void)fprintf(stderr, "%s: no space for file system entry %s\n", Pn, buf); - Error(); + Error(ctx); } (void)snpf(Fsinfo[i - 1], len, "%s", buf); } @@ -988,38 +986,36 @@ static struct lnch *LNC_nc = (struct lnch *)NULL; * Local function prototypes */ -_PROTOTYPE(static struct lnch *DIN_addr, (dev_t * d, unsigned long i)); +static struct lnch *DIN_addr(dev_t *d, unsigned long i); # if OSRV >= 500 # if OSRV >= 504 -_PROTOTYPE(static void DNLC_load, ()); +static void DNLC_load(); # else /* OSRV<504 */ -_PROTOTYPE(static void DTFS_load, ()); -_PROTOTYPE(static void HTFS_load, ()); +static void DTFS_load(); +static void HTFS_load(); # endif /* OSRV>=504 */ # endif /* OSRV>=500 */ -_PROTOTYPE(static int LNC_enter, - (struct lnch * le, char *nm, int nl, char *fs)); -_PROTOTYPE(static void LNC_nosp, (int len)); +static int LNC_enter(struct lnch *le, char *nm, int nl, char *fs); +static void LNC_nosp(int len); # if defined(HAS_NFS) -_PROTOTYPE(static struct lnch *NFS_addr, (KA_T r)); -_PROTOTYPE(static void NFS_load, (void)); -_PROTOTYPE(static int NFS_root, (KA_T r)); +static struct lnch *NFS_addr(KA_T r); +static void NFS_load(void); +static int NFS_root(KA_T r); # endif /* defined(HAS_NFS) */ # if OSRV < 504 -_PROTOTYPE(static void SYSV_load, ()); +static void SYSV_load(); # endif /* OSRV<504 */ /* * DIN_addr() - look up a node's local device-inode address */ -static struct lnch *DIN_addr(d, i) -dev_t *d; /* device number */ -unsigned long i; /* inode number */ +static struct lnch *DIN_addr(dev_t *d, /* device number */ + unsigned long i) /* inode number */ { struct lnch_hh *hh = DIN_hash(*d, i); struct lnch *lc = hh->hp[0]; @@ -1075,14 +1071,14 @@ static void DNLC_load() { * get the array's address. If that fails, return without comment * and without further action. */ - if (kread(ka, (char *)&ka, sizeof(ka))) + if (kread(ctx, ka, (char *)&ka, sizeof(ka))) return; } /* * Get the kernel's DNLC name cache size. */ if (get_Nl_value("ndnlc", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&dnlce, sizeof(dnlce)) || dnlce < 1) + kread(ctx, v, (char *)&dnlce, sizeof(dnlce)) || dnlce < 1) return; /* * Allocate space for a copy of a portion ("chunk") of the kernel's @@ -1095,7 +1091,7 @@ static void DNLC_load() { "%s: can't allocate %d bytes for DNLC chunk\n", Pn, chl); cha = 0; - Error(); + Error(ctx); } } /* @@ -1116,7 +1112,7 @@ static void DNLC_load() { */ ccs = ((dnlce - i) < cha) ? (dnlce - i) : cha; ccl = sizeof(struct dnlc__cachent) * ccs; - if (kread((KA_T)wa, (char *)dnlc, ccl)) + if (kread(ctx, (KA_T)wa, (char *)dnlc, ccl)) break; /* * Process the "chunk". @@ -1178,7 +1174,7 @@ static void DTFS_load() { * Get the kernel's DTFS name cache size. */ if (get_Nl_value("ndtnc", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&dtnce, sizeof(dtnce)) || dtnce < 1) + kread(ctx, v, (char *)&dtnce, sizeof(dtnce)) || dtnce < 1) return; /* * Allocate space for a copy of the kernel's DTFS name cache. @@ -1188,13 +1184,13 @@ static void DTFS_load() { (void)fprintf(stderr, "%s: can't allocate %d bytes for DTFS name cache\n", Pn, kcl); - Error(); + Error(ctx); } } /* * Read the kernel's DTFS name cache. */ - if (!dtnc || !kcl || !ka || kread(ka, (char *)dtnc, kcl)) + if (!dtnc || !kcl || !ka || kread(ctx, ka, (char *)dtnc, kcl)) return; /* * Build a local copy of the kernel's DTFS name cache. @@ -1255,7 +1251,7 @@ static void HTFS_load() { * Get the kernel's HTFS name cache size. */ if (get_Nl_value("nhtnc", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&htnce, sizeof(htnce)) || htnce < 1) + kread(ctx, v, (char *)&htnce, sizeof(htnce)) || htnce < 1) return; /* * Allocate space for a copy of the kernel's HTFS name cache. @@ -1265,13 +1261,13 @@ static void HTFS_load() { (void)fprintf(stderr, "%s: can't allocate %d bytes for HTFS name cache\n", Pn, kcl); - Error(); + Error(ctx); } } /* * Read the kernel's HTFS name cache. */ - if (!htnc || !kcl || !ka || kread(ka, (char *)htnc, kcl)) + if (!htnc || !kcl || !ka || kread(ctx, ka, (char *)htnc, kcl)) return; /* * Build a local copy of the kernel's HTFS name cache. @@ -1309,11 +1305,10 @@ static void HTFS_load() { * LNC_enter() - make a local name cache entry */ -static int LNC_enter(le, nm, nl, fs) -struct lnch *le; /* skeleton local entry */ -char *nm; /* name */ -int nl; /* name length */ -char *fs; /* file system name */ +static int LNC_enter(struct lnch *le, /* skeleton local entry */ + char *nm, /* name */ + int nl, /* name length */ + char *fs) /* file system name */ { struct lnch *lc; MALLOC_S len; @@ -1325,7 +1320,7 @@ char *fs; /* file system name */ (void)fprintf( stderr, "%s: no more space for %d byte local name cache: %s\n", Pn, len, fs); - Error(); + Error(ctx); } } lc = &LNC_nc[LNC_csz]; @@ -1374,7 +1369,7 @@ static void LNC_nosp(len) int len; /* attempted length */ if (!Fwarn) (void)fprintf(stderr, "%s: no space for %d byte local name cache\n", Pn, len); - Error(); + Error(ctx); } /* @@ -1453,7 +1448,7 @@ void ncache_load() { stderr, "%s: can't allocate %d bytes for name cache hash table\n", Pn, LNCHHLEN * sizeof(struct lnch_hh)); - Error(); + Error(ctx); } } else (void)zeromem((void *)LNC_hh, (LNCHHLEN * sizeof(struct lnch_hh))); @@ -1545,10 +1540,9 @@ void ncache_load() { * ncache_lookup() - look up a node's name in the kernel's name caches */ -char *ncache_lookup(buf, blen, fp) -char *buf; /* receiving name buffer */ -int blen; /* receiving buffer length */ -int *fp; /* full path reply */ +char *ncache_lookup(char *buf, /* receiving name buffer */ + int blen, /* receiving buffer length */ + int *fp) /* full path reply */ { char *cp = buf; int nl, rlen; @@ -1702,7 +1696,7 @@ static void NFS_load() { * Get the kernel's NFS name cache size. */ if (get_Nl_value("nnfnc", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&nfnce, sizeof(nfnce)) || nfnce < 1) + kread(ctx, v, (char *)&nfnce, sizeof(nfnce)) || nfnce < 1) return; /* * Allocate space for a copy of the kernel's NFS name cache. @@ -1712,13 +1706,13 @@ static void NFS_load() { (void)fprintf(stderr, "%s: can't allocate %d bytes for NFS name cache\n", Pn, kcl); - Error(); + Error(ctx); } } /* * Read the kernel's NFS name cache. */ - if (!nfnc || !kcl || !ka || kread(ka, (char *)nfnc, kcl)) + if (!nfnc || !kcl || !ka || kread(ctx, ka, (char *)nfnc, kcl)) return; /* * Build a local copy of the kernel's NFS name cache. @@ -1780,7 +1774,7 @@ KA_T r; /* node's rnode address */ /* * Read rnode and get the node number. */ - if (kread(r, (char *)&rn, sizeof(rn))) + if (kread(ctx, r, (char *)&rn, sizeof(rn))) return (0); # if OSRV < 500 @@ -1811,7 +1805,7 @@ KA_T r; /* node's rnode address */ } if (!rc) { (void)fprintf(stderr, "%s: no space for root rnode table\n", Pn); - Error(); + Error(ctx); } } rc[rnc++] = r; @@ -1852,7 +1846,7 @@ static void SYSV_load() { s5nce = Var.v_s5cacheents; # else /* OSRV>=500 */ if (get_Nl_value("nsfnc", Drive_Nl, &v) < 0 || !v || - kread(v, (char *)&s5nce, sizeof(s5nce))) + kread(ctx, v, (char *)&s5nce, sizeof(s5nce))) return; # endif /* OSRV<500 */ @@ -1866,13 +1860,13 @@ static void SYSV_load() { (void)fprintf(stderr, "%s: can't allocate %d bytes for SYSV name cache\n", Pn, kcl); - Error(); + Error(ctx); } } /* * Read the kernel's SYSV name cache. */ - if (!s5nc || !kcl || !ka || kread(ka, (char *)s5nc, kcl)) + if (!s5nc || !kcl || !ka || kread(ctx, ka, (char *)s5nc, kcl)) return; /* * Build a local copy of the kernel's SYSV name cache. diff --git a/lib/dialects/osr/dproto.h b/lib/dialects/osr/dproto.h index 8c0807cb..553c20d2 100644 --- a/lib/dialects/osr/dproto.h +++ b/lib/dialects/osr/dproto.h @@ -34,27 +34,27 @@ * $Id: dproto.h,v 1.5 99/06/22 08:22:28 abe Exp $ */ -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern void process_socket, (struct inode * i)); -_PROTOTYPE(extern int get_max_fd, (void)); +extern int is_file_named(char *p, int cd); +extern void process_socket(struct inode *i); +extern int get_max_fd(void); #if OSRV < 500 -_PROTOTYPE(extern int endservent, (void)); -_PROTOTYPE(extern int setservent, (int)); +extern int endservent(void); +extern int setservent(int); # if defined(HASSTATLSTAT) -_PROTOTYPE(extern int statlstat, (const char *, struct stat *)); +extern int statlstat(const char *, struct stat *); # endif /* defined(HASTSTATLSTAT) */ -_PROTOTYPE(extern int strcasecmp, (char *, char *)); -_PROTOTYPE(extern int strncasecmp, (char *, char *, unsigned int)); -_PROTOTYPE(extern pid_t wait, ()); +extern int strcasecmp(char *, char *); +extern int strncasecmp(char *, char *, unsigned int); +extern pid_t wait(); #endif /* OSRV<500 */ -_PROTOTYPE(extern int sysi86, ()); -_PROTOTYPE(extern int sysfs, ()); -_PROTOTYPE(extern void udp_tm, (time_t tm)); +extern int sysi86(); +extern int sysfs(); +extern void udp_tm(time_t tm); #if !defined(N_UNIX) -_PROTOTYPE(extern char *get_nlist_path, (int pd)); +extern char *get_nlist_path(int pd); #endif /* !defined(N_UNIX) */ diff --git a/lib/dialects/osr/dsock.c b/lib/dialects/osr/dsock.c index 621b66df..aa3f3cc9 100644 --- a/lib/dialects/osr/dsock.c +++ b/lib/dialects/osr/dsock.c @@ -77,12 +77,12 @@ void process_socket(i) struct inode *i; /* inode pointer */ return; } spa = Socktab + (GET_MIN_DEV(i->i_rdev) * sizeof(struct socket *)); - if (kread(spa, (char *)&sa, sizeof(sa))) { + if (kread(ctx, spa, (char *)&sa, sizeof(sa))) { (void)snpf(Namech, Namechl, "can't read socket pointer at %s", print_kptr(spa, (char *)NULL, 0)); enter_nm(Namech); } - if (kread(sa, (char *)&s, sizeof(s))) { + if (kread(ctx, sa, (char *)&s, sizeof(s))) { (void)snpf(Namech, Namechl, "can't read socket structure at %s", print_kptr(sa, (char *)NULL, 0)); enter_nm(Namech); @@ -92,7 +92,7 @@ void process_socket(i) struct inode *i; /* inode pointer */ * Read domain structure. */ if (!s.so_proto.pr_domain || - kread((KA_T)s.so_proto.pr_domain, (char *)&d, sizeof(d))) { + kread(ctx, (KA_T)s.so_proto.pr_domain, (char *)&d, sizeof(d))) { (void)snpf(Namech, Namechl, "can't read protocol domain from %s", print_kptr((KA_T)s.so_proto.pr_domain, (char *)NULL, 0)); enter_nm(Namech); @@ -116,7 +116,7 @@ void process_socket(i) struct inode *i; /* inode pointer */ shs = 1; if (shs && sh.q_ptr) { enter_dev_ch(print_kptr((KA_T)sh.q_ptr, (char *)NULL, 0)); - if (kread((KA_T)sh.q_ptr, (char *)&pcb, sizeof(pcb)) == 0) + if (kread(ctx, (KA_T)sh.q_ptr, (char *)&pcb, sizeof(pcb)) == 0) pcbs = 1; } /* @@ -130,7 +130,7 @@ void process_socket(i) struct inode *i; /* inode pointer */ * at the PCB's per-protocol control block address. It * may contain a foreign address. */ - if (!kread((KA_T)pcb.inp_ppcb, (char *)&udp, sizeof(udp))) { + if (!kread(ctx, (KA_T)pcb.inp_ppcb, (char *)&udp, sizeof(udp))) { #if OSRV >= 500 if (udp.ud_lsin.sin_addr.s_addr != INADDR_ANY || @@ -184,7 +184,7 @@ void process_socket(i) struct inode *i; /* inode pointer */ (void)udp_tm(udp.ud_ftime); } if (pcb.inp_ppcb && strcasecmp(Lf->iproto, "tcp") == 0 && - kread((KA_T)pcb.inp_ppcb, (char *)&t, sizeof(t)) == 0) { + kread(ctx, (KA_T)pcb.inp_ppcb, (char *)&t, sizeof(t)) == 0) { ts = 1; /* * Save the TCP state from its control block. @@ -206,11 +206,11 @@ void process_socket(i) struct inode *i; /* inode pointer */ } } #else /* OSRV>=500 */ - if (s.so_name && !kread((KA_T)s.so_name, (char *)&si, sizeof(si))) { + if (s.so_name && !kread(ctx, (KA_T)s.so_name, (char *)&si, sizeof(si))) { la = (unsigned char *)&si.sin_addr; lp = (int)ntohs(si.sin_port); } - if (s.so_peer && !kread((KA_T)s.so_peer, (char *)&si, sizeof(si))) { + if (s.so_peer && !kread(ctx, (KA_T)s.so_peer, (char *)&si, sizeof(si))) { if (si.sin_addr.s_addr != INADDR_ANY || si.sin_port != 0) { fa = (unsigned char *)&si.sin_addr; fp = (int)ntohs(si.sin_port); @@ -279,7 +279,7 @@ void process_socket(i) struct inode *i; /* inode pointer */ enter_dev_ch(print_kptr(sa, (char *)NULL, 0)); if (s.so_stp && !readstdata((KA_T)s.so_stp, &sd) && !readsthead((KA_T)sd.sd_wrq, &sh)) { - if (!sh.q_ptr || kread((KA_T)sh.q_ptr, (char *)&ud, sizeof(ud))) { + if (!sh.q_ptr || kread(ctx, (KA_T)sh.q_ptr, (char *)&ud, sizeof(ud))) { (void)snpf(Namech, Namechl, "can't read un_dev from %s", print_kptr((KA_T)sh.q_ptr, (char *)NULL, 0)); break; @@ -337,7 +337,7 @@ void udp_tm(tm) time_t tm; /* time when packet was sent */ */ if (!Lbolt) return; - if (Hz < 0 || kread((KA_T)Lbolt, (char *)&lbolt, sizeof(lbolt)) || + if (Hz < 0 || kread(ctx, (KA_T)Lbolt, (char *)&lbolt, sizeof(lbolt)) || tm >= lbolt || (et = (time_t)((lbolt - tm) / Hz)) == 0) return; /* @@ -387,7 +387,7 @@ void udp_tm(tm) time_t tm; /* time when packet was sent */ if (!(cp = (char *)malloc(len))) { (void)fprintf(stderr, "%s: no space for %d character UDP time\n", Pn, len); - Error(); + Error(ctx); } (void)snpf(cp, len, "%s", buf); Lf->nma = cp; diff --git a/lib/dialects/sun/ddev.c b/lib/dialects/sun/ddev.c index 0e9b10c5..559c43db 100644 --- a/lib/dialects/sun/ddev.c +++ b/lib/dialects/sun/ddev.c @@ -52,15 +52,17 @@ static int Devx = 0; /* current Devtp[] index */ * Local function prototypes */ -_PROTOTYPE(static void make_devtp, (struct stat * s, char *p)); -_PROTOTYPE(static int rmdupdev, (struct l_dev * **dp, int n, int ty)); +static void make_devtp(struct lsof_context *ctx, struct stat *s, char *p); +static int rmdupdev(struct lsof_context *ctx, struct l_dev ***dp, int n, + int ty); /* * make_devtp() - make Devtp[] entry */ -static void make_devtp(s, p) struct stat *s; /* device lstat() buffer */ -char *p; /* device path name */ +static void make_devtp(struct lsof_context *ctx, /* context */ + struct stat *s, /* device lstat() buffer */ + char *p) /* device path name */ { /* @@ -76,7 +78,7 @@ char *p; /* device path name */ (MALLOC_P *)Devtp, (MALLOC_S)(sizeof(struct l_dev) * Ndev)); if (!Devtp) { (void)fprintf(stderr, "%s: no space for character device\n", Pn); - Error(); + Error(ctx); } } /* @@ -86,7 +88,7 @@ char *p; /* device path name */ if (!(Devtp[Devx].name = mkstrcpy(p, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for /dev/", Pn); safestrprt(p, stderr, 1); - Error(); + Error(ctx); } Devtp[Devx].rdev = s->st_rdev; Devtp[Devx].v = 0; @@ -97,17 +99,17 @@ char *p; /* device path name */ * printdevname() - print block or character device name */ -int printdevname(dev, rdev, f, nty) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ -int f; /* 1 = print trailing '\n' */ -int nty; /* node type: N_BLK or N_CHR */ +int printdevname(struct lsof_context *ctx, /* context */ + dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int f, /* 1 = print trailing '\n' */ + int nty) /* node type: N_BLK or N_CHR */ { struct clone *c; struct l_dev *dp; struct pseudo *p; - readdev(0); + readdev(ctx, 0); /* * Search device table for a full match. */ @@ -120,11 +122,11 @@ int nty; /* node type: N_BLK or N_CHR */ #if defined(HASBLKDEV) if (nty == N_BLK) - dp = lkupbdev(dev, rdev, 1, 0); + dp = lkupbdev(ctx, dev, rdev, 1, 0); else #endif /* defined(HASBLKDEV) */ - dp = lkupdev(dev, rdev, 1, 0); + dp = lkupdev(ctx, dev, rdev, 1, 0); if (dp) { safestrprt(dp->name, stdout, f); return (1); @@ -135,11 +137,11 @@ int nty; /* node type: N_BLK or N_CHR */ #if defined(HASBLKDEV) if (nty == N_BLK) - dp = lkupbdev(&DevDev, rdev, 0, 0); + dp = lkupbdev(ctx, &DevDev, rdev, 0, 0); else #endif /* defined(HASBLKDEV) */ - dp = lkupdev(&DevDev, rdev, 0, 0); + dp = lkupdev(ctx, &DevDev, rdev, 0, 0); if (dp) { /* @@ -153,10 +155,10 @@ int nty; /* node type: N_BLK or N_CHR */ if (!(cp = (char *)malloc((MALLOC_S)(len + 1)))) { (void)fprintf(stderr, "%s: no nma space for: (%s %s)\n", Pn, ttl, dp->name); - Error(); + Error(ctx); } (void)snpf(cp, len + 1, "(%s %s)", ttl, dp->name); - (void)add_nma(cp, len); + (void)add_nma(ctx, cp, len); (void)free((MALLOC_P *)cp); return (0); } @@ -168,7 +170,7 @@ int nty; /* node type: N_BLK or N_CHR */ if (GET_MAJ_DEV(*rdev) == GET_MIN_DEV(c->cd.rdev)) { #if defined(HASDCACHE) - if (DCunsafe && !c->cd.v && !vfy_dev(&c->cd)) + if (DCunsafe && !c->cd.v && !vfy_dev(ctx, &c->cd)) goto printchdevname_again; #endif /* defined(HASDCACHE) */ @@ -185,7 +187,7 @@ int nty; /* node type: N_BLK or N_CHR */ if (GET_MAJ_DEV(*rdev) == GET_MAJ_DEV(p->pd.rdev)) { #if defined(HASDCACHE) - if (DCunsafe && !p->pd.v && vfy_dev(&p->pd)) + if (DCunsafe && !p->pd.v && vfy_dev(ctx, &p->pd)) goto printchdevname_again; #endif /* defined(HASDCACHE) */ @@ -201,7 +203,7 @@ int nty; /* node type: N_BLK or N_CHR */ * the device cache. */ if (DCunsafe) { - (void)rereaddev(); + (void)rereaddev(ctx); goto printchdevname_again; } #endif /* defined(HASDCACHE) */ @@ -213,7 +215,7 @@ int nty; /* node type: N_BLK or N_CHR */ * read_clone() - read Solaris clone device information */ -void read_clone() { +void read_clone(struct lsof_context *ctx) { struct clone *c; char *cn; DIR *dfp; @@ -232,7 +234,7 @@ void read_clone() { */ if (!(path = mkstrcat(DVCH_DEVPATH, -1, "/", 1, "pseudo ", -1, &pl))) { (void)fprintf(stderr, "%s: no space for %s/pseudo\n", DVCH_DEVPATH, Pn); - Error(); + Error(ctx); } path[pl - 1] = '\0'; if (!(dfp = OpenDir(path))) { @@ -266,7 +268,7 @@ void read_clone() { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(path, stderr, 0); safestrprt(dp->d_name, stderr, 1); - Error(); + Error(ctx); } #if defined(USE_STAT) @@ -294,7 +296,7 @@ void read_clone() { /* * Make Devtp[] entry. */ - make_devtp(&sb, fp); + make_devtp(ctx, &sb, fp); /* * Create a clone structure entry for "clone*:" devices. * @@ -310,7 +312,7 @@ void read_clone() { (void)fprintf(stderr, "%s: no space for network clone device: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } /* * Allocate space for the path name. @@ -318,7 +320,7 @@ void read_clone() { if (!(c->cd.name = mkstrcpy(fp, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for clone name: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } /* * Save the inode and device numbers. Clear the verify flag. @@ -351,7 +353,7 @@ void read_clone() { if (!(p = (struct pseudo *)malloc(sizeof(struct pseudo)))) { (void)fprintf(stderr, "%s: no space for pseudo device: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } /* * Save the path name, and inode and device numbers. Clear the @@ -378,7 +380,8 @@ void read_clone() { * or /device (Solaris) */ -void readdev(skip) int skip; /* skip device cache read if 1 */ +void readdev(struct lsof_context *ctx, /* context */ + int skip) /* skip device cache read if 1 */ { #if defined(HASDCACHE) @@ -409,7 +412,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ */ if (!skip) { if (DCstate == 2 || DCstate == 3) { - if ((dcrd = read_dcache()) == 0) + if ((dcrd = read_dcache(ctx)) == 0) return; } } else @@ -420,12 +423,12 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for: %s/pseudo\n", Pn, DVCH_DEVPATH); - Error(); + Error(ctx); } - read_clone(); + read_clone(ctx); Dstk = (char **)NULL; Dstkn = Dstkx = 0; - (void)stkdir(DVCH_DEVPATH); + (void)stkdir(ctx, DVCH_DEVPATH); /* * Unstack the next directory. */ @@ -454,7 +457,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ mkstrcat(Dstk[Dstkx], -1, "/", 1, (char *)NULL, -1, &pl))) { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(Dstk[Dstkx], stderr, 1); - Error(); + Error(ctx); } (void)free((FREE_P *)Dstk[Dstkx]); Dstk[Dstkx] = (char *)NULL; @@ -476,7 +479,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(path, stderr, 0); safestrprt(dp->d_name, stderr, 1); - Error(); + Error(ctx); } #if defined(USE_STAT) @@ -512,7 +515,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ */ if (strcmp(fp, ppath) == 0) continue; - (void)stkdir(fp); + (void)stkdir(ctx, fp); continue; } if ((sb.st_mode & S_IFMT) == S_IFCHR) { @@ -520,7 +523,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ /* * Make Devtp[] entry. */ - make_devtp(&sb, fp); + make_devtp(ctx, &sb, fp); } #if defined(HASBLKDEV) @@ -541,7 +544,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!BDevtp) { (void)fprintf(stderr, "%s: no space for block device\n", Pn); - Error(); + Error(ctx); } } BDevtp[j].rdev = sb.st_rdev; @@ -586,14 +589,14 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (MALLOC_S)(sizeof(struct l_dev *) * BNdev)))) { (void)fprintf(stderr, "%s: no space for block device sort pointers\n", Pn); - Error(); + Error(ctx); } for (j = 0; j < BNdev; j++) { BSdev[j] = &BDevtp[j]; } (void)qsort((QSORT_P *)BSdev, (size_t)BNdev, (size_t)sizeof(struct l_dev *), compdev); - BNdev = rmdupdev(&BSdev, BNdev, 0); + BNdev = rmdupdev(ctx, &BSdev, BNdev, 0); } else { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: no block devices found\n", Pn); @@ -611,17 +614,17 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for character device sort pointers\n", Pn); - Error(); + Error(ctx); } for (i = 0; i < Ndev; i++) { Sdev[i] = &Devtp[i]; } (void)qsort((QSORT_P *)Sdev, (size_t)Ndev, (size_t)sizeof(struct l_dev *), compdev); - Ndev = rmdupdev(&Sdev, Ndev, 1); + Ndev = rmdupdev(ctx, &Sdev, Ndev, 1); } else { (void)fprintf(stderr, "%s: no character devices found\n", Pn); - Error(); + Error(ctx); } #if defined(HASDCACHE) @@ -629,7 +632,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * Write device cache file, as required. */ if (DCstate == 1 || (DCstate == 3 && dcrd)) - write_dcache(); + write_dcache(ctx); #endif /* defined(HASDCACHE) */ } @@ -637,7 +640,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * clr_sect() - clear cached clone and pseudo sections */ -void clr_sect() { +void clr_sect(struct lsof_context *ctx) { if (Clone) { struct clone *c, *c1; @@ -667,8 +670,8 @@ void clr_sect() { * rw_clone_sect() - read/write the device cache file clone section */ -int rw_clone_sect(m) -int m; /* mode: 1 = read; 2 = write */ +int rw_clone_sect(struct lsof_context *ctx, + int m) /* mode: 1 = read; 2 = write */ { char buf[MAXPATHLEN * 2], *cp; struct clone *c; @@ -716,7 +719,7 @@ int m; /* mode: 1 = read; 2 = write */ if (!(c = (struct clone *)calloc(1, sizeof(struct clone)))) { (void)fprintf(stderr, "%s: no space for cached clone: ", Pn); safestrprt(buf, stderr, 1); - Error(); + Error(ctx); } /* * Enter the clone device number. @@ -777,7 +780,7 @@ int m; /* mode: 1 = read; 2 = write */ (void)fprintf(stderr, "%s: no space for cached clone path: ", Pn); safestrprt(buf, stderr, 1); - Error(); + Error(ctx); } c->cd.v = 0; c->next = Clone; @@ -814,7 +817,7 @@ int m; /* mode: 1 = read; 2 = write */ * A shouldn't-happen case: mode neither 1 nor 2. */ (void)fprintf(stderr, "%s: internal rw_clone_sect error: %d\n", Pn, m); - Error(); + Error(ctx); return (1); /* to make code analyzers happy */ } @@ -822,16 +825,16 @@ int m; /* mode: 1 = read; 2 = write */ * rereaddev() - reread device names, modes and types */ -void rereaddev() { - (void)clr_devtab(); - (void)clr_sect(); +void rereaddev(struct lsof_context *ctx) { + (void)clr_devtab(ctx); + (void)clr_sect(ctx); Devx = 0; # if defined(DCACHE_CLR) - (void)DCACHE_CLR(); + (void)DCACHE_CLR(ctx); # endif /* defined(DCACHE_CLR) */ - readdev(1); + readdev(ctx, 1); DCunsafe = 0; } @@ -839,8 +842,8 @@ void rereaddev() { * rw_pseudo_sect() - read/write the device cache pseudo section */ -int rw_pseudo_sect(m) -int m; /* mode: 1 = read; 2 = write */ +int rw_pseudo_sect(struct lsof_context *ctx, + int m) /* mode: 1 = read; 2 = write */ { char buf[MAXPATHLEN * 2], *cp; struct pseudo *p; @@ -888,7 +891,7 @@ int m; /* mode: 1 = read; 2 = write */ if (!(p = (struct pseudo *)calloc(1, sizeof(struct pseudo)))) { (void)fprintf(stderr, "%s: no space for cached pseudo: ", Pn); safestrprt(buf, stderr, 1); - Error(); + Error(ctx); } /* * Enter the pseudo device number. @@ -939,7 +942,7 @@ int m; /* mode: 1 = read; 2 = write */ (void)fprintf(stderr, "%s: no space for cached pseudo path: ", Pn); safestrprt(buf, stderr, 1); - Error(); + Error(ctx); } *(cp + len - 1) = '\0'; (void)snpf(p->pd.name, len, "%s", cp); @@ -987,8 +990,8 @@ int m; /* mode: 1 = read; 2 = write */ * Note: rereads entire device table when an entry can't be verified. */ -int vfy_dev(dp) -struct l_dev *dp; /* device table pointer */ +int vfy_dev(struct lsof_context *ctx, /* context */ + struct l_dev *dp) /* device table pointer */ { struct stat sb; @@ -1002,7 +1005,7 @@ struct l_dev *dp; /* device table pointer */ # endif /* defined(USE_STAT) */ || dp->rdev != sb.st_rdev || dp->inode != (INODETYPE)sb.st_ino) { - (void)rereaddev(); + (void)rereaddev(ctx); return (0); } dp->v = 1; @@ -1014,10 +1017,10 @@ struct l_dev *dp; /* device table pointer */ * rmdupdev() - remove duplicate (major/minor/inode) devices */ -static int rmdupdev(dp, n, ty) -struct l_dev ***dp; /* device table pointers address */ -int n; /* number of pointers */ -int ty; /* type: 0 = block, 1 = char */ +static int rmdupdev(struct lsof_context *ctx, /* context */ + struct l_dev ***dp, /* device table pointers address */ + int n, /* number of pointers */ + int ty) /* type: 0 = block, 1 = char */ { struct clone *c, *cp; struct l_dev **d; @@ -1077,7 +1080,7 @@ int ty; /* type: 0 = block, 1 = char */ (MALLOC_P *)*dp, (MALLOC_S)(j * sizeof(struct l_dev *))))) { (void)fprintf(stderr, "%s: can't realloc %s device pointers\n", Pn, ty ? "char" : "block"); - Error(); + Error(ctx); } return (j); } diff --git a/lib/dialects/sun/dfile.c b/lib/dialects/sun/dfile.c index 24c4ead5..3545cd33 100644 --- a/lib/dialects/sun/dfile.c +++ b/lib/dialects/sun/dfile.c @@ -115,7 +115,7 @@ int get_max_fd() { * hashSfile() - hash Sfile entries for use in is_file_named() searches */ -void hashSfile() { +void hashSfile(struct lsof_context *ctx) { int cmaj, hvc, i; static int hs = 0; struct sfile *s; @@ -144,7 +144,7 @@ void hashSfile() { (void)fprintf( stderr, "%s: can't allocate space for %d clone hash buckets\n", Pn, SFCDHASH); - Error(); + Error(ctx); } } if (!(HbyFdi = (struct hsfile *)calloc((MALLOC_S)SFDIHASH, @@ -152,28 +152,28 @@ void hashSfile() { (void)fprintf( stderr, "%s: can't allocate space for %d (dev,ino) hash buckets\n", Pn, SFDIHASH); - Error(); + Error(ctx); } if (!(HbyFrd = (struct hsfile *)calloc((MALLOC_S)SFRDHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d rdev hash buckets\n", Pn, SFRDHASH); - Error(); + Error(ctx); } if (!(HbyFsd = (struct hsfile *)calloc((MALLOC_S)SFFSHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d file sys hash buckets\n", Pn, SFFSHASH); - Error(); + Error(ctx); } if (!(HbyNm = (struct hsfile *)calloc((MALLOC_S)SFNMHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d name hash buckets\n", Pn, SFNMHASH); - Error(); + Error(ctx); } hs++; /* @@ -223,7 +223,7 @@ void hashSfile() { (void)fprintf(stderr, "%s: can't allocate hsfile bucket for: %s\n", Pn, s->aname); - Error(); + Error(ctx); } sn->s = s; sn->next = sh->next; @@ -237,13 +237,13 @@ void hashSfile() { * is_file_named() - is this file named? */ -int is_file_named(p, nt, vt, ps) -char *p; /* path name; NULL = search by device - * and inode (from *Lf) */ -int nt; /* node type -- e.g., N_* */ -enum vtype vt; /* vnode type */ -int ps; /* print status: 0 = don't copy name - * to Namech */ +int is_file_named(struct lsof_context *ctx, /* context */ + char *p, /* path name; NULL = search by device + * and inode (from *Lf) */ + int nt, /* node type -- e.g., N_* */ + enum vtype vt, /* vnode type */ + int ps) /* print status: 0 = don't copy name + * to Namech */ { char *ep; int f = 0; @@ -336,7 +336,7 @@ int ps; /* print status: 0 = don't copy name */ (void)snpf(Namech, Namechl, "%s", s->name); if (s->devnm) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, " (%s)", s->devnm); } } @@ -352,9 +352,8 @@ int ps; /* print status: 0 = don't copy name * print_dev() - print device */ -char *print_dev(lf, dev) -struct lfile *lf; /* file whose device is to be printed */ -dev_t *dev; /* device to be printed */ +char *print_dev(struct lfile *lf, /* file whose device is to be printed */ + dev_t *dev) /* device to be printed */ { static char buf[128]; /* @@ -391,8 +390,8 @@ dev_t *dev; /* device to be printed */ * print_v_path() - print path name from vnode's v_path pointer */ -extern int print_v_path(lf) -struct lfile *lf; /* local file structure */ +extern int print_v_path(struct lsof_context *ctx, + struct lfile *lf) /* local file structure */ { char buf[MAXPATHLEN + 1]; unsigned char del = 0; @@ -409,7 +408,7 @@ struct lfile *lf; /* local file structure */ } # endif /* defined(HASVXFS) && defined(HASVXFSRNL) */ - (void)read_v_path((KA_T)lf->V_path, buf, (size_t)sizeof(buf)); + (void)read_v_path(ctx, (KA_T)lf->V_path, buf, (size_t)sizeof(buf)); if (buf[0]) { # if defined(HASMNTSTAT) @@ -420,7 +419,7 @@ struct lfile *lf; /* local file structure */ * If the device and inode for the file are known, it is probably * safe and worthwhile to apply stat(2) to the v_path. */ - if (!statsafely(buf, &sb)) { + if (!statsafely(ctx, buf, &sb)) { /* * The stat(2) succeeded. See if the device and inode match. @@ -485,9 +484,10 @@ struct lfile *lf; /* local file structure */ * read_v_path() - read path name from vnode's v_path pointer */ -extern void read_v_path(ka, rb, rbl) KA_T ka; /* kernel path address */ -char *rb; /* receiving buffer */ -size_t rbl; /* receiving buffer length */ +extern void read_v_path(struct lsof_context *ctx, + KA_T ka, /* kernel path address */ + char *rb, /* receiving buffer */ + size_t rbl) /* receiving buffer length */ { char *ba; size_t rl, tl; @@ -508,7 +508,7 @@ size_t rbl; /* receiving buffer length */ *(rb + rbl - 1) = '\0'; break; } - if (!kread(ka, ba, rl)) { + if (!kread(ctx, ka, ba, rl)) { *(ba + rl) = '\0'; if (strchr(ba, '\0') < (ba + rl)) break; @@ -520,7 +520,7 @@ size_t rbl; /* receiving buffer length */ * has been established that no more bytes can be read. */ for (rl--; rl > 0; rl--) { - if (!kread(ka, ba, rl)) { + if (!kread(ctx, ka, ba, rl)) { *(ba + rl) = '\0'; break; } @@ -537,7 +537,8 @@ size_t rbl; /* receiving buffer length */ * process_file() - process file */ -void process_file(fp) KA_T fp; /* kernel file structure address */ +void process_file(struct lsof_context *ctx, /* context */ + KA_T fp) /* kernel file structure address */ { struct file f; int flag; @@ -546,10 +547,10 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ FILEPTR = &f; #endif /* defined(FILEPTR) */ - if (kread(fp, (char *)&f, sizeof(f))) { + if (kread(ctx, fp, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "can't read file struct from %s", print_kptr(fp, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } Lf->off = (SZOFFTYPE)f.f_offset; @@ -584,10 +585,10 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ /* * Solaris file structures contain a vnode pointer. Process it. */ - process_node((KA_T)f.f_vnode); + process_node(ctx, (KA_T)f.f_vnode); return; } - enter_nm("no more information"); + enter_nm(ctx, "no more information"); } #if defined(HASIPv6) diff --git a/lib/dialects/sun/dlsof.h b/lib/dialects/sun/dlsof.h index 8cbfb003..34617338 100644 --- a/lib/dialects/sun/dlsof.h +++ b/lib/dialects/sun/dlsof.h @@ -520,7 +520,7 @@ typedef struct CTF_request { # define CTF_MEMBER(name) \ { #name, CTF_MEMBER_UNDEF } # define CTF_MEMBER_READ(ka, s, members, member) \ - kread((KA_T)(ka) + members[MX_##member].m_offset, \ + kread(ctx, (KA_T)(ka) + members[MX_##member].m_offset, \ (char *)&s->member, sizeof(s->member)) # endif /* defined(HAS_LIBCTF) */ diff --git a/lib/dialects/sun/dmnt.c b/lib/dialects/sun/dmnt.c index 9d8adef4..c417396b 100644 --- a/lib/dialects/sun/dmnt.c +++ b/lib/dialects/sun/dmnt.c @@ -42,18 +42,19 @@ static char copyright[] = static struct mounts *Lmi = (struct mounts *)NULL; /* local mount info */ static int Lmist = 0; /* Lmi status */ -_PROTOTYPE(static char *getmntdev, (char *o, int l, struct stat *s, char *f)); +static char *getmntdev(struct lsof_context *ctx, char *o, int l, struct stat *s, + char *f); /* * getmntdev() - get mount entry's device number */ -static char *getmntdev(o, l, s, f) -char *o; /* start of device option */ -int l; /* length of device keyword (not - * including `=') */ -struct stat *s; /* pointer to stat buffer to create */ -char *f; /* file system type */ +static char *getmntdev(struct lsof_context *ctx, /* context */ + char *o, /* start of device option */ + int l, /* length of device keyword (not + * including `=') */ + struct stat *s, /* pointer to stat buffer to create */ + char *f) /* file system type */ { char *opte; @@ -86,7 +87,7 @@ char *f; /* file system type */ * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { int devl, ignore; char *cp, *dir, *fs; char *dn = (char *)NULL; @@ -159,9 +160,9 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(dir, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } - if (!(ln = Readlink(dn))) { + if (!(ln = Readlink(ctx, dn))) { if (!Fwarn) { (void)fprintf(stderr, " Output information may be incomplete.\n"); @@ -182,7 +183,7 @@ struct mounts *readmnt() { */ dopt = hasmntopt(mp, MNTOPT_DEV); if (ignore) { - if (!dopt || !(dopte = getmntdev(dopt, devl, &sb, + if (!dopt || !(dopte = getmntdev(ctx, dopt, devl, &sb, #if defined(HASFSTYPE) mp->mnt_fstype @@ -193,9 +194,9 @@ struct mounts *readmnt() { ))) continue; stat = 1; - } else if (statsafely(dn, &sb)) { + } else if (statsafely(ctx, dn, &sb)) { if (dopt) { - if (!(dopte = getmntdev(dopt, devl, &sb, + if (!(dopte = getmntdev(ctx, dopt, devl, &sb, #if defined(HASFSTYPE) mp->mnt_fstype @@ -285,13 +286,13 @@ struct mounts *readmnt() { if (!(dn = mkstrcpy(fs, (MALLOC_S *)NULL))) goto no_space_for_mount; mtp->fsname = dn; - ln = Readlink(dn); + ln = Readlink(ctx, dn); dn = (char *)NULL; /* * Stat() the file system (mounted-on) name and add file system * information to the local mount table entry. */ - if (!ln || statsafely(ln, &sb)) + if (!ln || statsafely(ctx, ln, &sb)) sb.st_mode = 0; mtp->fsnmres = ln; mtp->fs_mode = sb.st_mode; @@ -335,12 +336,12 @@ struct mounts *readmnt() { * readvfs() - read vfs structure */ -struct l_vfs *readvfs(ka, la, lv) -KA_T ka; /* vfs structure kernel address, if - * must be read from kernel */ -struct vfs *la; /* local vfs structure address, non- - * NULL if already read from kernel */ -struct vnode *lv; /* local vnode */ +struct l_vfs *readvfs(struct lsof_context *ctx, /* context */ + KA_T ka, /* vfs structure kernel address, if + * must be read from kernel */ + struct vfs *la, /* local vfs structure address, non- + * NULL if already read from kernel */ + struct vnode *lv) /* local vnode */ { struct vfs *v, tv; struct l_vfs *vp; @@ -353,7 +354,7 @@ struct vnode *lv; /* local vnode */ } if (!(vp = (struct l_vfs *)malloc(sizeof(struct l_vfs)))) { (void)fprintf(stderr, "%s: PID %d, no space for vfs\n", Pn, Lp->pid); - Error(); + Error(ctx); } vp->dir = (char *)NULL; vp->fsname = (char *)NULL; @@ -369,7 +370,7 @@ struct vnode *lv; /* local vnode */ v = la; else { v = &tv; - if (kread((KA_T)ka, (char *)v, sizeof(tv))) { + if (kread(ctx, (KA_T)ka, (char *)v, sizeof(tv))) { (void)free((FREE_P *)vp); return ((struct l_vfs *)NULL); } @@ -381,7 +382,7 @@ struct vnode *lv; /* local vnode */ */ if (v->vfs_fstype == AFSfstype) { if (!AFSdevStat) - (void)readmnt(); + (void)readmnt(ctx); v->vfs_dev = AFSdevStat ? AFSdev : 0; } #endif /* defined(HAS_AFS) */ @@ -390,7 +391,7 @@ struct vnode *lv; /* local vnode */ * Complete mount information. */ - (void)completevfs(vp, (dev_t *)&v->vfs_dev); + (void)completevfs(ctx, vp, (dev_t *)&v->vfs_dev); vp->next = Lvfs; vp->addr = ka; Lvfs = vp; diff --git a/lib/dialects/sun/dnode.c b/lib/dialects/sun/dnode.c index a378e81b..e28fecf1 100644 --- a/lib/dialects/sun/dnode.c +++ b/lib/dialects/sun/dnode.c @@ -142,7 +142,8 @@ static CTF_request_t Sockfs_requests[] = { * Sockfs function prototypes */ -_PROTOTYPE(static int read_nsti, (struct sonode * so, sotpi_info_t *stpi)); +static int read_nsti(struct lsof_context *ctx, struct sonode *so, + sotpi_info_t *stpi); #endif /* solaris>=110000 && defined(HAS_LIBCTF) */ #if defined(HAS_ZFS) && defined(HAS_LIBCTF) @@ -272,12 +273,15 @@ static CTF_exception_t CTF_exceptions[] = {{ZNODE_TYPE_NAME, "z_phys"}, * ZFS function prototypes */ -_PROTOTYPE(static int read_nzn, (KA_T na, KA_T nza, znode_t *z)); -_PROTOTYPE(static int read_nznp, (KA_T nza, KA_T nzpa, znode_phys_t *zp)); -_PROTOTYPE(static int read_nzvfs, (KA_T nza, KA_T nzva, zfsvfs_t *zv)); +static int read_nzn(struct lsof_context *ctx, KA_T na, KA_T nza, znode_t *z); +static int read_nznp(struct lsof_context *ctx, KA_T nza, KA_T nzpa, + znode_phys_t *zp); +static int read_nzvfs(struct lsof_context *ctx, KA_T nza, KA_T nzva, + zfsvfs_t *zv); #endif /* defined(HAS_ZFS) && defined(HAS_LIBCTF) */ -_PROTOTYPE(static struct l_dev *finddev, (dev_t * dev, dev_t *rdev, int flags)); +static struct l_dev *finddev(struct lsof_context *ctx, dev_t *dev, dev_t *rdev, + int flags); /* * Finddev() "look-in " flags @@ -406,69 +410,88 @@ static v_optab_t **Voptab = (v_optab_t **)NULL; * Local function prototypes */ -_PROTOTYPE(static void build_Voptab, (void)); -_PROTOTYPE(static char isvlocked, (struct vnode * va)); -_PROTOTYPE(static int readinode, (KA_T ia, struct inode *i)); -_PROTOTYPE(static void read_mi, (KA_T s, dev_t *dev, caddr_t so, int *so_st, - KA_T *so_ad, struct l_dev **sdp)); +static void build_Voptab(struct lsof_context *ctx); +static char isvlocked(struct lsof_context *ctx, struct vnode *va); +static int readinode(struct lsof_context *ctx, KA_T ia, struct inode *i); +static void read_mi(struct lsof_context *ctx, KA_T s, dev_t *dev, caddr_t so, + int *so_st, KA_T *so_ad, struct l_dev **sdp); #if solaris >= 20500 # if solaris >= 20600 -_PROTOTYPE(static int read_nan, (KA_T na, KA_T aa, struct fnnode *rn)); -_PROTOTYPE(static int read_nson, (KA_T na, KA_T sa, struct sonode *sn)); -_PROTOTYPE(static int read_nusa, (struct soaddr * so, struct sockaddr_un *ua)); +static int read_nan(struct lsof_context *ctx, KA_T na, KA_T aa, + struct fnnode *rn); +static int read_nson(struct lsof_context *ctx, KA_T na, KA_T sa, + struct sonode *sn); +static int read_nusa(struct lsof_context *ctx, struct soaddr *so, + struct sockaddr_un *ua); # else /* solaris<20600 */ -_PROTOTYPE(static int read_nan, (KA_T na, KA_T aa, struct autonode *a)); +static int read_nan(struct lsof_context *ctx, KA_T na, KA_T aa, + struct autonode *a); # endif /* solaris>=20600 */ -_PROTOTYPE(static int idoorkeep, (struct door_node * d)); -_PROTOTYPE(static int read_ndn, (KA_T na, KA_T da, struct door_node *d)); +static int idoorkeep(struct lsof_context *ctx, struct door_node *d); +static int read_ndn(struct lsof_context *ctx, KA_T na, KA_T da, + struct door_node *d); #endif /* solaris>=20500 */ #if solaris >= 110000 -_PROTOTYPE(static int read_nsdn, - (KA_T na, KA_T sa, struct sdev_node *sdn, struct vattr *sdva)); +static int read_nsdn(struct lsof_context *ctx, KA_T na, KA_T sa, + struct sdev_node *sdn, struct vattr *sdva); #endif /* solaris>=110000 */ -_PROTOTYPE(static int read_nfn, (KA_T na, KA_T fa, struct fifonode *f)); -_PROTOTYPE(static int read_nhn, (KA_T na, KA_T ha, struct hsnode *h)); -_PROTOTYPE(static int read_nin, (KA_T na, KA_T ia, struct inode *i)); -_PROTOTYPE(static int read_nmn, (KA_T na, KA_T ia, struct mvfsnode *m)); -_PROTOTYPE(static int read_npn, (KA_T na, KA_T pa, struct pcnode *p)); -_PROTOTYPE(static int read_nrn, (KA_T na, KA_T ra, struct rnode *r)); +static int read_nfn(struct lsof_context *ctx, KA_T na, KA_T fa, + struct fifonode *f); +static int read_nhn(struct lsof_context *ctx, KA_T na, KA_T ha, + struct hsnode *h); +static int read_nin(struct lsof_context *ctx, KA_T na, KA_T ia, + struct inode *i); +static int read_nmn(struct lsof_context *ctx, KA_T na, KA_T ia, + struct mvfsnode *m); +static int read_npn(struct lsof_context *ctx, KA_T na, KA_T pa, + struct pcnode *p); +static int read_nrn(struct lsof_context *ctx, KA_T na, KA_T ra, + struct rnode *r); #if solaris >= 100000 -_PROTOTYPE(static int read_nctfsn, (int ty, KA_T na, KA_T ca, char *cn)); -_PROTOTYPE(static int read_nprtn, (KA_T na, KA_T ra, port_t *p)); -_PROTOTYPE(static int read_nrn4, (KA_T na, KA_T ra, struct rnode4 *r)); +static int read_nctfsn(struct lsof_context *ctx, int ty, KA_T na, KA_T ca, + char *cn); +static int read_nprtn(struct lsof_context *ctx, KA_T na, KA_T ra, port_t *p); +static int read_nrn4(struct lsof_context *ctx, KA_T na, KA_T ra, + struct rnode4 *r); #endif /* solaris>=100000 */ -_PROTOTYPE(static int read_nsn, (KA_T na, KA_T sa, struct snode *s)); -_PROTOTYPE(static int read_ntn, (KA_T na, KA_T ta, struct tmpnode *t)); -_PROTOTYPE(static int read_nvn, (KA_T na, KA_T va, struct vnode *v)); +static int read_nsn(struct lsof_context *ctx, KA_T na, KA_T sa, + struct snode *s); +static int read_ntn(struct lsof_context *ctx, KA_T na, KA_T ta, + struct tmpnode *t); +static int read_nvn(struct lsof_context *ctx, KA_T na, KA_T va, + struct vnode *v); #if defined(HASPROCFS) -_PROTOTYPE(static int read_npi, (KA_T na, struct vnode *v, struct pid *pids)); +static int read_npi(struct lsof_context *ctx, KA_T na, struct vnode *v, + struct pid *pids); #endif /* defined(HASPROCFS) */ -_PROTOTYPE(static char *ent_fa, (KA_T * a1, KA_T *a2, char *d, int *len)); -_PROTOTYPE(static int is_socket, (struct vnode * v)); -_PROTOTYPE(static int read_cni, - (struct snode * s, struct vnode *rv, struct vnode *v, - struct snode *rs, struct dev_info *di, char *din, int dinl)); +static char *ent_fa(KA_T *a1, KA_T *a2, char *d, int *len); +static int is_socket(struct lsof_context *ctx, struct vnode *v); +static int read_cni(struct lsof_context *ctx, struct snode *s, struct vnode *rv, + struct vnode *v, struct snode *rs, struct dev_info *di, + char *din, int dinl); #if defined(HASCACHEFS) -_PROTOTYPE(static int read_ncn, (KA_T na, KA_T ca, struct cnode *cn)); +static int read_ncn(struct lsof_context *ctx, KA_T na, KA_T ca, + struct cnode *cn); #endif /* defined(HASCACHEFS) */ -_PROTOTYPE(static int read_nln, (KA_T na, KA_T la, struct lnode *ln)); -_PROTOTYPE(static int read_nnn, (KA_T na, KA_T nna, struct namenode *n)); +static int read_nln(struct lsof_context *ctx, KA_T na, KA_T la, + struct lnode *ln); +static int read_nnn(struct lsof_context *ctx, KA_T na, KA_T nna, + struct namenode *n); #if solaris < 100000 -_PROTOTYPE(static void savesockmod, - (struct so_so * so, struct so_so *sop, int *so_st)); +static void savesockmod(struct so_so *so, struct so_so *sop, int *so_st); #else /* solaris>=100000 */ -_PROTOTYPE(static int read_ndvn, (KA_T na, KA_T da, struct dv_node *dv, - dev_t *dev, unsigned char *devs)); +static int read_ndvn(struct lsof_context *ctx, KA_T na, KA_T da, + struct dv_node *dv, dev_t *dev, unsigned char *devs); #endif /* solaris<100000 */ /* @@ -497,7 +520,7 @@ static KA_T Vvops[VXVOP_NUM]; /* addresses of: # define GETVOPS(name, nl, ops) \ if (get_Nl_value(name, nl, &ops) < 0) \ ops = (KA_T)0; \ - else if (kread(ops, (char *)&ops, sizeof(ops))) \ + else if (kread(ctx, ops, (char *)&ops, sizeof(ops))) \ ops = (KA_T)0 #else /* !defined(VOPNAME_OPEN) || solaris<100000 */ # define GETVOPS(name, nl, ops) \ @@ -512,7 +535,7 @@ static KA_T Vvops[VXVOP_NUM]; /* addresses of: * build_Voptab() -- build Voptab[] */ -static void build_Voptab() { +static void build_Voptab(struct lsof_context *ctx) { build_v_optab_t *bp; /* Build_v_optab[] pointer */ int fx; /* temporary file system type index */ int h; /* hash index */ @@ -534,12 +557,12 @@ static void build_Voptab() { if (!(Voptab = (v_optab_t **)calloc((MALLOC_S)VOPHASHBINS, sizeof(v_optab_t)))) { (void)fprintf(stderr, "%s: no space for Voptab\n", Pn); - Error(); + Error(ctx); } if (!(FxToVoptab = (v_optab_t **)calloc((MALLOC_S)Fsinfomax, sizeof(v_optab_t *)))) { (void)fprintf(stderr, "%s: no space for FxToVoptab\n", Pn); - Error(); + Error(ctx); } for (i = 0; i < VXVOP_NUM; i++) { Vvops[i] = (KA_T)NULL; @@ -580,7 +603,7 @@ static void build_Voptab() { if (!(nv = (v_optab_t *)malloc((MALLOC_S)sizeof(v_optab_t)))) { (void)fprintf(stderr, "%s: out of Voptab space at: %s\n", Pn, bp->dnm); - Error(); + Error(ctx); } nv->fsys = bp->fsys; nv->fx = -1; @@ -675,11 +698,11 @@ static void build_Voptab() { * CTF_getmem() -- get CTF members */ -int CTF_getmem(f, mod, ty, mem) -ctf_file_t *f; /* CTF file handle */ -const char *mod; /* module name */ -const char *ty; /* type */ -CTF_member_t *mem; /* member table */ +int CTF_getmem(struct lsof_context *ctx, /* context*/ + ctf_file_t *f, /* CTF file handle */ + const char *mod, /* module name */ + const char *ty, /* type */ + CTF_member_t *mem) /* member table */ { int err; /* error flag */ ctf_id_t id; /* CTF ID */ @@ -747,9 +770,10 @@ CTF_member_t *mem; /* member table */ * CTF_init - initialize CTF library access */ -void CTF_init(i, t, r) int *i; /* initialization status */ -char *t; /* kernel module template */ -CTF_request_t *r; /* CTF requests */ +void CTF_init(struct lsof_context *ctx, /* context */ + int *i, /* initialization status */ + char *t, /* kernel module template */ + CTF_request_t *r) /* CTF requests */ { int err; /* error status */ ctf_file_t *f; /* CTF file info handle */ @@ -780,7 +804,7 @@ CTF_request_t *r; /* CTF requests */ if (!isas) { if (sysinfo(SI_ARCHITECTURE_K, isa, sizeof(isa) - 1) == -1) { (void)fprintf(stderr, "%s: sysinfo: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } isas = 1; isa[sizeof(isa) - 1] = '\0'; @@ -797,7 +821,7 @@ CTF_request_t *r; /* CTF requests */ kernmod[sizeof(kernmod) - 1] = '\0'; kmp = kernmod; - if (statsafely(kmp, &sb)) { + if (statsafely(ctx, kmp, &sb)) { /* * The module at the specified path does not exist or is inaccessible. @@ -828,15 +852,15 @@ CTF_request_t *r; /* CTF requests */ if ((f = ctf_open(kmp, &err)) == NULL) { (void)fprintf(stderr, "%s: ctf_open: %s: %s\n", Pn, kmp, ctf_errmsg(err)); - Error(); + Error(ctx); } for (err = 0; r->name; r++) { - if (CTF_getmem(f, kmp, r->name, r->mem)) + if (CTF_getmem(ctx, f, kmp, r->name, r->mem)) err = 1; } (void)ctf_close(f); if (err) - Error(); + Error(ctx); *i = 1; } @@ -844,11 +868,10 @@ CTF_request_t *r; /* CTF requests */ * CTF_memCB() - Callback function for ctf_member_iter() */ -int CTF_memCB(name, id, offset, arg) const - char *name; /* structure member name */ -ctf_id_t id; /* CTF ID */ -ulong_t offset; /* member offset */ -void *arg; /* member table */ +int CTF_memCB(const char *name, /* structure member name */ + ctf_id_t id, /* CTF ID */ + ulong_t offset, /* member offset */ + void *arg) /* member table */ { CTF_member_t *mp; /* @@ -868,11 +891,10 @@ void *arg; /* member table */ * ent_fa() - enter fattach addresses in NAME column addition */ -static char *ent_fa(a1, a2, d, len) -KA_T *a1; /* first fattach address (NULL OK) */ -KA_T *a2; /* second fattach address */ -char *d; /* direction ("->" or "<-") */ -int *len; /* returned description length */ +static char *ent_fa(KA_T *a1, /* first fattach address (NULL OK) */ + KA_T *a2, /* second fattach address */ + char *d, /* direction ("->" or "<-") */ + int *len) /* returned description length */ { static char buf[1024]; size_t bufl = sizeof(buf); @@ -908,8 +930,8 @@ int *len; /* returned description length */ * is_socket() - is the stream a socket? */ -static int is_socket(v) -struct vnode *v; /* vnode pointer */ +static int is_socket(struct lsof_context *ctx, /* context */ + struct vnode *v) /* vnode pointer */ { char *cp, *ep, *pf; int i, j, len, n, pfl; @@ -989,7 +1011,7 @@ struct vnode *v; /* vnode pointer */ #endif /* solaris<80000 */ ) { - process_socket((KA_T)v->v_stream, tcpudp[i].proto); + process_socket(ctx, (KA_T)v->v_stream, tcpudp[i].proto); return (1); } } @@ -1000,8 +1022,8 @@ struct vnode *v; /* vnode pointer */ * isvlocked() - is Solaris vnode locked? */ -static char isvlocked(va) -struct vnode *va; /* local vnode address */ +static char isvlocked(struct lsof_context *ctx, /* context */ + struct vnode *va) /* local vnode address */ { #if solaris < 20500 @@ -1047,7 +1069,7 @@ struct vnode *va; /* local vnode address */ ff = fp = (KA_T)va->v_filocks; i = 0; do { - if (kread(fp, (char *)&f, sizeof(f))) + if (kread(ctx, fp, (char *)&f, sizeof(f))) return (' '); i++; if (f.set.l_pid != (pid_t)Lp->pid) @@ -1075,7 +1097,7 @@ struct vnode *va; /* local vnode address */ lf = lp = (KA_T)va->v_filocks; i = 0; do { - if (kread(lp, (char *)&ld, sizeof(ld))) + if (kread(ctx, lp, (char *)&ld, sizeof(ld))) return (' '); i++; if (!(LOCK_FLAGS & ACTIVE_LOCK) || LOCK_OWNER != (pid_t)Lp->pid) @@ -1111,18 +1133,18 @@ struct vnode *va; /* local vnode address */ * finddev() - look up device by device number */ -static struct l_dev *finddev(dev, rdev, flags) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ -int flags; /* look flags -- see LOOKDEV_* symbol - * definitions */ +static struct l_dev *finddev(struct lsof_context *ctx, /* context */ + dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int flags) /* look flags -- see LOOKDEV_* symbol + * definitions */ { struct clone *c; struct l_dev *dp; struct pseudo *p; if (!Sdev) - readdev(0); + readdev(ctx, 0); /* * Search device table for match. */ @@ -1134,7 +1156,7 @@ int flags; /* look flags -- see LOOKDEV_* symbol #endif /* defined(HASDCACHE) */ if (flags & LOOKDEV_TAB) { - if ((dp = lkupdev(dev, rdev, 0, 0))) + if ((dp = lkupdev(ctx, dev, rdev, 0, 0))) return (dp); } /* @@ -1145,7 +1167,7 @@ int flags; /* look flags -- see LOOKDEV_* symbol if (GET_MAJ_DEV(*rdev) == GET_MIN_DEV(c->cd.rdev)) { #if defined(HASDCACHE) - if (DCunsafe && !c->cd.v && !vfy_dev(&c->cd)) + if (DCunsafe && !c->cd.v && !vfy_dev(ctx, &c->cd)) goto finddev_again; #endif /* defined(HASDCACHE) */ @@ -1161,7 +1183,7 @@ int flags; /* look flags -- see LOOKDEV_* symbol if (GET_MAJ_DEV(*rdev) == GET_MAJ_DEV(p->pd.rdev)) { #if defined(HASDCACHE) - if (DCunsafe && !p->pd.v && !vfy_dev(&p->pd)) + if (DCunsafe && !p->pd.v && !vfy_dev(ctx, &p->pd)) goto finddev_again; #endif /* defined(HASDCACHE) */ @@ -1177,8 +1199,8 @@ int flags; /* look flags -- see LOOKDEV_* symbol * idoorkeep() -- identify door keeper process */ -static int idoorkeep(d) -struct door_node *d; /* door's node */ +static int idoorkeep(struct lsof_context *ctx, /* context */ + struct door_node *d) /* door's node */ { char buf[1024]; size_t bufl = sizeof(buf); @@ -1187,9 +1209,10 @@ struct door_node *d; /* door's node */ /* * Get the proc structure and its pid structure for the door target. */ - if (!d->door_target || kread((KA_T)d->door_target, (char *)&dp, sizeof(dp))) + if (!d->door_target || + kread(ctx, (KA_T)d->door_target, (char *)&dp, sizeof(dp))) return (0); - if (!dp.p_pidp || kread((KA_T)dp.p_pidp, (char *)&dpid, sizeof(dpid))) + if (!dp.p_pidp || kread(ctx, (KA_T)dp.p_pidp, (char *)&dpid, sizeof(dpid))) return (0); /* * Form a description of the door. @@ -1204,7 +1227,7 @@ struct door_node *d; /* door's node */ (void)snpf(buf, bufl, "(door to %.64s[%ld])", dp.p_user.u_comm, (long)dpid.pid_id); } - (void)add_nma(buf, (int)strlen(buf)); + (void)add_nma(ctx, buf, (int)strlen(buf)); return (1); } #endif /* solaris>=20500 */ @@ -1213,7 +1236,8 @@ struct door_node *d; /* door's node */ * process_node() - process vnode */ -void process_node(va) KA_T va; /* vnode kernel space address */ +void process_node(struct lsof_context *ctx, /* context */ + KA_T va) /* vnode kernel space address */ { #if defined(HASCACHEFS) @@ -1353,14 +1377,14 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* solaris<100000 */ if (ft) { - (void)build_Voptab(); + (void)build_Voptab(ctx); ft = 0; } /* * Read the vnode. */ if (!va) { - enter_nm("no vnode address"); + enter_nm(ctx, "no vnode address"); return; } if (!v) { @@ -1385,11 +1409,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HAS_AFS) */ ); - Error(); + Error(ctx); } } - if (readvnode(va, v)) { - enter_nm(Namech); + if (readvnode(ctx, va, v)) { + enter_nm(ctx, Namech); return; } @@ -1410,13 +1434,13 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Check for a Solaris socket. */ - if (is_socket(v)) + if (is_socket(ctx, v)) return; /* * Obtain the Solaris virtual file system structure. */ if ((ka = (KA_T)v->v_vfsp)) { - if (kread(ka, (char *)&kv, sizeof(kv))) { + if (kread(ctx, ka, (char *)&kv, sizeof(kv))) { vka = va; vfs_read_error: @@ -1425,7 +1449,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ print_kptr(vka, tbuf, sizeof(tbuf)), print_kptr(ka, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return; } kvs = 1; @@ -1447,7 +1471,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Determine the Solaris vnode type. */ - if ((Ntype = vop2ty(v, fx)) < 0) { + if ((Ntype = vop2ty(ctx, v, fx)) < 0) { if (v->v_type == VFIFO) { vty = N_REGLR; Ntype = N_FIFO; @@ -1461,7 +1485,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ fxs ? " (" : "", fxs ? Fsinfo[fx] : "", fxs ? ")" : "", print_kptr((KA_T)v->v_op, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return; } } else { @@ -1481,7 +1505,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * See if it's covering a socket as well and process accordingly. */ if (vty == N_NM) { - if (read_nnn(va, (KA_T)v->v_data, &nn)) + if (read_nnn(ctx, va, (KA_T)v->v_data, &nn)) return; nns = 1; if (nn.nm_mountpt) @@ -1496,10 +1520,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* solaris>=20500 */ if (Ntype != N_FIFO && nn.nm_filevp && - !kread((KA_T)nn.nm_filevp, (char *)&rv, sizeof(rv))) { + !kread(ctx, (KA_T)nn.nm_filevp, (char *)&rv, sizeof(rv))) { rvs = 1; if ((ka = (KA_T)rv.v_vfsp) && - !kread(ka, (char *)&rkv, sizeof(rkv)) && + !kread(ctx, ka, (char *)&rkv, sizeof(rkv)) && ((rfx = rkv.vfs_fstype - 1) >= 0) && (rfx < Fsinfomax)) { rfxs = 1; } else { @@ -1511,7 +1535,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->na = (KA_T)nn.nm_filevp; #endif /* defined(HASNCACHE) */ - if (is_socket(&rv)) + if (is_socket(ctx, &rv)) return; } } @@ -1525,13 +1549,13 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Determine the Solaris lock state. */ - Lf->lock = isvlocked(v); + Lf->lock = isvlocked(ctx, v); /* * Establish the Solaris local virtual file system structure. */ if (!(ka = (KA_T)v->v_vfsp) || !kvs) vfs = (struct l_vfs *)NULL; - else if (!(vfs = readvfs(ka, &kv, v))) { + else if (!(vfs = readvfs(ctx, ka, &kv, v))) { vka = va; goto vfs_read_error; } @@ -1547,11 +1571,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * type -- e.g. NFS, HSFS. Its vnode points to an snode. Subsequent * node structures are implied by the underlying node type. */ - if (read_nsn(va, (KA_T)v->v_data, &s)) + if (read_nsn(ctx, va, (KA_T)v->v_data, &s)) return; realvp = (KA_T)s.s_realvp; if (!realvp && s.s_commonvp) { - if (read_cni(&s, &rv, v, &rs, &di, din, sizeof(din)) == 1) + if (read_cni(ctx, &s, &rv, v, &rs, &di, din, sizeof(din)) == 1) return; if (!rv.v_stream) { if (din[0]) { @@ -1574,10 +1598,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ vty = N_STREAM; #if solaris < 100000 - read_mi(vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, so_ad, - &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, + so_ad, &sdp); #else /* solaris>=100000 */ - read_mi(vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); #endif /* solaris<100000 */ vs = (KA_T)NULL; @@ -1587,7 +1611,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HAS_AFS) case N_AFS: - if (readafsnode(va, v, &an)) + if (readafsnode(ctx, va, v, &an)) return; break; #endif /* defined(HAS_AFS) */ @@ -1596,9 +1620,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_AUTO: # if solaris < 20600 - if (read_nan(va, (KA_T)v->v_data, &au)) + if (read_nan(ctx, va, (KA_T)v->v_data, &au)) # else /* solaris>=20600 */ - if (read_nan(va, (KA_T)v->v_data, &fnn)) + if (read_nan(ctx, va, (KA_T)v->v_data, &fnn)) # endif /* solaris<20600 */ return; @@ -1606,14 +1630,14 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # if solaris >= 100000 case N_DEV: - if (read_ndvn(va, (KA_T)v->v_data, &dv, &dv_dev, &dv_devs)) + if (read_ndvn(ctx, va, (KA_T)v->v_data, &dv, &dv_dev, &dv_devs)) return; dvs = 1; break; # endif /* solaris>=100000 */ case N_DOOR: - if (read_ndn(va, (KA_T)v->v_data, &dn)) + if (read_ndn(ctx, va, (KA_T)v->v_data, &dn)) return; dns = 1; break; @@ -1621,7 +1645,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASCACHEFS) case N_CACHE: - if (read_ncn(va, (KA_T)v->v_data, &cn)) + if (read_ncn(ctx, va, (KA_T)v->v_data, &cn)) return; break; #endif /* defined(HASCACHEFS) */ @@ -1638,7 +1662,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_CTFSSYM: case N_CTFSTDIR: case N_CTFSTMPL: - if (read_nctfsn(Ntype, va, (KA_T)v->v_data, (char *)&ctfs)) + if (read_nctfsn(ctx, Ntype, va, (KA_T)v->v_data, (char *)&ctfs)) return; break; #endif /* solaris>=100000 */ @@ -1646,7 +1670,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if solaris >= 20600 case N_SOCK: sona = (KA_T)v->v_data; - if (read_nson(va, sona, &so)) + if (read_nson(ctx, va, sona, &so)) return; break; #endif /* solaris>=20600 */ @@ -1655,17 +1679,17 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* Information comes from the l_vfs structure. */ break; case N_MVFS: - if (read_nmn(va, (KA_T)v->v_data, &m)) + if (read_nmn(ctx, va, (KA_T)v->v_data, &m)) return; break; case N_NFS: - if (read_nrn(va, (KA_T)v->v_data, &r)) + if (read_nrn(ctx, va, (KA_T)v->v_data, &r)) return; break; #if solaris >= 100000 case N_NFS4: - if (read_nrn4(va, (KA_T)v->v_data, &r4)) + if (read_nrn4(ctx, va, (KA_T)v->v_data, &r4)) return; break; #endif /* solaris>=100000 */ @@ -1692,7 +1716,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ if (vty == N_NM && nns) { if (nn.nm_filevp) { - if (read_nfn(va, (KA_T)nn.nm_filevp, &f)) + if (read_nfn(ctx, va, (KA_T)nn.nm_filevp, &f)) return; realvp = (KA_T)NULL; vty = N_FIFO; @@ -1704,7 +1728,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ return; } } else { - if (read_nfn(va, (KA_T)v->v_data, &f)) + if (read_nfn(ctx, va, (KA_T)v->v_data, &f)) return; realvp = (KA_T)f.fn_realvp; } @@ -1723,7 +1747,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* solaris>=80000 Solaris 8 and above hack! */ Lf->inp_ty = 1; - enter_dev_ch(print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr((KA_T)v->v_data, (char *)NULL, 0)); if (f.fn_flag & ISPIPE) { (void)snpf(tbuf, sizeof(tbuf), "PIPE"); tbufx = (int)strlen(tbuf); @@ -1745,112 +1769,114 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* solaris<20500 */ if (tbufx) - (void)add_nma(tbuf, tbufx); + (void)add_nma(ctx, tbuf, tbufx); break; } break; case N_HSFS: - if (read_nhn(va, (KA_T)v->v_data, &h)) + if (read_nhn(ctx, va, (KA_T)v->v_data, &h)) return; break; case N_LOFS: llc = 0; do { rvs = 0; - if (read_nln(va, llc ? (KA_T)rv.v_data : (KA_T)v->v_data, &lo)) { + if (read_nln(ctx, va, llc ? (KA_T)rv.v_data : (KA_T)v->v_data, + &lo)) { return; } if (!(realvp = (KA_T)lo.lo_vp)) { (void)snpf(Namech, Namechl - 1, "lnode at %s: no real vnode", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return; } - if (read_nvn((KA_T)v->v_data, (KA_T)realvp, &rv)) + if (read_nvn(ctx, (KA_T)v->v_data, (KA_T)realvp, &rv)) return; rvs = 1; llc++; if ((ka = (KA_T)rv.v_vfsp) && - !kread(ka, (char *)&rkv, sizeof(rkv)) && + !kread(ctx, ka, (char *)&rkv, sizeof(rkv)) && ((rfx = rkv.vfs_fstype - 1) >= 0) && (rfx < Fsinfomax)) { rfxs = 1; } else { rfx = fx; rfxs = fxs; } - if (((vty_tmp = vop2ty(&rv, rfx)) == N_LOFS) && (llc > 1000)) { + if (((vty_tmp = vop2ty(ctx, &rv, rfx)) == N_LOFS) && (llc > 1000)) { (void)snpf(Namech, Namechl - 1, "lnode at %s: loop > 1000", print_kptr((KA_T)v->v_data, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return; } } while (vty_tmp == N_LOFS); break; case N_PCFS: - if (read_npn(va, (KA_T)v->v_data, &pc)) + if (read_npn(ctx, va, (KA_T)v->v_data, &pc)) return; break; #if solaris >= 100000 case N_PORT: - if (read_nprtn(va, (KA_T)v->v_data, &pn)) + if (read_nprtn(ctx, va, (KA_T)v->v_data, &pn)) return; break; #endif /* solaris>=100000 */ #if defined(HASPROCFS) case N_PROC: - if (read_npi(va, v, &pids)) + if (read_npi(ctx, va, v, &pids)) return; break; #endif /* defined(HASPROCFS) */ #if solaris >= 110000 case N_SDEV: - if (read_nsdn(va, (KA_T)v->v_data, &sdn, &sdva)) + if (read_nsdn(ctx, va, (KA_T)v->v_data, &sdn, &sdva)) return; sdns = 1; break; #endif /* solaris>=110000 */ case N_SAMFS: - (void)add_nma(SAMFS_NMA_MSG, (int)strlen(SAMFS_NMA_MSG)); + (void)add_nma(ctx, SAMFS_NMA_MSG, (int)strlen(SAMFS_NMA_MSG)); break; case N_SHARED: break; /* No more sharedfs information is available. */ case N_STREAM: - if (read_nsn(va, (KA_T)v->v_data, &s)) + if (read_nsn(ctx, va, (KA_T)v->v_data, &s)) return; if (vs) { Lf->is_stream = 1; #if solaris < 100000 - read_mi(vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, so_ad, &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, so_ad, + &sdp); #else /* solaris>=100000 */ - read_mi(vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); #endif /* solaris<100000 */ vs = (KA_T)NULL; } break; case N_TMP: - if (read_ntn(va, (KA_T)v->v_data, &t)) + if (read_ntn(ctx, va, (KA_T)v->v_data, &t)) return; break; #if defined(HASVXFS) case N_VXFS: - if (read_vxnode(va, v, vfs, fx, &vx, Vvops)) + if (read_vxnode(ctx, va, v, vfs, fx, &vx, Vvops)) return; break; #endif /* defined(HASVXFS) */ #if defined(HAS_ZFS) case N_ZFS: - if (read_nzn(va, (KA_T)v->v_data, &zn)) + if (read_nzn(ctx, va, (KA_T)v->v_data, &zn)) return; zns = 1; break; @@ -1858,7 +1884,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_REGLR: default: - if (read_nin(va, (KA_T)v->v_data, &i)) + if (read_nin(ctx, va, (KA_T)v->v_data, &i)) return; ins = 1; } @@ -1871,7 +1897,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ fx = rfx; fxs = rfxs; } else { - if (read_nvn((KA_T)v->v_data, (KA_T)realvp, v)) + if (read_nvn(ctx, (KA_T)v->v_data, (KA_T)realvp, v)) return; else { @@ -1880,7 +1906,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #endif /* defined(HASNCACHE) */ if ((ka = (KA_T)v->v_vfsp) && - !kread(ka, (char *)&kv, sizeof(kv))) { + !kread(ctx, ka, (char *)&kv, sizeof(kv))) { kvs = 1; } if (kvs && ((fx = kv.vfs_fstype - 1) >= 0) && @@ -1897,9 +1923,10 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->is_stream = 1; #if solaris < 100000 - read_mi(vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, so_ad, &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, so_ad, + &sdp); #else /* solaris>=100000 */ - read_mi(vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); #endif /* solaris<100000 */ vs = (KA_T)NULL; @@ -1907,7 +1934,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Get the real vnode's type. */ - if ((vty = vop2ty(v, fx)) < 0) { + if ((vty = vop2ty(ctx, v, fx)) < 0) { if (Ntype != N_FIFO && vs) vty = N_STREAM; else { @@ -1931,12 +1958,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ /* * Base further processing on the "real" vnode. */ - Lf->lock = isvlocked(v); + Lf->lock = isvlocked(ctx, v); switch (vty) { #if defined(HAS_AFS) case N_AFS: - if (readafsnode(va, v, &an)) + if (readafsnode(ctx, va, v, &an)) return; break; #endif /* defined(HAS_AFS) */ @@ -1945,9 +1972,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_AUTO: # if solaris < 20600 - if (read_nan(va, (KA_T)v->v_data, &au)) + if (read_nan(ctx, va, (KA_T)v->v_data, &au)) # else /* solaris>=20600 */ - if (read_nan(va, (KA_T)v->v_data, &fnn)) + if (read_nan(ctx, va, (KA_T)v->v_data, &fnn)) # endif /* solaris<20600 */ return; @@ -1955,7 +1982,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ # if solaris >= 100000 case N_DEV: - if (read_ndvn(va, (KA_T)v->v_data, &dv, &dv_dev, &dv_devs)) + if (read_ndvn(ctx, va, (KA_T)v->v_data, &dv, &dv_dev, &dv_devs)) return; dvs = 1; break; @@ -1964,9 +1991,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_DOOR: # if solaris < 20600 - if (read_ndn(realvp, (KA_T)v->v_data, &dn)) + if (read_ndn(ctx, realvp, (KA_T)v->v_data, &dn)) # else /* solaris>=20600 */ - if (read_ndn(va, (KA_T)v->v_data, &dn)) + if (read_ndn(ctx, va, (KA_T)v->v_data, &dn)) # endif /* solaris<20500 */ return; @@ -1976,7 +2003,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HASCACHEFS) case N_CACHE: - if (read_ncn(va, (KA_T)v->v_data, &cn)) + if (read_ncn(ctx, va, (KA_T)v->v_data, &cn)) return; break; #endif /* defined(HASCACHEFS) */ @@ -1993,57 +2020,57 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_CTFSSYM: case N_CTFSTDIR: case N_CTFSTMPL: - if (read_nctfsn(vty, va, (KA_T)v->v_data, (char *)&ctfs)) + if (read_nctfsn(ctx, vty, va, (KA_T)v->v_data, (char *)&ctfs)) return; break; #endif /* solaris>=100000 */ case N_HSFS: - if (read_nhn(va, (KA_T)v->v_data, &h)) + if (read_nhn(ctx, va, (KA_T)v->v_data, &h)) return; break; case N_MNT: /* Information comes from the l_vfs structure. */ break; case N_MVFS: - if (read_nmn(va, (KA_T)v->v_data, &m)) + if (read_nmn(ctx, va, (KA_T)v->v_data, &m)) return; break; case N_NFS: - if (read_nrn(va, (KA_T)v->v_data, &r)) + if (read_nrn(ctx, va, (KA_T)v->v_data, &r)) return; break; #if solaris >= 100000 case N_NFS4: - if (read_nrn4(va, (KA_T)v->v_data, &r4)) + if (read_nrn4(ctx, va, (KA_T)v->v_data, &r4)) return; break; #endif /* solaris>=100000 */ case N_NM: - if (read_nnn(va, (KA_T)v->v_data, &nn)) + if (read_nnn(ctx, va, (KA_T)v->v_data, &nn)) return; nns = 1; break; #if solaris >= 100000 case N_PORT: - if (read_nprtn(va, (KA_T)v->v_data, &pn)) + if (read_nprtn(ctx, va, (KA_T)v->v_data, &pn)) return; break; #endif /* solaris>=100000 */ case N_PCFS: - if (read_npn(va, (KA_T)v->v_data, &pc)) + if (read_npn(ctx, va, (KA_T)v->v_data, &pc)) return; break; case N_SAMFS: - (void)add_nma(SAMFS_NMA_MSG, (int)strlen(SAMFS_NMA_MSG)); + (void)add_nma(ctx, SAMFS_NMA_MSG, (int)strlen(SAMFS_NMA_MSG)); #if solaris >= 110000 case N_SDEV: - if (read_nsdn(va, (KA_T)v->v_data, &sdn, &sdva)) + if (read_nsdn(ctx, va, (KA_T)v->v_data, &sdn, &sdva)) return; if (Lf->is_stream) { @@ -2063,7 +2090,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if solaris >= 20600 case N_SOCK: sona = (KA_T)v->v_data; - if (read_nson(va, sona, &so)) + if (read_nson(ctx, va, sona, &so)) return; break; #endif /* solaris>=20600 */ @@ -2073,30 +2100,30 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->is_stream = 1; #if solaris < 100000 - read_mi(vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, so_ad, - &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, (caddr_t)&soso, &so_st, + so_ad, &sdp); #else /* solaris>=100000 */ - read_mi(vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); + read_mi(ctx, vs, (dev_t *)&s.s_dev, NULL, NULL, NULL, &sdp); #endif /* solaris<100000 */ vs = (KA_T)NULL; } break; case N_TMP: - if (read_ntn(va, (KA_T)v->v_data, &t)) + if (read_ntn(ctx, va, (KA_T)v->v_data, &t)) return; break; #if defined(HASVXFS) case N_VXFS: - if (read_vxnode(va, v, vfs, fx, &vx, Vvops)) + if (read_vxnode(ctx, va, v, vfs, fx, &vx, Vvops)) return; break; #endif /* defined(HASVXFS) */ #if defined(HAS_ZFS) case N_ZFS: - if (read_nzn(va, (KA_T)v->v_data, &zn)) + if (read_nzn(ctx, va, (KA_T)v->v_data, &zn)) return; zns = 1; break; @@ -2104,7 +2131,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_REGLR: default: - if (read_nin(va, (KA_T)v->v_data, &i)) + if (read_nin(ctx, va, (KA_T)v->v_data, &i)) return; ins = 1; } @@ -2247,7 +2274,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ dev = (dev_t)nn.nm_vattr.va_fsid; devs = 1; } else - enter_dev_ch(" NMFS"); + enter_dev_ch(ctx, " NMFS"); break; #if solaris >= 100000 @@ -2315,7 +2342,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * * Get its sotpi_info_t structure; */ - if (read_nsti(&so, &sti)) + if (read_nsti(ctx, &so, &sti)) return; /* * Get its device numbers. If they are located, start the NAME @@ -2325,7 +2352,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ nmrl = Namechl - 1; Namech[Namechl - 1] = '\0'; if (!sdp) - sdp = finddev(&DevDev, &sti.sti_dev, LOOKDEV_ALL); + sdp = finddev(ctx, &DevDev, &sti.sti_dev, LOOKDEV_ALL); if (sdp) { dev = DevDev; rdev = v->v_rdev; @@ -2402,9 +2429,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * they exist and as indicated by the socket node's state. */ if ((so.so_state & SS_ISBOUND) && - ((len = read_nusa(&sti.sti_laddr, &ua)) > 0) && + ((len = read_nusa(ctx, &sti.sti_laddr, &ua)) > 0) && (nmrl > (len + 5))) { - if (Sfile && is_file_named(ua.sun_path, Ntype, VSOCK, 0)) + if (Sfile && is_file_named(ctx, ua.sun_path, Ntype, VSOCK, 0)) Lf->sf |= SELNM; if (len > nmrl) len = nmrl; @@ -2417,9 +2444,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ } } if ((so.so_state & SS_ISCONNECTED) && - ((len = read_nusa(&sti.sti_faddr, &ua)) > 0) && + ((len = read_nusa(ctx, &sti.sti_faddr, &ua)) > 0) && (nmrl > (len + 5))) { - if (Sfile && is_file_named(ua.sun_path, Ntype, VSOCK, 0)) + if (Sfile && is_file_named(ctx, ua.sun_path, Ntype, VSOCK, 0)) Lf->sf |= SELNM; if (len > nmrl) len = nmrl; @@ -2441,7 +2468,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case AF_INET: case AF_INET6: case AF_ROUTE: - if (process_VSOCK((KA_T)va, v, &so)) + if (process_VSOCK(ctx, (KA_T)va, v, &so)) return; } } @@ -2489,7 +2516,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ nl = snl = (int)strlen(Namech); if ((len = read_nusa(&so.so_laddr, &ua))) { - if (Sfile && is_file_named(ua.sun_path, Ntype, VSOCK, 0)) + if (Sfile && is_file_named(ctx, ua.sun_path, Ntype, VSOCK, 0)) Lf->sf |= SELNM; sepl = Namech[0] ? 2 : 0; if (len > (Namechl - nl - sepl - 1)) @@ -2502,7 +2529,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ } } if ((len = read_nusa(&so.so_faddr, &ua))) { - if (Sfile && is_file_named(ua.sun_path, Ntype, VSOCK, 0)) + if (Sfile && is_file_named(ctx, ua.sun_path, Ntype, VSOCK, 0)) Lf->sf |= SELNM; sepl = Namech[0] ? 2 : 0; if (len > (Namechl - nl - sepl - 1)) @@ -2649,10 +2676,12 @@ void process_node(va) KA_T va; /* vnode kernel space address */ devs = 0; } if (soso.laddr.buf && soso.laddr.len == sizeof(ua)) { - if (kread((KA_T)soso.laddr.buf, (char *)&ua, sizeof(ua)) == 0) { + if (kread(ctx, (KA_T)soso.laddr.buf, (char *)&ua, sizeof(ua)) == + 0) { ua.sun_path[sizeof(ua.sun_path) - 1] = '\0'; if (ua.sun_path[0]) { - if (Sfile && is_file_named(ua.sun_path, Ntype, type, 0)) + if (Sfile && + is_file_named(ctx, ua.sun_path, Ntype, type, 0)) Lf->sf |= SELNM; len = (int)strlen(ua.sun_path); nl = (int)strlen(Namech); @@ -2706,9 +2735,9 @@ void process_node(va) KA_T va; /* vnode kernel space address */ #if defined(HAS_ZFS) case N_ZFS: if (zns) { - if (!read_nzvfs((KA_T)v->v_data, (KA_T)zn.z_zfsvfs, &zvfs) && + if (!read_nzvfs(ctx, (KA_T)v->v_data, (KA_T)zn.z_zfsvfs, &zvfs) && zvfs.z_vfs && - !kread((KA_T)zvfs.z_vfs, (char *)&zgvfs, sizeof(zgvfs))) { + !kread(ctx, (KA_T)zvfs.z_vfs, (char *)&zgvfs, sizeof(zgvfs))) { dev = zgvfs.vfs_dev; devs = 1; } @@ -2738,7 +2767,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ } type = v->v_type; if (devs && vfs && !vfs->dir) { - (void)completevfs(vfs, &dev); + (void)completevfs(ctx, vfs, &dev); #if defined(HAS_AFS) if (vfs->dir && (Ntype == N_AFS || vty == N_AFS) && !AFSVfsp) @@ -2870,7 +2899,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ case N_PCFS: if (kvs && kv.vfs_data && - !kread((KA_T)kv.vfs_data, (char *)&pcfs, sizeof(pcfs))) { + !kread(ctx, (KA_T)kv.vfs_data, (char *)&pcfs, sizeof(pcfs))) { #if solaris >= 70000 # if defined(HAS_PC_DIRENTPERSEC) @@ -3336,7 +3365,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Namech[Namechl - 1] = '\0'; # else /* solaris>=20600 */ if (fnn.fn_name && (len = fnn.fn_namelen) > 0 && len < (Namechl - 1)) { - if (kread((KA_T)fnn.fn_name, Namech, len)) + if (kread(ctx, (KA_T)fnn.fn_name, Namech, len)) Namech[0] = '\0'; else Namech[len] = '\0'; @@ -3353,11 +3382,11 @@ void process_node(va) KA_T va; /* vnode kernel space address */ */ if (nns && (!vfs || (!vfs->dir && !vfs->fsname)) && devs && (dev == nn.nm_vattr.va_fsid) && nn.nm_mountpt) { - if (!readvnode((KA_T)nn.nm_mountpt, &fv) && fv.v_vfsp) { - if ((nvfs = readvfs((KA_T)fv.v_vfsp, (struct vfs *)NULL, + if (!readvnode(ctx, (KA_T)nn.nm_mountpt, &fv) && fv.v_vfsp) { + if ((nvfs = readvfs(ctx, (KA_T)fv.v_vfsp, (struct vfs *)NULL, nn.nm_filevp)) && !nvfs->dir) { - (void)completevfs(nvfs, &dev); + (void)completevfs(ctx, nvfs, &dev); } # if defined(HASNCACHE) @@ -3461,7 +3490,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ Lf->rdev_def = rdevs; ty = "DOOR"; if (dns) - (void)idoorkeep(&dn); + (void)idoorkeep(ctx, &dn); break; #endif /* solaris>=20500 */ @@ -3536,8 +3565,8 @@ void process_node(va) KA_T va; /* vnode kernel space address */ else { ty = "sock"; - (void)printunkaf(so.so_family, 0); - ep = endnm(&sz); + (void)printunkaf(ctx, so.so_family, 0); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, ", %s", printsockty(so.so_type)); } } @@ -3586,7 +3615,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * If a file attach description remains, put it in the NAME column addition. */ if (fa) - (void)add_nma(fa, fal); + (void)add_nma(ctx, fa, fal); #if defined(HASBLKDEV) /* @@ -3594,7 +3623,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * supply one. */ if ((Lf->inp_ty == 0) && (type == VBLK)) - find_bl_ino(); + find_bl_ino(ctx); #endif /* defined(HASBLKDEV) */ /* @@ -3602,7 +3631,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * supply one. */ if ((Lf->inp_ty == 0) && (type == VCHR)) { - find_ch_ino(); + find_ch_ino(ctx); /* * If the VCHR inode number still isn't known and this is a COMMON * vnode file or a stream, or if a pseudo node ID lookup has been @@ -3617,13 +3646,13 @@ void process_node(va) KA_T va; /* vnode kernel space address */ if (!sdp) { if (rdevs || devs) { if (Lf->is_stream && !pnl) - sdp = finddev(devs ? &dev : &DevDev, + sdp = finddev(ctx, devs ? &dev : &DevDev, rdevs ? &rdev : &Lf->dev, LOOKDEV_CLONE); else - sdp = finddev(devs ? &dev : &DevDev, + sdp = finddev(ctx, devs ? &dev : &DevDev, rdevs ? &rdev : &Lf->dev, LOOKDEV_PSEUDO); if (!sdp) - sdp = finddev(devs ? &dev : &DevDev, + sdp = finddev(ctx, devs ? &dev : &DevDev, rdevs ? &rdev : &Lf->dev, LOOKDEV_ALL); if (sdp) { if (!rdevs) { @@ -3670,7 +3699,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ stderr, "%s: no space for (COMMON): PID %d; FD %s\n", Pn, Lp->pid, Lf->fd); - Error(); + Error(ctx); } (void)snpf(Lf->nma, len, "(COMMON)"); } @@ -3721,7 +3750,7 @@ void process_node(va) KA_T va; /* vnode kernel space address */ tdef = Lf->rdev_def; Lf->rdev_def = 1; } - if (is_file_named(NULL, Ntype, type, 1)) + if (is_file_named(ctx, NULL, Ntype, type, 1)) Lf->sf |= SELNM; if (trdevs) { Lf->rdev = rdev; @@ -3733,40 +3762,41 @@ void process_node(va) KA_T va; /* vnode kernel space address */ * Enter name characters. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } /* * read_cni() - read common snode information */ -static int read_cni(s, rv, v, rs, di, din, dinl) -struct snode *s; /* starting snode */ -struct vnode *rv; /* "real" vnode receiver */ -struct vnode *v; /* starting vnode */ -struct snode *rs; /* "real" snode receiver */ -struct dev_info *di; /* dev_info structure receiver */ -char *din; /* device info name receiver */ -int dinl; /* sizeof(*din) */ +static int read_cni(struct lsof_context *ctx, /* context */ + struct snode *s, /* starting snode */ + struct vnode *rv, /* "real" vnode receiver */ + struct vnode *v, /* starting vnode */ + struct snode *rs, /* "real" snode receiver */ + struct dev_info *di, /* dev_info structure receiver */ + char *din, /* device info name receiver */ + int dinl) /* sizeof(*din) */ { char tbuf[32]; - if (read_nvn((KA_T)v->v_data, (KA_T)s->s_commonvp, rv)) + if (read_nvn(ctx, (KA_T)v->v_data, (KA_T)s->s_commonvp, rv)) return (1); - if (read_nsn((KA_T)s->s_commonvp, (KA_T)rv->v_data, rs)) + if (read_nsn(ctx, (KA_T)s->s_commonvp, (KA_T)rv->v_data, rs)) return (1); *din = '\0'; if (rs->s_dip) { - if (kread((KA_T)rs->s_dip, (char *)di, sizeof(struct dev_info))) { + if (kread(ctx, (KA_T)rs->s_dip, (char *)di, sizeof(struct dev_info))) { (void)snpf(Namech, Namechl - 1, "common snode at %s: no dev info: %s", print_kptr((KA_T)rv->v_data, tbuf, sizeof(tbuf)), print_kptr((KA_T)rs->s_dip, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } - if (di->devi_name && kread((KA_T)di->devi_name, din, dinl - 1) == 0) + if (di->devi_name && + kread(ctx, (KA_T)di->devi_name, din, dinl - 1) == 0) din[dinl - 1] = '\0'; } return (0); @@ -3776,15 +3806,15 @@ int dinl; /* sizeof(*din) */ * readinode() - read inode */ -static int readinode(ia, i) -KA_T ia; /* inode kernel address */ -struct inode *i; /* inode buffer */ +static int readinode(struct lsof_context *ctx, /* context */ + KA_T ia, /* inode kernel address */ + struct inode *i) /* inode buffer */ { - if (kread((KA_T)ia, (char *)i, sizeof(struct inode))) { + if (kread(ctx, (KA_T)ia, (char *)i, sizeof(struct inode))) { (void)snpf(Namech, Namechl - 1, "can't read inode at %s", print_kptr((KA_T)ia, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -3795,19 +3825,19 @@ struct inode *i; /* inode buffer */ * read_ndn() - read node's door node */ -static int read_ndn(na, da, dn) -KA_T na; /* containing vnode's address */ -KA_T da; /* door node's address */ -struct door_node *dn; /* door node receiver */ +static int read_ndn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing vnode's address */ + KA_T da, /* door node's address */ + struct door_node *dn) /* door node receiver */ { char tbuf[32]; - if (!da || kread((KA_T)da, (char *)dn, sizeof(struct door_node))) { + if (!da || kread(ctx, (KA_T)da, (char *)dn, sizeof(struct door_node))) { (void)snpf(Namech, Namechl - 1, "vnode at %s: can't read door_node: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(da, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -3818,13 +3848,13 @@ struct door_node *dn; /* door node receiver */ * read_mi() - read stream's module information */ -static void read_mi(s, rdev, so, so_st, so_ad, - sdp) KA_T s; /* kernel stream pointer address */ -dev_t *rdev; /* raw device pointer */ -caddr_t so; /* so_so return (Solaris) */ -int *so_st; /* so_so status */ -KA_T *so_ad; /* so_so addresses */ -struct l_dev **sdp; /* returned device pointer */ +static void read_mi(struct lsof_context *ctx, /* context */ + KA_T s, /* kernel stream pointer address */ + dev_t *rdev, /* raw device pointer */ + caddr_t so, /* so_so return (Solaris) */ + int *so_st, /* so_so status */ + KA_T *so_ad, /* so_so addresses */ + struct l_dev **sdp) /* returned device pointer */ { struct l_dev *dp; int i, j, k, nl; @@ -3841,11 +3871,11 @@ struct l_dev **sdp; /* returned device pointer */ */ if (!s) return; - if (kread((KA_T)s, (char *)&sd, sizeof(sd))) { + if (kread(ctx, (KA_T)s, (char *)&sd, sizeof(sd))) { (void)snpf(Namech, Namechl - 1, "can't read stream head: %s", print_kptr(s, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return; } /* @@ -3860,8 +3890,8 @@ struct l_dev **sdp; /* returned device pointer */ */ k = 0; Namech[0] = '\0'; - if (!(dp = finddev(&DevDev, rdev, LOOKDEV_CLONE))) - dp = finddev(&DevDev, rdev, LOOKDEV_ALL); + if (!(dp = finddev(ctx, &DevDev, rdev, LOOKDEV_CLONE))) + dp = finddev(ctx, &DevDev, rdev, LOOKDEV_ALL); if (dp) { (void)snpf(Namech, Namechl - 1, "%s", dp->name); Namech[Namechl - 1] = '\0'; @@ -3873,15 +3903,15 @@ struct l_dev **sdp; /* returned device pointer */ mn[nl] = '\0'; qp = (KA_T)sd.sd_wrq; for (i = 0; qp && i < 20; i++, qp = (KA_T)q.q_next) { - if (!qp || kread(qp, (char *)&q, sizeof(q))) + if (!qp || kread(ctx, qp, (char *)&q, sizeof(q))) break; if ((ka = (KA_T)q.q_qinfo) == (KA_T)NULL || - kread(ka, (char *)&qi, sizeof(qi))) + kread(ctx, ka, (char *)&qi, sizeof(qi))) continue; if ((ka = (KA_T)qi.qi_minfo) == (KA_T)NULL || - kread(ka, (char *)&mi, sizeof(mi))) + kread(ctx, ka, (char *)&mi, sizeof(mi))) continue; - if ((ka = (KA_T)mi.mi_idname) == (KA_T)NULL || kread(ka, mn, nl)) + if ((ka = (KA_T)mi.mi_idname) == (KA_T)NULL || kread(ctx, ka, mn, nl)) continue; if ((j = (int)strlen(mn)) < 1) continue; @@ -3898,7 +3928,7 @@ struct l_dev **sdp; /* returned device pointer */ struct so_so s; - if (!kread((KA_T)q.q_ptr, (char *)&s, sizeof(s))) { + if (!kread(ctx, (KA_T)q.q_ptr, (char *)&s, sizeof(s))) { if (!(*so_st)) so_ad[0] = (KA_T)q.q_ptr; else @@ -3928,23 +3958,23 @@ struct l_dev **sdp; /* returned device pointer */ * read_nan(na, ca, cn) - read node's autofs node */ -static int read_nan(na, aa, rn) -KA_T na; /* containing node's address */ -KA_T aa; /* autofs node address */ +static int read_nan(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T aa, /* autofs node address */ # if solaris < 20600 -struct autonode *rn; /* autofs node receiver */ -# else /* solaris>=20600 */ -struct fnnode *rn; /* autofs node receiver */ -# endif /* solaris<20600 */ + struct autonode *rn) /* autofs node receiver */ +# else /* solaris>=20600 */ + struct fnnode *rn) /* autofs node receiver */ +# endif /* solaris<20600 */ { char tbuf[32]; # if solaris < 20600 - if (!aa || kread((KA_T)aa, (char *)rn, sizeof(struct autonode))) + if (!aa || kread(ctx, (KA_T)aa, (char *)rn, sizeof(struct autonode))) # else /* solaris>=20600 */ - if (!aa || kread((KA_T)aa, (char *)rn, sizeof(struct fnnode))) + if (!aa || kread(ctx, (KA_T)aa, (char *)rn, sizeof(struct fnnode))) # endif /* solaris<20600 */ { @@ -3959,7 +3989,7 @@ struct fnnode *rn; /* autofs node receiver */ print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(aa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -3971,19 +4001,19 @@ struct fnnode *rn; /* autofs node receiver */ * read_ncn(na, ca, cn) - read node's cache node */ -static int read_ncn(na, ca, cn) -KA_T na; /* containing node's address */ -KA_T ca; /* cache node address */ -struct cnode *cn; /* cache node receiver */ +static int read_ncn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ca, /* cache node address */ + struct cnode *cn) /* cache node receiver */ { char tbuf[32]; - if (!ca || kread((KA_T)ca, (char *)cn, sizeof(struct cnode))) { + if (!ca || kread(ctx, (KA_T)ca, (char *)cn, sizeof(struct cnode))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read cnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ca, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -3995,11 +4025,11 @@ struct cnode *cn; /* cache node receiver */ * read_nctfsn(ty, na, ca, cn) - read node's cache node */ -static int read_nctfsn(ty, na, ca, cn) -int ty; /* node type -- i.e., N_CTFS* */ -KA_T na; /* containing node's address */ -KA_T ca; /* cache node address */ -char *cn; /* CTFS node receiver */ +static int read_nctfsn(struct lsof_context *ctx, /* context */ + int ty, /* node type -- i.e., N_CTFS* */ + KA_T na, /* containing node's address */ + KA_T ca, /* cache node address */ + char *cn) /* CTFS node receiver */ { char *cp, *nm, tbuf[32]; READLEN_T sz; @@ -4052,16 +4082,16 @@ char *cn; /* CTFS node receiver */ default: (void)snpf(Namech, Namechl - 1, "unknown CTFS node type: %d", ty); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } - if (!ca || kread((KA_T)ca, cn, sz)) { + if (!ca || kread(ctx, (KA_T)ca, cn, sz)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read CTFS %s node: %s", print_kptr(na, tbuf, sizeof(tbuf)), nm, print_kptr(ca, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4072,19 +4102,19 @@ char *cn; /* CTFS node receiver */ * read_nfn() - read node's fifonode */ -static int read_nfn(na, fa, f) -KA_T na; /* containing node's address */ -KA_T fa; /* fifonode address */ -struct fifonode *f; /* fifonode receiver */ +static int read_nfn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T fa, /* fifonode address */ + struct fifonode *f) /* fifonode receiver */ { char tbuf[32]; - if (!fa || readfifonode(fa, f)) { + if (!fa || readfifonode(ctx, fa, f)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read fifonode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(fa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4094,19 +4124,19 @@ struct fifonode *f; /* fifonode receiver */ * read_nhn() - read node's High Sierra node */ -static int read_nhn(na, ha, h) -KA_T na; /* containing node's address */ -KA_T ha; /* hsnode address */ -struct hsnode *h; /* hsnode receiver */ +static int read_nhn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ha, /* hsnode address */ + struct hsnode *h) /* hsnode receiver */ { char tbuf[32]; - if (!ha || readhsnode(ha, h)) { + if (!ha || readhsnode(ctx, ha, h)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read hsnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ha, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4116,19 +4146,19 @@ struct hsnode *h; /* hsnode receiver */ * read_nin() - read node's inode */ -static int read_nin(na, ia, i) -KA_T na; /* containing node's address */ -KA_T ia; /* kernel inode address */ -struct inode *i; /* inode receiver */ +static int read_nin(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ia, /* kernel inode address */ + struct inode *i) /* inode receiver */ { char tbuf[32]; - if (!ia || readinode(ia, i)) { + if (!ia || readinode(ctx, ia, i)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read inode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ia, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4138,19 +4168,19 @@ struct inode *i; /* inode receiver */ * read_nln(na, la, ln) - read node's loopback node */ -static int read_nln(na, la, ln) -KA_T na; /* containing node's address */ -KA_T la; /* loopback node address */ -struct lnode *ln; /* loopback node receiver */ +static int read_nln(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T la, /* loopback node address */ + struct lnode *ln) /* loopback node receiver */ { char tbuf[32]; - if (!la || kread((KA_T)la, (char *)ln, sizeof(struct lnode))) { + if (!la || kread(ctx, (KA_T)la, (char *)ln, sizeof(struct lnode))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read lnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(la, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4160,19 +4190,19 @@ struct lnode *ln; /* loopback node receiver */ * read_nnn() - read node's namenode */ -static int read_nnn(na, nna, nn) -KA_T na; /* containing node's address */ -KA_T nna; /* namenode address */ -struct namenode *nn; /* namenode receiver */ +static int read_nnn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T nna, /* namenode address */ + struct namenode *nn) /* namenode receiver */ { char tbuf[32]; - if (!nna || kread((KA_T)nna, (char *)nn, sizeof(struct namenode))) { + if (!nna || kread(ctx, (KA_T)nna, (char *)nn, sizeof(struct namenode))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read namenode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(nna, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4182,19 +4212,19 @@ struct namenode *nn; /* namenode receiver */ * read_nmn() - read node's mvfsnode */ -static int read_nmn(na, ma, m) -KA_T na; /* containing node's address */ -KA_T ma; /* kernel mvfsnode address */ -struct mvfsnode *m; /* mvfsnode receiver */ +static int read_nmn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ma, /* kernel mvfsnode address */ + struct mvfsnode *m) /* mvfsnode receiver */ { char tbuf[32]; - if (!ma || kread((KA_T)ma, (char *)m, sizeof(struct mvfsnode))) { + if (!ma || kread(ctx, (KA_T)ma, (char *)m, sizeof(struct mvfsnode))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read mvfsnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ma, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4205,10 +4235,10 @@ struct mvfsnode *m; /* mvfsnode receiver */ * read_npi() - read node's /proc file system information */ -static int read_npi(na, v, pids) -KA_T na; /* containing node's address */ -struct vnode *v; /* containing vnode */ -struct pid *pids; /* pid structure receiver */ +static int read_npi(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + struct vnode *v, /* containing vnode */ + struct pid *pids) /* pid structure receiver */ { struct as as; struct proc p; @@ -4225,12 +4255,12 @@ struct pid *pids; /* pid structure receiver */ char *ty = (char *)NULL; # endif /* solaris>=20600 */ - if (!v->v_data || kread((KA_T)v->v_data, (char *)&pr, sizeof(pr))) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&pr, sizeof(pr))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read prnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_data, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } @@ -4246,35 +4276,36 @@ struct pid *pids; /* pid structure receiver */ if (v->v_type == VDIR) { (void)snpf(Namech, Namechl - 1, "/%s", HASPROCFS); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); Lf->inode = (INODETYPE)PR_ROOTINO; Lf->inp_ty = 1; } else { (void)snpf(Namech, Namechl - 1, "/%s/", HASPROCFS); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); Lf->inp_ty = 0; } return (0); } - if (kread((KA_T)pr.pr_proc, (char *)&p, sizeof(p))) { + if (kread(ctx, (KA_T)pr.pr_proc, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl - 1, "prnode at %s: can't read proc: %s", print_kptr((KA_T)v->v_data, tbuf, sizeof(tbuf)), print_kptr((KA_T)pr.pr_proc, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } - if (p.p_as && !kread((KA_T)p.p_as, (char *)&as, sizeof(as))) { + if (p.p_as && !kread(ctx, (KA_T)p.p_as, (char *)&as, sizeof(as))) { Lf->sz = (SZOFFTYPE)as.a_size; Lf->sz_def = 1; } - if (!p.p_pidp || kread((KA_T)p.p_pidp, (char *)pids, sizeof(struct pid))) { + if (!p.p_pidp || + kread(ctx, (KA_T)p.p_pidp, (char *)pids, sizeof(struct pid))) { (void)snpf(Namech, Namechl - 1, "proc struct at %s: can't read pid: %s", print_kptr((KA_T)pr.pr_proc, tbuf, sizeof(tbuf)), print_kptr((KA_T)p.p_pidp, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } (void)snpf(Namech, Namechl, "/%s/%d", HASPROCFS, (int)pids->pid_id); @@ -4295,38 +4326,40 @@ struct pid *pids; /* pid structure receiver */ * Identify the lwp PID (the thread ID). */ if (pr.pr_common && - kread((KA_T)pr.pr_common, (char *)&pc, sizeof(pc)) == 0) { + kread(ctx, (KA_T)pr.pr_common, (char *)&pc, sizeof(pc)) == 0) { pcs = 1; - if (pc.prc_proc && kread((KA_T)pc.prc_proc, (char *)&p, sizeof(p)) == 0) + if (pc.prc_proc && + kread(ctx, (KA_T)pc.prc_proc, (char *)&p, sizeof(p)) == 0) prpcs = 1; else prpcs = 0; } else pcs = prpcs = 0; if (pr.pr_pcommon && - kread((KA_T)pr.pr_pcommon, (char *)&ppc, sizeof(ppc)) == 0) { + kread(ctx, (KA_T)pr.pr_pcommon, (char *)&ppc, sizeof(ppc)) == 0) { ppcs = 1; if (ppc.prc_proc && - kread((KA_T)ppc.prc_proc, (char *)&pp, sizeof(pp)) == 0) + kread(ctx, (KA_T)ppc.prc_proc, (char *)&pp, sizeof(pp)) == 0) prppcs = 1; else prppcs = 0; } else ppcs = prppcs = 0; if (prpcs && p.p_pidp && - kread((KA_T)p.p_pidp, (char *)pids, sizeof(struct pid)) == 0) + kread(ctx, (KA_T)p.p_pidp, (char *)pids, sizeof(struct pid)) == 0) prpid = pids->pid_id; else if (prppcs && pp.p_pidp && - kread((KA_T)pp.p_pidp, (char *)pids, sizeof(struct pid)) == 0) + kread(ctx, (KA_T)pp.p_pidp, (char *)pids, sizeof(struct pid)) == 0) prpid = pids->pid_id; else pids->pid_id = prpid = (pid_t)0; if (pcs && pc.prc_thread && - kread((KA_T)pc.prc_thread, (char *)&thread, sizeof(kthread_t)) == 0) + kread(ctx, (KA_T)pc.prc_thread, (char *)&thread, sizeof(kthread_t)) == + 0) prtid = thread.t_tid; else if (ppcs && ppc.prc_thread && - kread((KA_T)ppc.prc_thread, (char *)&thread, sizeof(kthread_t)) == - 0) + kread(ctx, (KA_T)ppc.prc_thread, (char *)&thread, + sizeof(kthread_t)) == 0) prtid = thread.t_tid; else prtid = (id_t)0; @@ -4346,8 +4379,9 @@ struct pid *pids; /* pid structure receiver */ case PR_AS: (void)snpf(Namech, Namechl - 1, "/%s/%d/as", HASPROCFS, (int)prpid); ty = "PAS"; - if (prpcs && kread((KA_T)pc.prc_proc, (char *)&p, sizeof(p)) == 0 && - p.p_as && kread((KA_T)p.p_as, (char *)&as, sizeof(as)) == 0) { + if (prpcs && + kread(ctx, (KA_T)pc.prc_proc, (char *)&p, sizeof(p)) == 0 && + p.p_as && kread(ctx, (KA_T)p.p_as, (char *)&as, sizeof(as)) == 0) { Lf->sz = (SZOFFTYPE)as.a_size; Lf->sz_def = 1; } @@ -4525,7 +4559,7 @@ struct pid *pids; /* pid structure receiver */ # endif /* solaris<20600 */ Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (0); } #endif /* defined(HASPROCFS) */ @@ -4534,19 +4568,19 @@ struct pid *pids; /* pid structure receiver */ * read_npn() - read node's pcnode */ -static int read_npn(na, pa, p) -KA_T na; /* containing node's address */ -KA_T pa; /* pcnode address */ -struct pcnode *p; /* pcnode receiver */ +static int read_npn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T pa, /* pcnode address */ + struct pcnode *p) /* pcnode receiver */ { char tbuf[32]; - if (!pa || kread(pa, (char *)p, sizeof(struct pcnode))) { + if (!pa || kread(ctx, pa, (char *)p, sizeof(struct pcnode))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read pcnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(pa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4557,19 +4591,19 @@ struct pcnode *p; /* pcnode receiver */ * read_nprtn() - read node's port node */ -static int read_nprtn(na, pa, p) -KA_T na; /* containing node's address */ -KA_T pa; /* port node address */ -port_t *p; /* port node receiver */ +static int read_nprtn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T pa, /* port node address */ + port_t *p) /* port node receiver */ { char tbuf[32]; - if (!pa || kread(pa, (char *)p, sizeof(port_t))) { + if (!pa || kread(ctx, pa, (char *)p, sizeof(port_t))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read port node: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(pa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4580,19 +4614,19 @@ port_t *p; /* port node receiver */ * read_nrn() - read node's rnode */ -static int read_nrn(na, ra, r) -KA_T na; /* containing node's address */ -KA_T ra; /* rnode address */ -struct rnode *r; /* rnode receiver */ +static int read_nrn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ra, /* rnode address */ + struct rnode *r) /* rnode receiver */ { char tbuf[32]; - if (!ra || readrnode(ra, r)) { + if (!ra || readrnode(ctx, ra, r)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read rnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ra, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4603,19 +4637,19 @@ struct rnode *r; /* rnode receiver */ * read_nrn4() - read node's rnode4 */ -static int read_nrn4(na, ra, r) -KA_T na; /* containing node's address */ -KA_T ra; /* rnode address */ -struct rnode4 *r; /* rnode receiver */ +static int read_nrn4(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ra, /* rnode address */ + struct rnode4 *r) /* rnode receiver */ { char tbuf[32]; - if (!ra || kread((KA_T)ra, (char *)r, sizeof(struct rnode4))) { + if (!ra || kread(ctx, (KA_T)ra, (char *)r, sizeof(struct rnode4))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read rnode4: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ra, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4627,32 +4661,32 @@ struct rnode4 *r; /* rnode receiver */ * read_nsdn() - read node's sdev_node */ -static int read_nsdn(na, sa, sdn, sdva) -KA_T na; /* containing node's adress */ -KA_T sa; /* sdev_node address */ -struct sdev_node *sdn; /* sdev_node receiver */ -struct vattr *sdva; /* sdev_node's vattr receiver */ +static int read_nsdn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's adress */ + KA_T sa, /* sdev_node address */ + struct sdev_node *sdn, /* sdev_node receiver */ + struct vattr *sdva) /* sdev_node's vattr receiver */ { KA_T va; char tbuf[32], tbuf1[32]; - if (!sa || kread((KA_T)sa, (char *)sdn, sizeof(struct sdev_node))) { + if (!sa || kread(ctx, (KA_T)sa, (char *)sdn, sizeof(struct sdev_node))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read sdev_node: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(sa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } if (!(va = (KA_T)sdn->sdev_attr) || - kread(va, (char *)sdva, sizeof(struct vattr))) { + kread(ctx, va, (char *)sdva, sizeof(struct vattr))) { (void)snpf(Namech, Namechl - 1, "node at %s; sdev_node at %s: can't read vattr: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(sa, tbuf1, sizeof(tbuf1)), print_kptr(va, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4664,20 +4698,20 @@ struct vattr *sdva; /* sdev_node's vattr receiver */ * read_nson() - read node's sonode */ -static int read_nson(na, sa, sn) -KA_T na; /* containing node's address */ -KA_T sa; /* sonode address */ -struct sonode *sn; /* sonode receiver */ +static int read_nson(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T sa, /* sonode address */ + struct sonode *sn) /* sonode receiver */ { char tbuf[32]; - if (!sa || kread((KA_T)sa, (char *)sn, sizeof(struct sonode))) { + if (!sa || kread(ctx, (KA_T)sa, (char *)sn, sizeof(struct sonode))) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read sonode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(sa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4688,19 +4722,19 @@ struct sonode *sn; /* sonode receiver */ * read_nsn() - read node's snode */ -static int read_nsn(na, sa, s) -KA_T na; /* containing node's address */ -KA_T sa; /* snode address */ -struct snode *s; /* snode receiver */ +static int read_nsn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T sa, /* snode address */ + struct snode *s) /* snode receiver */ { char tbuf[32]; - if (!sa || readsnode(sa, s)) { + if (!sa || readsnode(ctx, sa, s)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read snode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(sa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4711,13 +4745,13 @@ struct snode *s; /* snode receiver */ * read_nsti() - read socket node's info */ -static int read_nsti(so, stpi) -struct sonode *so; /* socket's sonode */ -sotpi_info_t *stpi; /* local socket info receiver */ +static int read_nsti(struct lsof_context *ctx, /* context */ + struct sonode *so, /* socket's sonode */ + sotpi_info_t *stpi) /* local socket info receiver */ { char tbuf[32]; - (void)CTF_init(&Sockfs_ctfs, SOCKFS_MOD_FORMAT, Sockfs_requests); + (void)CTF_init(ctx, &Sockfs_ctfs, SOCKFS_MOD_FORMAT, Sockfs_requests); if (!so || !so->so_priv || CTF_MEMBER_READ(so->so_priv, stpi, sotpi_info_members, sti_dev) || CTF_MEMBER_READ(so->so_priv, stpi, sotpi_info_members, sti_laddr) || @@ -4729,7 +4763,7 @@ sotpi_info_t *stpi; /* local socket info receiver */ print_kptr((KA_T)so, tbuf, sizeof(tbuf)), print_kptr((KA_T)so->so_priv, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4740,19 +4774,19 @@ sotpi_info_t *stpi; /* local socket info receiver */ * read_ntn() - read node's tmpnode */ -static int read_ntn(na, ta, t) -KA_T na; /* containing node's address */ -KA_T ta; /* tmpnode address */ -struct tmpnode *t; /* tmpnode receiver */ +static int read_ntn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T ta, /* tmpnode address */ + struct tmpnode *t) /* tmpnode receiver */ { char tbuf[32]; - if (!ta || readtnode(ta, t)) { + if (!ta || readtnode(ctx, ta, t)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read tnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(ta, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4763,9 +4797,9 @@ struct tmpnode *t; /* tmpnode receiver */ * read_nusa() - read sondode's UNIX socket address */ -static int read_nusa(so, ua) -struct soaddr *so; /* kernel socket info structure */ -struct sockaddr_un *ua; /* local sockaddr_un address */ +static int read_nusa(struct lsof_context *ctx, /* context */ + struct soaddr *so, /* kernel socket info structure */ + struct sockaddr_un *ua) /* local sockaddr_un address */ { KA_T a; int len; @@ -4774,8 +4808,8 @@ struct sockaddr_un *ua; /* local sockaddr_un address */ ua->sun_path[0] = '\0'; if (!(a = (KA_T)so->soa_sa) || (len = so->soa_len) < (min + 2) || - len > (int)sizeof(struct sockaddr_un) || kread(a, (char *)ua, len) || - ua->sun_family != AF_UNIX) + len > (int)sizeof(struct sockaddr_un) || + kread(ctx, a, (char *)ua, len) || ua->sun_family != AF_UNIX) return (0); len -= min; if (len >= sizeof(ua->sun_path)) @@ -4789,19 +4823,19 @@ struct sockaddr_un *ua; /* local sockaddr_un address */ * read_nvn() - read node's vnode */ -static int read_nvn(na, va, v) -KA_T na; /* node's address */ -KA_T va; /* vnode address */ -struct vnode *v; /* vnode receiver */ +static int read_nvn(struct lsof_context *ctx, /* context */ + KA_T na, /* node's address */ + KA_T va, /* vnode address */ + struct vnode *v) /* vnode receiver */ { char tbuf[32]; - if (readvnode(va, v)) { + if (readvnode(ctx, va, v)) { (void)snpf(Namech, Namechl - 1, "node at %s: can't read real vnode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(va, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4812,17 +4846,17 @@ struct vnode *v; /* vnode receiver */ * read_nzn() - read node's ZFS node */ -static int read_nzn(na, nza, zn) -KA_T na; /* containing node's address */ -KA_T nza; /* znode address */ -znode_t *zn; /* znode receiver */ +static int read_nzn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing node's address */ + KA_T nza, /* znode address */ + znode_t *zn) /* znode receiver */ { int err = 0; /* error flag */ CTF_member_t *mp; /* member pointer */ char tbuf[32]; /* temporary buffer */ znode_phys_t zp; /* physical znode */ - (void)CTF_init(&ZFS_ctfs, ZFS_MOD_FORMAT, ZFS_requests); + (void)CTF_init(ctx, &ZFS_ctfs, ZFS_MOD_FORMAT, ZFS_requests); if (!nza || CTF_MEMBER_READ(nza, zn, znode_members, z_zfsvfs) || CTF_MEMBER_READ(nza, zn, znode_members, z_vnode) || CTF_MEMBER_READ(nza, zn, znode_members, z_id) || @@ -4833,7 +4867,7 @@ znode_t *zn; /* znode receiver */ print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(nza, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } /* @@ -4841,7 +4875,7 @@ znode_t *zn; /* znode receiver */ * and propagate its values to the znode. */ if (znode_members[MX_z_phys].m_offset != CTF_MEMBER_UNDEF) { - err = read_nznp(nza, (KA_T)zn->z_phys, &zp); + err = read_nznp(ctx, nza, (KA_T)zn->z_phys, &zp); if (!err) { zn->z_links = zp.zp_links; zn->z_size = zp.zp_size; @@ -4857,7 +4891,7 @@ znode_t *zn; /* znode receiver */ print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(nza, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); err = 1; } if (znode_members[MX_z_size].m_offset == CTF_MEMBER_UNDEF) { @@ -4865,7 +4899,7 @@ znode_t *zn; /* znode receiver */ print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(nza, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); err = 1; } } @@ -4876,14 +4910,14 @@ znode_t *zn; /* znode receiver */ * read_nznp() - read znode's persistent znode */ -static int read_nznp(nza, nzpa, zp) -KA_T nza; /* containing znode's address */ -KA_T nzpa; /* persistent znode address */ -znode_phys_t *zp; /* persistent znode receiver */ +static int read_nznp(struct lsof_context *ctx, /* context */ + KA_T nza, /* containing znode's address */ + KA_T nzpa, /* persistent znode address */ + znode_phys_t *zp) /* persistent znode receiver */ { char tbuf[32]; - (void)CTF_init(&ZFS_ctfs, ZFS_MOD_FORMAT, ZFS_requests); + (void)CTF_init(ctx, &ZFS_ctfs, ZFS_MOD_FORMAT, ZFS_requests); if (!nzpa || CTF_MEMBER_READ(nzpa, zp, znode_phys_members, zp_size) || CTF_MEMBER_READ(nzpa, zp, znode_phys_members, zp_links)) { (void)snpf(Namech, Namechl - 1, @@ -4892,7 +4926,7 @@ znode_phys_t *zp; /* persistent znode receiver */ print_kptr(nza, tbuf, sizeof(tbuf)), print_kptr(nzpa, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4902,20 +4936,20 @@ znode_phys_t *zp; /* persistent znode receiver */ * read_nzvfs() - read znode's associated vfs */ -static int read_nzvfs(nza, nzva, zv) -KA_T nza; /* containing znode's address */ -KA_T nzva; /* associated vfs address */ -zfsvfs_t *zv; /* associated vfs receiver */ +static int read_nzvfs(struct lsof_context *ctx, /* context */ + KA_T nza, /* containing znode's address */ + KA_T nzva, /* associated vfs address */ + zfsvfs_t *zv) /* associated vfs receiver */ { char tbuf[32]; - (void)CTF_init(&ZFS_ctfs, ZFS_MOD_FORMAT, ZFS_requests); + (void)CTF_init(ctx, &ZFS_ctfs, ZFS_MOD_FORMAT, ZFS_requests); if (!nzva || CTF_MEMBER_READ(nzva, zv, zfsvfs_members, z_vfs)) { (void)snpf(Namech, Namechl - 1, "znode at %s: can't read zfsvfs: %s", print_kptr(nza, tbuf, sizeof(tbuf)), print_kptr(nzva, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -4928,10 +4962,9 @@ zfsvfs_t *zv; /* associated vfs receiver */ */ static void - savesockmod(so, sop, - so_st) struct so_so *so; /* new so_so structure pointer */ -struct so_so *sop; /* previous so_so structure pointer */ -int *so_st; /* status of *sop (0 if not loaded) */ +savesockmod(struct so_so *so, /* new so_so structure pointer */ + struct so_so *sop, /* previous so_so structure pointer */ + int *so_st) /* status of *sop (0 if not loaded) */ { # if solaris < 20500 @@ -5088,9 +5121,9 @@ int *so_st; /* status of *sop (0 if not loaded) */ * vop2ty() - convert vnode operation switch address to internal type */ -int vop2ty(vp, fx) -struct vnode *vp; /* local vnode pointer */ -int fx; /* file system index (-1 if none) */ +int vop2ty(struct lsof_context *ctx, /* context */ + struct vnode *vp, /* local vnode pointer */ + int fx) /* file system index (-1 if none) */ { int h; register int i; @@ -5130,7 +5163,7 @@ int fx; /* file system index (-1 if none) */ if (!(nv = (v_optab_t *)malloc((MALLOC_S)sizeof(v_optab_t)))) { (void)fprintf(stderr, "%s: can't add \"%s\" to Voptab\n", Pn, Fsinfo[fx]); - Error(); + Error(ctx); } *nv = *v; nv->v_op = ka; @@ -5175,13 +5208,13 @@ int fx; /* file system index (-1 if none) */ * read_ndvn() -- read node's dv_node */ -static int read_ndvn(na, da, dv, dev, devs) -KA_T na; /* containing vnode's address */ -KA_T da; /* containing vnode's v_data */ -struct dv_node *dv; /* dv_node receiver */ -dev_t *dev; /* underlying file system device - * number receptor */ -unsigned char *devs; /* status of *dev */ +static int read_ndvn(struct lsof_context *ctx, /* context */ + KA_T na, /* containing vnode's address */ + KA_T da, /* containing vnode's v_data */ + struct dv_node *dv, /* dv_node receiver */ + dev_t *dev, /* underlying file system device + * number receptor */ + unsigned char *devs) /* status of *dev */ { struct vnode rv; struct snode s; @@ -5190,44 +5223,44 @@ unsigned char *devs; /* status of *dev */ /* * Read the snode. */ - if (!da || kread((KA_T)da, (char *)&s, sizeof(s))) { + if (!da || kread(ctx, (KA_T)da, (char *)&s, sizeof(s))) { (void)snpf(Namech, Namechl - 1, "dv_node vnode at %s: can't read snode: %s", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr(da, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } /* * Read the snode's real vnode. */ if (!s.s_realvp || - kread((KA_T)s.s_realvp, (char *)&rv, sizeof(struct dv_node))) { + kread(ctx, (KA_T)s.s_realvp, (char *)&rv, sizeof(struct dv_node))) { (void)snpf(Namech, Namechl - 1, "dv_node snode at %s: can't read real vnode: %s", print_kptr(da, tbuf, sizeof(tbuf)), print_kptr((KA_T)s.s_realvp, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } /* * Read the real vnode's dv_node. */ - if (!rv.v_data || kread((KA_T)rv.v_data, (char *)dv, sizeof(rv))) { + if (!rv.v_data || kread(ctx, (KA_T)rv.v_data, (char *)dv, sizeof(rv))) { (void)snpf(Namech, Namechl - 1, "dv_node real vnode at %s: can't read dv_node: %s", print_kptr((KA_T)s.s_realvp, tbuf, sizeof(tbuf)), print_kptr((KA_T)rv.v_data, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } /* * Return the device number of the underlying file system, if possible. */ - if (rv.v_vfsp && !kread((KA_T)rv.v_vfsp, (char *)&v, sizeof(v))) { + if (rv.v_vfsp && !kread(ctx, (KA_T)rv.v_vfsp, (char *)&v, sizeof(v))) { *dev = v.vfs_dev; *devs = 1; } diff --git a/lib/dialects/sun/dnode1.c b/lib/dialects/sun/dnode1.c index 8cec7eae..58785dc3 100644 --- a/lib/dialects/sun/dnode1.c +++ b/lib/dialects/sun/dnode1.c @@ -112,8 +112,8 @@ typedef struct afs_bozoLock afs_bozoLock_t; * Local function prototypes */ -_PROTOTYPE(static struct volume *getvolume, (struct VenusFid * f, int *vols)); -_PROTOTYPE(static int is_rootFid, (struct vcache * vc, int *rfid)); +static struct volume *getvolume(struct VenusFid *f, int *vols); +static int is_rootFid(struct vcache *vc, int *rfid); /* * alloc_vcache() - allocate space for vcache structure @@ -127,7 +127,7 @@ struct vnode *alloc_vcache() { * ckAFSsym() - check for missing X_AFS_* symbols in AFS name list file */ -void ckAFSsym(nl) struct nlist *nl; /* copy of Nl[] when empty */ +void ckAFSsym(struct nlist *nl) /* copy of Nl[] when empty */ { char *path = AFSAPATHDEF; int i; @@ -179,9 +179,8 @@ void ckAFSsym(nl) struct nlist *nl; /* copy of Nl[] when empty */ * getvolume() - get volume structure */ -static struct volume *getvolume(f, vols) -struct VenusFid *f; /* file ID pointer */ -int *vols; /* afs_volumes status return */ +static struct volume *getvolume(struct VenusFid *f, /* file ID pointer */ + int *vols) /* afs_volumes status return */ { int i; static KA_T ka = 0; @@ -208,10 +207,10 @@ int *vols; /* afs_volumes status return */ *vols = 1; i = (NVOLS - 1) & f->Fid.Volume; kh = (KA_T)((char *)ka + (i * sizeof(struct volume *))); - if (kread(kh, (char *)&vp, sizeof(vp))) + if (kread(ctx, kh, (char *)&vp, sizeof(vp))) return ((struct volume *)NULL); while (vp) { - if (kread((KA_T)vp, (char *)&v, sizeof(v))) + if (kread(ctx, (KA_T)vp, (char *)&v, sizeof(v))) return ((struct volume *)NULL); if (v.volume == f->Fid.Volume && v.cell == f->Cell) return (&v); @@ -224,8 +223,7 @@ int *vols; /* afs_volumes status return */ * hasAFS() - test for AFS presence via vfs structure */ -int hasAFS(vp) -struct vnode *vp; /* vnode pointer */ +int hasAFS(struct vnode *vp) /* vnode pointer */ { struct mounts *mp; int n; @@ -245,7 +243,7 @@ struct vnode *vp; /* vnode pointer */ if (!AFSdevStat) (void)readmnt(); if (!AFSdevStat || vp->v_data || !vp->v_vfsp || - kread((KA_T)vp->v_vfsp, (char *)&v, sizeof(v)) || v.vfs_data) + kread(ctx, (KA_T)vp->v_vfsp, (char *)&v, sizeof(v)) || v.vfs_data) return (0); if ((dev_t)v.vfs_fsid.val[0] == AFSdev) { AFSVfsp = (KA_T)vp->v_vfsp; @@ -284,9 +282,8 @@ struct vnode *vp; /* vnode pointer */ * 1 if root file ID structure address available */ -static int is_rootFid(vc, rfid) -struct vcache *vc; /* vcache structure */ -int *rfid; /* root file ID pointer status return */ +static int is_rootFid(struct vcache *vc, /* vcache structure */ + int *rfid) /* root file ID pointer status return */ { KA_T arFid; char *err; @@ -327,7 +324,7 @@ int *rfid; /* root file ID pointer status return */ *rfid = 0; return (0); } - if (kread(arFid, (char *)&r, sizeof(r))) { + if (kread(ctx, arFid, (char *)&r, sizeof(r))) { err = "can't read afs_rootFid from kernel"; goto rfid_unavailable; } @@ -348,10 +345,9 @@ int *rfid; /* root file ID pointer status return */ * readafsnode() - read AFS node */ -int readafsnode(va, v, an) -KA_T va; /* kernel vnode address */ -struct vnode *v; /* vnode buffer pointer */ -struct afsnode *an; /* afsnode recipient */ +int readafsnode(KA_T va, /* kernel vnode address */ + struct vnode *v, /* vnode buffer pointer */ + struct afsnode *an) /* afsnode recipient */ { char *cp, tbuf[32]; KA_T ka; @@ -362,12 +358,12 @@ struct afsnode *an; /* afsnode recipient */ cp = ((char *)v + sizeof(struct vnode)); ka = (KA_T)((char *)va + sizeof(struct vnode)); len = sizeof(struct vcache) - sizeof(struct vnode); - if (kread(ka, cp, len)) { + if (kread(ctx, ka, cp, len)) { (void)snpf(Namech, Namechl, "vnode at %s: can't read vcache remainder from %s", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr(ka, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } vc = (struct vcache *)v; diff --git a/lib/dialects/sun/dnode2.c b/lib/dialects/sun/dnode2.c index 9d81fa4b..8ecbde2d 100644 --- a/lib/dialects/sun/dnode2.c +++ b/lib/dialects/sun/dnode2.c @@ -44,12 +44,10 @@ static char copyright[] = # include # define EMSGPFX "vx_inode: " -_PROTOTYPE(static char *add2em, (char *em, char *fmt, char *arg)); -_PROTOTYPE(static char *ckptr, - (char *em, char *ptr, int len, int slen, char *nm)); -_PROTOTYPE(static char *getioffs, - (char **vx, int *vxl, char **dev, int *devl, char **ino, int *inol, - char **nl, int *nll, char **sz, int *szl)); +static char *add2em(char *em, char *fmt, char *arg); +static char *ckptr(char *em, char *ptr, int len, int slen, char *nm); +static char *getioffs(char **vx, int *vxl, char **dev, int *devl, char **ino, + int *inol, char **nl, int *nll, char **sz, int *szl); # else /* !defined(HASVXFSUTIL) */ # if defined(HASVXFS_FS_H) && !defined(HASVXFS_VX_INODE) # undef fs_bsize @@ -119,10 +117,9 @@ extern int access_vxfs_ioffsets() { * add2em() - add to error message */ -static char *add2em(em, fmt, arg) -char *em; /* current error message */ -char *fmt; /* message format */ -char *arg; /* format's single string argument */ +static char *add2em(char *em, /* current error message */ + char *fmt, /* message format */ + char *arg) /* format's single string argument */ { MALLOC_S al, eml, nl; char msg[1024]; @@ -138,14 +135,14 @@ char *arg; /* format's single string argument */ } else { if (!(eml = (MALLOC_S)strlen(em))) { (void)fprintf(stderr, "%s: add2em: previous message empty\n", Pn); - Error(); + Error(ctx); } al = eml + nl + 3; em = (char *)realloc((MALLOC_P *)em, al); } if (!em) { (void)fprintf(stderr, "%s: no VxFS error message space\n", Pn); - Error(); + Error(ctx); } (void)snpf(em + eml, al - eml, "%s%s%s", eml ? "" : EMSGPFX, eml ? "; " : "", msg); @@ -156,12 +153,11 @@ char *arg; /* format's single string argument */ * ckptr() - check pointer and length */ -static char *ckptr(em, ptr, len, slen, nm) -char *em; /* pointer to previous error message */ -char *ptr; /* pointer to check */ -int len; /* pointer's value length */ -int slen; /* value's storage length */ -char *nm; /* element name */ +static char *ckptr(char *em, /* pointer to previous error message */ + char *ptr, /* pointer to check */ + int len, /* pointer's value length */ + int slen, /* value's storage length */ + char *nm) /* element name */ { # if defined(_LP64) @@ -192,17 +188,16 @@ char *nm; /* element name */ * getioffs() - get the vx_inode offsets */ -static char *getioffs(vx, vxl, dev, devl, ino, inol, nl, nll, sz, szl) -char **vx; /* pointer to allocated vx_inode space */ -int *vxl; /* sizeof(*vx) */ -char **dev; /* pointer to device number element of *vx */ -int *devl; /* sizeof(*dev) */ -char **ino; /* pointer to node number element of *vx */ -int *inol; /* sizeof(*ino) */ -char **nl; /* pointer to nlink element of *vx */ -int *nll; /* sizeof(*nl) */ -char **sz; /* pointer to size element of *vx */ -int *szl; /* sizeof(*sz) */ +static char *getioffs(char **vx, /* pointer to allocated vx_inode space */ + int *vxl, /* sizeof(*vx) */ + char **dev, /* pointer to device number element of *vx */ + int *devl, /* sizeof(*dev) */ + char **ino, /* pointer to node number element of *vx */ + int *inol, /* sizeof(*ino) */ + char **nl, /* pointer to nlink element of *vx */ + int *nll, /* sizeof(*nl) */ + char **sz, /* pointer to size element of *vx */ + int *szl) /* sizeof(*sz) */ { char *tv; int tvl; @@ -220,7 +215,7 @@ int *szl; /* sizeof(*sz) */ return (add2em((char *)NULL, "zero length %s", "vx_inode")); if (!(tv = (char *)malloc((MALLOC_S)tvl))) { (void)fprintf(stderr, "%s: no vx_inode space\n", Pn); - Error(); + Error(ctx); } *vx = tv; *vxl = tvl; @@ -244,8 +239,7 @@ int *szl; /* sizeof(*sz) */ * print_vxfs_rnl_path() -- print VxFS RNL path */ -int print_vxfs_rnl_path(lf) -struct lfile *lf; /* file whose name is to be printed */ +int print_vxfs_rnl_path(struct lfile *lf) /* file whose name is to be printed */ { char **bp = (char **)NULL; int i, j, n, p; @@ -291,7 +285,7 @@ struct lfile *lf; /* file whose name is to be printed */ if (!rm) { (void)fprintf(stderr, "%s: no RNL mount point cache space\n", Pn); - Error(); + Error(ctx); } } i = rmu; @@ -335,13 +329,12 @@ struct lfile *lf; /* file whose name is to be printed */ * read_vxnode() - read Veritas file system inode information */ -int read_vxnode(va, v, vfs, fx, li, vnops) -KA_T va; /* containing vnode's address */ -struct vnode *v; /* containing vnode */ -struct l_vfs *vfs; /* local vfs structure */ -int fx; /* file system index (-1 if none) */ -struct l_ino *li; /* local inode value receiver */ -KA_T *vnops; /* table of VxFS v_op values */ +int read_vxnode(KA_T va, /* containing vnode's address */ + struct vnode *v, /* containing vnode */ + struct l_vfs *vfs, /* local vfs structure */ + int fx, /* file system index (-1 if none) */ + struct l_ino *li, /* local inode value receiver */ + KA_T *vnops) /* table of VxFS v_op values */ { struct vnode cv; char tbuf[32]; @@ -383,12 +376,12 @@ KA_T *vnops; /* table of VxFS v_op values */ */ if (v->v_data && v->v_op && (VXVOP_FDDCH < VXVOP_NUM) && vnops[VXVOP_FDDCH] && ((KA_T)v->v_op == vnops[VXVOP_FDDCH])) { - if (kread((KA_T)v->v_data, (char *)&cv, sizeof(cv))) { + if (kread(ctx, (KA_T)v->v_data, (char *)&cv, sizeof(cv))) { (void)snpf(Namech, Namechl, "node at %s: can't read real vx vnode: %s", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } @@ -425,7 +418,7 @@ KA_T *vnops; /* table of VxFS v_op values */ } if (em) { (void)snpf(Namech, Namechl, "%s", em); - (void)enter_nm(Namech); + (void)enter_nm(ctx, Namech); return (1); } # endif /* !defined(HASVXFSUTIL) */ @@ -433,11 +426,11 @@ KA_T *vnops; /* table of VxFS v_op values */ /* * Read vnode's vx_inode. */ - if (!v->v_data || kread((KA_T)v->v_data, vxp, vxl)) { + if (!v->v_data || kread(ctx, (KA_T)v->v_data, vxp, vxl)) { (void)snpf(Namech, Namechl, "node at %s: can't read vx_inode: %s", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_data, (char *)NULL, 0)); - (void)enter_nm(Namech); + (void)enter_nm(ctx, Namech); return (1); } /* diff --git a/lib/dialects/sun/dproc.c b/lib/dialects/sun/dproc.c index dc62dde4..bbaeda3d 100644 --- a/lib/dialects/sun/dproc.c +++ b/lib/dialects/sun/dproc.c @@ -141,34 +141,34 @@ static znhash_t **ZoneNm = (znhash_t **)NULL; * Local function prototypes */ -_PROTOTYPE(static void get_kernel_access, (void)); -_PROTOTYPE(static void process_text, (KA_T pa)); -_PROTOTYPE(static void read_proc, (void)); -_PROTOTYPE(static void readfsinfo, (void)); +static void get_kernel_access(struct lsof_context *ctx); +static void process_text(struct lsof_context *ctx, KA_T pa); +static void read_proc(struct lsof_context *ctx); +static void readfsinfo(struct lsof_context *ctx); #if solaris >= 20501 -_PROTOTYPE(static void readkam, (KA_T addr)); +static void readkam(struct lsof_context *ctx, KA_T addr); #endif /* solaris>=20501 */ #if solaris >= 20501 && solaris < 70000 -_PROTOTYPE(extern u_longlong_t kvm_physaddr, (kvm_t *, struct as *, u_int)); +extern u_longlong_t kvm_physaddr(kvm_t *, struct as *, u_int); #endif /* solaris>=20501 && solaris<70000 */ #if defined(HASZONES) -_PROTOTYPE(static int hash_zn, (char *zn)); +static int hash_zn(char *zn); #endif /* defined(HASZONES) */ /* * close_kvm() - close kernel virtual memory access */ -void close_kvm() { +void close_kvm(struct lsof_context *ctx) { if (!Kd) return; if (Kd) { if (kvm_close(Kd) != 0) { (void)fprintf(stderr, "%s: kvm_close failed\n", Pn); - Error(); + Error(ctx); } Kd = (kvm_t *)NULL; } @@ -185,7 +185,7 @@ void close_kvm() { * gather_proc_info() - gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { short cckreg; /* conditional status of regular file * checking: * 0 = unconditionally check @@ -248,15 +248,15 @@ void gather_proc_info() { * will acquire a fresh address for the head of the linked list process * table. */ - close_kvm(); - open_kvm(); + close_kvm(ctx); + open_kvm(ctx); #if solaris >= 20501 /* * If not the first time and the ALLKMEM device isn't available, * re-read the kernel's address space map. */ - readkam((KA_T)NULL); + readkam(ctx, (KA_T)NULL); #endif /* solaris>=20501 */ } /* @@ -311,7 +311,7 @@ void gather_proc_info() { /* * Read the process table. */ - read_proc(); + read_proc(ctx); /* * Loop through processes. */ @@ -333,7 +333,7 @@ void gather_proc_info() { /* * Read credentials for Solaris 2.5 and above process. */ - if (kread((KA_T)p->p_cred, (char *)&pc, sizeof(pc))) + if (kread(ctx, (KA_T)p->p_cred, (char *)&pc, sizeof(pc))) continue; uid = pc.cr_uid; #endif /* solaris<20500 */ @@ -341,7 +341,7 @@ void gather_proc_info() { /* * See if the process is excluded. */ - if (is_proc_excl(pid, pgid, (UID_ARG)uid, &pss, &sf)) + if (is_proc_excl(ctx, pid, pgid, (UID_ARG)uid, &pss, &sf)) continue; #if defined(HASZONES) @@ -350,9 +350,10 @@ void gather_proc_info() { */ if (Fzone) { zn[0] = zn[sizeof(zn) - 1] = '\0'; - if (p->p_zone && !kread((KA_T)p->p_zone, (char *)&z, sizeof(z))) { + if (p->p_zone && + !kread(ctx, (KA_T)p->p_zone, (char *)&z, sizeof(z))) { if (!z.zone_name || - kread((KA_T)z.zone_name, (char *)&zn, sizeof(zn) - 1)) + kread(ctx, (KA_T)z.zone_name, (char *)&zn, sizeof(zn) - 1)) zn[0] = '\0'; } } @@ -365,7 +366,7 @@ void gather_proc_info() { /* * Allocate a local process structure and start filling it. */ - if (is_cmd_excl(u->u_comm, &pss, &sf)) + if (is_cmd_excl(ctx, u->u_comm, &pss, &sf)) continue; if (cckreg) { @@ -376,7 +377,7 @@ void gather_proc_info() { */ ckscko = (sf & SELPROC) ? 0 : 1; } - alloc_lproc(pid, pgid, (int)p->p_ppid, (UID_ARG)uid, u->u_comm, + alloc_lproc(ctx, pid, pgid, (int)p->p_ppid, (UID_ARG)uid, u->u_comm, (int)pss, (int)sf); Plf = (struct lfile *)NULL; @@ -414,7 +415,7 @@ void gather_proc_info() { (znhash_t **)calloc(HASHZONE, sizeof(znhash_t *)))) { (void)fprintf(stderr, "%s: no space for zone name hash\n", Pn); - Error(); + Error(ctx); } } for (zp = ZoneNm[zh]; zp; zp = zp->next) { @@ -429,13 +430,13 @@ void gather_proc_info() { if (!(zp = (znhash_t *)malloc((MALLOC_S)sizeof(znhash_t)))) { (void)fprintf(stderr, "%s: no zone name cache space: %s\n", Pn, zn); - Error(); + Error(ctx); } if (!(zp->zn = mkstrcpy(zn, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no zone name space at PID %d: %s\n", Pn, (int)Lp->pid, zn); - Error(); + Error(ctx); } zp->next = ZoneNm[zh]; ZoneNm[zh] = zp; @@ -452,29 +453,29 @@ void gather_proc_info() { * Save current working directory information. */ if (!ckscko && u->u_cdir) { - alloc_lfile(CWD, -1); + alloc_lfile(ctx, CWD, -1); #if defined(FILEPTR) FILEPTR = (struct file *)NULL; #endif /* defined(FILEPTR) */ - process_node((KA_T)u->u_cdir); + process_node(ctx, (KA_T)u->u_cdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } /* * Save root directory information. */ if (!ckscko && u->u_rdir) { - alloc_lfile(RTD, -1); + alloc_lfile(ctx, RTD, -1); #if defined(FILEPTR) FILEPTR = (struct file *)NULL; #endif /* defined(FILEPTR) */ - process_node((KA_T)u->u_rdir); + process_node(ctx, (KA_T)u->u_rdir); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } /* * Save information on text files. @@ -485,7 +486,7 @@ void gather_proc_info() { FILEPTR = (struct file *)NULL; #endif /* defined(FILEPTR) */ - process_text((KA_T)p->p_as); + process_text(ctx, (KA_T)p->p_as); } /* * Save information on file descriptors. @@ -503,7 +504,7 @@ void gather_proc_info() { if (++j > NFPCHUNK) { if (!u->u_flist.uf_next) break; - if (kread((KA_T)u->u_flist.uf_next, (char *)&u->u_flist, + if (kread(ctx, (KA_T)u->u_flist.uf_next, (char *)&u->u_flist, sizeof(struct ufchunk))) break; j = 1; @@ -515,7 +516,8 @@ void gather_proc_info() { k = u->u_nofiles - i; if (k > NFPREAD) k = NFPREAD; - if (kread((KA_T)((unsigned long)u->u_flist + + if (kread(ctx, + (KA_T)((unsigned long)u->u_flist + i * sizeof(uf_entry_t)), (char *)&uf, k * sizeof(uf_entry_t))) { break; @@ -526,14 +528,14 @@ void gather_proc_info() { #endif /* solaris<20400 */ continue; - alloc_lfile((char *)NULL, i); + alloc_lfile(ctx, (char *)NULL, i); #if solaris < 20400 pofv = (long)u->u_flist.uf_pofile[j - 1]; - process_file((KA_T)u->u_flist.uf_ofile[j - 1]); + process_file(ctx, (KA_T)u->u_flist.uf_ofile[j - 1]); #else /* solaris>=20400 */ pofv = uf[j - 1].uf_pofile; - process_file((KA_T)uf[j - 1].uf_ofile); + process_file(ctx, (KA_T)uf[j - 1].uf_ofile); #endif /* solaris <20400 */ if (Lf->sf) { @@ -542,13 +544,13 @@ void gather_proc_info() { Lf->pof = pofv; #endif /* defined(HASFSTRUCT) */ - link_lfile(); + link_lfile(ctx); } } /* * Examine results. */ - if (examine_lproc()) + if (examine_lproc(ctx)) return; } } @@ -557,7 +559,7 @@ void gather_proc_info() { * get_kernel_access() - access the required information in the kernel */ -static void get_kernel_access() { +static void get_kernel_access(struct lsof_context *ctx) { int i; struct stat sb; KA_T v; @@ -569,7 +571,7 @@ static void get_kernel_access() { /* * Check the Solaris or SunOS version number; check the SunOS architecture. */ - (void)ckkv("Solaris", LSOF_VSTR, (char *)NULL, (char *)NULL); + (void)ckkv(ctx, "Solaris", LSOF_VSTR, (char *)NULL, (char *)NULL); #if solaris >= 70000 /* @@ -591,7 +593,7 @@ static void get_kernel_access() { if (sysinfo(SI_ISALIST, isa, (long)sizeof(isa)) < 0) { (void)fprintf(stderr, "%s: can't get ISA list: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } for (cp = isa; *cp;) { if (strncmp(cp, ARCH64B, strlen(ARCH64B)) == 0) { @@ -609,7 +611,7 @@ static void get_kernel_access() { (void)fprintf( stderr, " but this machine has booted a %d bit kernel.\n", (int)kbits); - Error(); + Error(ctx); } } #endif /* solaris>=70000 */ @@ -618,8 +620,8 @@ static void get_kernel_access() { * Get kernel symbols. */ if (Nmlst && !is_readable(Nmlst, 1)) - Error(); - (void)build_Nl(Drive_Nl); + Error(ctx); + (void)build_Nl(ctx, Drive_Nl); #if defined(HAS_AFS) if (!Nmlst) { @@ -631,7 +633,7 @@ static void get_kernel_access() { */ if (!(nl = (struct nlist *)malloc(Nll))) { (void)fprintf(stderr, "%s: no space (%d) for Nl[] copy\n", Pn, Nll); - Error(); + Error(ctx); } (void)memcpy((void *)nl, (void *)Nl, (size_t)Nll); } @@ -640,7 +642,7 @@ static void get_kernel_access() { if (nlist(Nmlst ? Nmlst : N_UNIX, Nl) < 0) { (void)fprintf(stderr, "%s: can't read namelist from %s\n", Pn, Nmlst ? Nmlst : N_UNIX); - Error(); + Error(ctx); } #if defined(HAS_AFS) @@ -668,7 +670,7 @@ static void get_kernel_access() { * If ALLKMEM isn't available, the active processes will be gathered via the * kvm_*proc() functions. */ - if (statsafely(ALLKMEM, &sb) == 0) + if (statsafely(ctx, ALLKMEM, &sb) == 0) HasALLKMEM = 1; #if defined(HASVXFSUTIL) @@ -709,19 +711,19 @@ static void get_kernel_access() { * before attempting to open the (Memory) file. */ if (Memory) - (void)dropgid(); + (void)dropgid(ctx); #else /* !defined(WILLDROPGID) */ /* * See if the non-KMEM memory file is readable. */ if (Memory && !is_readable(Memory, 1)) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ /* * Open access to kernel memory. */ - open_kvm(); + open_kvm(ctx); #if solaris >= 20500 /* @@ -729,10 +731,10 @@ static void get_kernel_access() { */ v = (KA_T)0; if (get_Nl_value("kbase", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&Kb, sizeof(Kb))) { + kread(ctx, (KA_T)v, (char *)&Kb, sizeof(Kb))) { (void)fprintf(stderr, "%s: can't read kernel base address from %s\n", Pn, print_kptr(v, (char *)NULL, 0)); - Error(); + Error(ctx); } #endif /* solaris>=20500 */ @@ -744,7 +746,7 @@ static void get_kernel_access() { if (get_Nl_value("clmaj_alt", Drive_Nl, &v) < 0) v = (KA_T)0; } - if (v && kread((KA_T)v, (char *)&CloneMaj, sizeof(CloneMaj)) == 0) + if (v && kread(ctx, (KA_T)v, (char *)&CloneMaj, sizeof(CloneMaj)) == 0) HaveCloneMaj = 1; /* * If the ALLKMEM device is available, check for the address of the kernel's @@ -766,7 +768,7 @@ static void get_kernel_access() { PSMask = PageSz - 1; for (i = 1, PSShft = 0; i < PageSz; i <<= 1, PSShft++) ; - (void)readkam(v); + (void)readkam(ctx, v); } } #endif /* solaris>=20501 */ @@ -778,7 +780,7 @@ static void get_kernel_access() { * drop setgid permission, do so. */ if (HasALLKMEM) - (void)dropgid(); + (void)dropgid(ctx); #endif /* defined(WILLDROPGID) */ } @@ -787,8 +789,8 @@ static void get_kernel_access() { * enter_zone_arg() - enter zone name argument */ -int enter_zone_arg(zn) -char *zn; /* zone name */ +int enter_zone_arg(struct lsof_context *ctx, /* context */ + char *zn) /* zone name */ { int zh; znhash_t *zp, *zpn; @@ -798,7 +800,7 @@ char *zn; /* zone name */ if (!ZoneArg) { if (!(ZoneArg = (znhash_t **)calloc(HASHZONE, sizeof(znhash_t *)))) { (void)fprintf(stderr, "%s: no space for zone arg hash\n", Pn); - Error(); + Error(ctx); } } /* @@ -823,7 +825,7 @@ char *zn; /* zone name */ */ if (!(zpn = (znhash_t *)malloc((MALLOC_S)sizeof(znhash_t)))) { (void)fprintf(stderr, "%s no hash space for zone: %s\n", Pn, zn); - Error(); + Error(ctx); } zpn->f = 0; zpn->zn = zn; @@ -836,8 +838,7 @@ char *zn; /* zone name */ * hash_zn() - hash zone name */ -static int hash_zn(zn) -char *zn; /* zone name */ +static int hash_zn(char *zn) /* zone name */ { register int i, h; size_t l; @@ -857,17 +858,17 @@ char *zn; /* zone name */ * initialize() - perform all initialization */ -void initialize() { - get_kernel_access(); +void initialize(struct lsof_context *ctx) { + get_kernel_access(ctx); /* * Read Solaris file system information and construct the clone table. * * The clone table is needed to identify sockets. */ - readfsinfo(); + readfsinfo(ctx); #if defined(HASDCACHE) - readdev(0); + readdev(ctx, 0); #else /* !defined(HASDCACHE) */ read_clone(); #endif /*defined(HASDCACHE) */ @@ -877,10 +878,10 @@ void initialize() { * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, /* context */ + KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { register int br; /* @@ -948,7 +949,7 @@ READLEN_T len; /* length to read */ return (1); if (!(kp = (kvmhash_t *)malloc(sizeof(kvmhash_t)))) { (void)fprintf(stderr, "%s: no kvmhash_t space\n", Pn); - Error(); + Error(ctx); } kp->nxt = KVMhb[h]; pa = kp->pa = (pa & ~(KPHYS)PSMask); @@ -995,7 +996,7 @@ READLEN_T len; /* length to read */ * open_kvm() - open kernel virtual memory access */ -void open_kvm() { +void open_kvm(struct lsof_context *ctx) { if (Kd) return; @@ -1004,21 +1005,21 @@ void open_kvm() { * If this Solaris process began with setgid permission and its been * surrendered, regain it. */ - (void)restoregid(); + (void)restoregid(ctx); #endif /* defined(WILLDROPGID) */ if (!(Kd = kvm_open(Nmlst, Memory, NULL, O_RDONLY, Pn))) { (void)fprintf(stderr, "%s: kvm_open(namelist=%s, corefile=%s): %s\n", Pn, Nmlst ? Nmlst : "default", Memory ? Memory : "default", strerror(errno)); - Error(); + Error(ctx); } #if solaris >= 20501 && solaris < 70000 if ((Kmd = open((Memory ? Memory : KMEM), O_RDONLY)) < 0) { (void)fprintf(stderr, "%s: open(\"/dev/mem\"): %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } #endif /* solaris>=20501 && solaris<70000 */ @@ -1027,7 +1028,7 @@ void open_kvm() { * If this process has setgid permission, and is willing to surrender it, * do so. */ - (void)dropgid(); + (void)dropgid(ctx); /* * If this Solaris process must switch GIDs, enable switching after the * first call to this function. @@ -1055,10 +1056,11 @@ void open_kvm() { */ # define READ_AVL_NODE(n, o, s) \ - if (kread((KA_T)AVL_NODE2DATA(n, o), (char *)s, sizeof(*s))) \ + if (kread(ctx, (KA_T)AVL_NODE2DATA(n, o), (char *)s, sizeof(*s))) \ return -1 -static int get_first_seg(avl_tree_t *av, struct seg *s) { +static int get_first_seg(struct lsof_context *ctx, avl_tree_t *av, + struct seg *s) { avl_node_t *node = av->avl_root; size_t off = av->avl_offset; int count = 0; @@ -1072,7 +1074,8 @@ static int get_first_seg(avl_tree_t *av, struct seg *s) { return -1; } -static int get_next_seg(avl_tree_t *av, struct seg *s) { +static int get_next_seg(struct lsof_context *ctx, avl_tree_t *av, + struct seg *s) { avl_node_t *node = &s->s_tree; size_t off = av->avl_offset; int count = 0; @@ -1108,7 +1111,8 @@ static int get_next_seg(avl_tree_t *av, struct seg *s) { return -1; } -static void process_text(pa) KA_T pa; /* address space description pointer */ +static void process_text(struct lsof_context *ctx, /* context */ + KA_T pa) /* address space description pointer */ { struct as as; int i, j, k; @@ -1119,13 +1123,13 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ /* * Get address space description. */ - if (kread((KA_T)pa, (char *)&as, sizeof(as))) { - alloc_lfile(" txt", -1); + if (kread(ctx, (KA_T)pa, (char *)&as, sizeof(as))) { + alloc_lfile(ctx, " txt", -1); (void)snpf(Namech, Namechl, "can't read text segment list (%s)", print_kptr(pa, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) - link_lfile(); + link_lfile(ctx); return; } /* @@ -1136,10 +1140,10 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ */ for (avtp = &as.a_segtree, i = j = 0; (i < MAXSEGS) && (j < 2 * MAXSEGS); j++) { - if (j ? get_next_seg(avtp, &s) : get_first_seg(avtp, &s)) + if (j ? get_next_seg(ctx, avtp, &s) : get_first_seg(ctx, avtp, &s)) break; if ((KA_T)s.s_ops == Sgvops && s.s_data) { - if (kread((KA_T)s.s_data, (char *)&vn, sizeof(vn))) + if (kread(ctx, (KA_T)s.s_data, (char *)&vn, sizeof(vn))) break; if (vn.vp) { @@ -1155,15 +1159,15 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ } if (k >= i) { v[i++] = (KA_T)vn.vp; - alloc_lfile(" txt", -1); + alloc_lfile(ctx, " txt", -1); # if defined(FILEPTR) FILEPTR = (struct file *)NULL; # endif /* defined(FILEPTR) */ - process_node((KA_T)vn.vp); + process_node(ctx, (KA_T)vn.vp); if (Lf->sf) - link_lfile(); + link_lfile(ctx); } } } @@ -1178,7 +1182,8 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ # define S_NEXT s_next # endif /* solaris>=20400 */ -static void process_text(pa) KA_T pa; /* address space description pointer */ +static void process_text(struct lsof_context *ctx, /* context */ + KA_T pa) /* address space description pointer */ { struct as as; int i, j, k; @@ -1188,11 +1193,11 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ /* * Get address space description. */ - if (kread((KA_T)pa, (char *)&as, sizeof(as))) { + if (kread(ctx, (KA_T)pa, (char *)&as, sizeof(as))) { alloc_lfile(" txt", -1); (void)snpf(Namech, Namechl, "can't read text segment list (%s)", print_kptr(pa, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); if (Lf->sf) link_lfile(); return; @@ -1204,10 +1209,10 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ * have been examined. */ for (s.s_next = as.a_segs, i = j = 0; i < MAXSEGS && j < 2 * MAXSEGS; j++) { - if (!s.S_NEXT || kread((KA_T)s.S_NEXT, (char *)&s, sizeof(s))) + if (!s.S_NEXT || kread(ctx, (KA_T)s.S_NEXT, (char *)&s, sizeof(s))) break; if ((KA_T)s.s_ops == Sgvops && s.s_data) { - if (kread((KA_T)s.s_data, (char *)&vn, sizeof(vn))) + if (kread(ctx, (KA_T)s.s_data, (char *)&vn, sizeof(vn))) break; if (vn.vp) { @@ -1229,7 +1234,7 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ FILEPTR = (struct file *)NULL; # endif /* defined(FILEPTR) */ - process_node((KA_T)vn.vp); + process_node(ctx, (KA_T)vn.vp); if (Lf->sf) link_lfile(); } @@ -1256,26 +1261,26 @@ static void process_text(pa) KA_T pa; /* address space description pointer */ * readfsinfo() - read file system information */ -static void readfsinfo() { +static void readfsinfo(struct lsof_context *ctx) { char buf[FSTYPSZ + 1]; int i, len; if ((Fsinfomax = sysfs(GETNFSTYP)) == -1) { (void)fprintf(stderr, "%s: sysfs(GETNFSTYP) error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (Fsinfomax == 0) return; if (!(Fsinfo = (char **)malloc((MALLOC_S)(Fsinfomax * sizeof(char *))))) { (void)fprintf(stderr, "%s: no space for sysfs info\n", Pn); - Error(); + Error(ctx); } for (i = 1; i <= Fsinfomax; i++) { if (sysfs(GETFSTYP, i, buf) == -1) { (void)fprintf(stderr, "%s: sysfs(GETFSTYP) error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (buf[0] == '\0') { Fsinfo[i - 1] = ""; @@ -1286,7 +1291,7 @@ static void readfsinfo() { if (!(Fsinfo[i - 1] = (char *)malloc((MALLOC_S)len))) { (void)fprintf(stderr, "%s: no space for file system entry %s\n", Pn, buf); - Error(); + Error(ctx); } (void)snpf(Fsinfo[i - 1], len, "%s", buf); @@ -1302,7 +1307,8 @@ static void readfsinfo() { * readkam() - read kernel's address map structure */ -static void readkam(addr) KA_T addr; /* kernel virtual address */ +static void readkam(struct lsof_context *ctx, /* context */ + KA_T addr) /* kernel virtual address */ { register int i; register kvmhash_t *kp, *kpp; @@ -1313,7 +1319,7 @@ static void readkam(addr) KA_T addr; /* kernel virtual address */ Kas = (struct as *)NULL; # if solaris < 70000 - if (kas && !kread(kas, (char *)&Kam, sizeof(Kam))) + if (kas && !kread(ctx, kas, (char *)&Kam, sizeof(Kam))) Kas = (KA_T)&Kam; # else /* solaris>=70000 */ Kas = (struct as *)kas; @@ -1326,7 +1332,7 @@ static void readkam(addr) KA_T addr; /* kernel virtual address */ (void)fprintf(stderr, "%s: no space (%d) for KVM hash buckets\n", Pn, (int)(KVMHASHBN * sizeof(kvmhash_t *))); - Error(); + Error(ctx); } } else if (!addr) { for (i = 0; i < KVMHASHBN; i++) { @@ -1350,7 +1356,7 @@ static void readkam(addr) KA_T addr; /* kernel virtual address */ * As a side-effect, Kd is set by a call to kvm_open(). */ -static void read_proc() { +static void read_proc(struct lsof_context *ctx) { int ct, ctl, knp, n, try; MALLOC_S len; struct proc *p; @@ -1365,7 +1371,7 @@ static void read_proc() { * Get a proc structure count estimate. */ if (get_Nl_value("nproc", Drive_Nl, &pa) < 0 || !pa || - kread(pa, (char *)&knp, sizeof(knp)) || knp < 1) + kread(ctx, pa, (char *)&knp, sizeof(knp)) || knp < 1) knp = PROCDFLT; /* * Pre-allocate space, as required. @@ -1383,7 +1389,7 @@ static void read_proc() { P = (struct proc *)malloc(len); if (!P) { (void)fprintf(stderr, "%s: no proc table space\n", Pn); - Error(); + Error(ctx); } /* * Pre-allocate PGID and PID number space. @@ -1396,7 +1402,7 @@ static void read_proc() { Pgid = (int *)malloc(len); if (!Pgid) { (void)fprintf(stderr, "%s: no PGID table space\n", Pn); - Error(); + Error(ctx); } } if (Pid) @@ -1405,7 +1411,7 @@ static void read_proc() { Pid = (int *)malloc(len); if (!Pid) { (void)fprintf(stderr, "%s: no PID table space\n", Pn); - Error(); + Error(ctx); } Npa = n; } @@ -1415,10 +1421,10 @@ static void read_proc() { * Prepare for a proc table scan via direct reading of the active * chain. */ - if (!PrAct || kread(PrAct, (char *)&paf, sizeof(pa))) { + if (!PrAct || kread(ctx, PrAct, (char *)&paf, sizeof(pa))) { (void)fprintf(stderr, "%s: can't read practive from %s\n", Pn, print_kptr(PrAct, (char *)NULL, 0)); - Error(); + Error(ctx); } ct = 1; ctl = knp << 3; @@ -1432,7 +1438,7 @@ static void read_proc() { if (kvm_setproc(Kd) != 0) { (void)fprintf(stderr, "%s: kvm_setproc: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } } /* @@ -1450,7 +1456,7 @@ static void read_proc() { if (!(P = (struct proc *)realloc((MALLOC_P *)P, len))) { (void)fprintf(stderr, "%s: no more (%d) proc space\n", Pn, Npa); - Error(); + Error(ctx); } /* * Expand the PGID and PID tables. @@ -1460,13 +1466,13 @@ static void read_proc() { if (!(Pgid = (int *)realloc((MALLOC_P *)Pgid, len))) { (void)fprintf(stderr, "%s: no more (%d) PGID space\n", Pn, Npa); - Error(); + Error(ctx); } } if (!(Pid = (int *)realloc((MALLOC_P *)Pid, len))) { (void)fprintf(stderr, "%s: no more (%d) PID space\n", Pn, Npa); - Error(); + Error(ctx); } } /* @@ -1488,7 +1494,7 @@ static void read_proc() { if (!pa) break; p = (struct proc *)&P[Np]; - if (kread(pa, (char *)p, sizeof(struct proc))) + if (kread(ctx, pa, (char *)p, sizeof(struct proc))) break; pan = (KA_T)p->p_next; } else { @@ -1519,11 +1525,11 @@ static void read_proc() { */ if (Fpgid) { if (!p->p_pgidp || - kread((KA_T)p->p_pgidp, (char *)&pg, sizeof(pg))) + kread(ctx, (KA_T)p->p_pgidp, (char *)&pg, sizeof(pg))) continue; } if (!p->p_pidp || - kread((KA_T)p->p_pidp, (char *)&pids, sizeof(pids))) + kread(ctx, (KA_T)p->p_pidp, (char *)&pids, sizeof(pids))) continue; /* * Save the PGID and PID numbers in local tables. @@ -1549,8 +1555,8 @@ static void read_proc() { if (Np >= PROCMIN) break; if (!HasALLKMEM) { - close_kvm(); - open_kvm(); + close_kvm(ctx); + open_kvm(ctx); } } /* @@ -1558,7 +1564,7 @@ static void read_proc() { */ if (try >= PROCTRYLM) { (void)fprintf(stderr, "%s: can't read proc table\n", Pn); - Error(); + Error(ctx); } if (Np < Npa && !RptTm) { @@ -1570,7 +1576,7 @@ static void read_proc() { if (!(P = (struct proc *)realloc((MALLOC_P *)P, len))) { (void)fprintf(stderr, "%s: can't reduce proc table to %d\n", Pn, Np); - Error(); + Error(ctx); } /* * Reduce the Solaris PGID and PID tables to their minimum if @@ -1581,12 +1587,12 @@ static void read_proc() { if (!(Pgid = (int *)realloc((MALLOC_P *)Pgid, len))) { (void)fprintf(stderr, "%s: can't reduce PGID table to %d\n", Pn, Np); - Error(); + Error(ctx); } } if (!(Pid = (int *)realloc((MALLOC_P *)Pid, len))) { (void)fprintf(stderr, "%s: can't reduce PID table to %d\n", Pn, Np); - Error(); + Error(ctx); } Npa = Np; } @@ -1597,12 +1603,12 @@ static void read_proc() { * restoregid() -- restore setgid permission, as required */ -void restoregid() { +void restoregid(struct lsof_context *ctx) { if (Switchgid == 2 && !Setgid) { if (setgid(Savedgid) != 0) { (void)fprintf(stderr, "%s: can't set effective GID to %d: %s\n", Pn, (int)Savedgid, strerror(errno)); - Error(); + Error(ctx); } Setgid = 1; } @@ -1635,11 +1641,11 @@ static KA_T NegVN = (KA_T)NULL; /* negative vnode address */ static int Nla = 0; /* entries allocated to Ncache[] */ static int Nlu = 0; /* entries used in Ncache[] */ -_PROTOTYPE(static struct l_nch *ncache_addr, (KA_T v)); +static struct l_nch *ncache_addr(KA_T v); # define ncachehash(v) Nchash + ((((int)(v) >> 2) * 31415) & Mhl) -_PROTOTYPE(static int ncache_isroot, (KA_T va, char *cp)); +static int ncache_isroot(KA_T va, char *cp); # define LNCHINCRSZ 64 /* local size increment */ # define XNC \ @@ -1654,8 +1660,7 @@ _PROTOTYPE(static int ncache_isroot, (KA_T va, char *cp)); static struct l_nch * -ncache_addr(v) -KA_T v; /* vnode's address */ +ncache_addr(KA_T v) /* vnode's address */ { struct l_nch **hp; @@ -1670,9 +1675,8 @@ KA_T v; /* vnode's address */ * ncache_isroot() - is head of name cache path a file system root? */ -static int ncache_isroot(va, cp) -KA_T va; /* kernel vnode address */ -char *cp; /* partial path */ +static int ncache_isroot(KA_T va, /* kernel vnode address */ + char *cp) /* partial path */ { char buf[MAXPATHLEN]; int i; @@ -1703,7 +1707,7 @@ char *cp; /* partial path */ * matches the one we have for this file. If it does, then the path is * complete. */ - if (kread((KA_T)va, (char *)&v, sizeof(v)) || v.v_type != VDIR || + if (kread(ctx, (KA_T)va, (char *)&v, sizeof(v)) || v.v_type != VDIR || !(v.v_flag & VROOT)) { /* @@ -1741,7 +1745,7 @@ char *cp; /* partial path */ vc = (KA_T *)realloc(vc, len); if (!vc) { (void)fprintf(stderr, "%s: no space for root vnode table\n", Pn); - Error(); + Error(ctx); } } vc[vcn++] = va; @@ -1780,7 +1784,7 @@ void ncache_load() { */ v = (KA_T)0; if (get_Nl_value(X_NCSIZE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&Nch, sizeof(Nch))) { + kread(ctx, (KA_T)v, (char *)&Nch, sizeof(Nch))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read DNLC hash size: %s\n", @@ -1805,7 +1809,7 @@ void ncache_load() { */ v = (KA_T)0; if (get_Nl_value(X_NCACHE, (struct drive_Nl *)NULL, (KA_T *)&v) < 0 || - !v || kread(v, (char *)&kha, sizeof(kha)) || !kha) { + !v || kread(ctx, v, (char *)&kha, sizeof(kha)) || !kha) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: no DNLC hash address\n", Pn); @@ -1819,7 +1823,7 @@ void ncache_load() { if (!(khl = (nc_hash_t *)malloc((MALLOC_S)len))) { (void)fprintf(stderr, "%s: can't allocate DNLC hash space: %d\n", Pn, len); - Error(); + Error(ctx); } /* * Allocate space for a kernel DNLC entry, plus additional name space @@ -1829,7 +1833,7 @@ void ncache_load() { if (!(nc = (ncache_t *)malloc((MALLOC_S)(sizeof(ncache_t) + XNC)))) { (void)fprintf(stderr, "%s: can't allocate DNLC ncache_t space\n", Pn); - Error(); + Error(ctx); } nmo = offsetof(struct ncache, name); /* @@ -1838,7 +1842,7 @@ void ncache_load() { */ v = (KA_T)0; if ((get_Nl_value("hshav", (struct drive_Nl *)NULL, (KA_T *)&v) < 0) || - !v || kread(v, (char *)&i, sizeof(i)) || (i < 1)) { + !v || kread(ctx, v, (char *)&i, sizeof(i)) || (i < 1)) { i = 16; if (!Fwarn) { (void)fprintf(stderr, @@ -1854,7 +1858,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: no space for %d byte local name cache\n", Pn, len); - Error(); + Error(ctx); } } else { @@ -1885,7 +1889,7 @@ void ncache_load() { /* * Read the kernel's DNLC hash. */ - if (kread(kha, (char *)khl, (Nch * sizeof(nc_hash_t)))) { + if (kread(ctx, kha, (char *)khl, (Nch * sizeof(nc_hash_t)))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read DNLC hash: %s\n", Pn, print_kptr(kha, (char *)NULL, 0)); @@ -1908,7 +1912,7 @@ void ncache_load() { for (kn = (KA_T)kh->hash_next, h = 0; kn && (h < Nch) && (!h || (h && kn != (KA_T)kh->hash_next)); kn = (KA_T)nc->hash_next, h++) { - if (kread(kn, (char *)nc, sizeof(ncache_t) + XNC)) + if (kread(ctx, kn, (char *)nc, sizeof(ncache_t) + XNC)) break; if (!nc->vp || (len = (int)nc->namlen) < 1) continue; @@ -1933,13 +1937,13 @@ void ncache_load() { (void)fprintf(stderr, "%s: can't extend DNLC ncache_t buffer\n", Pn); - Error(); + Error(ctx); } } cp = &nc->name[XNC + 1]; v = (KA_T)((char *)kn + nmo + XNC + 1); xl = len - XNC - 1; - if (kread(v, cp, xl)) + if (kread(ctx, v, cp, xl)) continue; } /* @@ -1949,7 +1953,7 @@ void ncache_load() { (void)fprintf( stderr, "%s: can't allocate %d bytes for name cache name\n", Pn, len + 1); - Error(); + Error(ctx); } (void)strncpy(cp, nc->name, len); cp[len] = '\0'; @@ -1963,7 +1967,7 @@ void ncache_load() { Ncache, (MALLOC_S)(Nla * sizeof(struct l_nch))))) { (void)fprintf(stderr, "%s: can't enlarge local name cache\n", Pn); - Error(); + Error(ctx); } lc = &Ncache[n]; } @@ -2024,7 +2028,7 @@ void ncache_load() { (struct l_nch **)calloc(Nhl + Nlu, sizeof(struct l_nch *)))) { (void)fprintf(stderr, "%s: no space for %d name cache hash pointers\n", Pn, Nhl + Nlu); - Error(); + Error(ctx); } for (i = 0, lc = Ncache; i < Nlu; i++, lc++) { for (hp = ncachehash(lc->vp), h = 1; *hp; hp++) { @@ -2056,10 +2060,9 @@ void ncache_load() { * ncache_lookup() - look up a node's name in the kernel's name cache */ -char *ncache_lookup(buf, blen, fp) -char *buf; /* receiving name buffer */ -int blen; /* receiving buffer length */ -int *fp; /* full path reply */ +char *ncache_lookup(char *buf, /* receiving name buffer */ + int blen, /* receiving buffer length */ + int *fp) /* full path reply */ { char *cp = buf; struct l_nch *lc; diff --git a/lib/dialects/sun/dproto.h b/lib/dialects/sun/dproto.h index 4b09788a..014c28f2 100644 --- a/lib/dialects/sun/dproto.h +++ b/lib/dialects/sun/dproto.h @@ -35,74 +35,77 @@ */ #if defined(HASVXFSUTIL) -_PROTOTYPE(extern int access_vxfs_ioffsets, (void)); +extern int access_vxfs_ioffsets(void); #endif /* defined(HASVXFSUTIL) */ -_PROTOTYPE(extern void completevfs, (struct l_vfs * vfs, dev_t *dev)); +extern void completevfs(struct lsof_context *ctx, struct l_vfs *vfs, + dev_t *dev); #if defined(HAS_LIBCTF) -_PROTOTYPE(extern int CTF_getmem, (ctf_file_t * f, const char *mod, - const char *ty, CTF_member_t *mem)); -_PROTOTYPE(extern void CTF_init, (int *i, char *t, CTF_request_t *r)); -_PROTOTYPE(extern int CTF_memCB, - (const char *name, ctf_id_t id, ulong_t offset, void *arg)); +extern int CTF_getmem(struct lsof_context *ctx, ctf_file_t *f, const char *mod, + const char *ty, CTF_member_t *mem); +extern void CTF_init(struct lsof_context *ctx, int *i, char *t, + CTF_request_t *r); +extern int CTF_memCB(const char *name, ctf_id_t id, ulong_t offset, void *arg); #endif /* defined(HAS_LIBCTF) */ -_PROTOTYPE(extern int is_file_named, (char *p, int nt, enum vtype vt, int ps)); -_PROTOTYPE(extern struct l_vfs *readvfs, - (KA_T ka, struct vfs *la, struct vnode *lv)); -_PROTOTYPE(extern int vop2ty, (struct vnode * vp, int fx)); +extern int is_file_named(struct lsof_context *ctx, char *p, int nt, + enum vtype vt, int ps); +extern struct l_vfs *readvfs(struct lsof_context *ctx, KA_T ka, struct vfs *la, + struct vnode *lv); +extern int vop2ty(struct lsof_context *ctx, struct vnode *vp, int fx); #if defined(HAS_AFS) -_PROTOTYPE(extern struct vnode *alloc_vcache, (void)); -_PROTOTYPE(extern void ckAFSsym, (struct nlist * nl)); -_PROTOTYPE(extern int hasAFS, (struct vnode * vp)); -_PROTOTYPE(extern int readafsnode, - (KA_T va, struct vnode *v, struct afsnode *an)); +extern struct vnode *alloc_vcache(void); +extern void ckAFSsym(struct nlist *nl); +extern int hasAFS(struct vnode *vp); +extern int readafsnode(KA_T va, struct vnode *v, struct afsnode *an); #endif /* defined(HAS_AFS) */ #if defined(HASDCACHE) -_PROTOTYPE(extern int rw_clone_sect, (int m)); -_PROTOTYPE(extern void clr_sect, (void)); -_PROTOTYPE(extern int rw_pseudo_sect, (int m)); +extern int rw_clone_sect(struct lsof_context *ctx, int m); +extern void clr_sect(struct lsof_context *ctx); +extern int rw_pseudo_sect(struct lsof_context *ctx, int m); #endif /* defined(HASDCACHE) */ #if defined(HASIPv6) -_PROTOTYPE(extern struct hostent *gethostbyname2, (const char *nm, int proto)); +extern struct hostent *gethostbyname2(const char *nm, int proto); #endif /* defined(HASIPv6) */ #if defined(HAS_V_PATH) -_PROTOTYPE(extern int print_v_path, (struct lfile * lf)); -_PROTOTYPE(extern void read_v_path, (KA_T ka, char *rb, size_t rbl)); +extern int print_v_path(struct lsof_context *ctx, struct lfile *lf); +extern void read_v_path(struct lsof_context *ctx, KA_T ka, char *rb, + size_t rbl); #endif /* defined(HAS_V_PATH) */ #if defined(HASVXFS) -_PROTOTYPE(extern int read_vxnode, (KA_T va, struct vnode *v, struct l_vfs *vfs, - int fx, struct l_ino *li, KA_T *vnops)); +extern int read_vxnode(struct lsof_context *ctx, KA_T va, struct vnode *v, + struct l_vfs *vfs, int fx, struct l_ino *li, + KA_T *vnops); # if defined(HASVXFSRNL) -_PROTOTYPE(extern int print_vxfs_rnl_path, (struct lfile * lf)); +extern int print_vxfs_rnl_path(struct lfile *lf); # endif /* defined(HASVXFSRNL) */ #endif /* defined(HASVXFS) */ #if defined(HASZONES) -_PROTOTYPE(extern int enter_zone_arg, (char *zn)); +extern int enter_zone_arg(struct lsof_context *ctx, char *zn); #endif /* defined(HASZONES) */ -_PROTOTYPE(extern void close_kvm, (void)); -_PROTOTYPE(extern void open_kvm, (void)); -_PROTOTYPE(extern void process_socket, (KA_T sa, char *ty)); +extern void close_kvm(struct lsof_context *ctx); +extern void open_kvm(struct lsof_context *ctx); +extern void process_socket(struct lsof_context *ctx, KA_T sa, char *ty); #if solaris >= 110000 -_PROTOTYPE(extern int process_VSOCK, - (KA_T va, struct vnode *v, struct sonode *so)); +extern int process_VSOCK(struct lsof_context *ctx, KA_T va, struct vnode *v, + struct sonode *so); #endif /* solaris>=11000 */ -_PROTOTYPE(extern void read_clone, (void)); +extern void read_clone(struct lsof_context *ctx); #if solaris < 20500 -_PROTOTYPE(extern int get_max_fd, (void)); +extern int get_max_fd(void); #endif /* solaris<20500 */ #if defined(WILLDROPGID) -_PROTOTYPE(extern void restoregid, (void)); +extern void restoregid(struct lsof_context *ctx); #endif /* defined(WILLDROPGID) */ diff --git a/lib/dialects/sun/dsock.c b/lib/dialects/sun/dsock.c index 0124a66e..7463b90b 100644 --- a/lib/dialects/sun/dsock.c +++ b/lib/dialects/sun/dsock.c @@ -227,9 +227,11 @@ static CTF_request_t IRU_requests[] = {{ICMP_T_TYPE_NAME, icmp_t_members}, * Icmp_t, rts_t and udp_t function prototypes */ -_PROTOTYPE(static int read_icmp_t, (KA_T va, KA_T ph, KA_T ia, icmp_t *ic)); -_PROTOTYPE(static int read_rts_t, (KA_T va, KA_T ph, KA_T ra, rts_t *rt)); -_PROTOTYPE(static int read_udp_t, (KA_T ua, udp_t *uc)); +static int read_icmp_t(struct lsof_context *ctx, KA_T va, KA_T ph, KA_T ia, + icmp_t *ic); +static int read_rts_t(struct lsof_context *ctx, KA_T va, KA_T ph, KA_T ra, + rts_t *rt); +static int read_udp_t(struct lsof_context *ctx, KA_T ua, udp_t *uc); #endif /* defined(HAS_LIBCTF) && solaris>=110000 */ #if solaris < 80000 || defined(HAS_IPCLASSIFIER_H) @@ -299,50 +301,49 @@ typedef struct tcpb { * Local function prototypes */ -_PROTOTYPE(static void save_TCP_size, (tcp_t * tc)); -_PROTOTYPE(static void save_TCP_states, - (tcp_t * tc, caddr_t *fa, tcpb_t *tb, caddr_t *xp)); +static void save_TCP_size(tcp_t *tc); +static void save_TCP_states(tcp_t *tc, caddr_t *fa, tcpb_t *tb, caddr_t *xp); /* * build_IPstates() -- build the TCP and UDP state tables */ -void build_IPstates() { +void build_IPstates(struct lsof_context *ctx) { if (!TcpSt) { - (void)enter_IPstate("TCP", "CLOSED", TCPS_CLOSED); - (void)enter_IPstate("TCP", "IDLE", TCPS_IDLE); - (void)enter_IPstate("TCP", "BOUND", TCPS_BOUND); - (void)enter_IPstate("TCP", "LISTEN", TCPS_LISTEN); - (void)enter_IPstate("TCP", "SYN_SENT", TCPS_SYN_SENT); - (void)enter_IPstate("TCP", "SYN_RCVD", TCPS_SYN_RCVD); - (void)enter_IPstate("TCP", "ESTABLISHED", TCPS_ESTABLISHED); - (void)enter_IPstate("TCP", "CLOSE_WAIT", TCPS_CLOSE_WAIT); - (void)enter_IPstate("TCP", "FIN_WAIT_1", TCPS_FIN_WAIT_1); - (void)enter_IPstate("TCP", "CLOSING", TCPS_CLOSING); - (void)enter_IPstate("TCP", "LAST_ACK", TCPS_LAST_ACK); - (void)enter_IPstate("TCP", "FIN_WAIT_2", TCPS_FIN_WAIT_2); - (void)enter_IPstate("TCP", "TIME_WAIT", TCPS_TIME_WAIT); - (void)enter_IPstate("TCP", (char *)NULL, 0); + (void)enter_IPstate(ctx, "TCP", "CLOSED", TCPS_CLOSED); + (void)enter_IPstate(ctx, "TCP", "IDLE", TCPS_IDLE); + (void)enter_IPstate(ctx, "TCP", "BOUND", TCPS_BOUND); + (void)enter_IPstate(ctx, "TCP", "LISTEN", TCPS_LISTEN); + (void)enter_IPstate(ctx, "TCP", "SYN_SENT", TCPS_SYN_SENT); + (void)enter_IPstate(ctx, "TCP", "SYN_RCVD", TCPS_SYN_RCVD); + (void)enter_IPstate(ctx, "TCP", "ESTABLISHED", TCPS_ESTABLISHED); + (void)enter_IPstate(ctx, "TCP", "CLOSE_WAIT", TCPS_CLOSE_WAIT); + (void)enter_IPstate(ctx, "TCP", "FIN_WAIT_1", TCPS_FIN_WAIT_1); + (void)enter_IPstate(ctx, "TCP", "CLOSING", TCPS_CLOSING); + (void)enter_IPstate(ctx, "TCP", "LAST_ACK", TCPS_LAST_ACK); + (void)enter_IPstate(ctx, "TCP", "FIN_WAIT_2", TCPS_FIN_WAIT_2); + (void)enter_IPstate(ctx, "TCP", "TIME_WAIT", TCPS_TIME_WAIT); + (void)enter_IPstate(ctx, "TCP", (char *)NULL, 0); } if (!UdpSt) { - (void)enter_IPstate("UDP", "Unbound", TS_UNBND); - (void)enter_IPstate("UDP", "Wait_BIND_REQ_Ack", TS_WACK_BREQ); - (void)enter_IPstate("UDP", "Wait_UNBIND_REQ_Ack", TS_WACK_UREQ); - (void)enter_IPstate("UDP", "Idle", TS_IDLE); - (void)enter_IPstate("UDP", "Wait_OPT_REQ_Ack", TS_WACK_OPTREQ); - (void)enter_IPstate("UDP", "Wait_CONN_REQ_Ack", TS_WACK_CREQ); - (void)enter_IPstate("UDP", "Wait_CONN_REQ_Confirm", TS_WCON_CREQ); - (void)enter_IPstate("UDP", "Wait_CONN_IND_Response", TS_WRES_CIND); - (void)enter_IPstate("UDP", "Wait_CONN_RES_Ack", TS_WACK_CRES); - (void)enter_IPstate("UDP", "Wait_Data_Xfr", TS_DATA_XFER); - (void)enter_IPstate("UDP", "Wait_Read_Release", TS_WIND_ORDREL); - (void)enter_IPstate("UDP", "Wait_Write_Release", TS_WREQ_ORDREL); - (void)enter_IPstate("UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ6); - (void)enter_IPstate("UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ7); - (void)enter_IPstate("UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ9); - (void)enter_IPstate("UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ10); - (void)enter_IPstate("UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ11); - (void)enter_IPstate("UDP", (char *)NULL, 0); + (void)enter_IPstate(ctx, "UDP", "Unbound", TS_UNBND); + (void)enter_IPstate(ctx, "UDP", "Wait_BIND_REQ_Ack", TS_WACK_BREQ); + (void)enter_IPstate(ctx, "UDP", "Wait_UNBIND_REQ_Ack", TS_WACK_UREQ); + (void)enter_IPstate(ctx, "UDP", "Idle", TS_IDLE); + (void)enter_IPstate(ctx, "UDP", "Wait_OPT_REQ_Ack", TS_WACK_OPTREQ); + (void)enter_IPstate(ctx, "UDP", "Wait_CONN_REQ_Ack", TS_WACK_CREQ); + (void)enter_IPstate(ctx, "UDP", "Wait_CONN_REQ_Confirm", TS_WCON_CREQ); + (void)enter_IPstate(ctx, "UDP", "Wait_CONN_IND_Response", TS_WRES_CIND); + (void)enter_IPstate(ctx, "UDP", "Wait_CONN_RES_Ack", TS_WACK_CRES); + (void)enter_IPstate(ctx, "UDP", "Wait_Data_Xfr", TS_DATA_XFER); + (void)enter_IPstate(ctx, "UDP", "Wait_Read_Release", TS_WIND_ORDREL); + (void)enter_IPstate(ctx, "UDP", "Wait_Write_Release", TS_WREQ_ORDREL); + (void)enter_IPstate(ctx, "UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ6); + (void)enter_IPstate(ctx, "UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ7); + (void)enter_IPstate(ctx, "UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ9); + (void)enter_IPstate(ctx, "UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ10); + (void)enter_IPstate(ctx, "UDP", "Wait_DISCON_REQ_Ack", TS_WACK_DREQ11); + (void)enter_IPstate(ctx, "UDP", (char *)NULL, 0); } } @@ -350,7 +351,8 @@ void build_IPstates() { * print_tcptpi() - print TCP/TPI info */ -void print_tcptpi(nl) int nl; /* 1 == '\n' required */ +void print_tcptpi(struct lsof_context *ctx, /* context */ + int nl) /* 1 == '\n' required */ { char *cp = (char *)NULL; char sbuf[128]; @@ -362,7 +364,7 @@ void print_tcptpi(nl) int nl; /* 1 == '\n' required */ switch (Lf->lts.type) { case 0: /* TCP */ if (!TcpSt) - (void)build_IPstates(); + (void)build_IPstates(ctx); if ((i = Lf->lts.state.i + TcpStOff) < 0 || i >= TcpNstates) { (void)snpf(sbuf, sizeof(sbuf), "UNKNOWN_TCP_STATE_%d", Lf->lts.state.i); @@ -372,7 +374,7 @@ void print_tcptpi(nl) int nl; /* 1 == '\n' required */ break; case 1: /* TPI */ if (!UdpSt) - (void)build_IPstates(); + (void)build_IPstates(ctx); if ((u = Lf->lts.state.ui + UdpStOff) < 0 || u >= UdpNstates) { (void)snpf(sbuf, sizeof(sbuf), "UNKNOWN_UDP_STATE_%u", Lf->lts.state.ui); @@ -677,10 +679,10 @@ void print_tcptpi(nl) int nl; /* 1 == '\n' required */ # define conn_src V4_PART_OF_V6(connua_v6addr.connua_laddr) # endif /* defined(HAS_CONN_NEW) */ -int process_VSOCK(va, v, so) -KA_T va; /* containing vnode address */ -struct vnode *v; /* pointer to containing vnode */ -struct sonode *so; /* pointer to socket's sonode */ +int process_VSOCK(struct lsof_context *ctx, /* context */ + KA_T va, /* containing vnode address */ + struct vnode *v, /* pointer to containing vnode */ + struct sonode *so) /* pointer to socket's sonode */ { int af; /* address family */ struct conn_s cs; /* connection info */ @@ -716,17 +718,17 @@ struct sonode *so; /* pointer to socket's sonode */ */ if (!(pha = (KA_T)so->so_proto_handle)) return (0); - if (kread(pha, (char *)&cs, sizeof(cs))) { + if (kread(ctx, pha, (char *)&cs, sizeof(cs))) { (void)snpf(Namech, Namechl, "vnode at %s; snode at %s; can't read proto handle at: %s", print_kptr(va, tbuf, sizeof(tbuf)), print_kptr((KA_T)v->v_data, tbuf1, sizeof(tbuf1)), print_kptr(pha, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } - enter_dev_ch(print_kptr(pha, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(pha, (char *)NULL, 0)); /* * Process connection info by protocol. */ @@ -750,12 +752,12 @@ struct sonode *so; /* pointer to socket's sonode */ * Process TCP socket; read its control structure. */ if (!(ka = (KA_T)cs.conn_proto_priv.cp_tcp) || - kread(ka, (char *)&tc, sizeof(tc))) { + kread(ctx, ka, (char *)&tc, sizeof(tc))) { (void)snpf(Namech, Namechl - 1, "can't read TCP socket's control structure: %s", print_kptr((KA_T)ka, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } /* @@ -824,20 +826,20 @@ struct sonode *so; /* pointer to socket's sonode */ af = AF_INET; } lp = (u_short)cs.conn_lport; - (void)ent_inaddr(la, (int)ntohs(lp), fa, (int)ntohs(fp), af); + (void)ent_inaddr(ctx, la, (int)ntohs(lp), fa, (int)ntohs(fp), af); /* * Save TCP state information. */ # if defined(HAS_CONN_NEW) if ((ka = (KA_T)cs.conn_ixa) && - !kread(ka, (char *)&xa, sizeof(xa))) { + !kread(ctx, ka, (char *)&xa, sizeof(xa))) { xp = (caddr_t *)&xa; } (void)save_TCP_states(&tc, (caddr_t *)&cs, (tcpb_t *)NULL, xp); # else /* !defined(HAS_CONN_NEW) */ if (tc.tcp_tcp_hdr_len && (ka = (KA_T)tc.tcp_tcph) && - !kread(ka, (char *)&th, sizeof(th))) { + !kread(ctx, ka, (char *)&th, sizeof(th))) { tha = &th; } (void)save_TCP_states(&tc, (caddr_t *)tha, (tcpb_t *)NULL, @@ -857,12 +859,12 @@ struct sonode *so; /* pointer to socket's sonode */ * Process UDP socket; read its control structure. */ if (!(ka = (KA_T)cs.conn_proto_priv.cp_udp) || - kread(ka, (char *)&uc, sizeof(uc))) { + kread(ctx, ka, (char *)&uc, sizeof(uc))) { (void)snpf(Namech, Namechl - 1, "can't read UDP socket's control structure: %s", print_kptr((KA_T)ka, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } /* @@ -917,7 +919,7 @@ struct sonode *so; /* pointer to socket's sonode */ fp = (u_short)cs.conn_fport; } lp = (u_short)cs.conn_lport; - (void)ent_inaddr(la, (int)ntohs(lp), fa, (int)ntohs(fp), af); + (void)ent_inaddr(ctx, la, (int)ntohs(lp), fa, (int)ntohs(fp), af); /* * Save UDP state and size information. */ @@ -973,7 +975,8 @@ struct sonode *so; /* pointer to socket's sonode */ /* * Read the ICMP control structure. */ - if (read_icmp_t(va, pha, (KA_T)cs.conn_proto_priv.cp_icmp, &ic)) + if (read_icmp_t(ctx, va, pha, (KA_T)cs.conn_proto_priv.cp_icmp, + &ic)) return (1); /* * Save ICMP size and state information. @@ -1003,7 +1006,7 @@ struct sonode *so; /* pointer to socket's sonode */ if (!IPv_ADDR_UNSPEC(af, ta)) fa = ta; if (la || fa) - (void)ent_inaddr(la, 0, fa, 0, af); + (void)ent_inaddr(ctx, la, 0, fa, 0, af); # if defined(HASSOOPT) /* @@ -1029,7 +1032,7 @@ struct sonode *so; /* pointer to socket's sonode */ "unsupported conn_s AF_INET%s protocol: %u", (af == AF_INET6) ? "6" : "", (unsigned int)cs.conn_ulp); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } break; @@ -1053,7 +1056,7 @@ struct sonode *so; /* pointer to socket's sonode */ /* * Read routing control structure. */ - if (read_rts_t(va, pha, (KA_T)cs.conn_proto_priv.cp_rts, &rt)) + if (read_rts_t(ctx, va, pha, (KA_T)cs.conn_proto_priv.cp_rts, &rt)) return (1); /* /* @@ -1093,7 +1096,7 @@ struct sonode *so; /* pointer to socket's sonode */ (void)snpf(Namech, Namechl - 1, "unsupported socket family: %u", so->so_family); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); Lf->inp_ty = 2; } return (1); @@ -1104,8 +1107,9 @@ struct sonode *so; /* pointer to socket's sonode */ * process_socket() - process Solaris socket */ -void process_socket(sa, ty) KA_T sa; /* stream's data address in kernel */ -char *ty; /* socket type name */ +void process_socket(struct lsof_context *ctx, /* context */ + KA_T sa, /* stream's data address in kernel */ + char *ty) /* socket type name */ { int af; unsigned char *fa = (unsigned char *)NULL; @@ -1285,28 +1289,28 @@ char *ty; /* socket type name */ /* * Read stream queue entries to obtain private IP, TCP, and UDP structures. */ - if (!sa || readstdata(sa, &sd)) + if (!sa || readstdata(ctx, sa, &sd)) qp = (KA_T)NULL; else qp = (KA_T)sd.sd_wrq; for (i = 0; qp && i < 20; i++, qp = (KA_T)q.q_next) { - if (kread(qp, (char *)&q, sizeof(q))) + if (kread(ctx, qp, (char *)&q, sizeof(q))) break; if ((ka = (KA_T)q.q_qinfo) == (KA_T)NULL || - kread(ka, (char *)&qi, sizeof(qi))) + kread(ctx, ka, (char *)&qi, sizeof(qi))) continue; if ((ka = (KA_T)qi.qi_minfo) == (KA_T)NULL || - kread(ka, (char *)&mi, sizeof(mi)) || + kread(ctx, ka, (char *)&mi, sizeof(mi)) || (ka = (KA_T)mi.mi_idname) == (KA_T)NULL) continue; - if (kread(ka, (char *)&tbuf, sizeof(tbuf) - 1)) + if (kread(ctx, ka, (char *)&tbuf, sizeof(tbuf) - 1)) continue; if ((pcb = (KA_T)q.q_ptr) == (KA_T)NULL) continue; #if solaris < 110000 if (strncasecmp(tbuf, "IP", 2) == 0) { - if (kread(pcb, (char *)&ic, sizeof(ic)) == 0) + if (kread(ctx, pcb, (char *)&ic, sizeof(ic)) == 0) ics = 1; continue; } @@ -1315,12 +1319,12 @@ char *ty; /* socket type name */ if (strncasecmp(tbuf, "TCP", 3) == 0) { #if solaris <= 90000 || !defined(HAS_IPCLASSIFIER_H) - if (!kread((KA_T)pcb, (char *)&tc, sizeof(tc))) + if (!kread(ctx, (KA_T)pcb, (char *)&tc, sizeof(tc))) # if solaris >= 80000 { if (tc.tcp_base && - !kread((KA_T)tc.tcp_base, (char *)&tcb, sizeof(tcb))) { + !kread(ctx, (KA_T)tc.tcp_base, (char *)&tcb, sizeof(tcb))) { tcs = 1; tcbp = &tcb; } @@ -1332,17 +1336,18 @@ char *ty; /* socket type name */ # endif /* solaris>=80000 */ #else /* solaris>90000 && defined(HAS_IPCLASSIFIER_H) */ # if solaris >= 110000 - if (!kread(pcb, (char *)&cs, sizeof(cs)) && + if (!kread(ctx, pcb, (char *)&cs, sizeof(cs)) && (cs.conn_ulp == IPPROTO_TCP)) { ics = 1; if ((ka = (KA_T)cs.conn_proto_priv.cp_tcp) && - !kread(ka, (char *)&tc, sizeof(tc))) { + !kread(ctx, ka, (char *)&tc, sizeof(tc))) { tcs = 1; } } # else /* solaris<110000 */ - if (!kread((KA_T)pcb, (char *)&ic, sizeof(ic)) && ic.conn_tcp && - !kread((KA_T)ic.conn_tcp, (char *)&tc, sizeof(tc))) { + if (!kread(ctx, (KA_T)pcb, (char *)&ic, sizeof(ic)) && + ic.conn_tcp && + !kread(ctx, (KA_T)ic.conn_tcp, (char *)&tc, sizeof(tc))) { ics = tcs = 1; } # endif /* solaris>=110000 */ @@ -1392,14 +1397,14 @@ char *ty; /* socket type name */ if (strncasecmp(tbuf, "UDP", 3) == 0) { #if solaris < 110000 - if (kread(pcb, (char *)&uc, sizeof(uc)) == 0) + if (kread(ctx, pcb, (char *)&uc, sizeof(uc)) == 0) ucs = 1; #else /* solaris>=110000 */ - if (!kread(pcb, (char *)&cs, sizeof(cs)) && + if (!kread(ctx, pcb, (char *)&cs, sizeof(cs)) && (cs.conn_ulp == IPPROTO_UDP)) { ics = 1; if ((ka = (KA_T)cs.conn_proto_priv.cp_udp) && - !read_udp_t(ka, &uc)) { + !read_udp_t(ctx, ka, &uc)) { ucs = 1; } } @@ -1452,7 +1457,7 @@ char *ty; /* socket type name */ * Print stream head's q_ptr address as protocol control block address. */ if (pcb) - enter_dev_ch(print_kptr(pcb, (char *)NULL, 0)); + enter_dev_ch(ctx, print_kptr(pcb, (char *)NULL, 0)); if (strncmp(Lf->iproto, "UDP", 3) == 0) { /* @@ -1508,7 +1513,8 @@ char *ty; /* socket type name */ # endif /* defined(HASIPv6) */ #endif /* solaris<110000 */ - (void)ent_inaddr(la, (int)ntohs(p), (unsigned char *)NULL, -1, af); + (void)ent_inaddr(ctx, la, (int)ntohs(p), (unsigned char *)NULL, -1, + af); if (ucs) { Lf->lts.type = 1; Lf->lts.state.ui = (unsigned int)uc.udp_state; @@ -1579,7 +1585,8 @@ char *ty; /* socket type name */ # endif /* solaris!=20400 && !defined(HASIPv6) */ if (tc.tcp_hdr_len && tc.tcp_tcph && - !kread((KA_T)tc.tcp_tcph, (char *)&th, sizeof(th))) { + !kread(ctx, (KA_T)tc.tcp_tcph, (char *)&th, + sizeof(th))) { tha = &th; s = (u_short *)&th.th_lport[0]; p = *s; @@ -1648,7 +1655,7 @@ char *ty; /* socket type name */ #endif /* defined(HASIPv6) */ if (fa || la) - (void)ent_inaddr(la, lp, fa, fp, af); + (void)ent_inaddr(ctx, la, lp, fa, fp, af); } /* * Save TCP state information. @@ -1672,7 +1679,7 @@ char *ty; /* socket type name */ * Enter name characters if there are some. */ if (Namech[0]) - enter_nm(Namech); + enter_nm(ctx, Namech); } #if solaris >= 110000 @@ -1680,12 +1687,12 @@ char *ty; /* socket type name */ * read_icmp_t() - read connections icmp_t info */ -static int read_icmp_t(va, ph, ia, ic) -KA_T va; /* containing vnode kernel address */ -KA_T ph; /* containing protocol handle kernel - * address */ -KA_T ia; /* icmp_t structure's kernel address */ -icmp_t *ic; /* local icmp_t receiver */ +static int read_icmp_t(struct lsof_context *ctx, /* context */ + KA_T va, /* containing vnode kernel address */ + KA_T ph, /* containing protocol handle kernel + * address */ + KA_T ia, /* icmp_t structure's kernel address */ + icmp_t *ic) /* local icmp_t receiver */ { char tbuf[32], tbuf1[32]; /* print_kptr() temporary buffers */ @@ -1696,7 +1703,7 @@ icmp_t *ic; /* local icmp_t receiver */ zeromem((char *)ic, sizeof(icmp_t)); # endif /* defined(HAS_CONN_NEW) */ - (void)CTF_init(&IRU_ctfs, IRU_MOD_FORMAT, IRU_requests); + (void)CTF_init(ctx, &IRU_ctfs, IRU_MOD_FORMAT, IRU_requests); if (!ia || CTF_MEMBER_READ(ia, ic, icmp_t_members, icmp_state) # if defined(HAS_CONN_NEW) @@ -1714,12 +1721,13 @@ icmp_t *ic; /* local icmp_t receiver */ print_kptr(ph, tbuf1, sizeof(tbuf1)), print_kptr(ia, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } # if defined(HAS_CONN_NEW) - if ((ka = (KA_T)ic->icmp_connp) && !kread(ka, (char *)&cs, sizeof(cs))) { + if ((ka = (KA_T)ic->icmp_connp) && + !kread(ctx, ka, (char *)&cs, sizeof(cs))) { struct ip_xmit_attr_s xa; /* @@ -1732,7 +1740,8 @@ icmp_t *ic; /* local icmp_t receiver */ ic->icmp_debug.icmp_reuseaddr = cs.conn_reuseaddr; ic->icmp_debug.icmp_useloopback = cs.conn_useloopback; ic->icmp_debug.icmp_dgram_errind = cs.conn_dgram_errind; - if ((ka = (KA_T)cs.conn_ixa) && !kread(ka, (char *)&xa, sizeof(xa))) { + if ((ka = (KA_T)cs.conn_ixa) && + !kread(ctx, ka, (char *)&xa, sizeof(xa))) { ic->icmp_debug.icmp_dontroute = (xa.ixa_flags & IXAF_DONTROUTE) ? 1 : 0; } @@ -1746,12 +1755,12 @@ icmp_t *ic; /* local icmp_t receiver */ * read_rts_t() - read connections rts_t info */ -static int read_rts_t(va, ph, ra, rt) -KA_T va; /* containing vnode kernel address */ -KA_T ph; /* containing protocol handle kernel - * address */ -KA_T ra; /* rts_t structure's kernel address */ -rts_t *rt; /* local rts_t receiver */ +static int read_rts_t(struct lsof_context *ctx, /* context */ + KA_T va, /* containing vnode kernel address */ + KA_T ph, /* containing protocol handle kernel + * address */ + KA_T ra, /* rts_t structure's kernel address */ + rts_t *rt) /* local rts_t receiver */ { char tbuf[32], tbuf1[32]; /* print_kptr() temporary buffers */ @@ -1762,7 +1771,7 @@ rts_t *rt; /* local rts_t receiver */ zeromem((char *)rt, sizeof(rts_t)); # endif /* defined(HAS_CONN_NEW) */ - (void)CTF_init(&IRU_ctfs, IRU_MOD_FORMAT, IRU_requests); + (void)CTF_init(ctx, &IRU_ctfs, IRU_MOD_FORMAT, IRU_requests); if (!ra || CTF_MEMBER_READ(ra, rt, rts_t_members, rts_state) # if defined(HAS_CONN_NEW) @@ -1778,13 +1787,13 @@ rts_t *rt; /* local rts_t receiver */ print_kptr(ph, tbuf1, sizeof(tbuf1)), print_kptr(ra, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } # if defined(HAS_CONN_NEW) if ((ka = (KA_T)rt->rts_connp) && - !kread(ka, (char *)&cs, sizeof(struct conn_s))) { + !kread(ctx, ka, (char *)&cs, sizeof(struct conn_s))) { struct ip_xmit_attr_s xa; /* @@ -1794,7 +1803,8 @@ rts_t *rt; /* local rts_t receiver */ rt->rts_debug.rts_broadcast = cs.conn_broadcast; rt->rts_debug.rts_reuseaddr = cs.conn_reuseaddr; rt->rts_debug.rts_useloopback = cs.conn_useloopback; - if ((ka = (KA_T)cs.conn_ixa) && !kread(ka, (char *)&xa, sizeof(xa))) { + if ((ka = (KA_T)cs.conn_ixa) && + !kread(ctx, ka, (char *)&xa, sizeof(xa))) { rt->rts_debug.rts_dontroute = (xa.ixa_flags & IXAF_DONTROUTE) ? 1 : 0; } @@ -1809,11 +1819,11 @@ rts_t *rt; /* local rts_t receiver */ * read_udp_t() - read UDP control structure */ -static int read_udp_t(ua, uc) -KA_T ua; /* ucp_t kernel address */ -udp_t *uc; /* receiving udp_t structure */ +static int read_udp_t(struct lsof_context *ctx, /* context */ + KA_T ua, /* ucp_t kernel address */ + udp_t *uc) /* receiving udp_t structure */ { - (void)CTF_init(&IRU_ctfs, IRU_MOD_FORMAT, IRU_requests); + (void)CTF_init(ctx, &IRU_ctfs, IRU_MOD_FORMAT, IRU_requests); if (!ua || CTF_MEMBER_READ(ua, uc, udp_t_members, udp_state) # if defined(HAS_CONN_NEW) @@ -1831,7 +1841,7 @@ udp_t *uc; /* receiving udp_t structure */ (void)snpf(Namech, Namechl, "can't read udp_t: %s", print_kptr(ua, (char *)NULL, 0)); Namech[Namechl - 1] = '\0'; - enter_nm(Namech); + enter_nm(ctx, Namech); return (1); } return (0); @@ -1842,9 +1852,7 @@ udp_t *uc; /* receiving udp_t structure */ * save_TCP_size() -- save TCP size information */ -static void - - save_TCP_size(tc) tcp_t *tc; /* pointer to TCP control structure */ +static void save_TCP_size(tcp_t *tc) /* pointer to TCP control structure */ { int rq, sq; diff --git a/lib/dialects/uw/dfile.c b/lib/dialects/uw/dfile.c index 9c9ce216..f5a174e3 100644 --- a/lib/dialects/uw/dfile.c +++ b/lib/dialects/uw/dfile.c @@ -51,7 +51,8 @@ int get_max_fd() { * process_file() - process file */ -void process_file(fp) KA_T fp; /* kernel file structure address */ +void process_file(struct lsof_context *ctx, /* context */ + KA_T fp) /* kernel file structure address */ { struct file f; int flag; @@ -60,7 +61,7 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ FILEPTR = &f; #endif /* defined(FILEPTR) */ - if (kread(fp, (char *)&f, sizeof(f))) { + if (kread(ctx, fp, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "can't read file struct from %s", print_kptr(fp, (char *)NULL, 0)); enter_nm(Namech); @@ -149,9 +150,7 @@ static short CIMap[] = { * strcasecmp() - case insentitive character compare (from BSD) */ -int strcasecmp(s1, s2) -char *s1, *s2; -{ +int strcasecmp(char *s1, char *s2) { short *mp = CIMap; unsigned char *cp1 = (unsigned char *)s1; unsigned char *cp2 = (unsigned char *)s2; @@ -169,10 +168,7 @@ char *s1, *s2; * (from BSD) */ -int strncasecmp(s1, s2, n) -char *s1, *s2; -int n; -{ +int strncasecmp(char *s1, char *s2, int n) { short *mp = CIMap; unsigned char *cp1, *cp2; diff --git a/lib/dialects/uw/dmnt.c b/lib/dialects/uw/dmnt.c index 3cf47a74..3cea99fe 100644 --- a/lib/dialects/uw/dmnt.c +++ b/lib/dialects/uw/dmnt.c @@ -46,7 +46,7 @@ static int Lmist = 0; /* Lmi status */ * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char *dn = (char *)NULL; char *ln; struct mnttab me; @@ -97,7 +97,7 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(me.mnt_mountp, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } if (!(ln = Readlink(dn))) { if (!Fwarn) { diff --git a/lib/dialects/uw/dnode.c b/lib/dialects/uw/dnode.c index 56dbf293..d923b595 100644 --- a/lib/dialects/uw/dnode.c +++ b/lib/dialects/uw/dnode.c @@ -52,27 +52,25 @@ static char copyright[] = # include #endif /* defined(HASXNAMNODE) */ -_PROTOTYPE(static void ent_fa, (KA_T * a1, KA_T *a2, char *d)); -_PROTOTYPE(static int get_vty, - (struct vnode * v, KA_T va, struct vfs *kv, int *fx)); +static void ent_fa(KA_T *a1, KA_T *a2, char *d); +static int get_vty(struct vnode *v, KA_T va, struct vfs *kv, int *fx); #if UNIXWAREV < 70103 -_PROTOTYPE(static int examine_stream, - (KA_T vs, struct queue *q, char *mn, char *sn, KA_T *sqp)); +static int examine_stream(KA_T vs, struct queue *q, char *mn, char *sn, + KA_T *sqp); #else /* UNIXWAREV>=70103 */ -_PROTOTYPE(static int examine_stream, (KA_T vs, struct queue *q, char **mch, - char **mn, char *sn, KA_T *sqp)); -_PROTOTYPE(static struct l_dev *findspdev, (dev_t * dev, dev_t *rdev)); -_PROTOTYPE(static void getspdev, (void)); -_PROTOTYPE(static int get_vty, - (struct vnode * v, KA_T va, struct vfs *kv, int *fx)); -_PROTOTYPE(static struct l_dev *ismouse, - (struct vnode * va, struct l_ino *i, int fx, struct vfs *kv)); +static int examine_stream(KA_T vs, struct queue *q, char **mch, char **mn, + char *sn, KA_T *sqp); +static struct l_dev *findspdev(dev_t *dev, dev_t *rdev); +static void getspdev(void); +static int get_vty(struct vnode *v, KA_T va, struct vfs *kv, int *fx); +static struct l_dev *ismouse(struct vnode *va, struct l_ino *i, int fx, + struct vfs *kv); #endif /* UNIXWAREV<70103 */ -_PROTOTYPE(static struct l_dev *findstrdev, (dev_t * dev, dev_t *rdev)); -_PROTOTYPE(static char isvlocked, (struct vnode * va)); -_PROTOTYPE(static int readlino, (int fx, struct vnode *v, struct l_ino *i)); +static struct l_dev *findstrdev(dev_t *dev, dev_t *rdev); +static char isvlocked(struct vnode *va); +static int readlino(int fx, struct vnode *v, struct l_ino *i); /* * Local variables and definitions @@ -129,7 +127,7 @@ char *d; /* direction ("->" or "<-") */ (void)fprintf(stderr, "%s: no space for fattach addresses at PID %d, FD %s\n", Pn, Lp->pid, Lf->fd); - Error(); + Error(ctx); } (void)snpf(cp, len, "%s", buf); Lf->nma = cp; @@ -139,28 +137,21 @@ char *d; /* direction ("->" or "<-") */ * examine_stream() - examine stream */ -static int - -#if UNIXWAREV < 70103 -examine_stream(vs, q, mn, sn, sqp) -#else /* UNIXWAREV>=70103 */ -examine_stream(vs, q, mch, mn, sn, sqp) -#endif /* UNIXWAREV<70103 */ - -KA_T vs; /* stream head's stdata kernel - * address */ -struct queue *q; /* queue structure buffer */ +static int examine_stream(struct lsof_context *ctx, /* context */ + KA_T vs, /* stream head's stdata kernel + * address */ + struct queue *q, /* queue structure buffer */ #if UNIXWAREV >= 70103 -char **mch; /* important stream module name chain, - * module names separated by "->" */ -char **mn; /* pointer to module name receiver */ -#else /* UNIXWAREV<70103 */ -char *mn; /* module name receiver */ -#endif /* UNIXWAREV>=70103 */ - -char *sn; /* special module name */ -KA_T *sqp; /* special module's q_ptr */ + char **mch, /* important stream module name chain, + * module names separated by "->" */ + char **mn, /* pointer to module name receiver */ +#else /* UNIXWAREV<70103 */ + char *mn, /* module name receiver */ +#endif /* UNIXWAREV>=70103 */ + + char *sn, /* special module name */ + KA_T *sqp) /* special module's q_ptr */ { struct module_info mi; KA_T qp; @@ -206,7 +197,7 @@ KA_T *sqp; /* special module's q_ptr */ /* * Read stream queue entry. */ - if (kread(qp, (char *)q, sizeof(struct queue))) { + if (kread(ctx, qp, (char *)q, sizeof(struct queue))) { (void)snpf(Namech, Namechl, "can't read stream queue from %s", print_kptr(qp, (char *)NULL, 0)); enter_nm(Namech); @@ -237,9 +228,9 @@ KA_T *sqp; /* special module's q_ptr */ */ #if UNIXWAREV < 70103 - if (!mi.mi_idname || kread((KA_T)mi.mi_idname, mn, STRNML - 1)) + if (!mi.mi_idname || kread(ctx, (KA_T)mi.mi_idname, mn, STRNML - 1)) #else /* UNIXWAREV>=70103 */ - if (!mi.mi_idname || kread((KA_T)mi.mi_idname, tmnb, STRNML)) + if (!mi.mi_idname || kread(ctx, (KA_T)mi.mi_idname, tmnb, STRNML)) #endif /* UNIXWAREV<70103 */ { @@ -288,7 +279,7 @@ KA_T *sqp; /* special module's q_ptr */ } if (!ab) { (void)fprintf(stderr, "%s: no space for stream chain", Pn); - Error(); + Error(ctx); } } (void)snpf(ap, aba - (al - 1), "%s%s", (ap == ab) ? "" : "->", @@ -314,9 +305,8 @@ KA_T *sqp; /* special module's q_ptr */ * findspdev() - find special device by raw major device number */ -static struct l_dev *findspdev(dev, rdev) -dev_t *dev; /* containing device */ -dev_t *rdev; /* raw device */ +static struct l_dev *findspdev(dev_t *dev, /* containing device */ + dev_t *rdev) /* raw device */ { int i; struct l_dev *dp; @@ -339,9 +329,8 @@ dev_t *rdev; /* raw device */ * findstrdev() - look up stream device by device number */ -static struct l_dev *findstrdev(dev, rdev) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ +static struct l_dev *findstrdev(dev_t *dev, /* device */ + dev_t *rdev) /* raw device */ { struct clone *c; struct l_dev *dp; @@ -426,11 +415,11 @@ static void getspdev() { * -3 if the vfs structure can't be read */ -static int get_vty(v, va, kv, fx) -struct vnode *v; /* vnode to test */ -KA_T va; /* vnode's kernel address */ -struct vfs *kv; /* copy of vnode's kernel vfs struct */ -int *fx; /* file system type index */ +static int get_vty(struct lsof_context *ctx, /* context */ + struct vnode *v, /* vnode to test */ + KA_T va, /* vnode's kernel address */ + struct vfs *kv, /* copy of vnode's kernel vfs struct */ + int *fx) /* file system type index */ { int fxt; int nty = N_REGLR; @@ -446,7 +435,7 @@ int *fx; /* file system type index */ return (N_STREAM); return (N_REGLR); } - if (!kread((KA_T)v->v_vfsp, (char *)kv, sizeof(struct vfs))) { + if (!kread(ctx, (KA_T)v->v_vfsp, (char *)kv, sizeof(struct vfs))) { /* * Check the file system type. @@ -495,11 +484,10 @@ int *fx; /* file system type index */ * ismouse() - is vnode attached to /dev/mouse */ -static struct l_dev *ismouse(va, i, fx, kv) -struct vnode *va; /* local vnode address */ -struct l_ino *i; /* local inode structure */ -int fx; /* file system index */ -struct vfs *kv; /* copy of kernel VFS structure */ +static struct l_dev *ismouse(struct vnode *va, /* local vnode address */ + struct l_ino *i, /* local inode structure */ + int fx, /* file system index */ + struct vfs *kv) /* copy of kernel VFS structure */ { struct l_dev *dp; int j; @@ -528,8 +516,8 @@ struct vfs *kv; /* copy of kernel VFS structure */ * isvlocked() - is a vnode locked */ -static char isvlocked(va) -struct vnode *va; /* local vnode address */ +static char isvlocked(struct lsof_context *ctx, /* context */ + struct vnode *va) /* local vnode address */ { struct filock f; KA_T flf, flp; @@ -542,7 +530,7 @@ struct vnode *va; /* local vnode address */ do { if (i++ > 1000) break; - if (kread(flp, (char *)&f, sizeof(f))) + if (kread(ctx, flp, (char *)&f, sizeof(f))) break; if (f.set.l_sysid || f.set.l_pid != (pid_t)Lp->pid) continue; @@ -580,7 +568,8 @@ struct vnode *va; /* local vnode address */ * process_node() - process node */ -void process_node(na) KA_T na; /* vnode kernel space address */ +void process_node(struct lsof_context *ctx, /* context */ + KA_T na) /* vnode kernel space address */ { char *cp, *ep; dev_t dev, rdev; @@ -716,7 +705,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ } break; case N_NM: - if (!v.v_data || kread((KA_T)v.v_data, (char *)&nn, sizeof(nn))) { + if (!v.v_data || kread(ctx, (KA_T)v.v_data, (char *)&nn, sizeof(nn))) { (void)snpf(Namech, Namechl, "vnode@%s: no namenode (%s)", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr((KA_T)v.v_data, (char *)NULL, 0)); @@ -733,7 +722,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ * The name node is mounted over/to another vnode. Process that node. */ (void)ent_fa(&na, (KA_T *)&nn.nm_mountpt, "->"); - if (kread((KA_T)nn.nm_mountpt, (char *)&rv, sizeof(rv))) { + if (kread(ctx, (KA_T)nn.nm_mountpt, (char *)&rv, sizeof(rv))) { (void)snpf(Namech, Namechl, "vnode@%s: can't read namenode's mounted vnode (%s)", print_kptr(na, tbuf, sizeof(tbuf)), @@ -759,7 +748,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ #if defined(HASPROCFS) case N_PROC: ni = 1; - if (!v.v_data || kread((KA_T)v.v_data, (char *)&pr, sizeof(pr))) { + if (!v.v_data || kread(ctx, (KA_T)v.v_data, (char *)&pr, sizeof(pr))) { (void)snpf(Namech, Namechl, "vnode@%s: can't read prnode (%s)", print_kptr(na, tbuf, sizeof(tbuf)), print_kptr((KA_T)v.v_data, (char *)NULL, 0)); @@ -771,7 +760,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ i.number = (INODETYPE)pr.pr_ino; sd = 0; if (pr.pr_common && - !kread((KA_T)pr.pr_common, (char *)&prc, sizeof(prc))) { + !kread(ctx, (KA_T)pr.pr_common, (char *)&prc, sizeof(prc))) { pid = (long)prc.prc_pid; switch (pr.pr_type) { case PR_PIDDIR: @@ -831,14 +820,15 @@ void process_node(na) KA_T na; /* vnode kernel space address */ i.number = (INODETYPE)0; break; } - if (kread((KA_T)pr.pr_proc, (char *)&p, sizeof(p))) { + if (kread(ctx, (KA_T)pr.pr_proc, (char *)&p, sizeof(p))) { (void)snpf(Namech, Namechl, "prnode@%s: can't read proc (%s)", print_kptr((KA_T)v.v_data, tbuf, sizeof(tbuf)), print_kptr((KA_T)pr.pr_proc, (char *)NULL, 0)); enter_nm(Namech); return; } - if (!p.p_pidp || kread((KA_T)p.p_pidp, (char *)&pids, sizeof(pids))) { + if (!p.p_pidp || + kread(ctx, (KA_T)p.p_pidp, (char *)&pids, sizeof(pids))) { (void)snpf(Namech, Namechl, "proc struct at %s: can't read pid (%s)", print_kptr((KA_T)pr.pr_proc, tbuf, sizeof(tbuf)), @@ -849,7 +839,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ pid = (long)pids.pid_id; (void)snpf(Namech, Namechl, "/%s/%ld", HASPROCFS, pid); i.number = (INODETYPE)(pid + PR_INOBIAS); - if (!p.p_as || kread((KA_T)p.p_as, (char *)&as, sizeof(as))) + if (!p.p_as || kread(ctx, (KA_T)p.p_as, (char *)&as, sizeof(as))) sd = 0; else i.size = as.a_size; @@ -896,7 +886,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ * If this stream has a "sockmod" module with a non-NULL q_ptr, * try to use it to read an so_so structure. */ - if (sqp && kread(sqp, (char *)&so, sizeof(so)) == 0) + if (sqp && kread(ctx, sqp, (char *)&so, sizeof(so)) == 0) break; sqp = (KA_T)NULL; (void)snpf(Namech, Namechl, "STR"); @@ -1309,7 +1299,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ Lf->sf |= SELUNX; (void)snpf(Lf->type, sizeof(Lf->type), "unix"); if (!Namech[0] && so.laddr.buf && so.laddr.len == sizeof(ua) && - !kread((KA_T)so.laddr.buf, (char *)&ua, sizeof(ua))) { + !kread(ctx, (KA_T)so.laddr.buf, (char *)&ua, sizeof(ua))) { ua.sun_path[sizeof(ua.sun_path) - 1] = '\0'; (void)snpf(Namech, Namechl, "%s", ua.sun_path); if (Sfile && is_file_named(Namech, 0)) @@ -1375,7 +1365,7 @@ void process_node(na) KA_T na; /* vnode kernel space address */ stderr, "%s: can't allocate %d bytes for l_ino name addition\n", msz, Pn); - Error(); + Error(ctx); } (void)snpf(cp, msz + 1, "%s", i.nm); Lf->nma = cp; @@ -1389,10 +1379,9 @@ void process_node(na) KA_T na; /* vnode kernel space address */ * readlino() - read local inode information */ -static int readlino(fx, v, i) -int fx; /* file system index */ -struct vnode *v; /* vnode pointing to inode */ -struct l_ino *i; /* local inode */ +static int readlino(struct lsof_context *ctx, int fx, /* file system index */ + struct vnode *v, /* vnode pointing to inode */ + struct l_ino *i) /* local inode */ { #if defined(HAS_UW_CFS) @@ -1412,7 +1401,7 @@ struct l_ino *i; /* local inode */ return (1); if (!strcmp(Fsinfo[fx - 1], "fifofs") || !strcmp(Fsinfo[fx - 1], "sfs") || !strcmp(Fsinfo[fx - 1], "ufs")) { - if (kread((KA_T)v->v_data, (char *)&sn, sizeof(sn))) + if (kread(ctx, (KA_T)v->v_data, (char *)&sn, sizeof(sn))) return (1); i->dev = sn.i_dev; i->dev_def = 1; @@ -1429,7 +1418,7 @@ struct l_ino *i; /* local inode */ #if defined(HAS_UW_CFS) else if (!strcmp(Fsinfo[fx - 1], "nsc_cfs")) { - if (kread((KA_T)v->v_data, (char *)&cn, sizeof(cn))) + if (kread(ctx, (KA_T)v->v_data, (char *)&cn, sizeof(cn))) return (1); if (cn.c_attr.va_mask & AT_FSID) { i->dev = cn.c_attr.va_fsid; @@ -1468,7 +1457,7 @@ struct l_ino *i; /* local inode */ #if defined(HASXNAMNODE) else if (!strcmp(Fsinfo[fx - 1], "xnamfs") || !strcmp(Fsinfo[fx - 1], "XENIX")) { - if (kread((KA_T)v->v_data, (char *)&xn, sizeof(xn))) + if (kread(ctx, (KA_T)v->v_data, (char *)&xn, sizeof(xn))) return (1); i->dev = xn.x_dev; i->nlink = (long)xn.x_count; @@ -1481,7 +1470,7 @@ struct l_ino *i; /* local inode */ #endif /* defined(HASXNAMNODE) */ else if (!strcmp(Fsinfo[fx - 1], "memfs")) { - if (kread((KA_T)v->v_data, (char *)&mn, sizeof(mn))) + if (kread(ctx, (KA_T)v->v_data, (char *)&mn, sizeof(mn))) return (1); i->dev = mn.mno_fsid; i->dev_def = 1; diff --git a/lib/dialects/uw/dnode1.c b/lib/dialects/uw/dnode1.c index ed67fd71..b24f7d92 100644 --- a/lib/dialects/uw/dnode1.c +++ b/lib/dialects/uw/dnode1.c @@ -66,13 +66,12 @@ static char copyright[] = * reads5lino() - read s5 inode's local inode information */ -int reads5lino(v, i) -struct vnode *v; /* containing vnode */ -struct l_ino *i; /* local inode information */ +int reads5lino(struct lsof_context *ctx, struct vnode *v, /* containing vnode */ + struct l_ino *i) /* local inode information */ { struct inode s5i; - if (kread((KA_T)v->v_data, (char *)&s5i, sizeof(s5i))) + if (kread(ctx, (KA_T)v->v_data, (char *)&s5i, sizeof(s5i))) return (1); i->dev = s5i.i_dev; i->dev_def = 1; diff --git a/lib/dialects/uw/dnode2.c b/lib/dialects/uw/dnode2.c index a8079e25..2cd9d3d4 100644 --- a/lib/dialects/uw/dnode2.c +++ b/lib/dialects/uw/dnode2.c @@ -76,15 +76,15 @@ struct vx_inode { * readvxfslino() - read vxfs inode's local inode information */ -int readvxfslino(v, i) -struct vnode *v; /* containing vnode */ -struct l_ino *i; /* local inode information */ +int readvxfslino(struct lsof_context *ctx, + struct vnode *v, /* containing vnode */ + struct l_ino *i) /* local inode information */ { #if defined(HASVXFS) struct vx_inode vx; - if (kread((KA_T)v->v_data, (char *)&vx, sizeof(vx))) + if (kread(ctx, (KA_T)v->v_data, (char *)&vx, sizeof(vx))) return (1); i->dev = vx.i_dev; i->dev_def = 1; diff --git a/lib/dialects/uw/dnode3.c b/lib/dialects/uw/dnode3.c index 84cdf442..fc198627 100644 --- a/lib/dialects/uw/dnode3.c +++ b/lib/dialects/uw/dnode3.c @@ -108,16 +108,16 @@ static unsigned char Dos2Unix[] = { * readbfslino() - read bfs inode's local inode information */ -int readbfslino(v, i) -struct vnode *v; /* containing vnode */ -struct l_ino *i; /* local inode information */ +int readbfslino(struct lsof_context *ctx, /* context */ + struct vnode *v, /* containing vnode */ + struct l_ino *i) /* local inode information */ { struct inode b; struct vfs kv; - if (kread((KA_T)v->v_data, (char *)&b, sizeof(b))) + if (kread(ctx, (KA_T)v->v_data, (char *)&b, sizeof(b))) return (1); - if (!v->v_vfsp || kread((KA_T)v->v_vfsp, (char *)&kv, sizeof(kv))) + if (!v->v_vfsp || kread(ctx, (KA_T)v->v_vfsp, (char *)&kv, sizeof(kv))) return (1); i->dev = kv.vfs_dev; i->dev_def = 1; @@ -140,9 +140,9 @@ struct l_ino *i; /* local inode information */ * Adapted from work by Eric Dumazet . */ -int readcdfslino(v, i) -struct vnode *v; /* containing vnode */ -struct l_ino *i; /* local inode information */ +int readcdfslino(struct lsof_context *ctx, /* context */ + struct vnode *v, /* containing vnode */ + struct l_ino *i) /* local inode information */ { cdfs_inode_t ci; TYPELOGSECSHIFT lss; @@ -151,9 +151,9 @@ struct l_ino *i; /* local inode information */ /* * Read the CDFs node. Fill in return values from its contents. */ - if (!v->v_data || kread((KA_T)v->v_data, (char *)&ci, sizeof(ci))) + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&ci, sizeof(ci))) return (1); - if (!v->v_vfsp || kread((KA_T)v->v_vfsp, (char *)&kv, sizeof(kv))) + if (!v->v_vfsp || kread(ctx, (KA_T)v->v_vfsp, (char *)&kv, sizeof(kv))) return (1); i->dev = kv.vfs_dev; i->dev_def = 1; @@ -178,7 +178,7 @@ struct l_ino *i; /* local inode information */ if (!(ka = (KA_T)kv.vfs_data)) return (0); ka = (KA_T)((char *)ka + offsetof(struct cdfs, cdfs_LogSecShift)); - if (!kread(ka, (char *)&lss, sizeof(lss))) { + if (!kread(ctx, ka, (char *)&lss, sizeof(lss))) { i->number = (INODETYPE)((ci.i_Fid.fid_SectNum << lss) + ci.i_Fid.fid_Offset); i->number_def = 1; @@ -192,9 +192,9 @@ struct l_ino *i; /* local inode information */ * Adapted from work by Eric Dumazet . */ -int readdosfslino(v, i) -struct vnode *v; /* containing vnode */ -struct l_ino *i; /* local inode information */ +int readdosfslino(struct lsof_context *ctx, /* context */ + struct vnode *v, /* containing vnode */ + struct l_ino *i) /* local inode information */ { struct dosfs_inode { int pad1[19]; @@ -213,7 +213,7 @@ struct l_ino *i; /* local inode information */ /* * Read the DOSFS node. Fill in return values from its contents. */ - if (!v->v_data || kread((KA_T)v->v_data, (char *)&di, sizeof(di))) + if (!v->v_data || kread(ctx, (KA_T)v->v_data, (char *)&di, sizeof(di))) return (1); i->dev = (dev_t)di.device; i->dev_def = 1; @@ -234,7 +234,7 @@ struct l_ino *i; /* local inode information */ (void)fprintf(stderr, "%s: can't allocate %d bytes for DOS name\n", nml, Pn); - Error(); + Error(ctx); } } /* diff --git a/lib/dialects/uw/dproc.c b/lib/dialects/uw/dproc.c index 4ea77287..7ed95e54 100644 --- a/lib/dialects/uw/dproc.c +++ b/lib/dialects/uw/dproc.c @@ -58,17 +58,17 @@ static struct var Var; /* kernel variables */ * Local function prototypes. */ -_PROTOTYPE(static int get_clonemaj, (void)); -_PROTOTYPE(static void read_proc, (void)); -_PROTOTYPE(static void get_kernel_access, (void)); -_PROTOTYPE(static void readfsinfo, (void)); -_PROTOTYPE(static void process_text, (KA_T pa)); +static int get_clonemaj(void); +static void read_proc(void); +static void get_kernel_access(void); +static void readfsinfo(void); +static void process_text(KA_T pa); /* * gather_proc_info() -- gather process information */ -void gather_proc_info() { +void gather_proc_info(struct lsof_context *ctx) { struct cred cr; struct execinfo ex; static struct fd_entry *fe; @@ -103,19 +103,21 @@ void gather_proc_info() { /* * Get Process ID, Process group ID, and User ID. */ - if (!p->p_pidp || kread((KA_T)p->p_pidp, (char *)&pids, sizeof(pids))) + if (!p->p_pidp || + kread(ctx, (KA_T)p->p_pidp, (char *)&pids, sizeof(pids))) continue; pid = (int)pids.pid_id; #if defined(HAS_P_PGID) pgid = (int)p->p_pgid; #else /* !defined(HAS_P_PGID) */ - if (!p->p_pgidp || kread((KA_T)p->p_pgidp, (char *)&pids, sizeof(pids))) + if (!p->p_pgidp || + kread(ctx, (KA_T)p->p_pgidp, (char *)&pids, sizeof(pids))) continue; pgid = (int)pids.pid_id; #endif /* defined(HAS_P_PGID) */ - if (!p->p_cred || kread((KA_T)p->p_cred, (char *)&cr, sizeof(cr))) + if (!p->p_cred || kread(ctx, (KA_T)p->p_cred, (char *)&cr, sizeof(cr))) continue; uid = cr.cr_uid; if (is_proc_excl(pid, pgid, (UID_ARG)uid, &pss, &sf)) @@ -124,7 +126,7 @@ void gather_proc_info() { * Get the execution information -- for the command name. */ if (!p->p_execinfo || - kread((KA_T)p->p_execinfo, (char *)&ex, sizeof(ex))) + kread(ctx, (KA_T)p->p_execinfo, (char *)&ex, sizeof(ex))) continue; /* * Allocate a local process structure. @@ -172,18 +174,18 @@ void gather_proc_info() { (void)fprintf(stderr, "%s: PID %d; no space for %d file descriptors\n", Pn, pid, nf); - Error(); + Error(ctx); } nfea = nf; } - if (kread((KA_T)p->p_fdtab.fdt_entrytab, (char *)fe, len)) + if (kread(ctx, (KA_T)p->p_fdtab.fdt_entrytab, (char *)fe, len)) continue; for (f = fe, i = 0; i < nf; f++, i++) { if ((fa = (KA_T)f->fd_file) && (f->fd_status & FD_INUSE)) { #if UNIXWAREV >= 70103 if (f->fd_flag & FPOLLED) { - if (kread(fa, (char *)&plx, sizeof(plx)) || + if (kread(ctx, fa, (char *)&plx, sizeof(plx)) || !(fa = (KA_T)plx.px_fp)) continue; } @@ -213,7 +215,7 @@ void gather_proc_info() { * get_clonemaj() - get clone major device number */ -static int get_clonemaj() { +static int get_clonemaj(struct lsof_context *ctx) { KA_T v; #if UNIXWAREV < 70000 @@ -226,18 +228,18 @@ static int get_clonemaj() { * Read the cdevsw[] size and allocate temporary space for it. */ if (get_Nl_value("ncdev", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&sz, sizeof(sz)) || !sz) + kread(ctx, (KA_T)v, (char *)&sz, sizeof(sz)) || !sz) return (rv); len = (MALLOC_S)(sz * sizeof(struct cdevsw)); if (!(cd = (struct cdevsw *)malloc(len))) { (void)fprintf(stderr, "%s: can't allocate %d bytes for cdevsw\n", Pn); - Error(); + Error(ctx); } /* * Read the cdevsw[] from kernel memory. */ if (get_Nl_value("cdev", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)cd, (int)len)) { + kread(ctx, (KA_T)v, (char *)cd, (int)len)) { (void)free((MALLOC_P *)cd); return (rv); } @@ -248,7 +250,7 @@ static int get_clonemaj() { len = sizeof(buf) - 1; buf[len] = '\0'; for (c = cd, i = 0; i < sz; c++, i++) { - if (!c->d_name || kread((KA_T)c->d_name, buf, len) || + if (!c->d_name || kread(ctx, (KA_T)c->d_name, buf, len) || strcmp(buf, "clone") != 0) continue; CloneMaj = i; @@ -263,7 +265,7 @@ static int get_clonemaj() { * clonemajor variable. */ if (get_Nl_value("cmaj", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&CloneMaj, sizeof(CloneMaj))) + kread(ctx, (KA_T)v, (char *)&CloneMaj, sizeof(CloneMaj))) return (0); return ((HaveCloneMaj = 1)); #endif /* UNIXWAREV<70000 */ @@ -273,7 +275,7 @@ static int get_clonemaj() { * get_kernel_access() - get access to kernel memory */ -static void get_kernel_access() { +static void get_kernel_access(struct lsof_context *ctx) { KA_T v; /* * Check kernel version. @@ -292,7 +294,7 @@ static void get_kernel_access() { * See if the non-KMEM memory file is readable. */ if (Memory && !is_readable(Memory, 1)) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -301,7 +303,7 @@ static void get_kernel_access() { if ((Kd = open(Memory ? Memory : KMEM, O_RDONLY, 0)) < 0) { (void)fprintf(stderr, "%s: can't open %s: %s\n", Pn, Memory ? Memory : KMEM, strerror(errno)); - Error(); + Error(ctx); } #if defined(WILLDROPGID) @@ -315,7 +317,7 @@ static void get_kernel_access() { * See if the name list file is readable. */ if (Nmlst && !is_readable(Nmlst, 1)) - Error(); + Error(ctx); #endif /* defined(WILLDROPGID) */ /* @@ -325,17 +327,17 @@ static void get_kernel_access() { if (nlist(Nmlst ? Nmlst : N_UNIX, Nl) < 0) { (void)fprintf(stderr, "%s: can't read kernel name list from %s\n", Pn, Nmlst ? Nmlst : N_UNIX); - Error(); + Error(ctx); } if (get_Nl_value("var", Drive_Nl, &v) < 0 || !v || - kread((KA_T)v, (char *)&Var, sizeof(Var))) { + kread(ctx, (KA_T)v, (char *)&Var, sizeof(Var))) { (void)fprintf(stderr, "%s: can't read system configuration info\n", Pn); - Error(); + Error(ctx); } if (get_Nl_value("proc", Drive_Nl, &Pract) < 0 || !Pract) { (void)fprintf(stderr, "%s: can't find active process chain pointer\n", Pn); - Error(); + Error(ctx); } if (get_Nl_value("sgdnops", Drive_Nl, &Sgdnops) < 0 || !Sgdnops) Sgdnops = (unsigned long)0; @@ -356,19 +358,18 @@ static void get_kernel_access() { * initialize() - perform all initialization */ -void initialize() { +void initialize(struct lsof_context *ctx) { get_kernel_access(); - readfsinfo(); + readfsinfo(struct lsof_context * ctx); } /* * kread() - read from kernel memory */ -int kread(addr, buf, len) -KA_T addr; /* kernel memory address */ -char *buf; /* buffer to receive data */ -READLEN_T len; /* length to read */ +int kread(struct lsof_context *ctx, KA_T addr, /* kernel memory address */ + char *buf, /* buffer to receive data */ + READLEN_T len) /* length to read */ { READLEN_T br; @@ -401,7 +402,7 @@ static void process_text(pa) KA_T pa; /* kernel address space description /* * Get address space description. */ - if (kread(pa, (char *)&as, sizeof(as))) + if (kread(ctx, pa, (char *)&as, sizeof(as))) return; /* * Loop through the segments. The loop should stop when the segment @@ -410,7 +411,7 @@ static void process_text(pa) KA_T pa; /* kernel address space description */ s.s_next = as.a_segs; for (i = j = k = 0; i < MAXSEGS && j < 2 * MAXSEGS; j++) { - if (!s.s_next || kread((KA_T)s.s_next, (char *)&s, sizeof(s))) + if (!s.s_next || kread(ctx, (KA_T)s.s_next, (char *)&s, sizeof(s))) break; fd = (char *)NULL; vp = (KA_T)NULL; @@ -419,7 +420,7 @@ static void process_text(pa) KA_T pa; /* kernel address space description /* * Process a virtual node segment. */ - if (kread((KA_T)s.s_data, (char *)&vn, sizeof(vn))) + if (kread(ctx, (KA_T)s.s_data, (char *)&vn, sizeof(vn))) break; if ((vp = (KA_T)vn.svd_vp)) { if ((vn.svd_flags & SEGVN_PGPROT) || (vn.svd_prot & PROT_EXEC)) @@ -432,7 +433,7 @@ static void process_text(pa) KA_T pa; /* kernel address space description /* * Process a special device segment. */ - if (kread((KA_T)s.s_data, (char *)&dv, sizeof(dv))) + if (kread(ctx, (KA_T)s.s_data, (char *)&dv, sizeof(dv))) break; if ((vp = (KA_T)dv.vp)) fd = "mmap"; @@ -470,33 +471,33 @@ static void process_text(pa) KA_T pa; /* kernel address space description * readfsinfo() - read file system information */ -static void readfsinfo() { +static void readfsinfo(struct lsof_context *ctx) { char buf[FSTYPSZ + 1]; int i, len; if ((Fsinfomax = sysfs(GETNFSTYP)) == -1) { (void)fprintf(stderr, "%s: sysfs(GETNFSTYP) error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } if (Fsinfomax == 0) return; if (!(Fsinfo = (char **)malloc((MALLOC_S)(Fsinfomax * sizeof(char *))))) { (void)fprintf(stderr, "%s: no space for sysfs info\n", Pn); - Error(); + Error(ctx); } for (i = 1; i <= Fsinfomax; i++) { if (sysfs(GETFSTYP, i, buf) == -1) { (void)fprintf(stderr, "%s: sysfs(GETFSTYP) error: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } buf[FSTYPSZ] = '\0'; len = strlen(buf) + 1; if (!(Fsinfo[i - 1] = (char *)malloc((MALLOC_S)len))) { (void)fprintf(stderr, "%s: no space for file system entry %s\n", Pn, buf); - Error(); + Error(ctx); } (void)snpf(Fsinfo[i - 1], len, "%s", buf); } @@ -506,7 +507,7 @@ static void readfsinfo() { * read_proc() - read the process table */ -static void read_proc() { +static void read_proc(struct lsof_context *ctx) { MALLOC_S len; struct proc *p; KA_T pa; @@ -521,14 +522,14 @@ static void read_proc() { if ((Npa = Var.v_proc) < 1) { (void)fprintf(stderr, "%s: bad proc table size: %d\n", Pn, Var.v_proc); - Error(); + Error(ctx); } Npa += PROCINCR; len = (MALLOC_S)(Npa * sizeof(struct proc)); if (!(P = (struct proc *)malloc(len))) { (void)fprintf(stderr, "%s: no space for %d proc structures\n", Pn, Npa); - Error(); + Error(ctx); } } /* @@ -540,7 +541,7 @@ static void read_proc() { * Read the active process chain head. */ pa = (KA_T)NULL; - if (!Pract || kread((KA_T)Pract, (char *)&pa, sizeof(pa)) || !pa) { + if (!Pract || kread(ctx, (KA_T)Pract, (char *)&pa, sizeof(pa)) || !pa) { if (!Fwarn) (void)fprintf( stderr, "%s: active proc chain ptr err; addr=%s, val=%s\n", @@ -564,11 +565,11 @@ static void read_proc() { stderr, "%s: can't realloc %d proc table entries (%d)\n", Pn, Npa, len); - Error(); + Error(ctx); } p = &P[Np]; } - if (kread(pa, (char *)p, sizeof(struct proc))) + if (kread(ctx, pa, (char *)p, sizeof(struct proc))) break; pa = (KA_T)p->p_next; if ((p->p_flag & P_DESTROY) || (p->p_flag & P_GONE) || !p->p_pidp @@ -593,7 +594,7 @@ static void read_proc() { */ if (try >= PROCTRYLM) { (void)fprintf(stderr, "%s: can't read proc table\n", Pn); - Error(); + Error(ctx); } if (Np < Npa && !RptTm) { @@ -604,7 +605,7 @@ static void read_proc() { if (!(P = (struct proc *)realloc((MALLOC_P *)P, len))) { (void)fprintf(stderr, "%s: can't reduce proc table to %d entries\n", Pn, Np); - Error(); + Error(ctx); } Npa = Np; } diff --git a/lib/dialects/uw/dproto.h b/lib/dialects/uw/dproto.h index b7cd2435..cc7b8120 100644 --- a/lib/dialects/uw/dproto.h +++ b/lib/dialects/uw/dproto.h @@ -30,17 +30,17 @@ * 4. This notice may not be removed or altered. */ -_PROTOTYPE(extern int get_max_fd, (void)); -_PROTOTYPE(extern int is_file_named, (char *p, int cd)); -_PROTOTYPE(extern void process_socket, (char *pr, struct queue *q)); -_PROTOTYPE(extern int readbfslino, (struct vnode * v, struct l_ino *i)); -_PROTOTYPE(extern int readcdfslino, (struct vnode * v, struct l_ino *i)); -_PROTOTYPE(extern int readdosfslino, (struct vnode * v, struct l_ino *i)); -_PROTOTYPE(extern int reads5lino, (struct vnode * v, struct l_ino *i)); -_PROTOTYPE(extern int readvxfslino, (struct vnode * v, struct l_ino *i)); -_PROTOTYPE(extern int strcasecmp, (char *s1, char *s2)); -_PROTOTYPE(extern int strncasecmp, (char *s1, char *s2, int n)); +extern int get_max_fd(void); +extern int is_file_named(char *p, int cd); +extern void process_socket(char *pr, struct queue *q); +extern int readbfslino(struct vnode *v, struct l_ino *i); +extern int readcdfslino(struct vnode *v, struct l_ino *i); +extern int readdosfslino(struct vnode *v, struct l_ino *i); +extern int reads5lino(struct vnode *v, struct l_ino *i); +extern int readvxfslino(struct vnode *v, struct l_ino *i); +extern int strcasecmp(char *s1, char *s2); +extern int strncasecmp(char *s1, char *s2, int n); #if UNIXWAREV >= 70101 -_PROTOTYPE(extern int process_unix_sockstr, (struct vnode * v, KA_T na)); +extern int process_unix_sockstr(struct vnode *v, KA_T na); #endif /* UNIXWAREV>=70101 */ diff --git a/lib/dialects/uw/dsock.c b/lib/dialects/uw/dsock.c index 0aa29d70..b309b52f 100644 --- a/lib/dialects/uw/dsock.c +++ b/lib/dialects/uw/dsock.c @@ -41,7 +41,7 @@ static char copyright[] = */ #if UNIXWAREV >= 70101 && UNIXWAREV < 70103 -_PROTOTYPE(static struct sockaddr_un *find_unix_sockaddr_un, (KA_T ka)); +static struct sockaddr_un *find_unix_sockaddr_un(KA_T ka); #endif /* UNIXWAREV>=70101 && UNIXWAREV<70103 */ /* @@ -749,8 +749,9 @@ void print_tcptpi(nl) int nl; /* 1 == '\n' required */ * process_socket() - process socket */ -void process_socket(pr, q) char *pr; /* protocol name */ -struct queue *q; /* queue at end of stream */ +void process_socket(struct lsof_context *ctx, /* context */ + char *pr, /* protocol name */ + struct queue *q) /* queue at end of stream */ { unsigned char *fa = (unsigned char *)NULL; int fp, ipv, lp; @@ -805,7 +806,7 @@ struct queue *q; /* queue at end of stream */ if (q->q_ptr) { enter_dev_ch(print_kptr((KA_T)q->q_ptr, (char *)NULL, 0)); if (tcp || udp) { - if (kread((KA_T)q->q_ptr, (char *)&inp, sizeof(inp))) { + if (kread(ctx, (KA_T)q->q_ptr, (char *)&inp, sizeof(inp))) { (void)snpf(Namech, Namechl, "can't read inpcb from %s", print_kptr((KA_T)q->q_ptr, (char *)NULL, 0)); enter_nm(Namech); @@ -821,7 +822,7 @@ struct queue *q; /* queue at end of stream */ (void)ent_inaddr(la, lp, fa, fp, AF_INET); if (tcp) { if (inp.inp_ppcb && - !kread((KA_T)inp.inp_ppcb, (char *)&t, sizeof(t))) { + !kread(ctx, (KA_T)inp.inp_ppcb, (char *)&t, sizeof(t))) { ts = 1; Lf->lts.type = 0; Lf->lts.state.i = (int)t.t_state; @@ -892,9 +893,9 @@ struct queue *q; /* queue at end of stream */ * process_unix_sockstr() - process a UNIX socket stream, if applicable */ -int process_unix_sockstr(v, na) -struct vnode *v; /* the stream's vnode */ -KA_T na; /* kernel vnode address */ +int process_unix_sockstr(struct lsof_context *ctx, + struct vnode *v, /* the stream's vnode */ + KA_T na) /* kernel vnode address */ { int as; char *ep, tbuf[32], tbuf1[32], *ty; @@ -938,7 +939,7 @@ KA_T na; /* kernel vnode address */ */ if (!(sa = (KA_T)sd.sd_socket)) return (0); - if (kread(sa, (char *)&ss, sizeof(ss))) { + if (kread(ctx, sa, (char *)&ss, sizeof(ss))) { (void)snpf(Namech, Namechl, "vnode at %s; stream head at %s; can't read socket at %s", print_kptr(na, (char *)NULL, 0), @@ -972,7 +973,7 @@ KA_T na; /* kernel vnode address */ if (((as = (KA_T)ss.local_addrsz) > 0) && (ka = (KA_T)ss.local_addr)) { if (as > sizeof(la)) as = (int)sizeof(la); - if (!kread(ka, (char *)&la, as)) { + if (!kread(ctx, ka, (char *)&la, as)) { la.sun_path[up] = '\0'; if (la.sun_path[0]) { las = 1; @@ -996,7 +997,7 @@ KA_T na; /* kernel vnode address */ if (((as = (KA_T)ss.remote_addrsz) > 0) && (ka = (KA_T)ss.remote_addr)) { if (as > sizeof(la)) as = (int)sizeof(ra); - if (!kread(ka, (char *)&ra, as)) { + if (!kread(ctx, ka, (char *)&ra, as)) { ra.sun_path[up] = '\0'; if (ra.sun_path[0]) { ras = 1; diff --git a/lib/dvch.c b/lib/dvch.c index 1e7cfbf5..11f2e4e9 100644 --- a/lib/dvch.c +++ b/lib/dvch.c @@ -91,7 +91,7 @@ static int crctbl[CRC_TBLL]; /* crc partial results table */ # if defined(HAS_STD_CLONE) && HAS_STD_CLONE == 1 # define DCACHE_CLR clr_sect # define DCACHE_CLR_LOCAL 1 -_PROTOTYPE(static void clr_sect, (void)); +static void clr_sect(void); # endif /* defined(HAS_STD_CLONE) && HAS_STD_CLONE==1 */ # endif /* !defined(DCACHE_CLR) */ @@ -100,7 +100,7 @@ _PROTOTYPE(static void clr_sect, (void)); # if defined(HAS_STD_CLONE) && HAS_STD_CLONE == 1 # define DCACHE_CLONE rw_clone_sect # define DCACHE_CLONE_LOCAL 1 -_PROTOTYPE(static int rw_clone_sect, (int m)); +static int rw_clone_sect(int m); # endif /* defined(HAS_STD_CLONE) && HAS_STD_CLONE==1 */ # endif /*!defined(DCACHE_CLONE) */ @@ -109,16 +109,16 @@ _PROTOTYPE(static int rw_clone_sect, (int m)); * alloc_bdcache() - allocate block device cache */ -void alloc_bdcache() { +void alloc_bdcache(struct lsof_context *ctx) { if (!(BDevtp = (struct l_dev *)calloc((MALLOC_S)BNdev, sizeof(struct l_dev)))) { (void)fprintf(stderr, "%s: no space for block devices\n", Pn); - Error(); + Error(ctx); } if (!(BSdev = (struct l_dev **)malloc( (MALLOC_S)(sizeof(struct l_dev *) * BNdev)))) { (void)fprintf(stderr, "%s: no space for block device pointers\n", Pn); - Error(); + Error(ctx); } } # endif /* defined(HASBLKDEV) */ @@ -127,16 +127,16 @@ void alloc_bdcache() { * alloc_dcache() - allocate device cache */ -void alloc_dcache() { +void alloc_dcache(struct lsof_context *ctx) { if (!(Devtp = (struct l_dev *)calloc((MALLOC_S)Ndev, sizeof(struct l_dev)))) { (void)fprintf(stderr, "%s: no space for devices\n", Pn); - Error(); + Error(ctx); } if (!(Sdev = (struct l_dev **)malloc( (MALLOC_S)(sizeof(struct l_dev *) * Ndev)))) { (void)fprintf(stderr, "%s: no space for device pointers\n", Pn); - Error(); + Error(ctx); } } @@ -144,7 +144,7 @@ void alloc_dcache() { * clr_devtab() - clear the device tables and free their space */ -void clr_devtab() { +void clr_devtab(struct lsof_context *ctx) { int i; if (Devtp) { @@ -204,9 +204,9 @@ static void clr_sect() { * crc(b, l, s) - compute a crc for a block of bytes */ -void crc(b, l, s) char *b; /* block address */ -int l; /* length */ -unsigned *s; /* sum */ +void crc(char *b, /* block address */ + int l, /* length */ + unsigned *s) /* sum */ { char *cp; /* character pointer */ char *lm; /* character limit pointer */ @@ -248,10 +248,9 @@ void crcbld() { * dcpath() - define device cache file paths */ -int dcpath(rw, npw) -int rw; /* read (1) or write (2) mode */ -int npw; /* inhibit (0) or enable (1) no - * path warning message */ +int dcpath(struct lsof_context *ctx, int rw, /* read (1) or write (2) mode */ + int npw) /* inhibit (0) or enable (1) no + * path warning message */ { char buf[MAXPATHLEN + 1], *cp1, *cp2, hn[MAXPATHLEN + 1]; int endf; @@ -575,7 +574,7 @@ int npw; /* inhibit (0) or enable (1) no * will have been issued to stderr. */ if (merr) - Error(); + Error(ctx); /* * Return the index of the first defined path. Since DCpath[] is arranged * in priority order, searching it beginning to end follows priority. @@ -595,10 +594,9 @@ int npw; /* inhibit (0) or enable (1) no * open_dcache() - open device cache file */ -int open_dcache(m, r, s) -int m; /* mode: 1 = read; 2 = write */ -int r; /* create DCpath[] if 0, reuse if 1 */ -struct stat *s; /* stat() receiver */ +int open_dcache(struct lsof_context *ctx, int m, /* mode: 1 = read; 2 = write */ + int r, /* create DCpath[] if 0, reuse if 1 */ + struct stat *s) /* stat() receiver */ { char buf[128]; char *w = (char *)NULL; @@ -606,7 +604,7 @@ struct stat *s; /* stat() receiver */ * Get the device cache file paths. */ if (!r) { - if ((DCpathX = dcpath(m, 1)) < 0) + if ((DCpathX = dcpath(ctx, m, 1)) < 0) return (1); } /* @@ -715,7 +713,7 @@ struct stat *s; /* stat() receiver */ * Oops! */ (void)fprintf(stderr, "%s: internal error: open_dcache=%d\n", Pn, m); - Error(); + Error(ctx); } return (1); } @@ -724,7 +722,7 @@ struct stat *s; /* stat() receiver */ * read_dcache() - read device cache file */ -int read_dcache() { +int read_dcache(struct lsof_context *ctx) { char buf[MAXPATHLEN * 2], cbuf[64], *cp; int i, len, ov; struct stat sb, devsb; @@ -735,11 +733,11 @@ int read_dcache() { * the real UID of this process is not zero, try to open a device cache * file at HASPERSDC. */ - if ((ov = open_dcache(1, 0, &sb)) != 0) { + if ((ov = open_dcache(ctx, 1, 0, &sb)) != 0) { if (DCpathX == 2) { if (ov == 2 && DCpath[3]) { DCpathX = 3; - if (open_dcache(1, 1, &sb) != 0) + if (open_dcache(ctx, 1, 1, &sb) != 0) return (1); } else return (1); @@ -780,10 +778,10 @@ int read_dcache() { (void)fclose(DCfs); DCfd = -1; DCfs = (FILE *)NULL; - (void)clr_devtab(); + (void)clr_devtab(ctx); # if defined(DCACHE_CLR) - (void)DCACHE_CLR(); + (void)DCACHE_CLR(ctx); # endif /* defined(DCACHE_CLR) */ return (1); @@ -852,7 +850,7 @@ int read_dcache() { */ if ((Ndev = atoi(&buf[len])) < 1) goto read_dhdr; - alloc_dcache(); + alloc_dcache(ctx); /* * Read the device lines and store their information in Devtp[]. * Construct the Sdev[] pointers to Devtp[]. @@ -913,7 +911,7 @@ int read_dcache() { (void)fprintf(stderr, "%s: device %d: no space for path: line ", Pn, i + 1); safestrprt(buf, stderr, 1 + 4 + 8); - Error(); + Error(ctx); } Devtp[i].v = 0; Sdev[i] = &Devtp[i]; @@ -941,7 +939,7 @@ int read_dcache() { * Compute the block device count; allocate BSdev[] and BDevtp[] space. */ if ((BNdev = atoi(&buf[len])) > 0) { - alloc_bdcache(); + alloc_bdcache(ctx); /* * Read the block device lines and store their information in BDevtp[]. * Construct the BSdev[] pointers to BDevtp[]. @@ -1006,7 +1004,7 @@ int read_dcache() { "%s: block dev %d: no space for path: line", Pn, i + 1); safestrprt(buf, stderr, 1 + 4 + 8); - Error(); + Error(ctx); } BDevtp[i].v = 0; BSdev[i] = &BDevtp[i]; @@ -1018,7 +1016,7 @@ int read_dcache() { /* * Read the clone section. */ - if (DCACHE_CLONE(1)) + if (DCACHE_CLONE(ctx, 1)) goto read_close; # endif /* defined(DCACHE_CLONE) */ @@ -1026,7 +1024,7 @@ int read_dcache() { /* * Read the pseudo section. */ - if (DCACHE_PSEUDO(1)) + if (DCACHE_PSEUDO(ctx, 1)) goto read_close; # endif /* defined(DCACHE_PSEUDO) */ @@ -1084,8 +1082,8 @@ int read_dcache() { * rw_clone_sect() - read/write the device cache file clone section */ -static int rw_clone_sect(m) -int m; /* mode: 1 = read; 2 = write */ +static int rw_clone_sect(struct lsof_context *ctx, + int m) /* mode: 1 = read; 2 = write */ { char buf[MAXPATHLEN * 2], *cp, *cp1; struct clone *c; @@ -1157,7 +1155,7 @@ int m; /* mode: 1 = read; 2 = write */ "%s: clone %d: no space for cached clone: line ", Pn, i + 1); safestrprt(buf, stderr, 1 + 4 + 8); - Error(); + Error(ctx); } c->dx = j; c->next = Clone; @@ -1203,7 +1201,7 @@ int m; /* mode: 1 = read; 2 = write */ * A shouldn't-happen case: mode neither 1 nor 2. */ (void)fprintf(stderr, "%s: internal rw_clone_sect error: %d\n", Pn, m); - Error(); + Error(ctx); return (1); /* This useless return(1) keeps some * compilers happy. */ } @@ -1213,7 +1211,7 @@ int m; /* mode: 1 = read; 2 = write */ * write_dcache() - write device cache file */ -void write_dcache() { +void write_dcache(struct lsof_context *ctx) { char buf[MAXPATHLEN * 2], *cp; struct l_dev *dp; int i; @@ -1221,7 +1219,7 @@ void write_dcache() { /* * Open the cache file; set up the CRC table; write the section count. */ - if (open_dcache(2, 0, &sb)) + if (open_dcache(ctx, 2, 0, &sb)) return; i = 1; cp = ""; @@ -1283,7 +1281,7 @@ void write_dcache() { /* * Write the clone section. */ - if (DCACHE_CLONE(2)) + if (DCACHE_CLONE(ctx, 2)) return; # endif /* defined(DCACHE_CLONE) */ @@ -1291,7 +1289,7 @@ void write_dcache() { /* * Write the pseudo section. */ - if (DCACHE_PSEUDO(2)) + if (DCACHE_PSEUDO(ctx, 2)) return; # endif /* defined(DCACHE_PSEUDO) */ @@ -1324,9 +1322,8 @@ void write_dcache() { * wr2DCfd() - write to the DCfd file descriptor */ -int wr2DCfd(b, c) -char *b; /* buffer */ -unsigned *c; /* checksum receiver */ +int wr2DCfd(char *b, /* buffer */ + unsigned *c) /* checksum receiver */ { int bl, bw; diff --git a/lib/fino.c b/lib/fino.c index de2fc912..693fba38 100644 --- a/lib/fino.c +++ b/lib/fino.c @@ -51,11 +51,11 @@ char *fino_d2 = fino_d1; * find_bl_ino() - find the inode number for a block device file */ -void find_bl_ino() { +void find_bl_ino(struct lsof_context *ctx) { dev_t ldev, tdev; int low, hi, mid; - readdev(0); + readdev(ctx, 0); # if defined(HASDCACHE) find_bl_ino_again: @@ -76,7 +76,7 @@ void find_bl_ino() { else { # if defined(HASDCACHE) - if (DCunsafe && !BSdev[mid]->v && !vfy_dev(BSdev[mid])) + if (DCunsafe && !BSdev[mid]->v && !vfy_dev(ctx, BSdev[mid])) goto find_bl_ino_again; # endif /* defined(HASDCACHE) */ @@ -94,11 +94,11 @@ void find_bl_ino() { * find_ch_ino() - find the inode number for a character device file */ -void find_ch_ino() { +void find_ch_ino(struct lsof_context *ctx) { dev_t ldev, tdev; int low, hi, mid; - readdev(0); + readdev(ctx, 0); # if defined(HASDCACHE) find_ch_ino_again: @@ -119,7 +119,7 @@ void find_ch_ino() { else { # if defined(HASDCACHE) - if (DCunsafe && !Sdev[mid]->v && !vfy_dev(Sdev[mid])) + if (DCunsafe && !Sdev[mid]->v && !vfy_dev(ctx, Sdev[mid])) goto find_ch_ino_again; # endif /* defined(HASDCACHE) */ diff --git a/lib/isfn.c b/lib/isfn.c index 2760aab8..2dc2c3a2 100644 --- a/lib/isfn.c +++ b/lib/isfn.c @@ -131,7 +131,7 @@ static int HbyNmCt = 0; /* HbyNm entry count */ * hashSfile() - hash Sfile entries for use in is_file_named() searches */ -void hashSfile() { +void hashSfile(struct lsof_context *ctx) { static int hs = 0; int i; int sfplm = 3; @@ -155,7 +155,7 @@ void hashSfile() { (void)fprintf( stderr, "%s: can't allocate space for %d clone hash buckets\n", Pn, SFCDHASH); - Error(); + Error(ctx); } sfplm++; } @@ -166,28 +166,28 @@ void hashSfile() { (void)fprintf( stderr, "%s: can't allocate space for %d (dev,ino) hash buckets\n", Pn, SFDIHASH); - Error(); + Error(ctx); } if (!(HbyFrd = (struct hsfile *)calloc((MALLOC_S)SFRDHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d rdev hash buckets\n", Pn, SFRDHASH); - Error(); + Error(ctx); } if (!(HbyFsd = (struct hsfile *)calloc((MALLOC_S)SFFSHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d file sys hash buckets\n", Pn, SFFSHASH); - Error(); + Error(ctx); } if (!(HbyNm = (struct hsfile *)calloc((MALLOC_S)SFNMHASH, sizeof(struct hsfile)))) { (void)fprintf(stderr, "%s: can't allocate space for %d name hash buckets\n", Pn, SFNMHASH); - Error(); + Error(ctx); } hs++; /* @@ -245,7 +245,7 @@ void hashSfile() { (void)fprintf(stderr, "%s: can't allocate hsfile bucket for: %s\n", Pn, s->aname); - Error(); + Error(ctx); } sn->s = s; sn->next = sh->next; @@ -259,12 +259,12 @@ void hashSfile() { * is_file_named() - is this file named? */ -int is_file_named(p, cd) -char *p; /* path name; NULL = search by device - * and inode (from *Lf) */ -int cd; /* character or block type file -- - * VCHR or VBLK vnode, or S_IFCHR - * or S_IFBLK inode */ +int is_file_named(struct lsof_context *ctx, + char *p, /* path name; NULL = search by device + * and inode (from *Lf) */ + int cd) /* character or block type file -- + * VCHR or VBLK vnode, or S_IFCHR + * or S_IFBLK inode */ { char *ep; int f = 0; @@ -359,7 +359,7 @@ int cd; /* character or block type file -- */ (void)snpf(Namech, Namechl, "%s", s->name); if (s->devnm) { - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, " (%s)", s->devnm); } } diff --git a/lib/lkud.c b/lib/lkud.c index a60c3c77..221b7046 100644 --- a/lib/lkud.c +++ b/lib/lkud.c @@ -51,14 +51,14 @@ char *lkud_d2 = lkud_d1; * lkupbdev() - look up a block device */ -struct l_dev *lkupbdev(dev, rdev, i, r) -dev_t *dev; /* pointer to device number */ -dev_t *rdev; /* pointer to raw device number */ -int i; /* inode match status */ -int r; /* if 1, rebuild the device cache with - * rereaddev() when no match is found - * and HASDCACHE is defined and - * DCunsafe is one */ +struct l_dev *lkupbdev(struct lsof_context *ctx, + dev_t *dev, /* pointer to device number */ + dev_t *rdev, /* pointer to raw device number */ + int i, /* inode match status */ + int r) /* if 1, rebuild the device cache with + * rereaddev() when no match is found + * and HASDCACHE is defined and + * DCunsafe is one */ { INODETYPE inode = (INODETYPE)0; int low, hi, mid; @@ -67,7 +67,7 @@ int r; /* if 1, rebuild the device cache with if (*dev != DevDev) return ((struct l_dev *)NULL); - readdev(0); + readdev(ctx, 0); if (i) { inode = Lf->inode; ty = Lf->inp_ty; @@ -95,7 +95,7 @@ int r; /* if 1, rebuild the device cache with if ((i == 0) || (ty != 1) || (inode == dp->inode)) { # if defined(HASDCACHE) - if (DCunsafe && !dp->v && !vfy_dev(dp)) + if (DCunsafe && !dp->v && !vfy_dev(ctx, dp)) goto lkupbdev_again; # endif /* defined(HASDCACHE) */ @@ -110,7 +110,7 @@ int r; /* if 1, rebuild the device cache with # if defined(HASDCACHE) if (DCunsafe && r) { - (void)rereaddev(); + (void)rereaddev(ctx); goto lkupbdev_again; } # endif /* defined(HASDCACHE) */ @@ -124,14 +124,14 @@ int r; /* if 1, rebuild the device cache with * lkupdev() - look up a character device */ -struct l_dev *lkupdev(dev, rdev, i, r) -dev_t *dev; /* pointer to device number */ -dev_t *rdev; /* pointer to raw device number */ -int i; /* inode match status */ -int r; /* if 1, rebuild the device cache with - * rereaddev() when no match is found - * and HASDCACHE is defined and - * DCunsafe is one */ +struct l_dev *lkupdev(struct lsof_context *ctx, + dev_t *dev, /* pointer to device number */ + dev_t *rdev, /* pointer to raw device number */ + int i, /* inode match status */ + int r) /* if 1, rebuild the device cache with + * rereaddev() when no match is found + * and HASDCACHE is defined and + * DCunsafe is one */ { INODETYPE inode = (INODETYPE)0; int low, hi, mid; @@ -140,7 +140,7 @@ int r; /* if 1, rebuild the device cache with if (*dev != DevDev) return ((struct l_dev *)NULL); - readdev(0); + readdev(ctx, 0); if (i) { inode = Lf->inode; ty = Lf->inp_ty; @@ -168,7 +168,7 @@ int r; /* if 1, rebuild the device cache with if ((i == 0) || (ty != 1) || (inode == dp->inode)) { # if defined(HASDCACHE) - if (DCunsafe && !dp->v && !vfy_dev(dp)) + if (DCunsafe && !dp->v && !vfy_dev(ctx, dp)) goto lkupdev_again; # endif /* defined(HASDCACHE) */ @@ -183,7 +183,7 @@ int r; /* if 1, rebuild the device cache with # if defined(HASDCACHE) if (DCunsafe && r) { - (void)rereaddev(); + (void)rereaddev(ctx); goto lkupdev_again; } # endif /* defined(HASDCACHE) */ diff --git a/lib/misc.c b/lib/misc.c index b178f042..e7ad9f25 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -29,6 +29,7 @@ */ #include "common.h" +#include "dlsof.h" #if defined(HASWIDECHAR) # if defined(WIDECHARINCL) @@ -51,16 +52,17 @@ * Local function prototypes */ -_PROTOTYPE(static void closePipes, (void)); -_PROTOTYPE(static int dolstat, (char *path, char *buf, int len)); -_PROTOTYPE(static int dostat, (char *path, char *buf, int len)); -_PROTOTYPE(static int doreadlink, (char *path, char *buf, int len)); -_PROTOTYPE(static int doinchild, (int (*fn)(), char *fp, char *rbuf, int rbln)); +static void closePipes(void); +static int dolstat(char *path, char *buf, int len); +static int dostat(char *path, char *buf, int len); +static int doreadlink(char *path, char *buf, int len); +static int doinchild(struct lsof_context *ctx, int (*fn)(), char *fp, + char *rbuf, int rbln); #if defined(HASINTSIGNAL) -_PROTOTYPE(static int handleint, (int sig)); +static int handleint(int sig); #else /* !defined(HASINTSIGNAL) */ -_PROTOTYPE(static void handleint, (int sig)); +static void handleint(int sig); #endif /* defined(HASINTSIGNAL) */ /* @@ -86,7 +88,8 @@ static int CtSigs[] = {0, SIGINT, SIGKILL}; static struct drive_Nl *Build_Nl = (struct drive_Nl *)NULL; /* the default Drive_Nl address */ -void build_Nl(d) struct drive_Nl *d; /* data to drive the construction */ +void build_Nl(struct lsof_context *ctx, + struct drive_Nl *d) /* data to drive the construction */ { struct drive_Nl *dp; int i, n; @@ -96,7 +99,7 @@ void build_Nl(d) struct drive_Nl *d; /* data to drive the construction */ if (n < 1) { (void)fprintf(stderr, "%s: can't calculate kernel name list length\n", Pn); - Error(); + Error(ctx); } if (!(Nl = (struct NLIST_TYPE *)calloc((n + 1), sizeof(struct NLIST_TYPE)))) { @@ -104,7 +107,7 @@ void build_Nl(d) struct drive_Nl *d; /* data to drive the construction */ stderr, "%s: can't allocate %d bytes to kernel name list structure\n", Pn, (int)((n + 1) * sizeof(struct NLIST_TYPE))); - Error(); + Error(ctx); } for (dp = d, i = 0; i < n; dp++, i++) { Nl[i].NL_NAME = dp->knm; @@ -118,7 +121,7 @@ void build_Nl(d) struct drive_Nl *d; /* data to drive the construction */ * childx() - make child process exit (if possible) */ -void childx() { +void childx(struct lsof_context *ctx) { static int at, sx; pid_t wpid; @@ -196,9 +199,7 @@ static void closePipes() { * compdev() - compare Devtp[] entries */ -int compdev(a1, a2) -COMP_P *a1, *a2; -{ +int compdev(COMP_P *a1, COMP_P *a2) { struct l_dev **p1 = (struct l_dev **)a1; struct l_dev **p2 = (struct l_dev **)a2; @@ -236,10 +237,11 @@ void closefrom_shim(int low) { * doinchild() -- do a function in a child process */ -static int doinchild(fn, fp, rbuf, rbln) int (*fn)(); /* function to perform */ -char *fp; /* function parameter */ -char *rbuf; /* response buffer */ -int rbln; /* response buffer length */ +static int doinchild(struct lsof_context *ctx, + int (*fn)(), /* function to perform */ + char *fp, /* function parameter */ + char *rbuf, /* response buffer */ + int rbln) /* response buffer length */ { int en, rv; @@ -250,7 +252,7 @@ int rbln; /* response buffer length */ (void)fprintf(stderr, "%s: doinchild error; response buffer too large: %d\n", Pn, rbln); - Error(); + Error(ctx); } /* * Set up to handle an alarm signal; handle an alarm signal; build @@ -265,7 +267,7 @@ int rbln; /* response buffer length */ */ (void)alarm(0); (void)signal(SIGALRM, SIG_DFL); - (void)childx(); + (void)childx(ctx); errno = ETIMEDOUT; return (1); } else if (!Cpid) { @@ -277,7 +279,7 @@ int rbln; /* response buffer length */ if (pipe(Pipes) < 0 || pipe(&Pipes[2]) < 0) { (void)fprintf(stderr, "%s: can't open pipes: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } /* * Fork a child to execute functions. @@ -312,7 +314,7 @@ int rbln; /* response buffer length */ (void)fprintf(stderr, "%s: can't dup Pipes[0] to fd 0: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } Pipes[0] = 0; rc = dup2(Pipes[3], 1); @@ -320,7 +322,7 @@ int rbln; /* response buffer length */ (void)fprintf(stderr, "%s: can't dup Pipes.[3] to fd 1: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } Pipes[3] = 1; (void)closefrom_shim(2); @@ -381,7 +383,7 @@ int rbln; /* response buffer length */ if (Cpid < 0) { (void)fprintf(stderr, "%s: can't fork: %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } (void)close(Pipes[0]); (void)close(Pipes[3]); @@ -406,7 +408,7 @@ int rbln; /* response buffer length */ read(Pipes[2], rbuf, rbln) != rbln) { (void)alarm(0); (void)signal(SIGALRM, SIG_DFL); - (void)childx(); + (void)childx(ctx); errno = ECHILD; return (-1); } @@ -433,49 +435,52 @@ int rbln; /* response buffer length */ * dolstat() - do an lstat() function */ -static int dolstat(path, rbuf, rbln) -char *path; /* path */ -char *rbuf; /* response buffer */ -int rbln; /* response buffer length */ +static int dolstat(char *path, /* path */ + char *rbuf, /* response buffer */ + int rbln) /* response buffer length */ /* ARGSUSED */ -{ return (lstat(path, (struct stat *)rbuf)); } +{ + return (lstat(path, (struct stat *)rbuf)); +} /* * doreadlink() -- do a readlink() function */ -static int doreadlink(path, rbuf, rbln) -char *path; /* path */ -char *rbuf; /* response buffer */ -int rbln; /* response buffer length */ -{ return (readlink(path, rbuf, rbln)); } +static int doreadlink(char *path, /* path */ + char *rbuf, /* response buffer */ + int rbln) /* response buffer length */ +{ + return (readlink(path, rbuf, rbln)); +} /* * dostat() - do a stat() function */ -static int dostat(path, rbuf, rbln) -char *path; /* path */ -char *rbuf; /* response buffer */ -int rbln; /* response buffer length */ +static int dostat(char *path, /* path */ + char *rbuf, /* response buffer */ + int rbln) /* response buffer length */ /* ARGSUSED */ -{ return (stat(path, (struct stat *)rbuf)); } +{ + return (stat(path, (struct stat *)rbuf)); +} #if defined(WILLDROPGID) /* * dropgid() - drop setgid permission */ -void dropgid() { +void dropgid(struct lsof_context *ctx) { if (!Setuidroot && Setgid) { if (setgid(Mygid) < 0) { (void)fprintf(stderr, "%s: can't setgid(%d): %s\n", Pn, (int)Mygid, strerror(errno)); - Error(); + Error(ctx); } Setgid = 0; } @@ -486,8 +491,7 @@ void dropgid() { * enter_dev_ch() - enter device characters in file structure */ -void enter_dev_ch(m) char *m; -{ +void enter_dev_ch(struct lsof_context *ctx, char *m) { char *mp; if (!m || *m == '\0') @@ -496,7 +500,7 @@ void enter_dev_ch(m) char *m; (void)fprintf(stderr, "%s: no more dev_ch space at PID %d: \n", Pn, Lp->pid); safestrprt(m, stderr, 1); - Error(); + Error(ctx); } if (Lf->dev_ch) (void)free((FREE_P *)Lf->dev_ch); @@ -507,9 +511,9 @@ void enter_dev_ch(m) char *m; * enter_IPstate() -- enter a TCP or UDP state */ -void enter_IPstate(ty, nm, nr) char *ty; /* type -- TCP or UDP */ -char *nm; /* state name (may be NULL) */ -int nr; /* state number */ +void enter_IPstate(struct lsof_context *ctx, char *ty, /* type -- TCP or UDP */ + char *nm, /* state name (may be NULL) */ + int nr) /* state number */ { #if defined(USE_LIB_PRINT_TCPTPI) @@ -524,7 +528,7 @@ int nr; /* state number */ */ if (!ty) { (void)fprintf(stderr, "%s: no type specified to enter_IPstate()\n", Pn); - Error(); + Error(ctx); } if (!strcmp(ty, "TCP")) tx = 0; @@ -533,7 +537,7 @@ int nr; /* state number */ else { (void)fprintf(stderr, "%s: unknown type for enter_IPstate: %s\n", Pn, ty); - Error(); + Error(ctx); } /* * If the name argument is NULL, reduce the allocated table to its minimum @@ -550,7 +554,7 @@ int nr; /* state number */ len = (MALLOC_S)(UdpNstates * sizeof(char *)); if (!(UdpSt = (char **)realloc((MALLOC_P *)UdpSt, len))) { (void)fprintf(stderr, "%s: can't reduce UdpSt[]\n", Pn); - Error(); + Error(ctx); } } UdpStAlloc = UdpNstates; @@ -565,7 +569,7 @@ int nr; /* state number */ len = (MALLOC_S)(TcpNstates * sizeof(char *)); if (!(TcpSt = (char **)realloc((MALLOC_P *)TcpSt, len))) { (void)fprintf(stderr, "%s: can't reduce TcpSt[]\n", Pn); - Error(); + Error(ctx); } } TcpStAlloc = TcpNstates; @@ -579,7 +583,7 @@ int nr; /* state number */ if (strlen(nm) < 1) { (void)fprintf(stderr, "%s: bad %s name (\"%s\"), number=%d\n", Pn, ty, nm, nr); - Error(); + Error(ctx); } /* * Make a copy of the name. @@ -587,7 +591,7 @@ int nr; /* state number */ if (!(cp = mkstrcpy(nm, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: enter_IPstate(): no %s space for %s\n", Pn, ty, nm); - Error(); + Error(ctx); } /* * Set the necessary offset for using nr as an index. If it is @@ -664,7 +668,7 @@ int nr; /* state number */ no_IP_space: (void)fprintf(stderr, "%s: no %s state space\n", Pn, ty); - Error(); + Error(ctx); } UdpNstates = nn; UdpStAlloc = al; @@ -702,7 +706,7 @@ int nr; /* state number */ (void)fprintf( stderr, "%s: duplicate %s state %d (already %s): %s\n", Pn, ty, nr, tx ? UdpSt[nr + UdpStOff] : TcpSt[nr + TcpStOff], nm); - Error(); + Error(ctx); } UdpSt[nr + UdpStOff] = cp; } else { @@ -717,8 +721,7 @@ int nr; /* state number */ * enter_nm() - enter name in local file structure */ -void enter_nm(m) char *m; -{ +void enter_nm(struct lsof_context *ctx, char *m) { char *mp; if (!m || *m == '\0') @@ -727,7 +730,7 @@ void enter_nm(m) char *m; (void)fprintf(stderr, "%s: no more nm space at PID %d for: ", Pn, Lp->pid); safestrprt(m, stderr, 1); - Error(); + Error(ctx); } if (Lf->nm) (void)free((FREE_P *)Lf->nm); @@ -738,9 +741,9 @@ void enter_nm(m) char *m; * Exit() - do a clean exit() */ -void Exit(xv) enum ExitStatus xv; /* exit() value */ +void Exit(struct lsof_context *ctx, enum ExitStatus xv) /* exit() value */ { - (void)childx(); + (void)childx(ctx); #if defined(HASDCACHE) if (DCrebuilt && !Fwarn) @@ -754,19 +757,18 @@ void Exit(xv) enum ExitStatus xv; /* exit() value */ /* * Error() - exit with an error status */ -void Error(void) { Exit(LSOF_ERROR); } +void Error(struct lsof_context *ctx) { Exit(ctx, LSOF_ERROR); } #if defined(HASNLIST) /* * get_Nl_value() - get Nl value for nickname */ -int get_Nl_value(nn, d, v) -char *nn; /* nickname of requested entry */ -struct drive_Nl *d; /* drive_Nl table that built Nl - * (if NULL, use Build_Nl) */ -KA_T *v; /* returned value (if NULL, - * return nothing) */ +int get_Nl_value(char *nn, /* nickname of requested entry */ + struct drive_Nl *d, /* drive_Nl table that built Nl + * (if NULL, use Build_Nl) */ + KA_T *v) /* returned value (if NULL, + * return nothing) */ { int i; @@ -797,17 +799,16 @@ static void /* ARGSUSED */ -handleint(sig) -int sig; -{ longjmp(Jmp_buf, 1); } +handleint(int sig) { + longjmp(Jmp_buf, 1); +} /* * hashbyname() - hash by name */ -int hashbyname(nm, mod) -char *nm; /* pointer to NUL-terminated name */ -int mod; /* hash modulus */ +int hashbyname(char *nm, /* pointer to NUL-terminated name */ + int mod) /* hash modulus */ { int i, j; @@ -823,11 +824,10 @@ int mod; /* hash modulus */ * is_nw_addr() - is this network address selected? */ -int is_nw_addr(ia, p, af) -unsigned char *ia; /* Internet address */ -int p; /* port */ -int af; /* address family -- e.g., AF_INET, - * AF_INET6 */ +int is_nw_addr(unsigned char *ia, /* Internet address */ + int p, /* port */ + int af) /* address family -- e.g., AF_INET, + * AF_INET6 */ { struct nwad *n; @@ -887,11 +887,10 @@ int af; /* address family -- e.g., AF_INET, * copy length (optional) */ -char *mkstrcpy(src, rlp) -char *src; /* source */ -MALLOC_S *rlp; /* returned length pointer (optional) - * The returned length is an strlen() - * equivalent */ +char *mkstrcpy(char *src, /* source */ + MALLOC_S *rlp) /* returned length pointer (optional) + * The returned length is an strlen() + * equivalent */ { MALLOC_S len; char *ns; @@ -917,15 +916,14 @@ MALLOC_S *rlp; /* returned length pointer (optional) * copy string length (optional) */ -char *mkstrcat(s1, l1, s2, l2, s3, l3, clp) -char *s1; /* source string 1 */ -int l1; /* length of string 1 (-1 if none) */ -char *s2; /* source string 2 */ -int l2; /* length of string 2 (-1 if none) */ -char *s3; /* source string 3 (optional) */ -int l3; /* length of string 3 (-1 if none) */ -MALLOC_S *clp; /* pointer to return of copy length - * (optional) */ +char *mkstrcat(char *s1, /* source string 1 */ + int l1, /* length of string 1 (-1 if none) */ + char *s2, /* source string 2 */ + int l2, /* length of string 2 (-1 if none) */ + char *s3, /* source string 3 (optional) */ + int l3, /* length of string 3 (-1 if none) */ + MALLOC_S *clp) /* pointer to return of copy length + * (optional) */ { MALLOC_S cl, len1, len2, len3; char *cp; @@ -969,9 +967,8 @@ MALLOC_S *clp; /* pointer to return of copy length * is_readable() -- is file readable */ -int is_readable(path, msg) -char *path; /* file path */ -int msg; /* issue warning message if 1 */ +int is_readable(char *path, /* file path */ + int msg) /* issue warning message if 1 */ { if (access(path, R_OK) < 0) { if (!Fwarn && msg == 1) @@ -985,9 +982,8 @@ int msg; /* issue warning message if 1 */ * lstatsafely() - lstat path safely (i. e., with timeout) */ -int lstatsafely(path, buf) -char *path; /* file path */ -struct stat *buf; /* stat buffer address */ +int lstatsafely(struct lsof_context *ctx, char *path, /* file path */ + struct stat *buf) /* stat buffer address */ { if (Fblock) { if (!Fwarn) @@ -996,15 +992,15 @@ struct stat *buf; /* stat buffer address */ errno = EWOULDBLOCK; return (1); } - return (doinchild(dolstat, path, (char *)buf, sizeof(struct stat))); + return (doinchild(ctx, dolstat, path, (char *)buf, sizeof(struct stat))); } /* * Readlink() - read and interpret file system symbolic links */ -char *Readlink(arg) -char *arg; /* argument to be interpreted */ +char *Readlink(struct lsof_context *ctx, + char *arg) /* argument to be interpreted */ { char abuf[MAXPATHLEN + 1]; int alen; @@ -1056,7 +1052,8 @@ char *arg; /* argument to be interpreted */ /* * Dereference a symbolic link. */ - if ((llen = doinchild(doreadlink, tbuf, lbuf, sizeof(lbuf) - 1)) >= 0) { + if ((llen = doinchild(ctx, doreadlink, tbuf, lbuf, sizeof(lbuf) - 1)) >= + 0) { /* * If the link is a new absolute path, replace @@ -1143,7 +1140,7 @@ char *arg; /* argument to be interpreted */ (void)fprintf(stderr, "%s: no Readlink string space for ", Pn); safestrprt(abuf, stderr, 1); - Error(); + Error(ctx); } if (sx >= MAXSYMLINKS) { @@ -1181,7 +1178,7 @@ char *arg; /* argument to be interpreted */ ss = sx; } stk[sx - 1] = s1; - return (Readlink(s1)); + return (Readlink(ctx, s1)); } #if defined(HASSTREAMS) @@ -1189,11 +1186,11 @@ char *arg; /* argument to be interpreted */ * readstdata() - read stream's stdata structure */ -int readstdata(addr, buf) -KA_T addr; /* stdata address in kernel*/ -struct stdata *buf; /* buffer addess */ +int readstdata(struct lsof_context *ctx, /* context */ + KA_T addr, /* stdata address in kernel*/ + struct stdata *buf) /* buffer addess */ { - if (!addr || kread(addr, (char *)buf, sizeof(struct stdata))) { + if (!addr || kread(ctx, addr, (char *)buf, sizeof(struct stdata))) { (void)snpf(Namech, Namechl, "no stream data in %s", print_kptr(addr, (char *)NULL, 0)); return (1); @@ -1205,9 +1202,9 @@ struct stdata *buf; /* buffer addess */ * readsthead() - read stream head */ -int readsthead(addr, buf) -KA_T addr; /* starting queue pointer in kernel */ -struct queue *buf; /* buffer for queue head */ +int readsthead(struct lsof_context *ctx, /* context */ + KA_T addr, /* starting queue pointer in kernel */ + struct queue *buf) /* buffer for queue head */ { KA_T qp; @@ -1216,7 +1213,7 @@ struct queue *buf; /* buffer for queue head */ return (1); } for (qp = addr; qp; qp = (KA_T)buf->q_next) { - if (kread(qp, (char *)buf, sizeof(struct queue))) { + if (kread(ctx, qp, (char *)buf, sizeof(struct queue))) { (void)snpf(Namech, Namechl, "bad stream queue link at %s", print_kptr(qp, (char *)NULL, 0)); return (1); @@ -1229,12 +1226,12 @@ struct queue *buf; /* buffer for queue head */ * readstidnm() - read stream module ID name */ -int readstidnm(addr, buf, len) -KA_T addr; /* module ID name address in kernel */ -char *buf; /* receiving buffer address */ -READLEN_T len; /* buffer length */ +int readstidnm(struct lsof_context *ctx, /* context */ + KA_T addr, /* module ID name address in kernel */ + char *buf, /* receiving buffer address */ + READLEN_T len) /* buffer length */ { - if (!addr || kread(addr, buf, len)) { + if (!addr || kread(ctx, addr, buf, len)) { (void)snpf(Namech, Namechl, "can't read module ID name from %s", print_kptr(addr, (char *)NULL, 0)); return (1); @@ -1246,11 +1243,11 @@ READLEN_T len; /* buffer length */ * readstmin() - read stream's module info */ -int readstmin(addr, buf) -KA_T addr; /* module info address in kernel */ -struct module_info *buf; /* receiving buffer address */ +int readstmin(struct lsof_context *ctx, /* context */ + KA_T addr, /* module info address in kernel */ + struct module_info *buf) /* receiving buffer address */ { - if (!addr || kread(addr, (char *)buf, sizeof(struct module_info))) { + if (!addr || kread(ctx, addr, (char *)buf, sizeof(struct module_info))) { (void)snpf(Namech, Namechl, "can't read module info from %s", print_kptr(addr, (char *)NULL, 0)); return (1); @@ -1262,11 +1259,11 @@ struct module_info *buf; /* receiving buffer address */ * readstqinit() - read stream's queue information structure */ -int readstqinit(addr, buf) -KA_T addr; /* queue info address in kernel */ -struct qinit *buf; /* receiving buffer address */ +int readstqinit(struct lsof_context *ctx, /* context */ + KA_T addr, /* queue info address in kernel */ + struct qinit *buf) /* receiving buffer address */ { - if (!addr || kread(addr, (char *)buf, sizeof(struct qinit))) { + if (!addr || kread(ctx, addr, (char *)buf, sizeof(struct qinit))) { (void)snpf(Namech, Namechl, "can't read queue info from %s", print_kptr(addr, (char *)NULL, 0)); return (1); @@ -1283,11 +1280,10 @@ struct qinit *buf; /* receiving buffer address */ * cl = strlen(printable equivalent) */ -char *safepup(c, cl) -unsigned int c; /* unprintable (i.e., !isprint()) - * character and '\\' */ -int *cl; /* returned printable strlen -- NULL if - * no return needed */ +char *safepup(unsigned int c, /* unprintable (i.e., !isprint()) + * character and '\\' */ + int *cl) /* returned printable strlen -- NULL if + * no return needed */ { int len; char *rp; @@ -1336,14 +1332,13 @@ int *cl; /* returned printable strlen -- NULL if * non-printable characters when printed in a printable form */ -int safestrlen(sp, flags) -char *sp; /* string pointer */ -int flags; /* flags: - * bit 0: 0 (0) = no NL - * 1 (1) = add trailing NL - * 1: 0 (0) = ' ' printable - * 1 (2) = ' ' not printable - */ +int safestrlen(char *sp, /* string pointer */ + int flags) /* flags: + * bit 0: 0 (0) = no NL + * 1 (1) = add trailing NL + * 1: 0 (0) = ' ' printable + * 1 (2) = ' ' not printable + */ { char c; int len = 0; @@ -1368,21 +1363,21 @@ int flags; /* flags: * safestrprt() - print a string "safely" to the indicated stream -- i.e., * print unprintable characters in a printable form */ -void safestrprt(sp, fs, flags) char *sp; /* string to print pointer pointer */ -FILE *fs; /* destination stream -- e.g., stderr - * or stdout */ -int flags; /* flags: - * bit 0: 0 (0) = no NL - * 1 (1) = add trailing NL - * 1: 0 (0) = ' ' printable - * 1 (2) = ' ' not printable - * 2: 0 (0) = print string as is - * 1 (4) = surround string - * with '"' - * 4: 0 (0) = print ending '\n' - * 1 (8) = don't print ending - * '\n' - */ +void safestrprt(char *sp, /* string to print pointer pointer */ + FILE *fs, /* destination stream -- e.g., stderr + * or stdout */ + int flags) /* flags: + * bit 0: 0 (0) = no NL + * 1 (1) = add trailing NL + * 1: 0 (0) = ' ' printable + * 1 (2) = ' ' not printable + * 2: 0 (0) = print string as is + * 1 (4) = surround string + * with '"' + * 4: 0 (0) = print ending '\n' + * 1 (8) = don't print ending + * '\n' + */ { char c; int lnc, lnt, sl; @@ -1444,24 +1439,23 @@ int flags; /* flags: * "safely" to the indicated stream */ -void safestrprtn(sp, len, fs, - flags) char *sp; /* string to print pointer pointer */ -int len; /* safe number of characters to - * print */ -FILE *fs; /* destination stream -- e.g., stderr - * or stdout */ -int flags; /* flags: - * bit 0: 0 (0) = no NL - * 1 (1) = add trailing NL - * 1: 0 (0) = ' ' printable - * 1 (2) = ' ' not printable - * 2: 0 (0) = print string as is - * 1 (4) = surround string - * with '"' - * 4: 0 (0) = print ending '\n' - * 1 (8) = don't print ending - * '\n' - */ +void safestrprtn(char *sp, /* string to print pointer pointer */ + int len, /* safe number of characters to + * print */ + FILE *fs, /* destination stream -- e.g., stderr + * or stdout */ + int flags) /* flags: + * bit 0: 0 (0) = no NL + * 1 (1) = add trailing NL + * 1: 0 (0) = ' ' printable + * 1 (2) = ' ' not printable + * 2: 0 (0) = print string as is + * 1 (4) = surround string + * with '"' + * 4: 0 (0) = print ending '\n' + * 1 (8) = don't print ending + * '\n' + */ { char c, *up; int cl, i; @@ -1498,9 +1492,8 @@ int flags; /* flags: * statsafely() - stat path safely (i. e., with timeout) */ -int statsafely(path, buf) -char *path; /* file path */ -struct stat *buf; /* stat buffer address */ +int statsafely(struct lsof_context *ctx, char *path, /* file path */ + struct stat *buf) /* stat buffer address */ { if (Fblock) { if (!Fwarn) @@ -1509,14 +1502,14 @@ struct stat *buf; /* stat buffer address */ errno = EWOULDBLOCK; return (1); } - return (doinchild(dostat, path, (char *)buf, sizeof(struct stat))); + return (doinchild(ctx, dostat, path, (char *)buf, sizeof(struct stat))); } /* * stkdir() - stack directory name */ -void stkdir(p) char *p; /* directory path */ +void stkdir(struct lsof_context *ctx, char *p) /* directory path */ { MALLOC_S len; /* @@ -1532,7 +1525,7 @@ void stkdir(p) char *p; /* directory path */ if (!Dstk) { (void)fprintf(stderr, "%s: no space for directory stack at: ", Pn); safestrprt(p, stderr, 1); - Error(); + Error(ctx); } } /* @@ -1542,7 +1535,7 @@ void stkdir(p) char *p; /* directory path */ if (!(Dstk[Dstkx] = mkstrcpy(p, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(p, stderr, 1); - Error(); + Error(ctx); } Dstkx++; } @@ -1551,9 +1544,8 @@ void stkdir(p) char *p; /* directory path */ * x2dev() - convert hexadecimal ASCII string to device number */ -char *x2dev(s, d) -char *s; /* ASCII string */ -dev_t *d; /* device receptacle */ +char *x2dev(char *s, /* ASCII string */ + dev_t *d) /* device receptacle */ { char *cp, *cp1; int n; diff --git a/lib/node.c b/lib/node.c index ce275444..be2df866 100644 --- a/lib/node.c +++ b/lib/node.c @@ -34,10 +34,9 @@ * print_kptr() - print kernel pointer */ -char *print_kptr(kp, buf, bufl) -KA_T kp; /* kernel pointer address */ -char *buf; /* optional destination buffer */ -size_t bufl; /* size of buf[] */ +char *print_kptr(KA_T kp, /* kernel pointer address */ + char *buf, /* optional destination buffer */ + size_t bufl) /* size of buf[] */ { static char dbuf[32]; @@ -50,11 +49,11 @@ size_t bufl; /* size of buf[] */ * readcdrnode() - read CD-ROM node */ -int readcdrnode(ca, c) -KA_T ca; /* cdrnode kernel address */ -struct cdrnode *c; /* cdrnode buffer */ +int readcdrnode(struct lsof_context *ctx, /* context */ + KA_T ca, /* cdrnode kernel address */ + struct cdrnode *c) /* cdrnode buffer */ { - if (kread((KA_T)ca, (char *)c, sizeof(struct cdrnode))) { + if (kread(ctx, (KA_T)ca, (char *)c, sizeof(struct cdrnode))) { (void)snpf(Namech, Namechl, "can't read cdrnode at %s", print_kptr(ca, (char *)NULL, 0)); return (1); @@ -68,11 +67,11 @@ struct cdrnode *c; /* cdrnode buffer */ * readfifonode() - read fifonode */ -int readfifonode(fa, f) -KA_T fa; /* fifonode kernel address */ -struct fifonode *f; /* fifonode buffer */ +int readfifonode(struct lsof_context *ctx, /* context */ + KA_T fa, /* fifonode kernel address */ + struct fifonode *f) /* fifonode buffer */ { - if (kread((KA_T)fa, (char *)f, sizeof(struct fifonode))) { + if (kread(ctx, (KA_T)fa, (char *)f, sizeof(struct fifonode))) { (void)snpf(Namech, Namechl, "can't read fifonode at %s", print_kptr(fa, (char *)NULL, 0)); return (1); @@ -86,11 +85,11 @@ struct fifonode *f; /* fifonode buffer */ * readgnode() - read gnode */ -int readgnode(ga, g) -KA_T ga; /* gnode kernel address */ -struct gnode *g; /* gnode buffer */ +int readgnode(struct lsof_context *ctx, /* context */ + KA_T ga, /* gnode kernel address */ + struct gnode *g) /* gnode buffer */ { - if (kread((KA_T)ga, (char *)g, sizeof(struct gnode))) { + if (kread(ctx, (KA_T)ga, (char *)g, sizeof(struct gnode))) { (void)snpf(Namech, Namechl, "can't read gnode at %s", print_kptr(ga, (char *)NULL, 0)); return (1); @@ -104,11 +103,11 @@ struct gnode *g; /* gnode buffer */ * readhsnode() - read High Sierra file system node */ -int readhsnode(ha, h) -KA_T ha; /* hsnode kernel address */ -struct hsnode *h; /* hsnode buffer */ +int readhsnode(struct lsof_context *ctx, /* context */ + KA_T ha, /* hsnode kernel address */ + struct hsnode *h) /* hsnode buffer */ { - if (kread((KA_T)ha, (char *)h, sizeof(struct hsnode))) { + if (kread(ctx, (KA_T)ha, (char *)h, sizeof(struct hsnode))) { (void)snpf(Namech, Namechl, "can't read hsnode at %s", print_kptr(ha, (char *)NULL, 0)); return (1); @@ -122,11 +121,11 @@ struct hsnode *h; /* hsnode buffer */ * readinode() - read inode */ -int readinode(ia, i) -KA_T ia; /* inode kernel address */ -struct inode *i; /* inode buffer */ +int readinode(struct lsof_context *ctx, /* context */ + KA_T ia, /* inode kernel address */ + struct inode *i) /* inode buffer */ { - if (kread((KA_T)ia, (char *)i, sizeof(struct inode))) { + if (kread(ctx, (KA_T)ia, (char *)i, sizeof(struct inode))) { (void)snpf(Namech, Namechl, "can't read inode at %s", print_kptr(ia, (char *)NULL, 0)); return (1); @@ -140,11 +139,11 @@ struct inode *i; /* inode buffer */ * readpipenode() - read pipe node */ -int readpipenode(pa, p) -KA_T pa; /* pipe node kernel address */ -struct pipenode *p; /* pipe node buffer */ +int readpipenode(struct lsof_context *ctx, /* context */ + KA_T pa, /* pipe node kernel address */ + struct pipenode *p) /* pipe node buffer */ { - if (kread((KA_T)pa, (char *)p, sizeof(struct pipenode))) { + if (kread(ctx, (KA_T)pa, (char *)p, sizeof(struct pipenode))) { (void)snpf(Namech, Namechl, "can't read pipenode at %s", print_kptr(pa, (char *)NULL, 0)); return (1); @@ -158,11 +157,11 @@ struct pipenode *p; /* pipe node buffer */ * readrnode() - read rnode */ -int readrnode(ra, r) -KA_T ra; /* rnode kernel space address */ -struct rnode *r; /* rnode buffer pointer */ +int readrnode(struct lsof_context *ctx, /* context */ + KA_T ra, /* rnode kernel space address */ + struct rnode *r) /* rnode buffer pointer */ { - if (kread((KA_T)ra, (char *)r, sizeof(struct rnode))) { + if (kread(ctx, (KA_T)ra, (char *)r, sizeof(struct rnode))) { (void)snpf(Namech, Namechl, "can't read rnode at %s", print_kptr(ra, (char *)NULL, 0)); return (1); @@ -176,11 +175,11 @@ struct rnode *r; /* rnode buffer pointer */ * readsnode() - read snode */ -int readsnode(sa, s) -KA_T sa; /* snode kernel space address */ -struct snode *s; /* snode buffer pointer */ +int readsnode(struct lsof_context *ctx, /* context */ + KA_T sa, /* snode kernel space address */ + struct snode *s) /* snode buffer pointer */ { - if (kread((KA_T)sa, (char *)s, sizeof(struct snode))) { + if (kread(ctx, (KA_T)sa, (char *)s, sizeof(struct snode))) { (void)snpf(Namech, Namechl, "can't read snode at %s", print_kptr(sa, (char *)NULL, 0)); return (1); @@ -194,11 +193,11 @@ struct snode *s; /* snode buffer pointer */ * readtnode() - read tmpnode */ -int readtnode(ta, t) -KA_T ta; /* tmpnode kernel space address */ -struct tmpnode *t; /* tmpnode buffer pointer */ +int readtnode(struct lsof_context *ctx, /* context */ + KA_T ta, /* tmpnode kernel space address */ + struct tmpnode *t) /* tmpnode buffer pointer */ { - if (kread((KA_T)ta, (char *)t, sizeof(struct tmpnode))) { + if (kread(ctx, (KA_T)ta, (char *)t, sizeof(struct tmpnode))) { (void)snpf(Namech, Namechl, "can't read tmpnode at %s", print_kptr(ta, (char *)NULL, 0)); return (1); @@ -212,11 +211,11 @@ struct tmpnode *t; /* tmpnode buffer pointer */ * readvnode() - read vnode */ -int readvnode(va, v) -KA_T va; /* vnode kernel space address */ -struct vnode *v; /* vnode buffer pointer */ +int readvnode(struct lsof_context *ctx, /* context */ + KA_T va, /* vnode kernel space address */ + struct vnode *v) /* vnode buffer pointer */ { - if (kread((KA_T)va, (char *)v, sizeof(struct vnode))) { + if (kread(ctx, (KA_T)va, (char *)v, sizeof(struct vnode))) { (void)snpf(Namech, Namechl, "can't read vnode at %s", print_kptr(va, (char *)NULL, 0)); return (1); diff --git a/lib/pdvn.c b/lib/pdvn.c index b6949482..d553f673 100644 --- a/lib/pdvn.c +++ b/lib/pdvn.c @@ -61,11 +61,10 @@ char *pdvn_d2 = pdvn_d1; * printdevname() - print block or character device name */ -int printdevname(dev, rdev, f, nty) -dev_t *dev; /* device */ -dev_t *rdev; /* raw device */ -int f; /* 1 = print trailing '\n' */ -int nty; /* node type: N_BLK or N_CHR */ +int printdevname(struct lsof_context *ctx, dev_t *dev, /* device */ + dev_t *rdev, /* raw device */ + int f, /* 1 = print trailing '\n' */ + int nty) /* node type: N_BLK or N_CHR */ { # if defined(HAS_STD_CLONE) @@ -112,11 +111,11 @@ int nty; /* node type: N_BLK or N_CHR */ # if defined(HASBLKDEV) if (nty == N_BLK) - dp = lkupbdev(dev, rdev, 1, r); + dp = lkupbdev(ctx, dev, rdev, 1, r); else # endif /* defined(HASBLKDEV) */ - dp = lkupdev(dev, rdev, 1, r); + dp = lkupdev(ctx, dev, rdev, 1, r); if (dp) { safestrprt(dp->name, stdout, f); return (1); @@ -127,11 +126,11 @@ int nty; /* node type: N_BLK or N_CHR */ # if defined(HASBLKDEV) if (nty == N_BLK) - dp = lkupbdev(&DevDev, rdev, 0, r); + dp = lkupbdev(ctx, &DevDev, rdev, 0, r); else # endif /* defined(HASBLKDEV) */ - dp = lkupdev(&DevDev, rdev, 0, r); + dp = lkupdev(ctx, &DevDev, rdev, 0, r); if (dp) { /* * A match was found. Record it as a name column addition. @@ -144,10 +143,10 @@ int nty; /* node type: N_BLK or N_CHR */ if (!(cp = (char *)malloc((MALLOC_S)(len + 1)))) { (void)fprintf(stderr, "%s: no nma space for: (%s %s)\n", Pn, ttl, dp->name); - Error(); + Error(ctx); } (void)snpf(cp, len + 1, "(%s %s)", ttl, dp->name); - (void)add_nma(cp, len); + (void)add_nma(ctx, cp, len); (void)free((MALLOC_P *)cp); return (0); } @@ -160,7 +159,7 @@ int nty; /* node type: N_BLK or N_CHR */ * "unsafe," rebuild it. */ if (!r && DCunsafe) { - (void)rereaddev(); + (void)rereaddev(ctx); goto printdevname_again; } # endif /* defined(HASDCACHE) */ diff --git a/lib/prfp.c b/lib/prfp.c index 6bd4a166..6e573911 100644 --- a/lib/prfp.c +++ b/lib/prfp.c @@ -47,7 +47,8 @@ * #define FILEPTR foobar */ -void process_file(fp) KA_T fp; /* kernel file structure address */ +void process_file(struct lsof_context *ctx, + KA_T fp) /* kernel file structure address */ { struct file f; int flag; @@ -63,10 +64,10 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ /* * Read file structure. */ - if (kread((KA_T)fp, (char *)&f, sizeof(f))) { + if (kread(ctx, (KA_T)fp, (char *)&f, sizeof(f))) { (void)snpf(Namech, Namechl, "can't read file struct from %s", print_kptr(fp, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } Lf->off = (SZOFFTYPE)f.f_offset; @@ -118,7 +119,7 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ case DTYPE_PIPE: # if defined(HASPIPEFN) if (!Selinet) - HASPIPEFN((KA_T)f.f_data); + HASPIPEFN(ctx, (KA_T)f.f_data); # endif /* defined(HASPIPEFN) */ return; # endif /* defined(DTYPE_PIPE) */ @@ -126,7 +127,7 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ # if defined(DTYPE_PTS) case DTYPE_PTS: # if defined(HASPTSFN) - HASPTSFN((KA_T)f.f_data); + HASPTSFN(ctx, (KA_T)f.f_data); # endif /* defined(HASPTSFN) */ return; # endif /* defined(DTYPE_PIPE) */ @@ -152,37 +153,37 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ # endif /* defined(DTYPE_VNODE) */ # if defined(HASF_VNODE) - process_node((KA_T)f.f_vnode); + process_node(ctx, (KA_T)f.f_vnode); # else /* !defined(HASF_VNODE) */ - process_node((KA_T)f.f_data); + process_node(ctx, (KA_T)f.f_data); # endif /* defined(HASF_VNODE) */ return; case DTYPE_SOCKET: - process_socket((KA_T)f.f_data); + process_socket(ctx, (KA_T)f.f_data); return; # if defined(HASKQUEUE) case DTYPE_KQUEUE: - process_kqueue((KA_T)f.f_data); + process_kqueue(ctx, (KA_T)f.f_data); return; # endif /* defined(HASKQUEUE) */ # if defined(HASPSXSEM) case DTYPE_PSXSEM: - process_psxsem((KA_T)f.f_data); + process_psxsem(ctx, (KA_T)f.f_data); return; # endif /* defined(HASPSXSEM) */ # if defined(HASPSXSHM) case DTYPE_PSXSHM: - process_psxshm((KA_T)f.f_data); + process_psxshm(ctx, (KA_T)f.f_data); return; # endif /* defined(HASPSXSHM) */ # if defined(HASPRIVFILETYPE) case PRIVFILETYPE: - HASPRIVFILETYPE((KA_T)f.f_data); + HASPRIVFILETYPE(ctx, (KA_T)f.f_data); return; # endif /* defined(HASPRIVFILETYPE) */ @@ -193,7 +194,7 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ (void)snpf(Namech, Namechl, "no more information; ty=%d file may be closing", (int)f.f_type); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } # endif /* defined(X_BADFILEOPS) */ @@ -202,12 +203,12 @@ void process_file(fp) KA_T fp; /* kernel file structure address */ (void)snpf(Namech, Namechl, "%s file struct, ty=%d, op=%s", print_kptr(fp, tbuf, sizeof(tbuf)), (int)f.f_type, print_kptr((KA_T)f.f_ops, (char *)NULL, 0)); - enter_nm(Namech); + enter_nm(ctx, Namech); return; } } } - enter_nm("no more information"); + enter_nm(ctx, "no more information"); } #else /* !defined(USE_LIB_PROCESS_FILE) */ char prfp_d1[] = "d"; diff --git a/lib/proc.c b/lib/proc.c index 7e80c329..1ea2fdd6 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -29,23 +29,25 @@ */ #include "common.h" +#include "dlsof.h" #include "lsof.h" #if defined(HASEPTOPTS) -_PROTOTYPE(static void prt_pinfo, (pxinfo_t * pp, int ps)); -_PROTOTYPE(static void prt_psxmqinfo, (pxinfo_t * pp, int ps)); -_PROTOTYPE(static void prt_evtfdinfo, (pxinfo_t * pp, int ps)); +static void prt_pinfo(struct lsof_context *ctx, pxinfo_t *pp, int ps); +static void prt_psxmqinfo(struct lsof_context *ctx, pxinfo_t *pp, int ps); +static void prt_evtfdinfo(struct lsof_context *ctx, pxinfo_t *pp, int ps); #endif /* defined(HASEPTOPTS) */ #if defined(HASPTYEPT) -_PROTOTYPE(static void prt_ptyinfo, (pxinfo_t * pp, int prt_edev, int ps)); +static void prt_ptyinfo(struct lsof_context *ctx, pxinfo_t *pp, int prt_edev, + int ps); #endif /* defined(HASPTYEPT) */ /* * add_nma() - add to NAME column addition */ -void add_nma(cp, len) char *cp; /* string to add */ -int len; /* string length */ +void add_nma(struct lsof_context *ctx, char *cp, /* string to add */ + int len) /* string length */ { int nl; @@ -62,7 +64,7 @@ int len; /* string length */ if (!Lf->nma) { (void)fprintf(stderr, "%s: no name addition space: PID %ld, FD %s", Pn, (long)Lp->pid, Lf->fd); - Error(); + Error(ctx); } if (nl) { Lf->nma[nl] = ' '; @@ -75,16 +77,16 @@ int len; /* string length */ } #if defined(HASFSTRUCT) -_PROTOTYPE(static char *alloc_fflbuf, (char **bp, int *al, int lr)); +static char *alloc_fflbuf(struct lsof_context *ctx, char **bp, int *al, int lr); /* * alloc_fflbuf() - allocate file flags print buffer */ -static char *alloc_fflbuf(bp, al, lr) -char **bp; /* current buffer pointer */ -int *al; /* current allocated length */ -int lr; /* length required */ +static char *alloc_fflbuf(struct lsof_context *ctx, + char **bp, /* current buffer pointer */ + int *al, /* current allocated length */ + int lr) /* length required */ { int sz; @@ -97,7 +99,7 @@ int lr; /* length required */ *bp = (char *)malloc((MALLOC_S)sz); if (!*bp) { (void)fprintf(stderr, "%s: no space (%d) for print flags\n", Pn, sz); - Error(); + Error(ctx); } *al = sz; return (*bp); @@ -108,9 +110,10 @@ int lr; /* length required */ * alloc_lfile() - allocate local file structure space */ -void alloc_lfile(nm, num) char *nm; /* file descriptor name (may be NULL) */ -int num; /* file descriptor number -- -1 if - * none */ +void alloc_lfile(struct lsof_context *ctx, + char *nm, /* file descriptor name (may be NULL) */ + int num) /* file descriptor number -- -1 if + * none */ { int fds; @@ -136,7 +139,7 @@ int num; /* file descriptor number -- -1 if } else if (!(Lf = (struct lfile *)malloc(sizeof(struct lfile)))) { (void)fprintf(stderr, "%s: no local file space at PID %d\n", Pn, Lp->pid); - Error(); + Error(ctx); } /* * Initialize the structure. @@ -242,7 +245,7 @@ int num; /* file descriptor number -- -1 if */ if (!Fdl || (!nm && num < 0)) return; - fds = ck_fd_status(nm, num); + fds = ck_fd_status(ctx, nm, num); switch (FdlTy) { case 0: /* inclusion list */ if (fds == 2) @@ -258,13 +261,13 @@ int num; /* file descriptor number -- -1 if * alloc_lproc() - allocate local proc structure space */ -void alloc_lproc(pid, pgid, ppid, uid, cmd, pss, sf) int pid; /* Process ID */ -int pgid; /* process group ID */ -int ppid; /* parent process ID */ -UID_ARG uid; /* User ID */ -char *cmd; /* command */ -int pss; /* process select state */ -int sf; /* process select flags */ +void alloc_lproc(struct lsof_context *ctx, int pid, /* Process ID */ + int pgid, /* process group ID */ + int ppid, /* parent process ID */ + UID_ARG uid, /* User ID */ + char *cmd, /* command */ + int pss, /* process select state */ + int sf) /* process select flags */ { static int sz = 0; @@ -274,7 +277,7 @@ int sf; /* process select flags */ (void)fprintf(stderr, "%s: no malloc space for %d local proc structures\n", Pn, LPROCINCR); - Error(); + Error(ctx); } sz = LPROCINCR; } else if ((Nlproc + 1) > sz) { @@ -284,7 +287,7 @@ int sf; /* process select flags */ (void)fprintf(stderr, "%s: no realloc space for %d local proc structures\n", Pn, sz); - Error(); + Error(ctx); } } Lp = &Lproc[Nlproc++]; @@ -312,7 +315,7 @@ int sf; /* process select flags */ (void)fprintf(stderr, "%s: PID %d, no space for command name: ", Pn, pid); safestrprt(cmd, stderr, 1); - Error(); + Error(ctx); } #if defined(HASZONES) @@ -339,10 +342,10 @@ int sf; /* process select flags */ * 2 == FD is included */ -extern int ck_fd_status(nm, num) -char *nm; /* file descriptor name (may be NULL) */ -int num; /* file descriptor number -- -1 if - * none */ +extern int ck_fd_status(struct lsof_context *ctx, + char *nm, /* file descriptor name (may be NULL) */ + int num) /* file descriptor number -- -1 if + * none */ { char *cp; struct fd_lst *fp; @@ -387,9 +390,7 @@ int num; /* file descriptor number -- -1 if * comppid() - compare PIDs */ -int comppid(a1, a2) -COMP_P *a1, *a2; -{ +int comppid(COMP_P *a1, COMP_P *a2) { struct lproc **p1 = (struct lproc **)a1; struct lproc **p2 = (struct lproc **)a2; @@ -412,15 +413,15 @@ COMP_P *a1, *a2; * ent_inaddr() - enter Internet addresses */ -void ent_inaddr(la, lp, fa, fp, - af) unsigned char *la; /* local Internet address */ -int lp; /* local port */ -unsigned char *fa; /* foreign Internet address -- may - * be NULL to indicate no foreign - * address is known */ -int fp; /* foreign port */ -int af; /* address family -- e.g, AF_INET, - * AF_INET */ +void ent_inaddr(struct lsof_context *ctx, + unsigned char *la, /* local Internet address */ + int lp, /* local port */ + unsigned char *fa, /* foreign Internet address -- may + * be NULL to indicate no foreign + * address is known */ + int fp, /* foreign port */ + int af) /* address family -- e.g, AF_INET, + * AF_INET */ { int m; @@ -467,7 +468,7 @@ int af; /* address family -- e.g, AF_INET, * return: 1 = last process */ -int examine_lproc() { +int examine_lproc(struct lsof_context *ctx) { int sbp = 0; if (RptTm) @@ -488,10 +489,10 @@ int examine_lproc() { } if (Lp->pss && Npid == 1 && sbp) { print_init(); - (void)print_proc(); + (void)print_proc(ctx); PrPass++; if (PrPass < 2) - (void)print_proc(); + (void)print_proc(ctx); Lp->pss = 0; } /* @@ -512,8 +513,7 @@ int examine_lproc() { * free_lproc() - free lproc entry and its associated malloc'd space */ -void free_lproc(lp) struct lproc *lp; -{ +void free_lproc(struct lproc *lp) { struct lfile *lf, *nf; for (lf = lp->file; lf; lf = nf) { @@ -555,10 +555,9 @@ void free_lproc(lp) struct lproc *lp; * is_cmd_excl() - is command excluded? */ -int is_cmd_excl(cmd, pss, sf) -char *cmd; /* command name */ -short *pss; /* process state */ -short *sf; /* process select flags */ +int is_cmd_excl(struct lsof_context *ctx, char *cmd, /* command name */ + short *pss, /* process state */ + short *sf) /* process select flags */ { int i; struct str_lst *sp; @@ -613,9 +612,8 @@ short *sf; /* process select flags */ * is_file_sel() - is file selected? */ -int is_file_sel(lp, lf) -struct lproc *lp; /* lproc structure pointer */ -struct lfile *lf; /* lfile structure pointer */ +int is_file_sel(struct lproc *lp, /* lproc structure pointer */ + struct lfile *lf) /* lfile structure pointer */ { if (!lf || !lf->sf) return (0); @@ -640,24 +638,17 @@ struct lfile *lf; /* lfile structure pointer */ * is_proc_excl() - is process excluded? */ -int - +int is_proc_excl(struct lsof_context *ctx, int pid, /* Process ID */ + int pgid, /* process group ID */ + UID_ARG uid, /* User ID */ + short *pss, /* process select state for lproc */ #if defined(HASTASKS) -is_proc_excl(pid, pgid, uid, pss, sf, tid) -#else /* !defined(HASTASKS) */ - is_proc_excl(pid, pgid, uid, pss, sf) + short *sf, /* select flags for lproc */ + int tid) /* task ID (not a task if zero) */ +#else + short *sf) /* select flags for lproc */ #endif /* defined(HASTASKS) */ -int pid; /* Process ID */ -int pgid; /* process group ID */ -UID_ARG uid; /* User ID */ -short *pss; /* process select state for lproc */ -short *sf; /* select flags for lproc */ - -#if defined(HASTASKS) -int tid; /* task ID (not a task if zero) */ -#endif /* defined(HASTASKS) */ - { int i, j; @@ -858,7 +849,7 @@ int tid; /* task ID (not a task if zero) */ * link_lfile() - link local file structures */ -void link_lfile() { +void link_lfile(struct lsof_context *ctx) { if (Lf->sf & SELEXCLF) return; @@ -965,10 +956,11 @@ void link_lfile() { * selecting pipe end files (if requested) */ -void process_pinfo(f) int f; /* function: - * 0 == process selected pipe - * 1 == process end point - */ +void process_pinfo(struct lsof_context *ctx, + int f) /* function: + * 0 == process selected pipe + * 1 == process end point + */ { pxinfo_t *pp; /* previous pipe info */ @@ -991,14 +983,14 @@ void process_pinfo(f) int f; /* function: * its being a pipe. Look up the pipe's endpoints. */ do { - if ((pp = find_pepti(Lp->pid, Lf, pp))) { + if ((pp = find_pepti(ctx, Lp->pid, Lf, pp))) { /* * This pipe endpoint is linked to the selected pipe * file. Add its PID and FD to the name column * addition. */ - prt_pinfo(pp, (FeptE == 2)); + prt_pinfo(ctx, pp, (FeptE == 2)); pp = pp->next; } } while (pp); @@ -1014,8 +1006,8 @@ void process_pinfo(f) int f; /* function: Lf->sf = Selflags; Lp->pss |= PS_SEC; do { - if ((pp = find_pepti(Lp->pid, Lf, pp))) { - prt_pinfo(pp, 0); + if ((pp = find_pepti(ctx, Lp->pid, Lf, pp))) { + prt_pinfo(ctx, pp, 0); pp = pp->next; } } while (pp); @@ -1029,10 +1021,10 @@ void process_pinfo(f) int f; /* function: * prt_pinfo() -- print pipe information */ -static void prt_pinfo(pp, ps) pxinfo_t *pp; /* peer info */ -int ps; /* processing status: - * 0 == process immediately - * 1 == process later */ +static void prt_pinfo(struct lsof_context *ctx, pxinfo_t *pp, /* peer info */ + int ps) /* processing status: + * 0 == process immediately + * 1 == process later */ { struct lproc *ep; /* pipe endpoint process */ struct lfile *ef; /* pipe endpoint file */ @@ -1047,7 +1039,7 @@ int ps; /* processing status: } (void)snpf(nma, sizeof(nma) - 1, "%d,%.*s,%s%c", ep->pid, CmdLim, ep->cmd, &ef->fd[i], access_to_char(ef->access)); - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); if (ps) { /* @@ -1064,10 +1056,11 @@ int ps; /* processing status: * selecting posix mq end files (if requested) */ -void process_psxmqinfo(f) int f; /* function: - * 0 == process selected posix mq - * 1 == process end point - */ +void process_psxmqinfo(struct lsof_context *ctx, + int f) /* function: + * 0 == process selected posix mq + * 1 == process end point + */ { pxinfo_t *pp; /* previous posix mq info */ @@ -1090,14 +1083,14 @@ void process_psxmqinfo(f) int f; /* function: * its being a posix mq. Look up the posix mq's endpoints. */ do { - if ((pp = find_psxmqinfo(Lp->pid, Lf, pp))) { + if ((pp = find_psxmqinfo(ctx, Lp->pid, Lf, pp))) { /* * This posix mq endpoint is linked to the selected * posix mq file. Add its PID and FD to the name column * addition. */ - prt_psxmqinfo(pp, (FeptE == 2)); + prt_psxmqinfo(ctx, pp, (FeptE == 2)); pp = pp->next; } } while (pp); @@ -1113,8 +1106,8 @@ void process_psxmqinfo(f) int f; /* function: Lf->sf = Selflags; Lp->pss |= PS_SEC; do { - if ((pp = find_psxmqinfo(Lp->pid, Lf, pp))) { - prt_psxmqinfo(pp, 0); + if ((pp = find_psxmqinfo(ctx, Lp->pid, Lf, pp))) { + prt_psxmqinfo(ctx, pp, 0); pp = pp->next; } } while (pp); @@ -1128,10 +1121,11 @@ void process_psxmqinfo(f) int f; /* function: * prt_psxmqinfo() -- print posix mq information */ -static void prt_psxmqinfo(pp, ps) pxinfo_t *pp; /* peer info */ -int ps; /* processing status: - * 0 == process immediately - * 1 == process later */ +static void prt_psxmqinfo(struct lsof_context *ctx, + pxinfo_t *pp, /* peer info */ + int ps) /* processing status: + * 0 == process immediately + * 1 == process later */ { struct lproc *ep; /* posix mq endpoint process */ struct lfile *ef; /* posix mq endpoint file */ @@ -1146,7 +1140,7 @@ int ps; /* processing status: } (void)snpf(nma, sizeof(nma) - 1, "%d,%.*s,%s%c", ep->pid, CmdLim, ep->cmd, &ef->fd[i], access_to_char(ef->access)); - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); if (ps) { /* @@ -1163,10 +1157,11 @@ int ps; /* processing status: * selecting envetfd end files (if requested) */ -void process_evtfdinfo(f) int f; /* function: - * 0 == process selected eventfd - * 1 == process end point - */ +void process_evtfdinfo(struct lsof_context *ctx, + int f) /* function: + * 0 == process selected eventfd + * 1 == process end point + */ { pxinfo_t *pp; /* previous eventfd info */ @@ -1189,14 +1184,14 @@ void process_evtfdinfo(f) int f; /* function: * its being a eventfd. Look up the eventfd's endpoints. */ do { - if ((pp = find_evtfdinfo(Lp->pid, Lf, pp))) { + if ((pp = find_evtfdinfo(ctx, Lp->pid, Lf, pp))) { /* * This eventfd endpoint is linked to the selected * eventfd file. Add its PID and FD to the name column * addition. */ - prt_evtfdinfo(pp, (FeptE == 2)); + prt_evtfdinfo(ctx, pp, (FeptE == 2)); pp = pp->next; } } while (pp); @@ -1212,8 +1207,8 @@ void process_evtfdinfo(f) int f; /* function: Lf->sf = Selflags; Lp->pss |= PS_SEC; do { - if ((pp = find_evtfdinfo(Lp->pid, Lf, pp))) { - prt_evtfdinfo(pp, 0); + if ((pp = find_evtfdinfo(ctx, Lp->pid, Lf, pp))) { + prt_evtfdinfo(ctx, pp, 0); pp = pp->next; } } while (pp); @@ -1227,10 +1222,11 @@ void process_evtfdinfo(f) int f; /* function: * prt_evtfdinfo() -- print eventfd information */ -static void prt_evtfdinfo(pp, ps) pxinfo_t *pp; /* peer info */ -int ps; /* processing status: - * 0 == process immediately - * 1 == process later */ +static void prt_evtfdinfo(struct lsof_context *ctx, + pxinfo_t *pp, /* peer info */ + int ps) /* processing status: + * 0 == process immediately + * 1 == process later */ { struct lproc *ep; /* eventfd endpoint process */ struct lfile *ef; /* eventfd endpoint file */ @@ -1245,7 +1241,7 @@ int ps; /* processing status: } (void)snpf(nma, sizeof(nma) - 1, "%d,%.*s,%s%c", ep->pid, CmdLim, ep->cmd, &ef->fd[i], access_to_char(ef->access)); - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); if (ps) { /* @@ -1263,9 +1259,9 @@ int ps; /* processing status: * print_fflags() - print interpreted f_flag[s] */ -char *print_fflags(ffg, pof) -long ffg; /* file structure's flags value */ -long pof; /* process open files flags value */ +char *print_fflags(struct lsof_context *ctx, + long ffg, /* file structure's flags value */ + long pof) /* process open files flags value */ { int al, ct, fx; static int bl = 0; @@ -1300,7 +1296,7 @@ long pof; /* process open files flags value */ if (!tp->nm) break; al = (int)strlen(tp->nm) + sepl; - bp = alloc_fflbuf(&bp, &bl, al + ct); + bp = alloc_fflbuf(ctx, &bp, &bl, al + ct); (void)snpf(bp + ct, al + 1, "%s%s", sep, tp->nm); sep = ","; sepl = 1; @@ -1314,7 +1310,7 @@ long pof; /* process open files flags value */ if (wf || FsvFlagX) { (void)snpf(xbuf, sizeof(xbuf), "0x%lx", wf); al = (int)strlen(xbuf) + sepl; - bp = alloc_fflbuf(&bp, &bl, al + ct); + bp = alloc_fflbuf(ctx, &bp, &bl, al + ct); (void)snpf(bp + ct, al + 1, "%s%s", sep, xbuf); ct += al; } @@ -1323,7 +1319,7 @@ long pof; /* process open files flags value */ * Make sure there is at least a NUL terminated reply. */ if (!bp) { - bp = alloc_fflbuf(&bp, &bl, 0); + bp = alloc_fflbuf(ctx, &bp, &bl, 0); *bp = '\0'; } return (bp); @@ -1334,7 +1330,7 @@ long pof; /* process open files flags value */ * print_proc() - print process */ -int print_proc() { +int print_proc(struct lsof_context *ctx) { char buf[128], *cp; int lc, len, st, ty; int rv = 0; @@ -1409,7 +1405,7 @@ int print_proc() { 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); + cp = printuid(ctx, (UID_ARG)Lp->uid, &ty); if (ty == 0) (void)printf("%c%s%c", LSOF_FID_LOGIN, cp, Terminator); } @@ -1428,7 +1424,7 @@ int print_proc() { * output. */ if (!Ffield) { - print_file(); + print_file(ctx); continue; } lc = st = 0; @@ -1477,8 +1473,8 @@ int print_proc() { } 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); + (void)printf("%c%s%c", LSOF_FID_FG, + print_fflags(ctx, Lf->ffg, Lf->pof), Terminator); lc++; } if (FieldSel[LSOF_FIX_NI].st && (Fsv & FSV_NI) && (Lf->fsv & FSV_NI)) { @@ -1568,7 +1564,7 @@ int print_proc() { if (strncmp(Lf->nm, "STR:", 4) == 0 || strcmp(Lf->iproto, "STR") == 0) { putchar(LSOF_FID_STREAM); - printname(0); + printname(ctx, 0); putchar(Terminator); lc++; st++; @@ -1576,12 +1572,12 @@ int print_proc() { } if (st == 0 && FieldSel[LSOF_FIX_NAME].st) { putchar(LSOF_FID_NAME); - printname(0); + printname(ctx, 0); putchar(Terminator); lc++; } if (Lf->lts.type >= 0 && FieldSel[LSOF_FIX_TCPTPI].st) { - print_tcptpi(0); + print_tcptpi(ctx, 0); lc++; } if (Terminator == '\0' && lc) @@ -1596,9 +1592,10 @@ int print_proc() { *and selecting pseudoterminal end files (if requested) */ -void process_ptyinfo(f) int f; /* function: - * 0 == process selected pseudoterminal - * 1 == process end point */ +void process_ptyinfo(struct lsof_context *ctx, + int f) /* function: + * 0 == process selected pseudoterminal + * 1 == process end point */ { pxinfo_t *pp; /* previous pseudoterminal info */ int mos; /* master or slave indicator @@ -1631,14 +1628,14 @@ void process_ptyinfo(f) int f; /* function: */ pc = 1; do { - if ((pp = find_ptyepti(Lp->pid, Lf, !mos, pp))) { + if ((pp = find_ptyepti(ctx, Lp->pid, Lf, !mos, pp))) { /* * This pseudoterminal endpoint is linked to the * selected pseudoterminal file. Add its PID, FD and * access mode to the name column addition. */ - prt_ptyinfo(pp, (mos && pc), (FeptE == 2)); + prt_ptyinfo(ctx, pp, (mos && pc), (FeptE == 2)); pp = pp->next; pc = 0; } @@ -1656,8 +1653,8 @@ void process_ptyinfo(f) int f; /* function: Lp->pss |= PS_SEC; pc = 1; do { - if ((pp = find_ptyepti(Lp->pid, Lf, !mos, pp))) { - prt_ptyinfo(pp, (mos && pc), 0); + if ((pp = find_ptyepti(ctx, Lp->pid, Lf, !mos, pp))) { + prt_ptyinfo(ctx, pp, (mos && pc), 0); pp = pp->next; pc = 0; } @@ -1672,11 +1669,11 @@ void process_ptyinfo(f) int f; /* function: * prt_ptyinfo() -- print pseudoterminal information */ -static void prt_ptyinfo(pp, prt_edev, ps) pxinfo_t *pp; /* peer info */ -int prt_edev; /* print the end point device file */ -int ps; /* processing status: - * 0 == process immediately - * 1 == process later */ +static void prt_ptyinfo(struct lsof_context *ctx, pxinfo_t *pp, /* peer info */ + int prt_edev, /* print the end point device file */ + int ps) /* processing status: + * 0 == process immediately + * 1 == process later */ { struct lproc *ep; /* pseudoterminal endpoint process */ struct lfile *ef; /* pseudoterminal endpoint file */ @@ -1697,7 +1694,7 @@ int ps; /* processing status: (void)snpf(nma, sizeof(nma) - 1, "%d,%.*s,%s%c", ep->pid, CmdLim, ep->cmd, &ef->fd[i], access_to_char(ef->access)); } - (void)add_nma(nma, strlen(nma)); + (void)add_nma(ctx, nma, strlen(nma)); if (ps) { /* diff --git a/lib/proto.h b/lib/proto.h index 89d2e9de..8cd05110 100644 --- a/lib/proto.h +++ b/lib/proto.h @@ -35,19 +35,6 @@ #if !defined(PROTO_H) # define PROTO_H 1 -/* - * The _PROTOTYPE macro provides strict ANSI C prototypes if __STDC__ - * is defined, and old-style K&R prototypes otherwise. - * - * (With thanks to Andy Tanenbaum) - */ - -# if defined(__STDC__) -# define _PROTOTYPE(function, params) function params -# else /* !defined(__STDC__) */ -# define _PROTOTYPE(function, params) function() -# endif /* defined(__STDC__) */ - /* * The following define keeps gcc>=2.7 from complaining about the failure * of the Exit() function to return. @@ -62,93 +49,95 @@ # define exiting # endif /* gcc && gcc>=2.7 */ -_PROTOTYPE(extern void add_nma, (char *cp, int len)); -_PROTOTYPE(extern void alloc_lfile, (char *nm, int num)); -_PROTOTYPE(extern void alloc_lproc, (int pid, int pgid, int ppid, UID_ARG uid, - char *cmd, int pss, int sf)); -_PROTOTYPE(extern void build_IPstates, (void)); -_PROTOTYPE(extern void childx, (void)); -_PROTOTYPE(extern void closefrom_shim, (int low)); -_PROTOTYPE(extern int ck_fd_status, (char *nm, int num)); -_PROTOTYPE(extern int ck_file_arg, (int i, int ac, char *av[], int fv, int rs, - struct stat *sbp, int accept_deleted_file)); -_PROTOTYPE(extern void ckkv, (char *d, char *er, char *ev, char *ea)); -_PROTOTYPE(extern void clr_devtab, (void)); -_PROTOTYPE(extern int compdev, (COMP_P * a1, COMP_P *a2)); -_PROTOTYPE(extern int comppid, (COMP_P * a1, COMP_P *a2)); +extern void add_nma(struct lsof_context *ctx, char *cp, int len); +extern void alloc_lfile(struct lsof_context *ctx, char *nm, int num); +extern void alloc_lproc(struct lsof_context *ctx, int pid, int pgid, int ppid, + UID_ARG uid, char *cmd, int pss, int sf); +extern void build_IPstates(struct lsof_context *ctx); +extern void childx(struct lsof_context *ctx); +extern void closefrom_shim(int low); +extern int ck_fd_status(struct lsof_context *ctx, char *nm, int num); +extern int ck_file_arg(struct lsof_context *ctx, int i, int ac, char *av[], + int fv, int rs, struct stat *sbp, + int accept_deleted_file); +extern void ckkv(struct lsof_context *ctx, char *d, char *er, char *ev, + char *ea); +extern void clr_devtab(struct lsof_context *ctx); +extern int compdev(COMP_P *a1, COMP_P *a2); +extern int comppid(COMP_P *a1, COMP_P *a2); # if defined(WILLDROPGID) -_PROTOTYPE(extern void dropgid, (void)); +extern void dropgid(struct lsof_context *ctx); # endif /* defined(WILLDROPGID) */ -_PROTOTYPE(extern char *endnm, (size_t * sz)); -_PROTOTYPE(extern int enter_cmd_rx, (char *x)); -_PROTOTYPE(extern void enter_dev_ch, (char *m)); -_PROTOTYPE(extern int enter_dir, (char *d, int descend)); +extern char *endnm(struct lsof_context *ctx, size_t *sz); +extern int enter_cmd_rx(struct lsof_context *ctx, char *x); +extern void enter_dev_ch(struct lsof_context *ctx, char *m); +extern int enter_dir(struct lsof_context *ctx, char *d, int descend); # if defined(HASEOPT) -_PROTOTYPE(extern int enter_efsys, (char *e, int rdlnk)); +extern int enter_efsys(struct lsof_context *ctx, char *e, int rdlnk); # endif /* defined(HASEOPT) */ -_PROTOTYPE(extern int enter_fd, (char *f)); -_PROTOTYPE(extern int enter_network_address, (char *na)); -_PROTOTYPE(extern int enter_id, (enum IDType ty, char *p)); -_PROTOTYPE(extern void enter_IPstate, (char *ty, char *nm, int nr)); -_PROTOTYPE(extern void enter_nm, (char *m)); +extern int enter_fd(struct lsof_context *ctx, char *f); +extern int enter_network_address(struct lsof_context *ctx, char *na); +extern int enter_id(struct lsof_context *ctx, enum IDType ty, char *p); +extern void enter_IPstate(struct lsof_context *ctx, char *ty, char *nm, int nr); +extern void enter_nm(struct lsof_context *ctx, char *m); # if defined(HASTCPUDPSTATE) -_PROTOTYPE(extern int enter_state_spec, (char *ss)); +extern int enter_state_spec(struct lsof_context *ctx, char *ss); # endif /* defined(HASTCPUDPSTATE) */ -_PROTOTYPE(extern int enter_str_lst, - (char *opt, char *s, struct str_lst **lp, int *incl, int *excl)); -_PROTOTYPE(extern int enter_uid, (char *us)); -_PROTOTYPE(extern void ent_inaddr, - (unsigned char *la, int lp, unsigned char *fa, int fp, int af)); -_PROTOTYPE(extern int examine_lproc, (void)); -_PROTOTYPE(extern void Exit, (enum ExitStatus xv)) exiting; -_PROTOTYPE(extern void Error, ()) exiting; -_PROTOTYPE(extern void find_ch_ino, (void)); +extern int enter_str_lst(char *opt, char *s, struct str_lst **lp, int *incl, + int *excl); +extern int enter_uid(struct lsof_context *ctx, char *us); +extern void ent_inaddr(struct lsof_context *ctx, unsigned char *la, int lp, + unsigned char *fa, int fp, int af); +extern int examine_lproc(struct lsof_context *ctx); +extern void Exit(struct lsof_context *ctx, enum ExitStatus xv) exiting; +extern void Error(struct lsof_context *ctx) exiting; +extern void find_ch_ino(struct lsof_context *ctx); # if defined(HASEPTOPTS) -_PROTOTYPE(extern void clear_pinfo, (void)); -_PROTOTYPE(extern pxinfo_t *find_pepti, - (int pid, struct lfile *lf, pxinfo_t *pp)); -_PROTOTYPE(extern void process_pinfo, (int f)); -_PROTOTYPE(extern void clear_psxmqinfo, (void)); -_PROTOTYPE(extern pxinfo_t *find_psxmqinfo, - (int pid, struct lfile *lf, pxinfo_t *pp)); -_PROTOTYPE(extern void process_psxmqinfo, (int f)); +extern void clear_pinfo(struct lsof_context *ctx); +extern pxinfo_t *find_pepti(struct lsof_context *ctx, int pid, struct lfile *lf, + pxinfo_t *pp); +extern void process_pinfo(struct lsof_context *ctx, int f); +extern void clear_psxmqinfo(struct lsof_context *ctx); +extern pxinfo_t *find_psxmqinfo(struct lsof_context *ctx, int pid, + struct lfile *lf, pxinfo_t *pp); +extern void process_psxmqinfo(struct lsof_context *ctx, int f); # if defined(HASUXSOCKEPT) -_PROTOTYPE(extern void clear_uxsinfo, (void)); -_PROTOTYPE(extern struct uxsin *find_uxsepti, (struct lfile * lf)); -_PROTOTYPE(extern void process_uxsinfo, (int f)); +extern void clear_uxsinfo(struct lsof_context *ctx); +extern struct uxsin *find_uxsepti(struct lfile *lf); +extern void process_uxsinfo(struct lsof_context *ctx, int f); # endif /* defined(HASUXSOCKEPT) */ # if defined(HASPTYEPT) -_PROTOTYPE(extern void clear_ptyinfo, (void)); -_PROTOTYPE(extern void enter_ptmxi, (int mn)); -_PROTOTYPE(extern pxinfo_t *find_ptyepti, - (int pid, struct lfile *lf, int m, pxinfo_t *pp)); -_PROTOTYPE(extern int is_pty_slave, (int sm)); -_PROTOTYPE(extern int is_pty_ptmx, (dev_t dev)); -_PROTOTYPE(extern void process_ptyinfo, (int f)); +extern void clear_ptyinfo(struct lsof_context *ctx); +extern void enter_ptmxi(struct lsof_context *ctx, int mn); +extern pxinfo_t *find_ptyepti(struct lsof_context *ctx, int pid, + struct lfile *lf, int m, pxinfo_t *pp); +extern int is_pty_slave(int sm); +extern int is_pty_ptmx(dev_t dev); +extern void process_ptyinfo(struct lsof_context *ctx, int f); # endif /* defined(HASPTYEPT) */ -_PROTOTYPE(extern void clear_evtfdinfo, (void)); -_PROTOTYPE(extern void enter_evtfdinfo, (int id)); -_PROTOTYPE(extern pxinfo_t *find_evtfdinfo, - (int pid, struct lfile *lf, pxinfo_t *pp)); -_PROTOTYPE(extern void process_evtfdinfo, (int f)); -_PROTOTYPE(extern void clear_netsinfo, (void)); -_PROTOTYPE(extern void process_netsinfo, (int f)); +extern void clear_evtfdinfo(struct lsof_context *ctx); +extern void enter_evtfdinfo(struct lsof_context *ctx, int id); +extern pxinfo_t *find_evtfdinfo(struct lsof_context *ctx, int pid, + struct lfile *lf, pxinfo_t *pp); +extern void process_evtfdinfo(struct lsof_context *ctx, int f); +extern void clear_netsinfo(struct lsof_context *ctx); +extern void process_netsinfo(struct lsof_context *ctx, int f); # if defined(HASIPv6) -_PROTOTYPE(extern void clear_nets6info, (void)); -_PROTOTYPE(extern void process_nets6info, (int f)); +extern void clear_nets6info(struct lsof_context *ctx); +extern void process_nets6info(struct lsof_context *ctx, int f); # endif /* defined(HASIPv6) */ # endif /* defined(HASEPTOPTS) */ -_PROTOTYPE(extern void free_lproc, (struct lproc * lp)); -_PROTOTYPE(extern void gather_proc_info, (void)); -_PROTOTYPE(extern char *gethostnm, (unsigned char *ia, int af)); +extern void free_lproc(struct lproc *lp); +extern void gather_proc_info(struct lsof_context *ctx); +extern char *gethostnm(struct lsof_context *ctx, unsigned char *ia, int af); # if !defined(GET_MAX_FD) /* @@ -162,171 +151,176 @@ _PROTOTYPE(extern char *gethostnm, (unsigned char *ia, int af)); # define GET_MAX_FD getdtablesize # endif /* !defined(GET_MAX_FD) */ -_PROTOTYPE(extern int hashbyname, (char *nm, int mod)); -_PROTOTYPE(extern void hashSfile, (void)); -_PROTOTYPE(extern void initialize, (void)); -_PROTOTYPE(extern int is_cmd_excl, (char *cmd, short *pss, short *sf)); -_PROTOTYPE(extern int is_file_sel, (struct lproc * lp, struct lfile *lf)); -_PROTOTYPE(extern int is_nw_addr, (unsigned char *ia, int p, int af)); +extern int hashbyname(char *nm, int mod); +extern void hashSfile(struct lsof_context *ctx); +extern void initialize(struct lsof_context *ctx); +extern int is_cmd_excl(struct lsof_context *ctx, char *cmd, short *pss, + short *sf); +extern int is_file_sel(struct lproc *lp, struct lfile *lf); +extern int is_nw_addr(unsigned char *ia, int p, int af); # if defined(HASTASKS) -_PROTOTYPE(extern int is_proc_excl, - (int pid, int pgid, UID_ARG uid, short *pss, short *sf, int tid)); +extern int is_proc_excl(struct lsof_context *ctx, int pid, int pgid, + UID_ARG uid, short *pss, short *sf, int tid); # else /* !defined(HASTASKS) */ -_PROTOTYPE(extern int is_proc_excl, - (int pid, int pgid, UID_ARG uid, short *pss, short *sf)); +extern int is_proc_excl(struct lsof_context *ctx, int pid, int pgid, + UID_ARG uid, short *pss, short *sf); # endif /* defined(HASTASKS) */ -_PROTOTYPE(extern int is_readable, (char *path, int msg)); -_PROTOTYPE(extern int kread, (KA_T addr, char *buf, READLEN_T len)); -_PROTOTYPE(extern void link_lfile, (void)); -_PROTOTYPE(extern struct l_dev *lkupdev, - (dev_t * dev, dev_t *rdev, int i, int r)); -_PROTOTYPE(extern int main, (int argc, char *argv[])); -_PROTOTYPE(extern int lstatsafely, (char *path, struct stat *buf)); -_PROTOTYPE(extern char *mkstrcpy, (char *src, MALLOC_S *rlp)); -_PROTOTYPE(extern char *mkstrcat, (char *s1, int l1, char *s2, int l2, char *s3, - int l3, MALLOC_S *clp)); -_PROTOTYPE(extern int printdevname, (dev_t * dev, dev_t *rdev, int f, int nty)); -_PROTOTYPE(extern void print_file, (void)); -_PROTOTYPE(extern void print_init, (void)); -_PROTOTYPE(extern void printname, (int nl)); -_PROTOTYPE(extern char *print_kptr, (KA_T kp, char *buf, size_t bufl)); -_PROTOTYPE(extern int print_proc, (void)); -_PROTOTYPE(extern void printrawaddr, (struct sockaddr * sa)); -_PROTOTYPE(extern void print_tcptpi, (int nl)); -_PROTOTYPE(extern char *printuid, (UID_ARG uid, int *ty)); -_PROTOTYPE(extern void printunkaf, (int fam, int ty)); -_PROTOTYPE(extern char access_to_char, (enum lsof_file_access_mode access)); -_PROTOTYPE(extern char *printsockty, (int ty)); -_PROTOTYPE(extern void process_file, (KA_T fp)); -_PROTOTYPE(extern void process_node, (KA_T f)); -_PROTOTYPE(extern char *Readlink, (char *arg)); -_PROTOTYPE(extern void readdev, (int skip)); -_PROTOTYPE(extern struct mounts *readmnt, (void)); -_PROTOTYPE(extern void rereaddev, (void)); -_PROTOTYPE(extern char *safepup, (unsigned int c, int *cl)); -_PROTOTYPE(extern int safestrlen, (char *sp, int flags)); -_PROTOTYPE(extern void safestrprtn, (char *sp, int len, FILE *fs, int flags)); -_PROTOTYPE(extern void safestrprt, (char *sp, FILE *fs, int flags)); -_PROTOTYPE(extern int statsafely, (char *path, struct stat *buf)); -_PROTOTYPE(extern void stkdir, (char *p)); -_PROTOTYPE(extern void usage, (int err, int fh, int version)); -_PROTOTYPE(extern int util_strftime, (char *fmtr, int fmtl, char *fmt)); -_PROTOTYPE(extern int vfy_dev, (struct l_dev * dp)); -_PROTOTYPE(extern char *x2dev, (char *s, dev_t *d)); +extern int is_readable(char *path, int msg); +extern int kread(struct lsof_context *ctx, KA_T addr, char *buf, READLEN_T len); +extern void link_lfile(struct lsof_context *ctx); +extern struct l_dev *lkupdev(struct lsof_context *ctx, dev_t *dev, dev_t *rdev, + int i, int r); +extern int main(int argc, char *argv[]); +extern int lstatsafely(struct lsof_context *ctx, char *path, struct stat *buf); +extern char *mkstrcpy(char *src, MALLOC_S *rlp); +extern char *mkstrcat(char *s1, int l1, char *s2, int l2, char *s3, int l3, + MALLOC_S *clp); +extern int printdevname(struct lsof_context *ctx, dev_t *dev, dev_t *rdev, + int f, int nty); +extern void print_file(struct lsof_context *ctx); +extern void print_init(void); +extern void printname(struct lsof_context *ctx, int nl); +extern char *print_kptr(KA_T kp, char *buf, size_t bufl); +extern int print_proc(struct lsof_context *ctx); +extern void printrawaddr(struct lsof_context *ctx, struct sockaddr *sa); +extern void print_tcptpi(struct lsof_context *ctx, int nl); +extern char *printuid(struct lsof_context *ctx, UID_ARG uid, int *ty); +extern void printunkaf(struct lsof_context *ctx, int fam, int ty); +extern char access_to_char(enum lsof_file_access_mode access); +extern char *printsockty(int ty); +extern void process_file(struct lsof_context *ctx, KA_T fp); +extern void process_node(struct lsof_context *ctx, KA_T f); +extern char *Readlink(struct lsof_context *ctx, char *arg); +extern void readdev(struct lsof_context *ctx, int skip); +extern struct mounts *readmnt(struct lsof_context *ctx); +extern void rereaddev(struct lsof_context *ctx); +extern char *safepup(unsigned int c, int *cl); +extern int safestrlen(char *sp, int flags); +extern void safestrprtn(char *sp, int len, FILE *fs, int flags); +extern void safestrprt(char *sp, FILE *fs, int flags); +extern int statsafely(struct lsof_context *ctx, char *path, struct stat *buf); +extern void stkdir(struct lsof_context *ctx, char *p); +extern void usage(struct lsof_context *ctx, int err, int fh, int version); +extern int util_strftime(char *fmtr, int fmtl, char *fmt); +extern int vfy_dev(struct lsof_context *ctx, struct l_dev *dp); +extern char *x2dev(char *s, dev_t *d); # if defined(HASBLKDEV) -_PROTOTYPE(extern void find_bl_ino, (void)); -_PROTOTYPE(extern struct l_dev *lkupbdev, - (dev_t * dev, dev_t *rdev, int i, int r)); -_PROTOTYPE(extern int printbdevname, (dev_t * dev, dev_t *rdev, int f)); +extern void find_bl_ino(struct lsof_context *ctx); +extern struct l_dev *lkupbdev(struct lsof_context *ctx, dev_t *dev, dev_t *rdev, + int i, int r); +extern int printbdevname(dev_t *dev, dev_t *rdev, int f); # endif /* defined(HASBLKDEV) */ # if defined(HASCDRNODE) -_PROTOTYPE(extern int readcdrnode, (KA_T ca, struct cdrnode *c)); +extern int readcdrnode(struct lsof_context *ctx, KA_T ca, struct cdrnode *c); # endif /* defined(HASCDRNODE) */ # if defined(HASDCACHE) -_PROTOTYPE(extern void alloc_dcache, (void)); -_PROTOTYPE(extern void crc, (char *b, int l, unsigned *s)); -_PROTOTYPE(extern void crdbld, (void)); -_PROTOTYPE(extern int ctrl_dcache, (char *p)); -_PROTOTYPE(extern int dcpath, (int rw, int npw)); -_PROTOTYPE(extern int open_dcache, (int m, int r, struct stat *sb)); -_PROTOTYPE(extern int read_dcache, (void)); -_PROTOTYPE(extern int wr2DCfd, (char *b, unsigned *c)); -_PROTOTYPE(extern void write_dcache, (void)); +extern void alloc_dcache(struct lsof_context *ctx); +extern void crc(char *b, int l, unsigned *s); +extern void crdbld(void); +extern int ctrl_dcache(struct lsof_context *ctx, char *p); +extern int dcpath(struct lsof_context *ctx, int rw, int npw); +extern int open_dcache(struct lsof_context *ctx, int m, int r, struct stat *sb); +extern int read_dcache(struct lsof_context *ctx); +extern int wr2DCfd(char *b, unsigned *c); +extern void write_dcache(struct lsof_context *ctx); # endif /* defined(HASDCACHE) */ # if defined(HASFIFONODE) -_PROTOTYPE(extern int readfifonode, (KA_T fa, struct fifonode *f)); +extern int readfifonode(struct lsof_context *ctx, KA_T fa, struct fifonode *f); # endif /* defined(HASFIFONODE) */ # if defined(HASFSTRUCT) -_PROTOTYPE(extern char *print_fflags, (long ffg, long pof)); +extern char *print_fflags(struct lsof_context *ctx, long ffg, long pof); # endif /* defined(HASFSTRUCT) */ # if defined(HASGNODE) -_PROTOTYPE(extern int readgnode, (KA_T ga, struct gnode *g)); +extern int readgnode(struct lsof_context *ctx, KA_T ga, struct gnode *g); # endif /* defined(HASGNODE) */ # if defined(HASKQUEUE) -_PROTOTYPE(extern void process_kqueue, (KA_T ka)); +extern void process_kqueue(struct lsof_context *ctx, KA_T ka); # endif /* defined(HASKQUEUE) */ # if defined(HASHSNODE) -_PROTOTYPE(extern int readhsnode, (KA_T ha, struct hsnode *h)); +extern int readhsnode(struct lsof_context *ctx, KA_T ha, struct hsnode *h); # endif /* defined(HASHSNODE) */ # if defined(HASINODE) -_PROTOTYPE(extern int readinode, (KA_T ia, struct inode *i)); +extern int readinode(struct lsof_context *ctx, KA_T ia, struct inode *i); # endif /* defined(HASINODE) */ # if defined(HASNCACHE) -_PROTOTYPE(extern void ncache_load, (void)); -_PROTOTYPE(extern char *ncache_lookup, (char *buf, int blen, int *fp)); +extern void ncache_load(struct lsof_context *ctx); +extern char *ncache_lookup(struct lsof_context *ctx, char *buf, int blen, + int *fp); # endif /* defined(HASNCACHE) */ # if defined(HASNLIST) -_PROTOTYPE(extern void build_Nl, (struct drive_Nl * d)); -_PROTOTYPE(extern int get_Nl_value, (char *nn, struct drive_Nl *d, KA_T *v)); +extern void build_Nl(struct lsof_context *ctx, struct drive_Nl *d); +extern int get_Nl_value(char *nn, struct drive_Nl *d, KA_T *v); # endif /* defined(HASNLIST) */ # if defined(HASPIPENODE) -_PROTOTYPE(extern int readpipenode, (KA_T pa, struct pipenode *p)); +extern int readpipenode(struct lsof_context *ctx, KA_T pa, struct pipenode *p); # endif /* defined(HASPIPENODE) */ # if defined(HASPRINTDEV) -_PROTOTYPE(extern char *HASPRINTDEV, (struct lfile * lf, dev_t *dev)); +extern char *HASPRINTDEV(struct lfile *lf, dev_t *dev); # endif /* defined(HASPRINTDEV) */ # if defined(HASPRINTINO) -_PROTOTYPE(extern char *HASPRINTINO, (struct lfile * lf)); +extern char *HASPRINTINO(struct lfile *lf); # endif /* defined(HASPRINTINO) */ # if defined(HASPRINTNM) -_PROTOTYPE(extern void HASPRINTNM, (struct lfile * lf)); +extern void HASPRINTNM(struct lsof_context *ctx, struct lfile *lf); # endif /* defined(HASPRINTNM) */ # if defined(HASPRINTOFF) -_PROTOTYPE(extern char *HASPRINTOFF, (struct lfile * lf, int ty)); +extern char *HASPRINTOFF(struct lfile *lf, int ty); # endif /* defined(HASPRINTOFF) */ # if defined(HASPRIVNMCACHE) -_PROTOTYPE(extern int HASPRIVNMCACHE, (struct lfile * lf)); +extern int HASPRIVNMCACHE(struct lsof_context *ctx, struct lfile *lf); # endif /* defined(HASPRIVNMCACHE) */ # if !defined(HASPRIVPRIPP) -_PROTOTYPE(extern void printiproto, (int p)); +extern void printiproto(int p); # endif /* !defined(HASPRIVPRIPP) */ # if defined(HASRNODE) -_PROTOTYPE(extern int readrnode, (KA_T ra, struct rnode *r)); +extern int readrnode(struct lsof_context *ctx, KA_T ra, struct rnode *r); # endif /* defined(HASRNODE) */ # if defined(HASSPECDEVD) -_PROTOTYPE(extern void HASSPECDEVD, (char *p, struct stat *s)); +extern void HASSPECDEVD(struct lsof_context *ctx, char *p, struct stat *s); # endif /* defined(HASSPECDEVD) */ # if defined(HASSNODE) -_PROTOTYPE(extern int readsnode, (KA_T sa, struct snode *s)); +extern int readsnode(struct lsof_context *ctx, KA_T sa, struct snode *s); # endif /* defined(HASSNODE) */ # if defined(HASSTREAMS) -_PROTOTYPE(extern int readstdata, (KA_T addr, struct stdata *buf)); -_PROTOTYPE(extern int readsthead, (KA_T addr, struct queue *buf)); -_PROTOTYPE(extern int readstidnm, (KA_T addr, char *buf, READLEN_T len)); -_PROTOTYPE(extern int readstmin, (KA_T addr, struct module_info *buf)); -_PROTOTYPE(extern int readstqinit, (KA_T addr, struct qinit *buf)); +extern int readstdata(struct lsof_context *ctx, KA_T addr, struct stdata *buf); +extern int readsthead(struct lsof_context *ctx, KA_T addr, struct queue *buf); +extern int readstidnm(struct lsof_context *ctx, KA_T addr, char *buf, + READLEN_T len); +extern int readstmin(struct lsof_context *ctx, KA_T addr, + struct module_info *buf); +extern int readstqinit(struct lsof_context *ctx, KA_T addr, struct qinit *buf); # endif /* defined(HASSTREAMS) */ # if defined(HASTMPNODE) -_PROTOTYPE(extern int readtnode, (KA_T ta, struct tmpnode *t)); +extern int readtnode(struct lsof_context *ctx, KA_T ta, struct tmpnode *t); # endif /* defined(HASTMPNODE) */ # if defined(HASVNODE) -_PROTOTYPE(extern int readvnode, (KA_T va, struct vnode *v)); +extern int readvnode(struct lsof_context *ctx, KA_T va, struct vnode *v); # endif /* defined(HASVNODE) */ #endif /* !defined(PROTO_H) */ diff --git a/lib/rdev.c b/lib/rdev.c index 0d5afb0f..96a52970 100644 --- a/lib/rdev.c +++ b/lib/rdev.c @@ -33,7 +33,8 @@ #if defined(USE_LIB_READDEV) -_PROTOTYPE(static int rmdupdev, (struct l_dev * **dp, int n, char *nm)); +static int rmdupdev(struct lsof_context *ctx, struct l_dev ***dp, int n, + char *nm); /* * To use this source file: @@ -104,7 +105,8 @@ _PROTOTYPE(static int rmdupdev, (struct l_dev * **dp, int n, char *nm)); * readdev() - read device names, modes and types */ -void readdev(skip) int skip; /* skip device cache read if 1 */ +void readdev(struct lsof_context *ctx, + int skip) /* skip device cache read if 1 */ { # if defined(HAS_STD_CLONE) && HAS_STD_CLONE == 1 @@ -138,7 +140,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ */ if (!skip) { if (DCstate == 2 || DCstate == 3) { - if ((dcrd = read_dcache()) == 0) + if ((dcrd = read_dcache(ctx)) == 0) return; } } else @@ -147,7 +149,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ Dstkn = Dstkx = 0; Dstk = (char **)NULL; - (void)stkdir("/dev"); + (void)stkdir(ctx, "/dev"); /* * Unstack the next /dev or /dev/ directory. */ @@ -173,7 +175,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ mkstrcat(Dstk[Dstkx], -1, "/", 1, (char *)NULL, -1, &pl))) { (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(Dstk[Dstkx], stderr, 1); - Error(); + Error(ctx); } (void)free((FREE_P *)Dstk[Dstkx]); Dstk[Dstkx] = (char *)NULL; @@ -202,7 +204,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for: ", Pn); safestrprt(path, stderr, 0); safestrprtn(dp->d_name, dnamlen, stderr, 1); - Error(); + Error(ctx); } if (RDEV_STATFN(fp, &sb) != 0) { if (errno == ENOENT) /* a sym link to nowhere? */ @@ -225,7 +227,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * processing. */ if ((sb.st_mode & S_IFMT) == S_IFDIR) { - (void)stkdir(fp); + (void)stkdir(ctx, fp); continue; } if ((sb.st_mode & S_IFMT) == S_IFCHR) { @@ -245,7 +247,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!Devtp) { (void)fprintf( stderr, "%s: no space for character device\n", Pn); - Error(); + Error(ctx); } } Devtp[i].rdev = RDEV_EXPDEV(sb.st_rdev); @@ -253,7 +255,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!(Devtp[i].name = mkstrcpy(fp, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for device name: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } Devtp[i].v = 0; @@ -267,7 +269,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for clone device: ", Pn); safestrprt(fp, stderr, 1); - Error(); + Error(ctx); } c->dx = i; c->next = Clone; @@ -296,7 +298,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ if (!BDevtp) { (void)fprintf(stderr, "%s: no space for block device\n", Pn); - Error(); + Error(ctx); } } BDevtp[j].name = fp; @@ -338,14 +340,14 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (MALLOC_S)(sizeof(struct l_dev *) * BNdev)))) { (void)fprintf(stderr, "%s: no space for block device sort pointers\n", Pn); - Error(); + Error(ctx); } for (j = 0; j < BNdev; j++) { BSdev[j] = &BDevtp[j]; } (void)qsort((QSORT_P *)BSdev, (size_t)BNdev, (size_t)sizeof(struct l_dev *), compdev); - BNdev = rmdupdev(&BSdev, BNdev, "block"); + BNdev = rmdupdev(ctx, &BSdev, BNdev, "block"); } # if !defined(NOWARNBLKDEV) @@ -367,17 +369,17 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ (void)fprintf(stderr, "%s: no space for character device sort pointers\n", Pn); - Error(); + Error(ctx); } for (i = 0; i < Ndev; i++) { Sdev[i] = &Devtp[i]; } (void)qsort((QSORT_P *)Sdev, (size_t)Ndev, (size_t)sizeof(struct l_dev *), compdev); - Ndev = rmdupdev(&Sdev, Ndev, "char"); + Ndev = rmdupdev(ctx, &Sdev, Ndev, "char"); } else { (void)fprintf(stderr, "%s: no character devices found\n", Pn); - Error(); + Error(ctx); } # if defined(HASDCACHE) @@ -385,7 +387,7 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * Write device cache file, as required. */ if (DCstate == 1 || (DCstate == 3 && dcrd)) - write_dcache(); + write_dcache(ctx); # endif /* defined(HASDCACHE) */ } @@ -394,14 +396,14 @@ void readdev(skip) int skip; /* skip device cache read if 1 */ * rereaddev() - reread device names, modes and types */ -void rereaddev() { - (void)clr_devtab(); +void rereaddev(struct lsof_context *ctx) { + (void)clr_devtab(ctx); # if defined(DCACHE_CLR) (void)DCACHE_CLR(); # endif /* defined(DCACHE_CLR) */ - readdev(1); + readdev(ctx, 1); DCunsafe = 0; } # endif /* defined(HASDCACHE) */ @@ -410,10 +412,10 @@ void rereaddev() { * rmdupdev() - remove duplicate (major/minor/inode) devices */ -static int rmdupdev(dp, n, nm) -struct l_dev ***dp; /* device table pointers address */ -int n; /* number of pointers */ -char *nm; /* device table name for error message */ +static int rmdupdev(struct lsof_context *ctx, + struct l_dev ***dp, /* device table pointers address */ + int n, /* number of pointers */ + char *nm) /* device table name for error message */ { # if defined(HAS_STD_CLONE) && HAS_STD_CLONE == 1 @@ -455,7 +457,7 @@ char *nm; /* device table name for error message */ if (!(*dp = (struct l_dev **)realloc( (MALLOC_P *)*dp, (MALLOC_S)(j * sizeof(struct l_dev *))))) { (void)fprintf(stderr, "%s: can't realloc %s device pointers\n", Pn, nm); - Error(); + Error(ctx); } return (j); } @@ -467,8 +469,8 @@ char *nm; /* device table name for error message */ * Note: rereads entire device table when an entry can't be verified. */ -int vfy_dev(dp) -struct l_dev *dp; /* device table pointer */ +int vfy_dev(struct lsof_context *ctx, + struct l_dev *dp) /* device table pointer */ { struct stat sb; @@ -476,7 +478,7 @@ struct l_dev *dp; /* device table pointer */ return (1); if (RDEV_STATFN(dp->name, &sb) != 0 || dp->rdev != RDEV_EXPDEV(sb.st_rdev) || dp->inode != sb.st_ino) { - (void)rereaddev(); + (void)rereaddev(ctx); return (0); } dp->v = 1; diff --git a/lib/rmnt.c b/lib/rmnt.c index 89d7e202..36335c87 100644 --- a/lib/rmnt.c +++ b/lib/rmnt.c @@ -72,7 +72,7 @@ static int Lmist = 0; /* Lmi status */ * readmnt() - read mount table */ -struct mounts *readmnt() { +struct mounts *readmnt(struct lsof_context *ctx) { char *dn = (char *)NULL; char *ln; FILE *mfp; @@ -88,7 +88,7 @@ struct mounts *readmnt() { */ if (!(mfp = setmntent(MOUNTED, "r"))) { (void)fprintf(stderr, "%s: can't access %s\n", Pn, MOUNTED); - Error(); + Error(ctx); } /* * Read mount table entries. @@ -165,7 +165,7 @@ struct mounts *readmnt() { (void)fprintf(stderr, " ("); safestrprt(mp->mnt_dir, stderr, 0); (void)fprintf(stderr, ")\n"); - Error(); + Error(ctx); } mtp->dir = dn; dn = (char *)NULL; @@ -183,7 +183,7 @@ struct mounts *readmnt() { mkstrcpy(mp->RMNT_FSTYPE, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for fstype (%s): %s\n", Pn, mtp->dir, mp->RMNT_FSTYPE); - Error(); + Error(ctx); } (void)strcpy(mtp->MOUNTS_FSTYPE, mp->RMNT_FSTYPE); # endif /* defined(RMNT_FSTYP) && defined(MOUNTS_FSTYP) */ diff --git a/lib/rnam.c b/lib/rnam.c index ca1db9b5..312ef757 100644 --- a/lib/rnam.c +++ b/lib/rnam.c @@ -124,17 +124,17 @@ static int Ncfirst = 1; /* first-call status */ # if defined(NCACHE_NODEID) # define ncachehash(i, n) \ Nchash + (((((int)(n) >> 2) + ((int)(i))) * 31415) & Mch) -_PROTOTYPE(static struct l_nch *ncache_addr, (unsigned long i, KA_T na)); +static struct l_nch *ncache_addr(unsigned long i, KA_T na); # else /* !defined(NCACHE_NODEID) */ # define ncachehash(n) Nchash + ((((int)(n) >> 2) * 31415) & Mch) -_PROTOTYPE(static struct l_nch *ncache_addr, (KA_T na)); +static struct l_nch *ncache_addr(KA_T na); # endif /* defined(NCACHE_NODEID) */ # define DEFNCACHESZ 1024 /* local size if X_NCSIZE kernel value < 1 */ # define LNCHINCRSZ 64 /* local size increment */ # if !defined(NCACHE_NO_ROOT) -_PROTOTYPE(static int ncache_isroot, (KA_T na, char *cp)); +static int ncache_isroot(KA_T na, char *cp); # endif /* !defined(NCACHE_NO_ROOT) */ /* @@ -144,13 +144,12 @@ _PROTOTYPE(static int ncache_isroot, (KA_T na, char *cp)); static struct l_nch * # if defined(NCACHE_NODEID) -ncache_addr(i, na) -unsigned long i; /* node's capability ID */ -# else /* !defined(NCACHE_NODEID) */ -ncache_addr(na) -# endif /* defined(NCACHE_NODEID) */ +ncache_addr(unsigned long i, /* node's capability ID */ +# else /* !defined(NCACHE_NODEID) */ +ncache_addr( +# endif /* defined(NCACHE_NODEID) */ -KA_T na; /* node's address */ + KA_T na) /* node's address */ { struct l_nch **hp; @@ -178,9 +177,9 @@ KA_T na; /* node's address */ * ncache_isroot() - is head of name cache path a file system root? */ -static int ncache_isroot(na, cp) -KA_T na; /* kernel node address */ -char *cp; /* partial path */ +static int ncache_isroot(struct lsof_context *ctx, /* context */ + KA_T na, /* kernel node address */ + char *cp) /* partial path */ { char buf[MAXPATHLEN]; int i; @@ -211,7 +210,7 @@ char *cp; /* partial path */ * matches the one we have for this file. If it does, then the path is * complete. */ - if (kread((KA_T)na, (char *)&v, sizeof(v)) || v.v_type != VDIR || + if (kread(ctx, (KA_T)na, (char *)&v, sizeof(v)) || v.v_type != VDIR || !(v.v_flag & VROOT)) { /* @@ -250,7 +249,7 @@ char *cp; /* partial path */ } if (!nc) { (void)fprintf(stderr, "%s: no space for root node table\n", Pn); - Error(); + Error(ctx); } nca += 10; } @@ -291,7 +290,7 @@ void ncache_load() { */ v = (KA_T)0; if (get_Nl_value(X_NCSIZE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&Nc, sizeof(Nc))) { + kread(ctx, (KA_T)v, (char *)&Nc, sizeof(Nc))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read name cache size: %s\n", @@ -315,7 +314,7 @@ void ncache_load() { */ v = (KA_T)0; if (get_Nl_value(X_NCACHE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&kp, sizeof(kp))) { + kread(ctx, (KA_T)v, (char *)&kp, sizeof(kp))) { if (!Fwarn) (void)fprintf( stderr, "%s: WARNING: can't read name cache address: %s\n", @@ -337,7 +336,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: can't allocate name cache space: %d\n", Pn, len); - Error(); + Error(ctx); } # endif /* defined(NCACHE_NXT) */ @@ -353,7 +352,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: no space for %d byte local name cache\n", Pn, len); - Error(); + Error(ctx); } } else { @@ -377,7 +376,7 @@ void ncache_load() { /* * Read the kernel's name cache. */ - if (kread(kp, (char *)kca, (Nc * sizeof(struct NCACHE)))) { + if (kread(ctx, kp, (char *)kca, (Nc * sizeof(struct NCACHE)))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read kernel's name cache: %s\n", @@ -400,7 +399,7 @@ void ncache_load() { { # if defined(NCACHE_NXT) - if (kread(kp, (char *)kc, sizeof(nc))) + if (kread(ctx, kp, (char *)kc, sizeof(nc))) break; if ((kp = (KA_T)kc->NCACHE_NXT) == kf) kp = (KA_T)NULL; @@ -423,7 +422,7 @@ void ncache_load() { (void)fprintf( stderr, "%s: no more space for %d entry local name cache\n", Pn, Nc); - Error(); + Error(ctx); } lc = &Ncache[n]; } @@ -499,7 +498,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: no space for %d name cache hash pointers\n", Pn, Nch + Nc); - Error(); + Error(ctx); } for (i = 0, lc = Ncache; i < Nc; i++, lc++) { @@ -549,10 +548,9 @@ void ncache_load() { * ncache_lookup() - look up a node's name in the kernel's name cache */ -char *ncache_lookup(buf, blen, fp) -char *buf; /* receiving name buffer */ -int blen; /* receiving buffer length */ -int *fp; /* full path reply */ +char *ncache_lookup(char *buf, /* receiving name buffer */ + int blen, /* receiving buffer length */ + int *fp) /* full path reply */ { char *cp = buf; struct l_nch *lc; diff --git a/lib/rnch.c b/lib/rnch.c index 944883b0..ef13d1bf 100644 --- a/lib/rnch.c +++ b/lib/rnch.c @@ -147,15 +147,15 @@ static int NegVNSt = 0; /* NegVN status: 0 = not loaded */ # endif /* defined(NCACHE_NEGVN) */ # if defined(NCACHE_NODEID) -_PROTOTYPE(static struct l_nch *ncache_addr, (unsigned long i, KA_T v)); +static struct l_nch *ncache_addr(unsigned long i, KA_T v); # define ncachehash(i, v) \ Nchash + (((((int)(v) >> 2) + ((int)(i))) * 31415) & Mch) # else /* !defined(NCACHE_NODEID) */ -_PROTOTYPE(static struct l_nch *ncache_addr, (KA_T v)); +static struct l_nch *ncache_addr(KA_T v); # define ncachehash(v) Nchash + ((((int)(v) >> 2) * 31415) & Mch) # endif /* defined(NCACHE_NODEID) */ -_PROTOTYPE(static int ncache_isroot, (KA_T va, char *cp)); +static int ncache_isroot(KA_T va, char *cp); # define DEFNCACHESZ 1024 /* local size if X_NCSIZE kernel value < 1 */ # define LNCHINCRSZ 64 /* local size increment */ @@ -180,19 +180,11 @@ _PROTOTYPE(static int ncache_isroot, (KA_T va, char *cp)); * ncache_addr() - look up a node's local ncache address */ -static struct l_nch * - -# if defined(NCACHE_NODEID) -ncache_addr(i, v) -# else /* !defined(NCACHE_NODEID) */ -ncache_addr(v) -# endif /* defined(NCACHE_NODEID) */ - +static struct l_nch *ncache_addr( # if defined(NCACHE_NODEID) -unsigned long i; /* capability ID */ -# endif /* defined(NCACHE_NODEID) */ - -KA_T v; /* vnode's address */ + unsigned long i, /* capability ID */ +# endif /* defined(NCACHE_NODEID) */ + KA_T v) /* vnode's address */ { struct l_nch **hp; @@ -219,9 +211,8 @@ KA_T v; /* vnode's address */ * ncache_isroot() - is head of name cache path a file system root? */ -static int ncache_isroot(va, cp) -KA_T va; /* kernel vnode address */ -char *cp; /* partial path */ +static int ncache_isroot(KA_T va, /* kernel vnode address */ + char *cp) /* partial path */ { char buf[MAXPATHLEN]; int i; @@ -252,7 +243,7 @@ char *cp; /* partial path */ * matches the one we have for this file. If it does, then the path is * complete. */ - if (kread((KA_T)va, (char *)&v, sizeof(v)) || v.v_type != VDIR || + if (kread(ctx, (KA_T)va, (char *)&v, sizeof(v)) || v.v_type != VDIR || !(v.v_flag & VROOT)) { /* @@ -290,7 +281,7 @@ char *cp; /* partial path */ vc = (KA_T *)realloc(vc, len); if (!vc) { (void)fprintf(stderr, "%s: no space for root vnode table\n", Pn); - Error(); + Error(ctx); } } vc[vcn++] = va; @@ -301,7 +292,7 @@ char *cp; /* partial path */ * ncache_load() - load the kernel's name cache */ -void ncache_load() { +void ncache_load(struct lsof_context *ctx) { char *cp, *np; struct l_nch **hp, *lc; int i, len, n; @@ -337,7 +328,7 @@ void ncache_load() { # if defined(X_NCSIZE) v = (KA_T)0; if (get_Nl_value(X_NCSIZE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&Nc, sizeof(Nc))) { + kread(ctx, (KA_T)v, (char *)&Nc, sizeof(Nc))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read name cache size: %s\n", @@ -389,7 +380,7 @@ void ncache_load() { # else /* !defined(ADDR_NCACHE) */ v = (KA_T)0; if (get_Nl_value(X_NCACHE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&kp, sizeof(kp))) { + kread(ctx, (KA_T)v, (char *)&kp, sizeof(kp))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read name cache ptr: %s\n", @@ -410,7 +401,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: can't allocate name cache space: %d\n", Pn, len); - Error(); + Error(ctx); } # endif /* !defined(NCACHE_NXT) */ @@ -426,7 +417,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: no space for %d byte local name cache\n", Pn, len); - Error(); + Error(ctx); } } else { @@ -463,7 +454,7 @@ void ncache_load() { /* * Read the kernel's name cache. */ - if (kread(kp, (char *)kca, (Nc * sizeof(struct ncache)))) { + if (kread(ctx, kp, (char *)kca, (Nc * sizeof(struct ncache)))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read kernel's name cache: %s\n", @@ -486,7 +477,7 @@ void ncache_load() { { # if defined(NCACHE_NXT) - if (kread(kp, (char *)kc, sizeof(nc))) + if (kread(ctx, kp, (char *)kc, sizeof(nc))) break; if ((kp = (KA_T)kc->NCACHE_NXT) == kf) kp = (KA_T)NULL; @@ -515,10 +506,10 @@ void ncache_load() { stderr, "%s: can't allocate %d byte temporary name buffer\n", Pn, na); - Error(); + Error(ctx); } } - if (!kc->NCACHE_NAME || kread((KA_T)kc->NCACHE_NAME, nb, len)) + if (!kc->NCACHE_NAME || kread(ctx, (KA_T)kc->NCACHE_NAME, nb, len)) continue; np = nb; # else /* !defined(HASDNLCPTR) */ @@ -541,7 +532,7 @@ void ncache_load() { (void)fprintf( stderr, "%s: can't allocate %d bytes for name cache name: %s\n", Pn, len + 1, np); - Error(); + Error(ctx); } (void)strncpy(cp, np, len); cp[len] = '\0'; @@ -559,7 +550,7 @@ void ncache_load() { (void)fprintf( stderr, "%s: no more space for %d entry local name cache\n", Pn, Nc); - Error(); + Error(ctx); } lc = &Ncache[n]; iNc = Nc; @@ -644,7 +635,7 @@ void ncache_load() { (void)fprintf(stderr, "%s: no space for %d name cache hash pointers\n", Pn, Nch + Nc); - Error(); + Error(ctx); } for (i = 0, lc = Ncache; i < Nc; i++, lc++) { @@ -697,10 +688,9 @@ void ncache_load() { * ncache_lookup() - look up a node's name in the kernel's name cache */ -char *ncache_lookup(buf, blen, fp) -char *buf; /* receiving name buffer */ -int blen; /* receiving buffer length */ -int *fp; /* full path reply */ +char *ncache_lookup(char *buf, /* receiving name buffer */ + int blen, /* receiving buffer length */ + int *fp) /* full path reply */ { char *cp = buf; struct l_nch *lc; diff --git a/lib/rnmh.c b/lib/rnmh.c index 97c2380a..8df72d8e 100644 --- a/lib/rnmh.c +++ b/lib/rnmh.c @@ -159,14 +159,14 @@ static struct l_nch **Nchash = (struct l_nch **)NULL; # if defined(NCACHE_NODEID) # define ncachehash(i, n) \ Nchash + (((((int)(n) >> 2) + ((int)(i))) * 31415) & Mch) -_PROTOTYPE(static struct l_nch *ncache_addr, (unsigned long i, KA_T na)); +static struct l_nch *ncache_addr(unsigned long i, KA_T na); # else /* !defined(NCACHE_NODEID) */ # define ncachehash(n) Nchash + ((((int)(n) >> 2) * 31415) & Mch) -_PROTOTYPE(static struct l_nch *ncache_addr, (KA_T na)); +static struct l_nch *ncache_addr(KA_T na); # endif /* defined(NCACHE_NODEID) */ # if !defined(NCACHE_NO_ROOT) -_PROTOTYPE(static int ncache_isroot, (KA_T na, char *cp)); +static int ncache_isroot(struct lsof_context *ctx, KA_T na, char *cp); # endif /* !defined(NCACHE_NO_ROOT) */ /* @@ -176,13 +176,11 @@ _PROTOTYPE(static int ncache_isroot, (KA_T na, char *cp)); static struct l_nch * # if defined(NCACHE_NODEID) -ncache_addr(i, na) -unsigned long i; /* node's capability ID */ -# else /* !defined(NCACHE_NODEID) */ -ncache_addr(na) -# endif /* defined(NCACHE_NODEID) */ - -KA_T na; /* node's address */ +ncache_addr(unsigned long i, /* node's capability ID */ +# else /* !defined(NCACHE_NODEID) */ +ncache_addr( +# endif /* defined(NCACHE_NODEID) */ + KA_T na) /* node's address */ { struct l_nch **hp; @@ -210,9 +208,9 @@ KA_T na; /* node's address */ * ncache_isroot() - is head of name cache path a file system root? */ -static int ncache_isroot(na, cp) -KA_T na; /* kernel node address */ -char *cp; /* partial path */ +static int ncache_isroot(struct lsof_context *ctx, + KA_T na, /* kernel node address */ + char *cp) /* partial path */ { char buf[MAXPATHLEN]; int i; @@ -243,7 +241,7 @@ char *cp; /* partial path */ * matches the one we have for this file. If it does, then the path is * complete. */ - if (kread((KA_T)na, (char *)&v, sizeof(v)) || v.v_type != VDIR || + if (kread(ctx, (KA_T)na, (char *)&v, sizeof(v)) || v.v_type != VDIR || !(v.VNODE_VFLAG & NCACHE_VROOT)) { /* @@ -254,7 +252,7 @@ char *cp; /* partial path */ return (0); if ((len + 1 + strlen(cp) + 1) > sizeof(buf)) return (0); - for (mtp = readmnt(); mtp; mtp = mtp->next) { + for (mtp = readmnt(ctx); mtp; mtp = mtp->next) { if (!mtp->dir || !mtp->inode) continue; if (strcmp(Lf->fsdir, mtp->dir) == 0) @@ -266,7 +264,8 @@ char *cp; /* partial path */ if (buf[len - 1] != '/') buf[len++] = '/'; (void)strcpy(&buf[len], cp); - if (statsafely(buf, &sb) != 0 || (unsigned long)sb.st_ino != Lf->inode) + if (statsafely(ctx, buf, &sb) != 0 || + (unsigned long)sb.st_ino != Lf->inode) return (0); } /* @@ -282,7 +281,7 @@ char *cp; /* partial path */ } if (!nc) { (void)fprintf(stderr, "%s: no space for root node table\n", Pn); - Error(); + Error(ctx); } nca += 10; } @@ -295,7 +294,7 @@ char *cp; /* partial path */ * ncache_load() - load the kernel's name cache */ -void ncache_load() { +void ncache_load(struct lsof_context *ctx) { struct NCACHE c; struct l_nch **hp, *ln; KA_T ka, knx; @@ -342,7 +341,7 @@ void ncache_load() { */ v = (KA_T)0; if (get_Nl_value(X_NCSIZE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&khsz, sizeof(khsz))) { + kread(ctx, (KA_T)v, (char *)&khsz, sizeof(khsz))) { if (!Fwarn) (void)fprintf(stderr, "%s: WARNING: can't read name cache hash size: %s\n", @@ -363,7 +362,7 @@ void ncache_load() { ka = (KA_T)0; v = (KA_T)0; if (get_Nl_value(X_NCACHE, (struct drive_Nl *)NULL, &v) < 0 || !v || - kread((KA_T)v, (char *)&ka, sizeof(ka)) || !ka) { + kread(ctx, (KA_T)v, (char *)&ka, sizeof(ka)) || !ka) { if (!Fwarn) (void)fprintf( stderr, @@ -386,11 +385,11 @@ void ncache_load() { stderr, "%s: can't allocate %d bytes for name cache hash table\n", Pn, len); - Error(); + Error(ctx); } khpl = len; } - if (kread((KA_T)ka, (char *)khp, len)) { + if (kread(ctx, (KA_T)ka, (char *)khp, len)) { (void)fprintf(stderr, "%s: can't read name cache hash pointers from: %s\n", Pn, print_kptr(ka, (char *)NULL, 0)); @@ -413,7 +412,7 @@ void ncache_load() { Pn); break; } - if (kread(ka, (char *)&c, sizeof(c))) + if (kread(ctx, ka, (char *)&c, sizeof(c))) break; knx = (KA_T)c.NCACHE_NXT; if (!c.NCACHE_NODEADDR) @@ -427,7 +426,7 @@ void ncache_load() { * If it's possible to read the first four characters of the name, * do so and check for "." and "..". */ - if (!c.NCACHE_NM || kread((KA_T)c.NCACHE_NM, nbf, 4)) + if (!c.NCACHE_NM || kread(ctx, (KA_T)c.NCACHE_NM, nbf, 4)) continue; if (nbf[0] == '.') { if (!nbf[1] || ((nbf[1] == '.') && !nbf[2])) @@ -448,7 +447,7 @@ void ncache_load() { nbf[len + rl] = '\0'; } nk = (KA_T)((char *)c.NCACHE_NM + len); - if (kread(nk, np, rl)) { + if (kread(ctx, nk, np, rl)) { rl = -1; break; } @@ -489,7 +488,7 @@ void ncache_load() { stderr, "%s: can't allocate %d local name cache bytes\n", Pn, nlcl); - Error(); + Error(ctx); } lcl = nlcl; } @@ -520,7 +519,7 @@ void ncache_load() { */ if (cin > 0) (void)strncpy(lc->nm, c.NCACHE_NM, cin); - if (kread(ka + (KA_T)(nmo + cin), &lc->nm[cin], len - cin)) + if (kread(ctx, ka + (KA_T)(nmo + cin), &lc->nm[cin], len - cin)) continue; if ((cin < 2) && (len < 3) && (lc->nm[0] == '.')) { if (len == 1 || (len == 2 && lc->nm[1] == '.')) @@ -582,7 +581,7 @@ void ncache_load() { (void)fprintf( stderr, "%s: no space for %d local name cache hash pointers\n", Pn, len); - Error(); + Error(ctx); } for (lc = Ncache; lc; lc = lc->next) { @@ -624,10 +623,10 @@ void ncache_load() { * ncache_lookup() - look up a node's name in the kernel's name cache */ -char *ncache_lookup(buf, blen, fp) -char *buf; /* receiving name buffer */ -int blen; /* receiving buffer length */ -int *fp; /* full path reply */ +char *ncache_lookup(struct lsof_context *ctx, + char *buf, /* receiving name buffer */ + int blen, /* receiving buffer length */ + int *fp) /* full path reply */ { char *cp = buf; struct l_nch *lc; @@ -665,7 +664,7 @@ int *fp; /* full path reply */ */ if (!Lf->fsdir || !Lf->dev_def || Lf->inp_ty != 1) return ((char *)NULL); - for (mtp = readmnt(); mtp; mtp = mtp->next) { + for (mtp = readmnt(ctx); mtp; mtp = mtp->next) { if (!mtp->dir || !mtp->inode) continue; if (Lf->dev == mtp->dev && mtp->inode == Lf->inode && @@ -693,7 +692,7 @@ int *fp; /* full path reply */ if (!lc->pla) { # if !defined(NCACHE_NO_ROOT) - if (ncache_isroot(lc->pa, cp)) + if (ncache_isroot(ctx, lc->pa, cp)) *fp = 1; # endif /* !defined(NCACHE_NO_ROOT) */ diff --git a/lib/rnmt.c b/lib/rnmt.c index 35c4bf5c..709aad57 100644 --- a/lib/rnmt.c +++ b/lib/rnmt.c @@ -116,7 +116,8 @@ static int sanity_check_namecache(const struct namecache *nc) { return 0; } -static void ncache_walk(KA_T ncp, const struct lnc *plnc) { +static void ncache_walk(struct lsof_context *ctx, KA_T ncp, + const struct lnc *plnc) { struct l_nch *lc; static struct vnode_impl vi; static struct namecache nc; @@ -124,11 +125,11 @@ static void ncache_walk(KA_T ncp, const struct lnc *plnc) { KA_T vp; KA_T left, right; - if (kread(ncp, (char *)&nc, sizeof(nc))) { + if (kread(ctx, ncp, (char *)&nc, sizeof(nc))) { return; } vp = (KA_T)nc.nc_vp; - if (kread(vp, (char *)&vi, sizeof(vi))) { + if (kread(ctx, vp, (char *)&vi, sizeof(vi))) { vi.vi_vnode.v_type = VBAD; } left = (KA_T)nc.nc_tree.rb_nodes[0]; @@ -145,7 +146,7 @@ static void ncache_walk(KA_T ncp, const struct lnc *plnc) { ncache_walk(right, plnc); } -void ncache_load() { +void ncache_load(struct lsof_context *ctx) { KA_T rootvnode_addr; struct vnode_impl vi; @@ -153,9 +154,9 @@ void ncache_load() { if (get_Nl_value("rootvnode", (struct drive_Nl *)NULL, &rootvnode_addr) < 0 || !rootvnode_addr || - kread((KA_T)rootvnode_addr, (char *)&rootvnode_addr, + kread(ctx, (KA_T)rootvnode_addr, (char *)&rootvnode_addr, sizeof(rootvnode_addr)) || - kread((KA_T)rootvnode_addr, (char *)&vi, sizeof(vi))) { + kread(ctx, (KA_T)rootvnode_addr, (char *)&vi, sizeof(vi))) { errx(1, "can't read rootvnode\n"); } diff --git a/src/arg.c b/src/arg.c index 525584da..69813de0 100644 --- a/src/arg.c +++ b/src/arg.c @@ -29,6 +29,7 @@ */ #include "common.h" +#include "cli.h" #include /* @@ -47,24 +48,23 @@ static int NCmdRxA = 0; /* space allocated to CmdRx[] */ * Local function prototypes */ -_PROTOTYPE(static int ckfd_range, - (char *first, char *dash, char *last, int *lo, int *hi)); -_PROTOTYPE(static int enter_fd_lst, (char *nm, int lo, int hi, int excl)); -_PROTOTYPE(static int enter_nwad, - (struct nwad * n, int sp, int ep, char *s, struct hostent *he)); -_PROTOTYPE(static struct hostent *lkup_hostnm, (char *hn, struct nwad *n)); -_PROTOTYPE(static char *isIPv4addr, (char *hn, unsigned char *a, int al)); +static int ckfd_range(char *first, char *dash, char *last, int *lo, int *hi); +static int enter_fd_lst(struct lsof_context *ctx, char *nm, int lo, int hi, + int excl); +static int enter_nwad(struct lsof_context *ctx, struct nwad *n, int sp, int ep, + char *s, struct hostent *he); +static struct hostent *lkup_hostnm(char *hn, struct nwad *n); +static char *isIPv4addr(char *hn, unsigned char *a, int al); /* * ckfd_range() - check fd range */ -static int ckfd_range(first, dash, last, lo, hi) -char *first; /* starting character */ -char *dash; /* '-' location */ -char *last; /* '\0' location */ -int *lo; /* returned low value */ -int *hi; /* returned high value */ +static int ckfd_range(char *first, /* starting character */ + char *dash, /* '-' location */ + char *last, /* '\0' location */ + int *lo, /* returned low value */ + int *hi) /* returned high value */ { char *cp; /* @@ -106,17 +106,16 @@ int *hi; /* returned high value */ * ck_file_arg() - check file arguments */ -int ck_file_arg(i, ac, av, fv, rs, sbp, accept_deleted_file) -int i; /* first file argument index */ -int ac; /* argument count */ -char *av[]; /* argument vector */ -int fv; /* Ffilesys value (real or temporary) */ -int rs; /* Readlink() status if argument count == 1: - * 0 = undone; 1 = done */ -struct stat *sbp; /* if non-NULL, pointer to stat(2) buffer - * when argument count == 1 */ -int accept_deleted_file; /* if non-zero, don't report an error even - * when the file doesn't exist. */ +int ck_file_arg(struct lsof_context *ctx, int i, /* first file argument index */ + int ac, /* argument count */ + char *av[], /* argument vector */ + int fv, /* Ffilesys value (real or temporary) */ + int rs, /* Readlink() status if argument count == 1: + * 0 = undone; 1 = done */ + struct stat *sbp, /* if non-NULL, pointer to stat(2) buffer + * when argument count == 1 */ + int accept_deleted_file) /* if non-zero, don't report an error + * even when the file doesn't exist. */ { char *ap, *fnm, *fsnm, *path; short err = 0; @@ -148,7 +147,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even if (rs && (ac == 1) && (i == 0)) path = av[i]; else { - if (!(path = Readlink(av[i]))) { + if (!(path = Readlink(ctx, av[i]))) { ErrStat = 1; continue; } @@ -167,7 +166,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even if (!(ap = (char *)malloc((MALLOC_S)(k + 1)))) { (void)fprintf(stderr, "%s: no space for copy of %s\n", Pn, path); - Error(); + Error(ctx); } (void)strncpy(ap, path, k); ap[k] = '\0'; @@ -177,7 +176,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even /* * Check for file system argument. */ - for (ftype = 1, mp = readmnt(), nm = 0; (fv != 1) && mp; + for (ftype = 1, mp = readmnt(ctx), nm = 0; (fv != 1) && mp; mp = mp->next) { fsm = 0; if (strcmp(mp->dir, path) == 0) @@ -215,7 +214,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even if (!mmp) { (void)fprintf(stderr, "%s: no space for mount pointers\n", Pn); - Error(); + Error(ctx); } } mmp[nm++] = mp; @@ -240,7 +239,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even */ if (!(sfp = (struct sfile *)malloc(sizeof(struct sfile)))) { (void)fprintf(stderr, "%s: no space for files\n", Pn); - Error(); + Error(ctx); } sfp->next = Sfile; Sfile = sfp; @@ -259,7 +258,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even if (sbp && (ac == 1)) sb = *sbp; else { - if (statsafely(fnm, &sb) != 0) { + if (statsafely(ctx, fnm, &sb) != 0) { int en = errno; if (!accept_deleted_file) { (void)fprintf(stderr, "%s: status error on ", Pn); @@ -273,7 +272,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even } #if defined(HASSPECDEVD) - (void)HASSPECDEVD(fnm, &sb); + (void)HASSPECDEVD(ctx, fnm, &sb); #endif /* defined(HASSPECDEVD) */ } sfp->i = (INODETYPE)sb.st_ino; @@ -351,7 +350,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even if (!(sfp->name = mkstrcpy(fnm, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for file name: ", Pn); safestrprt(fnm, stderr, 1); - Error(); + Error(ctx); } #if defined(HASPROCFS) @@ -370,7 +369,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even (void)fprintf(stderr, "%s: no space for file system name: ", Pn); safestrprt(fsnm, stderr, 1); - Error(); + Error(ctx); } #if defined(HASPROCFS) @@ -381,7 +380,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even (void)fprintf(stderr, "%s: no space for argument file name: ", Pn); safestrprt(av[i], stderr, 1); - Error(); + Error(ctx); } #if defined(HASPROCFS) @@ -432,7 +431,7 @@ int accept_deleted_file; /* if non-zero, don't report an error even (void)fprintf(stderr, "%s: no space for %s ID: ", Pn, Mtprocfs->dir); safestrprt(path, stderr, 1); - Error(); + Error(ctx); } pfi->pid = pid; pfi->f = 0; @@ -474,8 +473,8 @@ int accept_deleted_file; /* if non-zero, don't report an error even * ctrl_dcache() - enter device cache control */ -int ctrl_dcache(c) -char *c; /* control string */ +int ctrl_dcache(struct lsof_context *ctx, /* context */ + char *c) /* control string */ { int rc = 0; @@ -554,7 +553,7 @@ char *c; /* control string */ if (!(DCpathArg = mkstrcpy(c, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for -D path: ", Pn); safestrprt(c, stderr, 1); - Error(); + Error(ctx); } } return (0); @@ -565,8 +564,7 @@ char *c; /* control string */ * enter_cmd_rx() - enter command regular expression */ -int enter_cmd_rx(x) -char *x; /* regular expression */ +int enter_cmd_rx(struct lsof_context *ctx, char *x) /* regular expression */ { int bmod = 0; int bxmod = 0; @@ -666,7 +664,7 @@ char *x; /* regular expression */ if (!(xp = (char *)malloc(xl + 1))) { (void)fprintf(stderr, "%s: no regexp space for: ", Pn); safestrprt(x, stderr, 1); - Error(); + Error(ctx); } (void)strncpy(xp, xb, xl); xp[(int)xl] = '\0'; @@ -687,7 +685,7 @@ char *x; /* regular expression */ if (!CmdRx) { (void)fprintf(stderr, "%s: no space for regexp: ", Pn); safestrprt(x, stderr, 1); - Error(); + Error(ctx); } } i = NCmdRxU; @@ -721,9 +719,9 @@ char *x; /* regular expression */ * eliminated */ -int enter_efsys(e, rdlnk) -char *e; /* file system path */ -int rdlnk; /* avoid readlink(2) if non-zero */ +int enter_efsys(struct lsof_context *ctx, /* context */ + char *e, /* file system path */ + int rdlnk) /* avoid readlink(2) if non-zero */ { char *ec; /* pointer to copy of path */ efsys_list_t *ep; /* file system path list pointer */ @@ -740,12 +738,12 @@ int rdlnk; /* avoid readlink(2) if non-zero */ if (!(ec = mkstrcpy(e, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for -e string: ", Pn); safestrprt(e, stderr, 1); - Error(); + Error(ctx); } if (rdlnk) path = ec; else { - if (!(path = Readlink(ec))) + if (!(path = Readlink(ctx, ec))) return (1); } /* @@ -765,7 +763,7 @@ int rdlnk; /* avoid readlink(2) if non-zero */ } if (!(ep = (efsys_list_t *)malloc((MALLOC_S)(sizeof(efsys_list_t))))) { (void)fprintf(stderr, "%s: no space for \"-e %s\" entry\n", Pn, e); - Error(); + Error(ctx); } ep->path = path; ep->pathl = i; @@ -781,8 +779,8 @@ int rdlnk; /* avoid readlink(2) if non-zero */ * enter_fd() - enter file descriptor list for searching */ -int enter_fd(f) -char *f; /* file descriptor list pointer */ +int enter_fd(struct lsof_context *ctx, /* context */ + char *f) /* file descriptor list pointer */ { char c, *cp1, *cp2, *dash; int err, excl, hi, lo; @@ -797,7 +795,7 @@ char *f; /* file descriptor list pointer */ if (!(fc = mkstrcpy(f, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for fd string: ", Pn); safestrprt(f, stderr, 1); - Error(); + Error(ctx); } /* * Isolate each file descriptor in the comma-separated list, then enter it @@ -826,11 +824,11 @@ char *f; /* file descriptor list pointer */ if (ckfd_range(cp1, dash, cp2, &lo, &hi)) err = 1; else { - if (enter_fd_lst((char *)NULL, lo, hi, excl)) + if (enter_fd_lst(ctx, (char *)NULL, lo, hi, excl)) err = 1; } } else { - if (enter_fd_lst(cp1, 0, 0, excl)) + if (enter_fd_lst(ctx, cp1, 0, 0, excl)) err = 1; } } @@ -846,11 +844,11 @@ char *f; /* file descriptor list pointer */ * enter_fd_lst() - make an entry in the FD list, Fdl */ -static int enter_fd_lst(nm, lo, hi, excl) -char *nm; /* FD name (none if NULL) */ -int lo; /* FD low boundary (if nm NULL) */ -int hi; /* FD high boundary (if nm NULL) */ -int excl; /* exclusion on match */ +static int enter_fd_lst(struct lsof_context *ctx, /* context */ + char *nm, /* FD name (none if NULL) */ + int lo, /* FD low boundary (if nm NULL) */ + int hi, /* FD high boundary (if nm NULL) */ + int excl) /* exclusion on match */ { char buf[256], *cp; int n; @@ -890,7 +888,7 @@ int excl; /* exclusion on match */ */ if (!(f = (struct fd_lst *)malloc((MALLOC_S)sizeof(struct fd_lst)))) { (void)fprintf(stderr, "%s: no space for FD list entry\n", Pn); - Error(); + Error(ctx); } if (nm) { @@ -910,7 +908,7 @@ int excl; /* exclusion on match */ if (*cp) { if (!(f->nm = mkstrcpy(nm, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for copy of: %s\n", Pn, nm); - Error(); + Error(ctx); } lo = 1; hi = 0; @@ -955,11 +953,11 @@ int excl; /* exclusion on match */ #define EDDEFFNL 128 /* default file name length */ -int enter_dir(d, descend) -char *d; /* directory path name pointer */ -int descend; /* subdirectory descend flag: - * 0 = don't descend - * 1 = descend */ +int enter_dir(struct lsof_context *ctx, /* context */ + char *d, /* directory path name pointer */ + int descend) /* subdirectory descend flag: + * 0 = don't descend + * 1 = descend */ { char *av[2]; dev_t ddev; @@ -983,9 +981,9 @@ int descend; /* subdirectory descend flag: Pn); return (1); } - if (!(dn = Readlink(d))) + if (!(dn = Readlink(ctx, d))) return (1); - if (statsafely(dn, &sb)) { + if (statsafely(ctx, dn, &sb)) { if (!Fwarn) { en = errno; (void)fprintf(stderr, "%s: WARNING: can't stat(", Pn); @@ -1011,7 +1009,7 @@ int descend; /* subdirectory descend flag: } #if defined(HASSPECDEVD) - (void)HASSPECDEVD(dn, &sb); + (void)HASSPECDEVD(ctx, dn, &sb); #endif /* defined(HASSPECDEVD) */ ddev = sb.st_dev; @@ -1020,11 +1018,11 @@ int descend; /* subdirectory descend flag: */ Dstkn = Dstkx = 0; Dstk = (char **)NULL; - (void)stkdir(dn); + (void)stkdir(ctx, dn); av[0] = (dn == d) ? mkstrcpy(dn, (MALLOC_S *)NULL) : dn; av[1] = (char *)NULL; dn = (char *)NULL; - if (!ck_file_arg(0, 1, av, 1, 1, &sb, 0)) { + if (!ck_file_arg(ctx, 0, 1, av, 1, 1, &sb, 0)) { av[0] = (char *)NULL; fct++; } @@ -1068,7 +1066,7 @@ int descend; /* subdirectory descend flag: stderr, "%s: no space for path to entries in directory: %s\n", Pn, dn); - Error(); + Error(ctx); } } (void)snpf(fp, (size_t)fpl, "%s%s", dn, sl ? "/" : ""); @@ -1113,7 +1111,7 @@ int descend; /* subdirectory descend flag: safestrprt(dn, stderr, 0); putc('/', stderr); safestrprtn(dp->d_name, dnamlen, stderr, 1); - Error(); + Error(ctx); } } (void)strncpy(fp + dnl + sl, dp->d_name, dnamlen); @@ -1123,7 +1121,7 @@ int descend; /* subdirectory descend flag: * * Stack entries that represent subdirectories. */ - if (lstatsafely(fp, &sb)) { + if (lstatsafely(ctx, fp, &sb)) { if ((en = errno) != ENOENT) { if (!Fwarn) { (void)fprintf(stderr, "%s: WARNING: can't lstat(", Pn); @@ -1135,7 +1133,7 @@ int descend; /* subdirectory descend flag: } #if defined(HASSPECDEVD) - (void)HASSPECDEVD(fp, &sb); + (void)HASSPECDEVD(ctx, fp, &sb); #endif /* defined(HASSPECDEVD) */ if (!(Fxover & XO_FILESYS)) { @@ -1156,7 +1154,7 @@ int descend; /* subdirectory descend flag: * Otherwise skip symbolic links. */ if (Fxover & XO_SYMLINK) { - if (statsafely(fp, &sb)) { + if (statsafely(ctx, fp, &sb)) { if ((en = errno) != ENOENT) { if (!Fwarn) { (void)fprintf(stderr, @@ -1181,12 +1179,12 @@ int descend; /* subdirectory descend flag: /* * Stack a subdirectory according to the descend argument. */ - stkdir(av[0]); + stkdir(ctx, av[0]); /* * Use ck_file_arg() to record the entry for searching. Force it * to consider the entry a file, not a file system. */ - if (!ck_file_arg(0, 1, av, 1, 1, &sb, 0)) { + if (!ck_file_arg(ctx, 0, 1, av, 1, 1, &sb, 0)) { av[0] = (char *)NULL; fct++; } @@ -1235,8 +1233,9 @@ int descend; /* subdirectory descend flag: * enter_id() - enter PGID or PID for searching */ -int enter_id(ty, p) enum IDType ty; /* type: PGID or PID */ -char *p; /* process group ID string pointer */ +int enter_id(struct lsof_context *ctx, /* context */ + enum IDType ty, /* type: PGID or PID */ + char *p) /* process group ID string pointer */ { char *cp; int err, i, id, j, mx, n, ni, nx, x; @@ -1269,7 +1268,7 @@ char *p; /* process group ID string pointer */ (void)fprintf(stderr, "%s: enter_id \"", Pn); safestrprt(p, stderr, 0); (void)fprintf(stderr, "\", invalid type: %d\n", ty); - Error(); + Error(ctx); } /* * Convert and store the ID. @@ -1336,7 +1335,7 @@ char *p; /* process group ID string pointer */ if (!s) { (void)fprintf(stderr, "%s: no space for %d process%s IDs", Pn, mx, (ty == PGID) ? " group" : ""); - Error(); + Error(ctx); } } s[n].f = 0; @@ -1370,8 +1369,8 @@ char *p; /* process group ID string pointer */ * enter_network_address() - enter Internet address for searching */ -int enter_network_address(na) -char *na; /* Internet address string pointer */ +int enter_network_address(struct lsof_context *ctx, /* context */ + char *na) /* Internet address string pointer */ { int ae, i, pr; int ep = -1; @@ -1764,7 +1763,7 @@ char *na; /* Internet address string pointer */ nwad_enter: for (i = 1; i;) { - if (enter_nwad(&n, sp, ep, na, he)) + if (enter_nwad(ctx, &n, sp, ep, na, he)) goto nwad_exit; #if defined(HASIPv6) @@ -1795,14 +1794,14 @@ char *na; /* Internet address string pointer */ * enter_nwad() - enter nwad structure */ -static int enter_nwad(n, sp, ep, s, he) -struct nwad *n; /* pointer to partially completed - * nwad (less port) */ -int sp; /* starting port number */ -int ep; /* ending port number */ -char *s; /* string that states the address */ -struct hostent *he; /* pointer to hostent struct from which - * network address came */ +static int enter_nwad(struct lsof_context *ctx, /* context */ + struct nwad *n, /* pointer to partially completed + * nwad (less port) */ + int sp, /* starting port number */ + int ep, /* ending port number */ + char *s, /* string that states the address */ + struct hostent *he) /* pointer to hostent struct from + * which network address came */ { int ac; unsigned char *ap; @@ -1817,7 +1816,7 @@ struct hostent *he; /* pointer to hostent struct from which (void)fprintf(stderr, "%s: no space for Internet argument: -i ", Pn); safestrprt(s, stderr, 1); - Error(); + Error(ctx); } } else n->arg = (char *)NULL; @@ -1914,8 +1913,8 @@ struct hostent *he; /* pointer to hostent struct from which * enter_state_spec() -- enter TCP and UDP state specifications */ -int enter_state_spec(ss) -char *ss; /* state specification string */ +int enter_state_spec(struct lsof_context *ctx, + char *ss) /* state specification string */ { char *cp, *ne, *ns, *pr; int err, d, f, i, tx, x; @@ -1946,7 +1945,7 @@ char *ss; /* state specification string */ (void)fprintf(stderr, "%s: no %s state names in: %s\n", Pn, pr, ss); return (1); } - (void)build_IPstates(); + (void)build_IPstates(ctx); if (!(tx ? UdpSt : TcpSt)) { (void)fprintf(stderr, "%s: no %s state names available: %s\n", Pn, pr, ss); @@ -1965,7 +1964,7 @@ char *ss; /* state specification string */ no_IorX_space: (void)fprintf(stderr, "%s: no %s table space\n", Pn, ty); - Error(); + Error(ctx); } } if (!UdpStX) { @@ -2003,7 +2002,7 @@ char *ss; /* state specification string */ if (!(ssc = mkstrcpy(cp, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no temporary state argument space for: %s\n", Pn, ss); - Error(); + Error(ctx); } cp = ssc; err = 0; @@ -2123,12 +2122,11 @@ char *ss; /* state specification string */ * enter_str_lst() - enter a string on a list */ -int enter_str_lst(opt, s, lp, incl, excl) -char *opt; /* option name */ -char *s; /* string to enter */ -struct str_lst **lp; /* string's list */ -int *incl; /* included count */ -int *excl; /* excluded count */ +int enter_str_lst(char *opt, /* option name */ + char *s, /* string to enter */ + struct str_lst **lp, /* string's list */ + int *incl, /* included count */ + int *excl) /* excluded count */ { char *cp; short i, x; @@ -2175,8 +2173,8 @@ int *excl; /* excluded count */ * enter_uid() - enter User Identifier for searching */ -int enter_uid(us) -char *us; /* User IDentifier string pointer */ +int enter_uid(struct lsof_context *ctx, /* context */ + char *us) /* User IDentifier string pointer */ { int err, i, j, lnml, nn; unsigned char excl; @@ -2288,14 +2286,14 @@ char *us; /* User IDentifier string pointer */ Suid = (struct seluid *)realloc((MALLOC_P *)Suid, len); if (!Suid) { (void)fprintf(stderr, "%s: no space for UIDs", Pn); - Error(); + Error(ctx); } } if (nn) { if (!(lp = mkstrcpy(lnm, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for login: ", Pn); safestrprt(lnm, stderr, 1); - Error(); + Error(ctx); } Suid[Nuid].lnm = lp; } else @@ -2314,10 +2312,9 @@ char *us; /* User IDentifier string pointer */ * isIPv4addr() - is host name an IPv4 address */ -static char *isIPv4addr(hn, a, al) -char *hn; /* host name */ -unsigned char *a; /* address receptor */ -int al; /* address receptor length */ +static char *isIPv4addr(char *hn, /* host name */ + unsigned char *a, /* address receptor */ + int al) /* address receptor length */ { int dc = 0; /* dot count */ int i; /* temorary index */ @@ -2387,9 +2384,9 @@ int al; /* address receptor length */ * lkup_hostnm() - look up host name */ -static struct hostent *lkup_hostnm(hn, n) -char *hn; /* host name */ -struct nwad *n; /* network address destination */ +static struct hostent * +lkup_hostnm(char *hn, /* host name */ + struct nwad *n) /* network address destination */ { unsigned char *ap; struct hostent *he; diff --git a/src/cli.h b/src/cli.h new file mode 100644 index 00000000..8c9dfdd3 --- /dev/null +++ b/src/cli.h @@ -0,0 +1,37 @@ +/* + * cli.h - header file for lsof cli + */ + +/* + * Copyright 1994 Purdue Research Foundation, West Lafayette, Indiana + * 47907. All rights reserved. + * + * Written by Victor A. Abell + * + * This software is not subject to any license of the American Telephone + * and Telegraph Company or the Regents of the University of California. + * + * Permission is granted to anyone to use this software for any purpose on + * any computer system, and to alter it and redistribute it freely, subject + * to the following restrictions: + * + * 1. Neither the authors nor Purdue University are responsible for any + * consequences of the use of this software. + * + * 2. The origin of this software must not be misrepresented, either by + * explicit claim or by omission. Credit to the authors and Purdue + * University must appear in documentation and sources. + * + * 3. Altered versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * + * 4. This notice may not be removed or altered. + */ + +#if !defined(CLI_H) +# define CLI_H + +# include "lsof.h" +# include "proto.h" + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c index e02f057b..58454f8e 100644 --- a/src/main.c +++ b/src/main.c @@ -31,6 +31,7 @@ */ #include "common.h" +#include "cli.h" /* * Local definitions @@ -42,17 +43,14 @@ static char *GOv = (char *)NULL; /* option `:' value pointer */ static int GOx1 = 1; /* first opt[][] index */ static int GOx2 = 0; /* second opt[][] index */ -_PROTOTYPE(static int GetOpt, (int ct, char *opt[], char *rules, int *err)); -_PROTOTYPE(static char *sv_fmt_str, (char *f)); +static int GetOpt(int ct, char *opt[], char *rules, int *err); +static char *sv_fmt_str(struct lsof_context *ctx, char *f); /* * main() - main function for lsof */ -int main(argc, argv) -int argc; -char *argv[]; -{ +int main(int argc, char *argv[]) { enum ExitStatus rv; int gopt_rv; int ad, c, i, n, se1, se2, ss; @@ -75,6 +73,8 @@ char *argv[]; int version = 0; int xover = 0; int pr_count = 0; + /** liblsof context */ + struct lsof_context *ctx = NULL; #if defined(HAS_STRFTIME) char *fmt = (char *)NULL; @@ -120,7 +120,7 @@ char *argv[]; while (((i = open("/dev/null", O_RDWR, 0)) >= 0) && (i < 2)) ; if (i < 0) - Error(); + Error(ctx); if (i > 2) (void)close(i); (void)umask(0); @@ -143,7 +143,7 @@ char *argv[]; Setuidroot = 1; if (!(Namech = (char *)malloc(MAXPATHLEN + 1))) { (void)fprintf(stderr, "%s: no space for name buffer\n", Pn); - Error(); + Error(ctx); } Namechl = (size_t)(MAXPATHLEN + 1); /* @@ -286,7 +286,7 @@ char *argv[]; break; } if (GOv && (*GOv == '/')) { - if (enter_cmd_rx(GOv)) + if (enter_cmd_rx(ctx, GOv)) err = 1; } else { if (enter_str_lst("-c", GOv, &Cmdl, &Cmdni, &Cmdnx)) @@ -314,20 +314,20 @@ char *argv[]; #endif /* defined(HASNCACHE) */ case 'd': if (GOp == '+') { - if (enter_dir(GOv, 0)) + if (enter_dir(ctx, GOv, 0)) err = 1; else { Selflags |= SELNM; xover = 1; } } else { - if (enter_fd(GOv)) + if (enter_fd(ctx, GOv)) err = 1; } break; case 'D': if (GOp == '+') { - if (enter_dir(GOv, 1)) + if (enter_dir(ctx, GOv, 1)) err = 1; else { Selflags |= SELNM; @@ -336,7 +336,7 @@ char *argv[]; } else { #if defined(HASDCACHE) - if (ctrl_dcache(GOv)) + if (ctrl_dcache(ctx, GOv)) err = 1; #else /* !defined(HASDCACHE) */ (void)fprintf(stderr, "%s: unsupported option: -D\n", Pn); @@ -347,7 +347,7 @@ char *argv[]; #if defined(HASEOPT) case 'e': - if (enter_efsys(GOv, ((GOp == '+') ? 1 : 0))) + if (enter_efsys(ctx, GOv, ((GOp == '+') ? 1 : 0))) err = 1; break; #endif /* defined(HASEOPT) */ @@ -555,7 +555,7 @@ char *argv[]; if (*GOv == '-' || *GOv == '+') { GOx1 = GObk[0]; GOx2 = GObk[1]; - } else if (enter_id(PGID, GOv)) + } else if (enter_id(ctx, PGID, GOv)) err = 1; } Fpgid = 1; @@ -577,7 +577,7 @@ char *argv[]; } break; } - if (enter_network_address(GOv)) + if (enter_network_address(ctx, GOv)) err = 1; break; @@ -739,7 +739,7 @@ char *argv[]; Fovhd = (GOp == '-') ? 1 : 0; break; case 'p': - if (enter_id(PID, GOv)) + if (enter_id(ctx, PID, GOv)) err = 1; break; case 'Q': @@ -805,7 +805,7 @@ char *argv[]; (void)fprintf( stderr, "%s: no space (%d) for result: \"%s\"\n", Pn, (int)fmtl, cp); - Error(); + Error(ctx); } if (util_strftime(fmtr, fmtl - 1, fmt) < 1) { (void)fprintf(stderr, "%s: illegal : \"%s\"\n", Pn, @@ -837,7 +837,7 @@ char *argv[]; GOx2 = GObk[1]; } } else { - if (enter_state_spec(GOv)) + if (enter_state_spec(ctx, GOv)) err = 1; } #else /* !defined(HASTCPUDPSTATE) */ @@ -921,7 +921,7 @@ char *argv[]; } break; case 'u': - if (enter_uid(GOv)) + if (enter_uid(ctx, GOv)) err = 1; break; case 'U': @@ -977,7 +977,7 @@ char *argv[]; /* * Add to the zone name argument hash. */ - if (enter_zone_arg(GOv)) + if (enter_zone_arg(ctx, GOv)) err = 1; } else if (GOv) { GOx1 = GObk[0]; @@ -998,7 +998,7 @@ char *argv[]; /* * Add to the context name argument hash. */ - if (enter_cntx_arg(GOv)) + if (enter_cntx_arg(ctx, GOv)) err = 1; } else if (GOv) { GOx1 = GObk[0]; @@ -1118,7 +1118,7 @@ char *argv[]; efsys_list_t *ep; /* Efsysl pointer */ struct mounts *mp, *mpw; /* local mount table pointers */ - if ((mp = readmnt())) { + if ((mp = readmnt(ctx))) { for (ep = Efsysl; ep; ep = ep->next) { for (mpw = mp; mpw; mpw = mpw->next) { if (!strcmp(mpw->dir, ep->path)) { @@ -1138,7 +1138,7 @@ char *argv[]; #endif /* defined(HASEOPT) */ if (DChelp || err || Fhelp || fh || version) - usage(err ? 1 : 0, fh, version); + usage(ctx, err ? 1 : 0, fh, version); /* * Reduce the size of Suid[], if necessary. */ @@ -1147,7 +1147,7 @@ char *argv[]; (MALLOC_P *)Suid, (MALLOC_S)(sizeof(struct seluid) * Nuid)))) { (void)fprintf(stderr, "%s: can't realloc UID table\n", Pn); - Error(); + Error(ctx); } Mxuid = Nuid; } @@ -1189,7 +1189,7 @@ char *argv[]; if (Selflags == 0) { if (Fand) { (void)fprintf(stderr, "%s: no select options to AND via -a\n", Pn); - usage(1, 0, 0); + usage(ctx, 1, 0, 0); } Selflags = SelAll; } else { @@ -1219,7 +1219,7 @@ char *argv[]; (void)fprintf(stderr, "%s: can't stat(/dev): %s\n", Pn, strerror(se2)); } - Error(); + Error(ctx); } } DevDev = sb.st_dev; @@ -1227,23 +1227,23 @@ char *argv[]; * Process the file arguments. */ if (GOx1 < argc) { - if (ck_file_arg(GOx1, argc, argv, Ffilesys, 0, (struct stat *)NULL, + if (ck_file_arg(ctx, GOx1, argc, argv, Ffilesys, 0, (struct stat *)NULL, FsearchErr == 0)) - Error(); + Error(ctx); } /* * Do dialect-specific initialization. */ - initialize(); + initialize(ctx); if (Sfile) - (void)hashSfile(); + (void)hashSfile(ctx); #if defined(WILLDROPGID) /* * If this process isn't setuid(root), but it is setgid(not_real_gid), * relinquish the setgid power. (If it hasn't already been done.) */ - (void)dropgid(); + (void)dropgid(ctx); #endif /* defined(WILLDROPGID) */ #if defined(HASDCACHE) @@ -1251,32 +1251,32 @@ char *argv[]; * If there is a device cache, prepare the device table. */ if (DCstate) - readdev(0); + readdev(ctx, 0); #endif /* defined(HASDCACHE) */ /* * Define the size and offset print formats. */ (void)snpf(options, sizeof(options), "%%%su", INODEPSPEC); - InodeFmt_d = sv_fmt_str(options); + InodeFmt_d = sv_fmt_str(ctx, options); (void)snpf(options, sizeof(options), "%%#%sx", INODEPSPEC); - InodeFmt_x = sv_fmt_str(options); + InodeFmt_x = sv_fmt_str(ctx, options); (void)snpf(options, sizeof(options), "0t%%%su", SZOFFPSPEC); - SzOffFmt_0t = sv_fmt_str(options); + SzOffFmt_0t = sv_fmt_str(ctx, options); (void)snpf(options, sizeof(options), "%%%su", SZOFFPSPEC); - SzOffFmt_d = sv_fmt_str(options); + SzOffFmt_d = sv_fmt_str(ctx, options); (void)snpf(options, sizeof(options), "%%*%su", SZOFFPSPEC); - SzOffFmt_dv = sv_fmt_str(options); + SzOffFmt_dv = sv_fmt_str(ctx, options); (void)snpf(options, sizeof(options), "%%#%sx", SZOFFPSPEC); - SzOffFmt_x = sv_fmt_str(options); + SzOffFmt_x = sv_fmt_str(ctx, options); #if defined(HASMNTSUP) /* * Report mount supplement information, as requested. */ if (MntSup == 1) { - (void)readmnt(); - Exit(LSOF_SUCCESS); + (void)readmnt(ctx); + Exit(ctx, LSOF_SUCCESS); } #endif /* defined(HASMNTSUP) */ @@ -1290,7 +1290,7 @@ char *argv[]; /* * Gather information about processes. */ - gather_proc_info(); + gather_proc_info(ctx); /* * If the local process table has more than one entry, sort it by PID. */ @@ -1305,7 +1305,7 @@ char *argv[]; if (!slp) { (void)fprintf(stderr, "%s: no space for %d sort pointers\n", Pn, Nlproc); - Error(); + Error(ctx); } } for (i = 0; i < Nlproc; i++) { @@ -1346,12 +1346,12 @@ char *argv[]; * process the file endpoints. */ if (Lp->pss && (Lp->ept & EPT_PIPE)) - (void)process_pinfo(0); + (void)process_pinfo(ctx, 0); /* * Process POSIX MQ endpoints. */ if (Lp->ept & EPT_PSXMQ) - (void)process_psxmqinfo(0); + (void)process_psxmqinfo(ctx, 0); # if defined(HASUXSOCKEPT) /* @@ -1360,7 +1360,7 @@ char *argv[]; * socket(s), process the file endpoints. */ if (Lp->pss && (Lp->ept & EPT_UXS)) - (void)process_uxsinfo(0); + (void)process_uxsinfo(ctx, 0); # endif /* defined(HASUXSOCKEPT) */ # if defined(HASPTYEPT) @@ -1370,27 +1370,27 @@ char *argv[]; * terminal files(s), process the file endpoints. */ if (Lp->pss && (Lp->ept & EPT_PTY)) - (void)process_ptyinfo(0); + (void)process_ptyinfo(ctx, 0); # endif /* defined(HASPTYEPT) */ /* * Process INET socket endpoints. */ if (Lp->ept & EPT_NETS) - (void)process_netsinfo(0); + (void)process_netsinfo(ctx, 0); # if defined(HASIPv6) /* * Process INET6 socket endpoints. */ if (Lp->ept & EPT_NETS6) - (void)process_nets6info(0); + (void)process_nets6info(ctx, 0); # endif /* defined(HASIPv6) */ /* * Process eventfd endpoints. */ if (Lp->ept & EPT_EVTFD) - (void)process_evtfdinfo(0); + (void)process_evtfdinfo(ctx, 0); } /* * In a second pass, look for unselected endpoint files, @@ -1403,19 +1403,19 @@ char *argv[]; * Process pipe endpoints. */ if (Lp->ept & EPT_PIPE_END) - (void)process_pinfo(1); + (void)process_pinfo(ctx, 1); /* * Process POSIX MQ endpoints. */ if (Lp->ept & EPT_PSXMQ_END) - (void)process_psxmqinfo(1); + (void)process_psxmqinfo(ctx, 1); # if defined(HASUXSOCKEPT) /* * Process UNIX socket endpoints. */ if (Lp->ept & EPT_UXS_END) - (void)process_uxsinfo(1); + (void)process_uxsinfo(ctx, 1); # endif /* defined(HASUXSOCKEPT) */ # if defined(HASPTYEPT) @@ -1423,28 +1423,28 @@ char *argv[]; * Process pseudo-terminal endpoints. */ if (Lp->ept & EPT_PTY_END) - (void)process_ptyinfo(1); + (void)process_ptyinfo(ctx, 1); # endif /* defined(HASPTYEPT) */ /* * Process INET socket endpoints. */ if (Lp->ept & EPT_NETS_END) - (void)process_netsinfo(1); + (void)process_netsinfo(ctx, 1); # if defined(HASIPv6) /* * Process INET6 socket endpoints. */ if (Lp->ept & EPT_NETS6_END) - (void)process_nets6info(1); + (void)process_nets6info(ctx, 1); # endif /* defined(HASIPv6) */ /* * Process envetfd endpoints. */ if (Lp->ept & EPT_EVTFD_END) - (void)process_evtfdinfo(1); + (void)process_evtfdinfo(ctx, 1); } Lf = lf; } @@ -1461,7 +1461,7 @@ char *argv[]; for (i = n = 0; i < Nlproc; i++) { Lp = (Nlproc > 1) ? slp[i] : &Lproc[i]; if (Lp->pss) { - if (print_proc()) + if (print_proc(ctx)) n++; } if (RptTm && PrPass) @@ -1478,25 +1478,25 @@ char *argv[]; if (RptTm) { #if defined(HASEPTOPTS) - (void)clear_pinfo(); + (void)clear_pinfo(ctx); - (void)clear_psxmqinfo(); + (void)clear_psxmqinfo(ctx); # if defined(HASUXSOCKEPT) - (void)clear_uxsinfo(); + (void)clear_uxsinfo(ctx); # endif /* defined(HASUXSOCKEPT) */ # if defined(HASPTYEPT) - (void)clear_ptyinfo(); + (void)clear_ptyinfo(ctx); # endif /* defined(HASPTYEPT) */ - (void)clear_netsinfo(); + (void)clear_netsinfo(ctx); # if defined(HASIPv6) - (void)clear_nets6info(); + (void)clear_nets6info(ctx); # endif /* defined(HASIPv6) */ - (void)clear_evtfdinfo(); + (void)clear_evtfdinfo(ctx); #endif /* defined(HASEPTOPTS) */ if (rc) { @@ -1540,7 +1540,7 @@ char *argv[]; puts(cp); } (void)fflush(stdout); - (void)childx(); + (void)childx(ctx); (void)sleep(RptTm); Hdr = Nlproc = 0; CkPasswd = 1; @@ -1552,7 +1552,7 @@ char *argv[]; * See if all requested information was displayed. Return zero if it * was; one, if not. If -V was specified, report what was not displayed. */ - (void)childx(); + (void)childx(ctx); rv = LSOF_SUCCESS; for (str = Cmdl; str; str = str->next) { @@ -1809,7 +1809,7 @@ char *argv[]; rv = ev; if (!rv && ErrStat) rv = LSOF_ERROR; - Exit(rv); + Exit(ctx, rv); return (rv); /* to make code analyzers happy */ } @@ -1824,11 +1824,10 @@ char *argv[]; * value doesn't have one -- e.g., has a default instead. */ -static int GetOpt(ct, opt, rules, err) -int ct; /* option count */ -char *opt[]; /* options */ -char *rules; /* option rules */ -int *err; /* error return */ +static int GetOpt(int ct, /* option count */ + char *opt[], /* options */ + char *rules, /* option rules */ + int *err) /* error return */ { register int c; register char *cp = (char *)NULL; @@ -1942,8 +1941,7 @@ int *err; /* error return */ * sv_fmt_str() - save format string */ -static char *sv_fmt_str(f) -char *f; /* format string */ +static char *sv_fmt_str(struct lsof_context *ctx, char *f) /* format string */ { char *cp; MALLOC_S l; @@ -1952,7 +1950,7 @@ char *f; /* format string */ if (!(cp = (char *)malloc(l))) { (void)fprintf(stderr, "%s: can't allocate %d bytes for format: %s\n", Pn, (int)l, f); - Error(); + Error(ctx); } (void)snpf(cp, l, "%s", f); return (cp); diff --git a/src/print.c b/src/print.c index 5a30458c..c17a9ccb 100644 --- a/src/print.c +++ b/src/print.c @@ -29,6 +29,7 @@ */ #include "common.h" +#include "cli.h" /* * Local definitions, structures and function prototypes @@ -79,22 +80,23 @@ static struct porttab **Pth[4] = {NULL, NULL, NULL, NULL}; #define HASHPORT(p) (((((int)(p)) * 31415) >> 3) & (PORTHASHBUCKETS - 1)) #if !defined(HASNORPC_H) -_PROTOTYPE(static void fill_portmap, (void)); -_PROTOTYPE(static void update_portmap, (struct porttab * pt, char *pn)); +static void fill_portmap(struct lsof_context *ctx); +static void update_portmap(struct lsof_context *ctx, struct porttab *pt, + char *pn); #endif /* !defined(HASNORPC_H) */ -_PROTOTYPE(static void fill_porttab, (void)); -_PROTOTYPE(static char *lkup_port, (int p, int pr, int src)); -_PROTOTYPE(static char *lkup_svcnam, (int h, int p, int pr, int ss)); -_PROTOTYPE(static int printinaddr, (void)); -_PROTOTYPE(static int human_readable_size, (SZOFFTYPE sz, int print, int col)); +static void fill_porttab(struct lsof_context *ctx); +static char *lkup_port(struct lsof_context *ctx, int p, int pr, int src); +static char *lkup_svcnam(struct lsof_context *ctx, int h, int p, int pr, + int ss); +static int printinaddr(struct lsof_context *ctx); +static int human_readable_size(SZOFFTYPE sz, int print, int col); /* * endnm() - locate end of Namech */ -char *endnm(sz) -size_t *sz; /* returned remaining size */ +char *endnm(struct lsof_context *ctx, size_t *sz) /* returned remaining size */ { register char *s; register size_t tsz; @@ -147,7 +149,7 @@ size_t *sz; /* returned remaining size */ * SUCH DAMAGE. */ -static void fill_portmap() { +static void fill_portmap(struct lsof_context *ctx) { static int already_run = 0; char buf[128], *cp, *nm; CLIENT *c; @@ -249,7 +251,7 @@ static void fill_portmap() { (void)fprintf(stderr, "%s: can't allocate space for portmap entry: ", Pn); safestrprt(cp, stderr, 1); - Error(); + Error(ctx); } if (!nl) { (void)free((FREE_P *)nm); @@ -263,7 +265,7 @@ static void fill_portmap() { (void)fprintf(stderr, "%s: can't allocate porttab entry for portmap: ", Pn); safestrprt(nm, stderr, 1); - Error(); + Error(ctx); } pt->name = nm; pt->nl = nl; @@ -281,7 +283,7 @@ static void fill_portmap() { * getservent() scan */ -static void fill_porttab() { +static void fill_porttab(struct lsof_context *ctx) { int h, p, pr; MALLOC_S nl; char *nm; @@ -324,7 +326,7 @@ static void fill_porttab() { (void)fprintf(stderr, "%s: can't allocate %d bytes for port %d name: %s\n", Pn, (int)(nl + 1), p, se->s_name); - Error(); + Error(ctx); } if (!nl) { (void)free((FREE_P *)nm); @@ -334,7 +336,7 @@ static void fill_porttab() { (void)fprintf(stderr, "%s: can't allocate porttab entry for port %d: %s\n", Pn, p, se->s_name); - Error(); + Error(ctx); } pt->name = nm; pt->nl = nl - 1; @@ -350,10 +352,10 @@ static void fill_porttab() { * gethostnm() - get host name */ -char *gethostnm(ia, af) -unsigned char *ia; /* Internet address */ -int af; /* address family -- e.g., AF_INET - * or AF_INET6 */ +char *gethostnm(struct lsof_context *ctx, /* context */ + unsigned char *ia, /* Internet address */ + int af) /* address family -- e.g., AF_INET + * or AF_INET6 */ { int al = MIN_AF_ADDR; char hbuf[256]; @@ -424,7 +426,7 @@ int af; /* address family -- e.g., AF_INET if (!(np = mkstrcpy(hn, (MALLOC_S *)NULL))) { (void)fprintf(stderr, "%s: no space for host name: ", Pn); safestrprt(hn, stderr, 1); - Error(); + Error(ctx); } /* * Add address/name entry to cache. Allocate cache space in HCINC chunks. @@ -438,7 +440,7 @@ int af; /* address family -- e.g., AF_INET hc = (struct hostcache *)realloc((MALLOC_P *)hc, len); if (!hc) { (void)fprintf(stderr, "%s: no space for host cache\n", Pn); - Error(); + Error(ctx); } } hc[hcx].af = af; @@ -453,11 +455,11 @@ int af; /* address family -- e.g., AF_INET * lkup_port() - look up port for protocol */ -static char *lkup_port(p, pr, src) -int p; /* port number */ -int pr; /* protocol index: 0 = tcp, 1 = udp */ -int src; /* port source: 0 = local - * 1 = foreign */ +static char *lkup_port(struct lsof_context *ctx, /* context */ + int p, /* port number */ + int pr, /* protocol index: 0 = tcp, 1 = udp */ + int src) /* port source: 0 = local + * 1 = foreign */ { int h, nh; MALLOC_S nl; @@ -483,7 +485,7 @@ int src; /* port source: 0 = local "%s: can't allocate %d bytes for %s %s hash buckets\n", Pn, (int)(2 * (PORTHASHBUCKETS * sizeof(struct porttab *))), (h & 1) ? "UDP" : "TCP", (h > 1) ? "portmap" : "port"); - Error(); + Error(ctx); } } } @@ -494,7 +496,7 @@ int src; /* port source: 0 = local * portmap table has been loaded. */ if (FportMap) - (void)fill_portmap(); + (void)fill_portmap(ctx); #endif /* !defined(HASNORPC_H) */ /* @@ -509,12 +511,12 @@ int src; /* port source: 0 = local if (pt->port != p) continue; if (!pt->ss) { - pn = Fport ? lkup_svcnam(h, p, pr, 0) : (char *)NULL; + pn = Fport ? lkup_svcnam(ctx, h, p, pr, 0) : (char *)NULL; if (!pn) { (void)snpf(pb, sizeof(pb), "%d", p); pn = pb; } - (void)update_portmap(pt, pn); + (void)update_portmap(ctx, pt, pn); } return (pt->name); } @@ -534,7 +536,7 @@ int src; /* port source: 0 = local * Don't cache %d conversions; a zero port number is a %d conversion that * is represented by "*". */ - pn = Fport ? lkup_svcnam(h, p, pr, 1) : (char *)NULL; + pn = Fport ? lkup_svcnam(ctx, h, p, pr, 1) : (char *)NULL; if (!pn || !strlen(pn)) { if (p) { (void)snpf(pb, sizeof(pb), "%d", p); @@ -548,7 +550,7 @@ int src; /* port source: 0 = local if (!(pt = (struct porttab *)malloc(sizeof(struct porttab)))) { (void)fprintf(stderr, "%s: can't allocate porttab entry for port %d\n", Pn, p); - Error(); + Error(ctx); } /* * Allocate space for the name; copy it to the porttab entry; and link the @@ -559,7 +561,7 @@ int src; /* port source: 0 = local if (!(nm = mkstrcpy(pn, &nl))) { (void)fprintf(stderr, "%s: can't allocate space for port name: ", Pn); safestrprt(pn, stderr, 1); - Error(); + Error(ctx); } pt->name = nm; pt->nl = nl; @@ -574,12 +576,12 @@ int src; /* port source: 0 = local * lkup_svcnam() - look up service name for port */ -static char *lkup_svcnam(h, p, pr, ss) -int h; /* porttab hash index */ -int p; /* port number */ -int pr; /* protocol: 0 = TCP, 1 = UDP */ -int ss; /* search status: 1 = Pth[pr][h] - * already searched */ +static char *lkup_svcnam(struct lsof_context *ctx, /* context */ + int h, /* porttab hash index */ + int p, /* port number */ + int pr, /* protocol: 0 = TCP, 1 = UDP */ + int ss) /* search status: 1 = Pth[pr][h] + * already searched */ { static int fl[PORTTABTHRESH]; static int fln = 0; @@ -628,7 +630,7 @@ int ss; /* search status: 1 = Pth[pr][h] fl[fln++] = p; return ((char *)NULL); } - (void)fill_porttab(); + (void)fill_porttab(ctx); ptf++; ss = 0; } @@ -639,7 +641,7 @@ int ss; /* search status: 1 = Pth[pr][h] * print_file() - print file */ -void print_file() { +void print_file(struct lsof_context *ctx) { char buf[128]; char *cp = (char *)NULL; dev_t dev; @@ -838,11 +840,11 @@ void print_file() { * Size or print the user ID or login name. */ if (!PrPass) { - if ((len = strlen(printuid((UID_ARG)Lp->uid, NULL))) > UserColW) + if ((len = strlen(printuid(ctx, (UID_ARG)Lp->uid, NULL))) > UserColW) UserColW = len; } else (void)printf(" %*.*s", UserColW, UserColW, - printuid((UID_ARG)Lp->uid, NULL)); + printuid(ctx, (UID_ARG)Lp->uid, NULL)); /* * Size or print the file descriptor, access mode and lock status. */ @@ -908,7 +910,7 @@ void print_file() { # if !defined(HASNOFSFLAGS) if (Fsv & FSV_FG) { if ((Lf->fsv & FSV_FG) && (FsvFlagX || Lf->ffg || Lf->pof)) - cp = print_fflags(Lf->ffg, Lf->pof); + cp = print_fflags(ctx, Lf->ffg, Lf->pof); else cp = ""; if (!PrPass) { @@ -1099,9 +1101,9 @@ void print_file() { putchar(' '); #if defined(HASPRINTNM) - HASPRINTNM(Lf); + HASPRINTNM(ctx, Lf); #else /* !defined(HASPRINTNM) */ - printname(1); + printname(ctx, 1); #endif /* defined(HASPRINTNM) */ } } @@ -1110,7 +1112,7 @@ void print_file() { * printinaddr() - print Internet addresses */ -static int printinaddr() { +static int printinaddr(struct lsof_context *ctx) { int i, len, src; char *host, *port; int nl = Namechl - 1; @@ -1151,7 +1153,7 @@ static int printinaddr() { (Lf->li[i].af == AF_INET && Lf->li[i].ia.a4.s_addr == INADDR_ANY)) host = "*"; else - host = gethostnm((unsigned char *)&Lf->li[i].ia, Lf->li[i].af); + host = gethostnm(ctx, (unsigned char *)&Lf->li[i].ia, Lf->li[i].af); #else /* !defined(HASIPv6) */ if (Lf->li[i].ia.a4.s_addr == INADDR_ANY) host = "*"; @@ -1216,9 +1218,9 @@ static int printinaddr() { #endif /* !defined(HASNORPC_H) */ if (strcasecmp(Lf->iproto, "TCP") == 0) - port = lkup_port(Lf->li[i].p, 0, src); + port = lkup_port(ctx, Lf->li[i].p, 0, src); else if (strcasecmp(Lf->iproto, "UDP") == 0) - port = lkup_port(Lf->li[i].p, 1, src); + port = lkup_port(ctx, Lf->li[i].p, 1, src); } if (!port) { (void)snpf(pbuf, sizeof(pbuf), "%d", Lf->li[i].p); @@ -1983,7 +1985,7 @@ void printiproto(p) int p; /* protocol number */ * printname() - print output name field */ -void printname(nl) int nl; /* NL status */ +void printname(struct lsof_context *ctx, int nl) /* NL status */ { #if defined(HASNCACHE) @@ -2010,12 +2012,12 @@ void printname(nl) int nl; /* NL status */ /* * If the file has Internet addresses, print them. */ - if (printinaddr()) + if (printinaddr(ctx)) ps++; goto print_nma; } if (((Lf->ntype == N_BLK) || (Lf->ntype == N_CHR)) && Lf->dev_def && - Lf->rdev_def && printdevname(&Lf->dev, &Lf->rdev, 0, Lf->ntype)) { + Lf->rdev_def && printdevname(ctx, &Lf->dev, &Lf->rdev, 0, Lf->ntype)) { /* * If this is a block or character device and it has a name, print it. @@ -2034,7 +2036,7 @@ void printname(nl) int nl; /* NL status */ } #if defined(HASPRIVNMCACHE) - if (HASPRIVNMCACHE(Lf)) { + if (HASPRIVNMCACHE(ctx, Lf)) { ps++; goto print_nma; } @@ -2046,7 +2048,7 @@ void printname(nl) int nl; /* NL status */ * Do a deferred local mount info table search for the file system * (mounted) directory name and inode number, and mounted device name. */ - for (mp = readmnt(); mp; mp = mp->next) { + for (mp = readmnt(ctx); mp; mp = mp->next) { if (Lf->dev == mp->dev) { Lf->fsdir = mp->dir; Lf->fsdev = mp->fsname; @@ -2085,7 +2087,7 @@ void printname(nl) int nl; /* NL status */ # endif /* defined(NCACHELDPFX) */ (void) - ncache_load(); + ncache_load(ctx); # if defined(NCACHELDSFX) NCACHELDSFX @@ -2093,7 +2095,7 @@ void printname(nl) int nl; /* NL status */ NcacheReload = 0; } - if ((cp = ncache_lookup(buf, sizeof(buf), &fp))) { + if ((cp = ncache_lookup(ctx, buf, sizeof(buf), &fp))) { char *cp1; if (*cp == '\0') @@ -2191,7 +2193,7 @@ void printname(nl) int nl; /* NL status */ )) { if (ps) putchar(' '); - (void)print_tcptpi(0); + (void)print_tcptpi(ctx, 0); } if (nl) putchar('\n'); @@ -2201,12 +2203,13 @@ void printname(nl) int nl; /* NL status */ * printrawaddr() - print raw socket address */ -void printrawaddr(sa) struct sockaddr *sa; /* socket address */ +void printrawaddr(struct lsof_context *ctx, + struct sockaddr *sa) /* socket address */ { char *ep; size_t sz; - ep = endnm(&sz); + ep = endnm(ctx, &sz); (void)snpf(ep, sz, "%u/%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u", sa->sa_family, (unsigned char)sa->sa_data[0], (unsigned char)sa->sa_data[1], (unsigned char)sa->sa_data[2], @@ -2222,8 +2225,7 @@ void printrawaddr(sa) struct sockaddr *sa; /* socket address */ * printsockty() - print socket type */ -char *printsockty(ty) -int ty; /* socket type -- e.g., from so_type */ +char *printsockty(int ty) /* socket type -- e.g., from so_type */ { static char buf[64]; char *cp; @@ -2272,12 +2274,12 @@ int ty; /* socket type -- e.g., from so_type */ * printuid() - print User ID or login name */ -char *printuid(uid, ty) -UID_ARG uid; /* User IDentification number */ -int *ty; /* returned UID type pointer (NULL - * (if none wanted). If non-NULL - * then: *ty = 0 = login name - * = 1 = UID number */ +char *printuid(struct lsof_context *ctx, /* context */ + UID_ARG uid, /* User IDentification number */ + int *ty) /* returned UID type pointer (NULL + * (if none wanted). If non-NULL + * then: *ty = 0 = login name + * = 1 = UID number */ { int i; struct passwd *pw; @@ -2300,7 +2302,7 @@ int *ty; /* returned UID type pointer (NULL if (stat("/etc/passwd", &sb) != 0) { (void)fprintf(stderr, "%s: can't stat(/etc/passwd): %s\n", Pn, strerror(errno)); - Error(); + Error(ctx); } } /* @@ -2312,7 +2314,7 @@ int *ty; /* returned UID type pointer (NULL (void)fprintf( stderr, "%s: no space for %d byte UID cache hash buckets\n", Pn, (int)(UIDCACHEL * (sizeof(struct uidcache *)))); - Error(); + Error(ctx); } if (CkPasswd) { sbs = sb; @@ -2368,7 +2370,7 @@ int *ty; /* returned UID type pointer (NULL (void)fprintf( stderr, "%s: no space for UID cache entry for: %lu, %s)\n", Pn, (unsigned long)uid, pw->pw_name); - Error(); + Error(ctx); } (void)strncpy(upn->nm, pw->pw_name, LOGINML); upn->nm[LOGINML] = '\0'; @@ -2393,8 +2395,8 @@ int *ty; /* returned UID type pointer (NULL * printunkaf() - print unknown address family */ -void printunkaf(fam, ty) int fam; /* unknown address family */ -int ty; /* output type: 0 = terse; 1 = full */ +void printunkaf(struct lsof_context *ctx, int fam, /* unknown address family */ + int ty) /* output type: 0 = terse; 1 = full */ { char *p, *s; @@ -2759,8 +2761,9 @@ int ty; /* output type: 0 = terse; 1 = full */ * name */ -static void update_portmap(pt, pn) struct porttab *pt; /* porttab entry */ -char *pn; /* port name */ +static void update_portmap(struct lsof_context *ctx, /* context */ + struct porttab *pt, /* porttab entry */ + char *pn) /* port name */ { MALLOC_S al, nl; char *cp; @@ -2776,7 +2779,7 @@ char *pn; /* port name */ (void)fprintf(stderr, "%s: can't allocate %d bytes for portmap name: %s[%s]\n", Pn, (int)(nl + 1), pn, pt->name); - Error(); + Error(ctx); } (void)snpf(cp, nl + 1, "%s[%s]", pn, pt->name); (void)free((FREE_P *)pt->name); diff --git a/src/ptti.c b/src/ptti.c index 3b60ccc1..ae3e005d 100644 --- a/src/ptti.c +++ b/src/ptti.c @@ -41,7 +41,7 @@ * Note: this module does not support a UDP state table. */ -void build_IPstates() { +void build_IPstates(struct lsof_context *ctx) { /* * Set the TcpNstates global variable. @@ -54,7 +54,7 @@ void build_IPstates() { * print_tcptpi() - print TCP/TPI info */ -void print_tcptpi(nl) int nl; /* 1 == '\n' required */ +void print_tcptpi(struct lsof_context *ctx, int nl) /* 1 == '\n' required */ { int ps = 0; int s; @@ -65,7 +65,7 @@ void print_tcptpi(nl) int nl; /* 1 == '\n' required */ else putchar('('); if (!TcpNstates) - (void)build_IPstates(); + (void)build_IPstates(ctx); if ((s = Lf->lts.state.i) < 0 || s >= TcpNstates) (void)printf("UNKNOWN_TCP_STATE_%d", s); else diff --git a/src/store.c b/src/store.c index c40e295b..58abe110 100644 --- a/src/store.c +++ b/src/store.c @@ -384,4 +384,4 @@ znhash_t **ZoneArg = (znhash_t **)NULL; /* zone arguments supplied with -z */ #endif /* defined(HASZONES) */ -int ZoneColW; /* ZONE column width */ +int ZoneColW; /* ZONE column width */ \ No newline at end of file diff --git a/src/usage.c b/src/usage.c index b8258fa6..b1dcc1e8 100644 --- a/src/usage.c +++ b/src/usage.c @@ -32,26 +32,26 @@ static char copyright[] = "Copyright 1998 Purdue Research Foundation. All rights reserved."; #include "common.h" +#include "cli.h" #include "version.h" /* * Local function prototypes */ -_PROTOTYPE(static char *isnullstr, (char *s)); -_PROTOTYPE(static int print_in_col, (int col, char *cp)); -_PROTOTYPE(static void report_HASDCACHE, (int type, char *ttl, char *det)); -_PROTOTYPE(static void report_HASKERNIDCK, (char *pfx, char *verb)); -_PROTOTYPE(static void report_SECURITY, (char *pfx, char *punct)); -_PROTOTYPE(static void report_WARNDEVACCESS, - (char *pfx, char *verb, char *punct)); +static char *isnullstr(char *s); +static int print_in_col(int col, char *cp); +static void report_HASDCACHE(struct lsof_context *ctx, int type, char *ttl, + char *det); +static void report_HASKERNIDCK(char *pfx, char *verb); +static void report_SECURITY(char *pfx, char *punct); +static void report_WARNDEVACCESS(char *pfx, char *verb, char *punct); /* * isnullstr() - is it a null string? */ -static char *isnullstr(s) -char *s; /* string pointer */ +static char *isnullstr(char *s) /* string pointer */ { if (!s) return ((char *)NULL); @@ -67,9 +67,8 @@ char *s; /* string pointer */ * print_in_col() -- print character string in help column */ -static int print_in_col(col, cp) -int col; /* column number */ -char *cp; /* what to print */ +static int print_in_col(int col, /* column number */ + char *cp) /* what to print */ { if (cp && *cp) { switch (col) { @@ -92,13 +91,13 @@ char *cp; /* what to print */ * report_HASDCACHE() -- report device cache file state */ -static void report_HASDCACHE(type, ttl, - det) int type; /* type: 0 == read path report - * 1 == full report */ -char *ttl; /* title lines prefix - * (NULL if none) */ -char *det; /* detail lines prefix - * (NULL if none) */ +static void report_HASDCACHE(struct lsof_context *ctx, /* context */ + int type, /* type: 0 == read path report + * 1 == full report */ + char *ttl, /* title lines prefix + * (NULL if none) */ + char *det) /* detail lines prefix + * (NULL if none) */ { #if defined(HASDCACHE) @@ -118,7 +117,7 @@ char *det; /* detail lines prefix */ (void)fprintf(stderr, "%sDevice cache file read-only paths:\n", ttl ? ttl : ""); - if ((dx = dcpath(1, 0)) < 0) + if ((dx = dcpath(ctx, 1, 0)) < 0) (void)fprintf(stderr, "%snone\n", det ? det : ""); else { (void)fprintf(stderr, "%sNamed via -D: %s\n", det ? det : "", @@ -154,7 +153,7 @@ char *det; /* detail lines prefix } (void)fprintf(stderr, "%sDevice cache file write paths:\n", ttl ? ttl : ""); - if ((dx = dcpath(2, 0)) < 0) + if ((dx = dcpath(ctx, 2, 0)) < 0) (void)fprintf(stderr, "%snone\n", det ? det : ""); else { (void)fprintf(stderr, "%sNamed via -D: %s\n", det ? det : "", @@ -193,7 +192,7 @@ char *det; /* detail lines prefix # if defined(HASENVDC) || defined(HASPERSDC) || defined(HASSYSDC) cp = NULL; # if defined(HASENVDC) - if ((dx = dcpath(1, 0)) >= 0) + if ((dx = dcpath(ctx, 1, 0)) >= 0) cp = DCpath[1]; # endif /* defined(HASENVDC) */ # if defined(HASSYSDC) @@ -201,7 +200,7 @@ char *det; /* detail lines prefix cp = HASSYSDC; # endif /* defined(HASSYSDC) */ # if defined(HASPERSDC) - if (!cp && dx != -1 && (dx = dcpath(1, 0)) >= 0) + if (!cp && dx != -1 && (dx = dcpath(ctx, 1, 0)) >= 0) cp = DCpath[3]; # endif /* defined(HASPERSDC) */ if (cp) @@ -286,10 +285,10 @@ char *punct; /* punctuation */ * usage() - display usage and exit */ -void usage(err, fh, - version) int err; /* it is called as part of error handlng? */ -int fh; /* ``-F ?'' status */ -int version; /* ``-v'' status */ +void usage(struct lsof_context *ctx, /* context */ + int err, /* it is called as part of error handlng? */ + int fh, /* ``-F ?'' status */ + int version) /* ``-v'' status */ { char buf[MAXPATHLEN + 1], *cp, *cp1, *cp2; int col, i; @@ -451,7 +450,7 @@ int version; /* ``-v'' status */ (void)fprintf(stderr, "Use the ``-h'' option to get more help information.\n"); if (!fh) - Exit(err ? LSOF_ERROR : LSOF_SUCCESS); + Exit(ctx, err ? LSOF_ERROR : LSOF_SUCCESS); } if (Fhelp) { (void)fprintf( @@ -646,8 +645,8 @@ int version; /* ``-v'' status */ # if defined(N_UNIX) : N_UNIX # else /* !defined(N_UNIX) */ - : (Nmlst = get_nlist_path(1)) ? Nmlst - : "none found" + : (Nmlst = get_nlist_path(ctx, 1)) ? Nmlst + : "none found" # endif /* defined(N_UNIX) */ ); @@ -798,7 +797,7 @@ int version; /* ``-v'' status */ (void)report_SECURITY(NULL, "; "); (void)report_WARNDEVACCESS(NULL, NULL, ";"); (void)report_HASKERNIDCK(" k", NULL); - (void)report_HASDCACHE(0, NULL, NULL); + (void)report_HASDCACHE(ctx, 0, NULL, NULL); #if defined(DIALECT_WARNING) (void)fprintf(stderr, "WARNING: %s\n", DIALECT_WARNING); @@ -860,7 +859,7 @@ int version; /* ``-v'' status */ #if defined(HASDCACHE) if (DChelp) - report_HASDCACHE(1, NULL, " "); + report_HASDCACHE(ctx, 1, NULL, " "); #endif /* defined(HASDCACHE) */ if (version) { @@ -992,7 +991,7 @@ int version; /* ``-v'' status */ (void)fprintf(stderr, " WARNING: %s\n", DIALECT_WARNING); #endif /* defined(DIALECT_WARNING) */ - (void)report_HASDCACHE(1, " ", "\t"); + (void)report_HASDCACHE(ctx, 1, " ", "\t"); } - Exit(err ? LSOF_ERROR : LSOF_SUCCESS); + Exit(ctx, err ? LSOF_ERROR : LSOF_SUCCESS); } diff --git a/src/util.c b/src/util.c index 7ad4ba19..d3fd374f 100644 --- a/src/util.c +++ b/src/util.c @@ -43,10 +43,9 @@ * file distractions */ -int util_strftime(fmtr, fmtl, fmt) -char *fmtr; /* format output receiver */ -int fmtl; /* sizeof(*fmtr) */ -char *fmt; /* format */ +int util_strftime(char *fmtr, /* format output receiver */ + int fmtl, /* sizeof(*fmtr) */ + char *fmt) /* format */ { #if defined(HAS_STRFTIME) diff --git a/tests/LTbasic.c b/tests/LTbasic.c index 79eae46b..a8b3b31f 100644 --- a/tests/LTbasic.c +++ b/tests/LTbasic.c @@ -51,16 +51,15 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *tstlsof, (char **texec, char **tkmem, char **tproc)); +static void cleanup(void); +static char *tstlsof(char **texec, char **tkmem, char **tproc); /* * Main program for dialects that support locking tests. */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ char *em; /* error message pointer */ @@ -136,10 +135,9 @@ static void cleanup() {} * tstlsof() -- test for the lsof process */ -static char *tstlsof(texec, tkmem, tproc) -char **texec; /* result of the executable test */ -char **tkmem; /* result of the /dev/kmem test */ -char **tproc; /* result of the lsof process test */ +static char *tstlsof(char **texec, /* result of the executable test */ + char **tkmem, /* result of the /dev/kmem test */ + char **tproc) /* result of the lsof process test */ { char buf[2048]; /* temporary buffer */ char *cem; /* current error message pointer */ diff --git a/tests/LTbigf.c b/tests/LTbigf.c index 123288e6..f6416328 100644 --- a/tests/LTbigf.c +++ b/tests/LTbigf.c @@ -44,9 +44,8 @@ * Main program for dialects that don't support large files */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char *pn; /* program name */ /* @@ -149,7 +148,7 @@ char *argv[]; /* arguments */ # define STATF stat /* define stat function */ # define STATS struct stat /* define stat structure */ -_PROTOTYPE(static int ck_Linux_offset_support, (void)); +static int ck_Linux_offset_support(void); # endif /* defined(LT_DIAL_linux) */ # if defined(LT_DIAL_hpux) @@ -255,16 +254,15 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static int tstwlsof, (int tt, char *opt, OFFSET_T sz)); +static void cleanup(void); +static int tstwlsof(int tt, char *opt, OFFSET_T sz); /* * Main program for dialects that support large files */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ int do_offt = OFFTST_STAT; /* do offset tests if == 1 */ @@ -511,10 +509,9 @@ static void cleanup() { * tstwlsof() -- test the open file with lsof */ -static int tstwlsof(tt, opt, sz) -int tt; /* test type -- i.e., TST_* */ -char *opt; /* additional lsof options */ -OFFSET_T sz; /* expected size (and offset) */ +static int tstwlsof(int tt, /* test type -- i.e., TST_* */ + char *opt, /* additional lsof options */ + OFFSET_T sz) /* expected size (and offset) */ { char buf[2048], buf1[2048]; /* temporary buffers */ LTfldo_t *cmdp; /* command pointer */ diff --git a/tests/LTdnlc.c b/tests/LTdnlc.c index 567ccbca..3f1b3776 100644 --- a/tests/LTdnlc.c +++ b/tests/LTdnlc.c @@ -81,16 +81,15 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *FindLsofCwd, (int *ff, LTdev_t *cwddc, char *ibuf)); +static void cleanup(void); +static char *FindLsofCwd(int *ff, LTdev_t *cwddc, char *ibuf); /* * Main program */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ char cwd[MAXPATHLEN + 1]; /* CWD */ @@ -253,10 +252,9 @@ static void cleanup() {} * FindLsofCwd() -- find the lsof CWD */ -static char *FindLsofCwd(ff, cwddc, ibuf) -int *ff; /* file-found response receptor */ -LTdev_t *cwddc; /* CWD device components */ -char *ibuf; /* CWD inode number in ASCII */ +static char *FindLsofCwd(int *ff, /* file-found response receptor */ + LTdev_t *cwddc, /* CWD device components */ + char *ibuf) /* CWD inode number in ASCII */ { char *cp; /* temporary character pointer */ char *cem; /* current error message pointer */ diff --git a/tests/LTlib.c b/tests/LTlib.c index 4e850db0..6cf8fe58 100644 --- a/tests/LTlib.c +++ b/tests/LTlib.c @@ -155,8 +155,7 @@ # define major_X(dp, em) (major_S(x2dev(dp, em))) # define minor_X(dp, em) (minor_S(x2dev(dp, em))) - -#endif /* defined(LT_DIAL_solaris) */ +#endif /* defined(LT_DIAL_solaris) */ #if defined(LT_DIAL_uw) /* @@ -202,11 +201,10 @@ static int Ufo = 0; /* Fo[] structures used */ * Local function prototypes */ -_PROTOTYPE(static void closepipe, (void)); -_PROTOTYPE(static void getlsofpath, (void)); -_PROTOTYPE(static int GetOpt, - (int ct, char *opt[], char *rules, char **em, char *pn)); -_PROTOTYPE(static X2DEV_T x2dev, (char *x, char **em)); +static void closepipe(void); +static void getlsofpath(void); +static int GetOpt(int ct, char *opt[], char *rules, char **em, char *pn); +static X2DEV_T x2dev(char *x, char **em); /* * Default major, minor, and unit macros. @@ -320,11 +318,10 @@ static void closepipe() { * Note: this function is dialect-specific. */ -char *ConvLsofDev(dev, ldev) -char *dev; /* lsof device string -- the value to the - * LSOF_FID_DEVN field of a LSOF_FID_FD block - * (see lsof_fields.h) */ -LTdev_t *ldev; /* results are returned to this structure */ +char *ConvLsofDev(char *dev, /* lsof device string -- the value to the + * LSOF_FID_DEVN field of a LSOF_FID_FD block + * (see lsof_fields.h) */ + LTdev_t *ldev) /* results are returned to this structure */ { char *dp; /* device pointer */ char *em; /* error message pointer */ @@ -362,9 +359,8 @@ LTdev_t *ldev; /* results are returned to this structure */ * Note: this function is dialect-specific. */ -char *ConvStatDev(dev, ldev) -dev_t *dev; /* device number to be converted */ -LTdev_t *ldev; /* results are returned to this structure */ +char *ConvStatDev(dev_t *dev, /* device number to be converted */ + LTdev_t *ldev) /* results are returned to this structure */ { /* @@ -388,10 +384,9 @@ LTdev_t *ldev; /* results are returned to this structure */ * in a child process */ -char *ExecLsof(opt) -char **opt; /* lsof options -- a pointer to an - * array of character pointers, - * terminated by a NULL pointer */ +char *ExecLsof(char **opt) /* lsof options -- a pointer to an + * array of character pointers, + * terminated by a NULL pointer */ { static char **av = (char **)NULL; /* lsof argument vector, dynamically * allocated */ @@ -561,13 +556,11 @@ static void getlsofpath() { * value doesn't have one -- e.g., has a default instead. */ -static int GetOpt(ct, opt, rules, em, pn) -int ct; /* option count */ -char *opt[]; /* options */ -char *rules; /* option rules */ -char **em; /* error message return */ -char *pn; -{ +static int GetOpt(int ct, /* option count */ + char *opt[], /* options */ + char *rules, /* option rules */ + char **em, /* error message return */ + char *pn) { register int c; /* character value */ register char *cp = (char *)NULL; /* character pointer */ char embf[2048]; /* error message buffer */ @@ -698,9 +691,8 @@ void LTlibClean() { (void)StopLsof(); } * MkStrCpy() -- make string copy */ -char *MkStrCpy(src, len) -char *src; /* string source to copy */ -int *len; /* returned length allocation */ +char *MkStrCpy(char *src, /* string source to copy */ + int *len) /* returned length allocation */ { char *rp; /* return pointer */ int srclen; /* source string length */ @@ -788,9 +780,8 @@ int xv; /* exit value */ * RdFrLsof() -- read from lsof */ -LTfldo_t *RdFrLsof(nf, em) -int *nf; /* number of fields receiver */ -char **em; /* error message pointer receiver */ +LTfldo_t *RdFrLsof(int *nf, /* number of fields receiver */ + char **em) /* error message pointer receiver */ { char buf[2048]; /* temporary buffer */ int bufl = (int)sizeof(buf); /* size of buf[] */ @@ -931,11 +922,10 @@ char **em; /* error message pointer receiver */ * ScanArg() -- scan arguments */ -int ScanArg(ac, av, opt, pn) -int ac; /* argument count */ -char *av[]; /* argument pointers */ -char *opt; /* option string */ -char *pn; /* program name */ +int ScanArg(int ac, /* argument count */ + char *av[], /* argument pointers */ + char *opt, /* option string */ + char *pn) /* program name */ { char *em; /* pointer to error message returned by * GetOpt() */ @@ -1017,9 +1007,8 @@ void StopLsof() { * x2dev() -- convert hex string to device number */ -static X2DEV_T x2dev(x, em) -char *x; /* hex string */ -char **em; /* error message receiver */ +static X2DEV_T x2dev(char *x, /* hex string */ + char **em) /* error message receiver */ { char buf[2048]; /* temporary message buffer */ int c; /* character holder */ diff --git a/tests/LTlock.c b/tests/LTlock.c index ca28a97c..60aa0f3f 100644 --- a/tests/LTlock.c +++ b/tests/LTlock.c @@ -167,9 +167,8 @@ * Main program for dialects that don't support flock() of fcntl() locking. */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char *pn; /* program name */ /* @@ -206,18 +205,17 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *lkfile, (int ty)); -_PROTOTYPE(static char *tstwlsof, (char *opt, char *xlk)); -_PROTOTYPE(static char *unlkfile, (int ty)); +static void cleanup(void); +static char *lkfile(int ty); +static char *tstwlsof(char *opt, char *xlk); +static char *unlkfile(int ty); /* * Main program for dialects that support locking tests. */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ char *em; /* error message pointer */ @@ -414,8 +412,7 @@ static void cleanup() { * lkfile() -- lock the test file */ -static char *lkfile(ty) -int ty; /* a *_*_LOCK requested */ +static char *lkfile(int ty) /* a *_*_LOCK requested */ { char buf[2048]; /* temporary buffer */ int ti; /* temporary integer */ @@ -499,9 +496,8 @@ int ty; /* a *_*_LOCK requested */ * tstwlsof() -- test the open file with lsof */ -static char *tstwlsof(opt, xlk) -char *opt; /* extra lsof options */ -char *xlk; /* expected lock value */ +static char *tstwlsof(char *opt, /* extra lsof options */ + char *xlk) /* expected lock value */ { char buf[2048]; /* temporary buffer */ LTfldo_t *cmdp; /* command pointer */ @@ -679,8 +675,7 @@ char *xlk; /* expected lock value */ * unlkfile() -- unlock the test file */ -static char *unlkfile(ty) -int ty; /* current *_*_LOCK lock typ */ +static char *unlkfile(int ty) /* current *_*_LOCK lock typ */ { char buf[2048]; /* temporary buffer */ int ti; /* temporary integer */ diff --git a/tests/LTnfs.c b/tests/LTnfs.c index 5549f9c5..df28412f 100644 --- a/tests/LTnfs.c +++ b/tests/LTnfs.c @@ -70,16 +70,15 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *FindNFSfile, (int *ff, char *szbuf)); +static void cleanup(void); +static char *FindNFSfile(int *ff, char *szbuf); /* * Main program */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ char *em; /* error message pointer */ @@ -263,10 +262,9 @@ static void cleanup() { * FindNFSfile() -- find the NFS file with lsof */ -static char *FindNFSfile(ff, szbuf) -int *ff; /* file-found response receptor */ -char *szbuf; /* expected file size in ASCII (if - * the file was created by this test */ +static char *FindNFSfile(int *ff, /* file-found response receptor */ + char *szbuf) /* expected file size in ASCII (if + * the file was created by this test */ { char buf[2048]; /* temporary buffer */ char *cem; /* current error message pointer */ diff --git a/tests/LTnlink.c b/tests/LTnlink.c index 5b72a012..a61136be 100644 --- a/tests/LTnlink.c +++ b/tests/LTnlink.c @@ -68,17 +68,16 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *FindFile, (char *opt, int *ff, int ie, LTdev_t *tfdc, - char *ibuf, char *xlnk, char *szbuf)); +static void cleanup(void); +static char *FindFile(char *opt, int *ff, int ie, LTdev_t *tfdc, char *ibuf, + char *xlnk, char *szbuf); /* * Main program */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ int do_unlink = 1; /* do the unlink test section */ @@ -332,14 +331,13 @@ static void cleanup() { * FindFile() -- find a file with lsof */ -static char *FindFile(opt, ff, ie, tfdc, ibuf, xlnk, szbuf) -char *opt; /* additional lsof options */ -int *ff; /* file-found response receptor */ -int ie; /* ignore errors if == 1 */ -LTdev_t *tfdc; /* test file device components */ -char *ibuf; /* inode number in ASCII */ -char *xlnk; /* expected link count */ -char *szbuf; /* file size in ASCII */ +static char *FindFile(char *opt, /* additional lsof options */ + int *ff, /* file-found response receptor */ + int ie, /* ignore errors if == 1 */ + LTdev_t *tfdc, /* test file device components */ + char *ibuf, /* inode number in ASCII */ + char *xlnk, /* expected link count */ + char *szbuf) /* file size in ASCII */ { char buf[2048]; /* temporary buffer */ char *cem; /* current error message pointer */ diff --git a/tests/LTsock.c b/tests/LTsock.c index a93177f4..7c582e18 100644 --- a/tests/LTsock.c +++ b/tests/LTsock.c @@ -171,20 +171,19 @@ int Ssock = -1; /* server socket */ * Local function prototypes */ -_PROTOTYPE(static void CleanupClnt, (void)); -_PROTOTYPE(static void CleanupSrvr, (void)); -_PROTOTYPE(static SIGHANDLER_T HandleClntAlarm, (int sig)); -_PROTOTYPE(static SIGHANDLER_T HandleSrvrAlarm, (int sig)); -_PROTOTYPE(static char *FindSock, (int fn)); -_PROTOTYPE(static void StartClnt, (struct sockaddr_in * cad)); +static void CleanupClnt(void); +static void CleanupSrvr(void); +static SIGHANDLER_T HandleClntAlarm(int sig); +static SIGHANDLER_T HandleSrvrAlarm(int sig); +static char *FindSock(int fn); +static void StartClnt(struct sockaddr_in *cad); /* * Main program */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { struct sockaddr_in aa; /* accept address */ struct sockaddr_in ba; /* bind address */ @@ -562,8 +561,7 @@ static void CleanupSrvr() { * FindSock() -- find sockets with lsof */ -static char *FindSock(fn) -int fn; /* function -- an LT_FBY* value */ +static char *FindSock(int fn) /* function -- an LT_FBY* value */ { char buf[2048]; /* temporary buffer */ int bufl = sizeof(buf); /* size of buf[] */ @@ -766,8 +764,7 @@ int fn; /* function -- an LT_FBY* value */ * HandleClntAlarm() -- handle client alarm */ -static SIGHANDLER_T HandleClntAlarm(sig) -int sig; /* the signal (SIGALRM) */ +static SIGHANDLER_T HandleClntAlarm(int sig) /* the signal (SIGALRM) */ { (void)PrtMsgX("ERROR!!! client caught an alarm signal", Pn, CleanupClnt, 1); @@ -777,8 +774,7 @@ int sig; /* the signal (SIGALRM) */ * Handle SrvrAlarm() -- handle server alarm */ -static SIGHANDLER_T HandleSrvrAlarm(sig) -int sig; /* the signal (SIGALRM) */ +static SIGHANDLER_T HandleSrvrAlarm(int sig) /* the signal (SIGALRM) */ { (void)PrtMsgX("ERROR!!! server caught an alarm signal.", Pn, CleanupSrvr, 1); diff --git a/tests/LTszoff.c b/tests/LTszoff.c index dcf3fc23..148a8910 100644 --- a/tests/LTszoff.c +++ b/tests/LTszoff.c @@ -51,7 +51,7 @@ * offsets -- see the function \ * ck_Linux_offset_support() */ -_PROTOTYPE(static int ck_Linux_offset_support, (void)); +static int ck_Linux_offset_support(void); #endif /* defined(LT_DIAL_linux) */ /* @@ -76,16 +76,15 @@ char *Pn = (char *)NULL; /* program name */ * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *testlsof, (int tt, char *opt, char *xval)); +static void cleanup(void); +static char *testlsof(int tt, char *opt, char *xval); /* * Main program */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ int do_offt = OFFTST_STAT; /* do offset tests if == 1 */ @@ -274,10 +273,9 @@ static void cleanup() { * testlsof() -- test the open file with lsof */ -static char *testlsof(tt, opt, xval) -int tt; /* test type -- TYTST_* symbol */ -char *opt; /* extra lsof options */ -char *xval; /* expected value */ +static char *testlsof(int tt, /* test type -- TYTST_* symbol */ + char *opt, /* extra lsof options */ + char *xval) /* expected value */ { char buf[2048]; /* temporary buffer */ char *cem; /* current error message pointer */ diff --git a/tests/LTunix.c b/tests/LTunix.c index 6bbf7abe..46c544b4 100644 --- a/tests/LTunix.c +++ b/tests/LTunix.c @@ -59,16 +59,15 @@ char *Path[2] = {(char *)NULL, (char *)NULL}; * Local function prototypes */ -_PROTOTYPE(static void cleanup, (void)); -_PROTOTYPE(static char *FindUsocks, (void)); +static void cleanup(void); +static char *FindUsocks(void); /* * Main program */ -int main(argc, argv) -int argc; /* argument count */ -char *argv[]; /* arguments */ +int main(int argc, /* argument count */ + char *argv[]) /* arguments */ { char buf[2048]; /* temporary buffer */ char cwd[MAXPATHLEN + 1]; /* CWD buffer */ diff --git a/tests/LsofTest.h b/tests/LsofTest.h index d54c1322..c4eff236 100644 --- a/tests/LsofTest.h +++ b/tests/LsofTest.h @@ -35,19 +35,6 @@ #if !defined(LSOF_TEST_H) # define LSOF_TEST_H 1 -/* - * The _PROTOTYPE macro provides strict ANSI C prototypes if __STDC__ - * is defined, and old-style K&R prototypes otherwise. - * - * (With thanks to Andy Tanenbaum) - */ - -# if defined(__STDC__) -# define _PROTOTYPE(function, params) function params -# else /* !defined(__STDC__) */ -# define _PROTOTYPE(function, params) function() -# endif /* defined(__STDC__) */ - /* * The following define keeps gcc>=2.7 from complaining about the failure * of the Exit() function to return. @@ -330,17 +317,17 @@ extern int errno; /* error number */ * these functions may be found in LTlib.c. */ -_PROTOTYPE(extern char *CanRdKmem, (void)); -_PROTOTYPE(extern char *ConvStatDev, (dev_t * dev, LTdev_t *ldev)); -_PROTOTYPE(extern char *ConvLsofDev, (char *dev, LTdev_t *ldev)); -_PROTOTYPE(extern char *ExecLsof, (char **opt)); -_PROTOTYPE(extern char *IsLsofExec, (void)); -_PROTOTYPE(extern void LTlibClean, (void)); -_PROTOTYPE(extern char *MkStrCpy, (char *src, int *len)); -_PROTOTYPE(extern LTfldo_t *RdFrLsof, (int *nf, char **em)); -_PROTOTYPE(extern void PrtMsg, (char *mp, char *pn)); -_PROTOTYPE(extern void PrtMsgX, (char *mp, char *pn, void (*f)(), int xv)); -_PROTOTYPE(extern int ScanArg, (int ac, char *av[], char *opt, char *pn)); -_PROTOTYPE(extern void StopLsof, (void)); +extern char *CanRdKmem(void); +extern char *ConvStatDev(dev_t *dev, LTdev_t *ldev); +extern char *ConvLsofDev(char *dev, LTdev_t *ldev); +extern char *ExecLsof(char **opt); +extern char *IsLsofExec(void); +extern void LTlibClean(void); +extern char *MkStrCpy(char *src, int *len); +extern LTfldo_t *RdFrLsof(int *nf, char **em); +extern void PrtMsg(char *mp, char *pn); +extern void PrtMsgX(char *mp, char *pn, void (*f)(), int xv); +extern int ScanArg(int ac, char *av[], char *opt, char *pn); +extern void StopLsof(void); #endif /* LSOF_TEST_H */