diff options
Diffstat (limited to 'dialects')
-rw-r--r-- | dialects/aix/dproc.c | 8 | ||||
-rw-r--r-- | dialects/darwin/libproc/Makefile | 2 | ||||
-rw-r--r-- | dialects/darwin/libproc/dfile.c | 8 | ||||
-rw-r--r-- | dialects/darwin/libproc/dproc.c | 6 | ||||
-rw-r--r-- | dialects/darwin/libproc/dstore.c | 2 | ||||
-rw-r--r-- | dialects/darwin/libproc/machine.h | 2 | ||||
-rw-r--r-- | dialects/freebsd/dlsof.h | 17 | ||||
-rw-r--r-- | dialects/freebsd/dmnt.c | 6 | ||||
-rw-r--r-- | dialects/freebsd/dnode.c | 169 | ||||
-rw-r--r-- | dialects/freebsd/dnode1.c | 32 | ||||
-rw-r--r-- | dialects/freebsd/dnode2.c | 3 | ||||
-rw-r--r-- | dialects/freebsd/dproc.c | 17 | ||||
-rw-r--r-- | dialects/freebsd/dproto.h | 10 | ||||
-rw-r--r-- | dialects/freebsd/dsock.c | 60 | ||||
-rw-r--r-- | dialects/freebsd/dstore.c | 11 | ||||
-rw-r--r-- | dialects/freebsd/machine.h | 13 | ||||
-rw-r--r-- | dialects/hpux/pstat/dproc.c | 4 | ||||
-rw-r--r-- | dialects/linux/dmnt.c | 4 | ||||
-rw-r--r-- | dialects/linux/dnode.c | 194 | ||||
-rw-r--r-- | dialects/linux/dproc.c | 161 | ||||
-rw-r--r-- | dialects/linux/dsock.c | 27 | ||||
-rw-r--r-- | dialects/sun/machine.h | 14 |
22 files changed, 674 insertions, 96 deletions
diff --git a/dialects/aix/dproc.c b/dialects/aix/dproc.c index c951717..eb7fffb 100644 --- a/dialects/aix/dproc.c +++ b/dialects/aix/dproc.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dproc.c,v 1.26 2008/10/21 16:14:18 abe Exp $"; +static char *rcsid = "$Id: dproc.c,v 1.27 2018/02/14 14:23:27 abe Exp $"; #endif @@ -409,7 +409,7 @@ gather_proc_info() * If only ORed process selection options have been specified, * enable conditional file skipping and socket file only checking. */ - if ((Selflags & SELFILE) || !(Selflags & SELPROC)) + if ((Selflags & SELFILE) || !(Selflags & SelProc)) cckreg = ckscko = 0; else cckreg = ckscko = 1; @@ -537,7 +537,7 @@ gather_proc_info() * socket file only checking, based on the process' selection * status. */ - ckscko = (sf & SELPROC) ? 0 : 1; + ckscko = (sf & SelProc) ? 0 : 1; } #else /* AIXV>=4300 */ @@ -557,7 +557,7 @@ gather_proc_info() * socket file only checking, based on the process' selection * status. */ - ckscko = (sf & SELPROC) ? 0 : 1; + ckscko = (sf & SelProc) ? 0 : 1; } if (!fds) { if (!(fds = (struct FDSINFO *)malloc((MALLOC_S)FDSINFOSIZE))) diff --git a/dialects/darwin/libproc/Makefile b/dialects/darwin/libproc/Makefile index 6433004..a3bdc3c 100644 --- a/dialects/darwin/libproc/Makefile +++ b/dialects/darwin/libproc/Makefile @@ -1,7 +1,7 @@ # Darwin libproc-based lsof Makefile # -# $Id: Makefile,v 1.7 2009/03/25 19:21:37 abe Exp abe $ +# $Id: Makefile,v 1.8 2018/02/14 14:27:57 abe Exp $ PROG= lsof diff --git a/dialects/darwin/libproc/dfile.c b/dialects/darwin/libproc/dfile.c index d7705f6..6b99c66 100644 --- a/dialects/darwin/libproc/dfile.c +++ b/dialects/darwin/libproc/dfile.c @@ -36,12 +36,16 @@ #ifndef lint static char copyright[] = "@(#) Copyright 2005-2007 Apple Inc. and Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dfile.c,v 1.8 2012/04/10 16:41:04 abe Exp abe $"; +static char *rcsid = "$Id: dfile.c,v 1.9 2018/02/14 14:27:57 abe Exp $"; #endif #include "lsof.h" +#if defined(PROC_FP_GUARDED) +#extern struct pff_tab Pgf_tab[]; +#endif /* defined(PROC_FP_GUARDED) */ + /* * enter_file_info() -- enter file information @@ -286,7 +290,7 @@ print_nm(lf) #if defined(PROC_FP_GUARDED) if (extra > 1) - putchar(`,'); + putchar(','); if (lf->guardflags) { struct pff_tab *tp; long gf; diff --git a/dialects/darwin/libproc/dproc.c b/dialects/darwin/libproc/dproc.c index e4a2f00..069dc2b 100644 --- a/dialects/darwin/libproc/dproc.c +++ b/dialects/darwin/libproc/dproc.c @@ -37,7 +37,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 2005-2007 Apple Inc. and Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dproc.c,v 1.9 2013/01/02 17:03:05 abe Exp $"; +static char *rcsid = "$Id: dproc.c,v 1.10 2018/02/14 14:27:57 abe Exp $"; #endif #include "lsof.h" @@ -221,7 +221,7 @@ gather_proc_info() * If only ORed process selection options have been specified, * enable conditional file skipping and socket file only checking. */ - if ((Selflags & SELFILE) || !(Selflags & SELPROC)) + if ((Selflags & SELFILE) || !(Selflags & SelProc)) cckreg = ckscko = 0; else cckreg = ckscko = 1; @@ -338,7 +338,7 @@ gather_proc_info() * socket file only checking, based on the process' selection * status. */ - ckscko = (sf & SELPROC) ? 0 : 1; + ckscko = (sf & SelProc) ? 0 : 1; } /* * Get root and current directory information. diff --git a/dialects/darwin/libproc/dstore.c b/dialects/darwin/libproc/dstore.c index 8727181..713070c 100644 --- a/dialects/darwin/libproc/dstore.c +++ b/dialects/darwin/libproc/dstore.c @@ -37,7 +37,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 2005 Apple Computer, Inc. and Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dstore.c,v 1.4 2008/10/21 16:15:16 abe Exp abe $"; +static char *rcsid = "$Id: dstore.c,v 1.5 2018/02/14 14:27:57 abe Exp $"; #endif diff --git a/dialects/darwin/libproc/machine.h b/dialects/darwin/libproc/machine.h index 050a49a..9918eb7 100644 --- a/dialects/darwin/libproc/machine.h +++ b/dialects/darwin/libproc/machine.h @@ -35,7 +35,7 @@ /* - * $Id: machine.h,v 1.10 2013/01/02 17:03:05 abe Exp abe $ + * $Id: machine.h,v 1.11 2018/02/14 14:27:57 abe Exp $ */ diff --git a/dialects/freebsd/dlsof.h b/dialects/freebsd/dlsof.h index b075e6a..bcb59bc 100644 --- a/dialects/freebsd/dlsof.h +++ b/dialects/freebsd/dlsof.h @@ -31,7 +31,7 @@ /* - * $Id: dlsof.h,v 1.47 2015/07/07 20:23:43 abe Exp $ + * $Id: dlsof.h,v 1.48 2018/02/14 14:26:03 abe Exp $ */ @@ -87,6 +87,14 @@ #define boolean_t int # endif /* defined(NEEDS_BOOLEAN_T) */ +/* + * Define KLD_MODULE to avoid the error "ARM_NMMUS is 0" from ARM's + * <machine/cpuconf.h>. + */ + +#define KLD_MODULE + + #include <sys/conf.h> # if defined(HAS_VM_MEMATTR_T) @@ -134,8 +142,10 @@ int getmntinfo(struct statfs **, int); #include <rpc/types.h> #include <sys/protosw.h> #include <sys/socket.h> +#define _WANT_SOCKET #include <sys/socketvar.h> #include <sys/un.h> +#define _WANT_UNPCB #include <sys/unpcb.h> # if FREEBSDV>=3000 @@ -146,12 +156,14 @@ int getmntinfo(struct statfs **, int); #include <netinet/in_systm.h> #include <netinet/ip.h> #include <net/route.h> +#define _WANT_INPCB /* for FreeBSD 12 and above */ #include <netinet/in_pcb.h> #include <netinet/ip_var.h> #include <netinet/tcp.h> #include <netinet/tcpip.h> #include <netinet/tcp_fsm.h> #include <netinet/tcp_timer.h> +#define _WANT_TCPCB /* for FreeBSD 12 and above */ #include <netinet/tcp_var.h> #include <sys/ucred.h> #include <sys/uio.h> @@ -476,6 +488,7 @@ struct vop_advlock_args { int dummy; }; /* to pacify lf_advlock() prototype */ # endif /* FREEBSDV<5000 */ # endif /* FREEBSDV>=2020 */ +#undef bzero /* avoid _KERNEL conflict */ #include <string.h> @@ -561,6 +574,8 @@ struct mounts { struct mounts *next; /* forward link */ }; +#define X_BADFILEOPS "badfileops" +extern KA_T X_bfopsa; #define X_NCACHE "ncache" #define X_NCSIZE "ncsize" #define NL_NAME n_name diff --git a/dialects/freebsd/dmnt.c b/dialects/freebsd/dmnt.c index b4db313..3459c7c 100644 --- a/dialects/freebsd/dmnt.c +++ b/dialects/freebsd/dmnt.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dmnt.c,v 1.17 2013/01/02 17:01:43 abe Exp $"; +static char *rcsid = "$Id: dmnt.c,v 1.18 2018/02/14 14:26:03 abe Exp $"; #endif @@ -329,8 +329,8 @@ no_space_for_mount: sb.st_mode = S_IFDIR | 0777; if (!Fwarn) { (void) fprintf(stderr, - " assuming \"dev=%x\" from mount table\n", - sb.st_dev); + " assuming \"dev=%lx\" from mount table\n", + (unsigned long)sb.st_dev); } } /* diff --git a/dialects/freebsd/dnode.c b/dialects/freebsd/dnode.c index 84467cb..bf743df 100644 --- a/dialects/freebsd/dnode.c +++ b/dialects/freebsd/dnode.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dnode.c,v 1.44 2015/07/07 20:23:43 abe Exp $"; +static char *rcsid = "$Id: dnode.c,v 1.45 2018/02/14 14:26:03 abe Exp $"; #endif @@ -52,6 +52,11 @@ _PROTOTYPE(static int lkup_dev_tty,(dev_t *dr, INODETYPE *ir)); #endif /* defined(HASFDESCFS) && HASFDESCFS==1 */ +#if defined(HASPTSFN) && defined(DTYPE_PTS) +#include <sys/tty.h> +#endif /* defined(HASPTSFN) && defined(DTYPE_PTS) */ + + #if defined(HAS_TMPFS) #define _KERNEL #include <fs/tmpfs/tmpfs.h> @@ -62,7 +67,7 @@ _PROTOTYPE(static void get_lock_state,(KA_T f)); /* - * get_lock_state() -- get the lock state + * get_lock_state() - get the lock state */ static void @@ -232,7 +237,7 @@ lkup_dev_tty_again: #if defined(HASKQUEUE) /* - * process_kqueue() -- process kqueue file + * process_kqueue() - process kqueue file * * Strictly speaking this function should appear in dfile.c, because it is * a file processing function. However, the Net and Open BSD sources don't @@ -272,6 +277,7 @@ process_node(va) struct nfsnode *n; size_t sz; char *ty; + unsigned char ums; enum vtype type; struct vnode *v, vb; struct l_vfs *vfs; @@ -320,6 +326,14 @@ process_node(va) #endif /* defined(HASFDESCFS) */ +#if defined(HASFUSEFS) + dev_t fuse_dev; + int fuse_dev_def, fuse_stat; + INODETYPE fuse_ino; + long fuse_links; + SZOFFTYPE fuse_sz; +#endif /* defined(HASFUSEFS) */ + #if FREEBSDV>=5000 # if defined(HAS_UFS1_2) int ufst; @@ -337,8 +351,8 @@ process_node(va) struct devfs_dirent *d; char vtbuf[32]; char *vtbp; - enum vtagtype { VT_DEVFS, VT_FDESC, VT_ISOFS, VT_PSEUDOFS, VT_NFS, - VT_NULL, VT_TMPFS, VT_UFS, VT_ZFS, VT_UNKNOWN + enum vtagtype { VT_DEVFS, VT_FDESC, VT_FUSEFS, VT_ISOFS, VT_PSEUDOFS, + VT_NFS, VT_NULL, VT_TMPFS, VT_UFS, VT_ZFS, VT_UNKNOWN }; # if defined(HAS_TMPFS) @@ -400,7 +414,7 @@ process_overlaid_node: * Initialize miscellaneous variables. This is done so that processing an * overlaid node will be a fresh start. */ - devs = rdevs = 0; + devs = rdevs = ums = 0; i = (struct inode *)NULL; n = (struct nfsnode *)NULL; Namech[0] = '\0'; @@ -413,6 +427,10 @@ process_overlaid_node: f = (struct fdescnode *)NULL; #endif /* defined(HASFDESCFS) */ +#if defined(HASFUSEFS) + fuse_dev_def = fuse_stat = 0; +#endif /* defined(HASFUSEFS) */ + #if FREEBSDV<5000 m = (struct mfsnode *)NULL; #else /* FREEBSDV>=5000 */ @@ -577,10 +595,14 @@ process_overlaid_node: vtag = VT_ISOFS; else if (!strcmp(vtbuf, "pseudofs")) vtag = VT_PSEUDOFS; + else if (!strcmp(vtbuf, "nullfs")) + vtag = VT_NULL; else if (!strcmp(vtbuf, "null")) vtag = VT_NULL; else if (!strcmp(vtbuf, "fdesc")) vtag = VT_FDESC; + else if (!strcmp(vtbuf, "fuse")) + vtag = VT_FUSEFS; else if (!strcmp(vtbuf, "tmpfs")) vtag = VT_TMPFS; } else @@ -631,6 +653,20 @@ process_overlaid_node: # endif /* FREEBSDV<2000 */ #endif /* defined(HASFDESCFS) */ +#if defined(HASFUSEFS) + case VT_FUSEFS: + if (read_fuse_node(v, &fuse_dev, &fuse_dev_def, &fuse_ino, + &fuse_links, &fuse_sz)) + { + (void) snpf(Namech, Namechl, "no fuse node: %s", + print_kptr((KA_T)v->v_data, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + fuse_stat = 1; + break; +#endif /* defined(HASFUSEFS) */ + #if defined(HAS9660FS) case VT_ISOFS: if (read_iso_node(v, &iso_dev, &iso_dev_def, &iso_ino, &iso_links, @@ -795,6 +831,7 @@ process_overlaid_node: # if defined(HAS_UFS1_2) if (i->i_ump && !kread((KA_T)i->i_ump, (char *)&um, sizeof(um))) { + ums = 1; if (um.um_fstype == UFS1) { if (i->i_din1 && !kread((KA_T)i->i_din1, (char *)&d1, sizeof(d1))) @@ -870,26 +907,33 @@ process_overlaid_node: } else if (i) { #if FREEBSDV>=4000 +# if defined(HAS_NO_IDEV) + if (ums) { + dev = Dev2Udev((KA_T)um.um_dev); + devs = 1; + } +# else /* !defined(HAS_NO_IDEV) */ if (i->i_dev -# if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) +# if !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) && !kread((KA_T)i->i_dev, (char *)&si, sizeof(si)) -# endif /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ +# endif/* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ ) { -# if defined(HAS_NO_SI_UDEV) -# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) +# if defined(HAS_NO_SI_UDEV) +# if defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) dev = Dev2Udev((KA_T)i->i_dev); -# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ +# else /* !defined(HAS_CONF_MINOR) && !defined(HAS_CDEV2PRIV) */ dev = Dev2Udev(&si); -# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ -# else /* !defined(HAS_NO_SI_UDEV) */ +# endif /* defined(HAS_CONF_MINOR) || defined(HAS_CDEV2PRIV) */ +# else /* !defined(HAS_NO_SI_UDEV) */ dev = si.si_udev; -# endif /* defined(HAS_NO_SI_UDEV) */ +# endif /* defined(HAS_NO_SI_UDEV) */ devs = 1; } +# endif /* defined(HAS_NO_IDEV) */ #else /* FREEBSDV<4000 */ dev = i->i_dev; devs = 1; @@ -937,7 +981,14 @@ process_overlaid_node: * Record information returned by readzfsnode(). */ if (vfs) { - dev = vfs->fsid.val[0]; + union { + int32_t val[2]; + dev_t dev; + } vfs_fsid; + + vfs_fsid.val[0] = vfs->fsid.val[0]; + vfs_fsid.val[1] = vfs->fsid.val[1]; + dev = vfs_fsid.dev; devs = 1; } if ((type == VCHR) || (type == VBLK)) { @@ -959,7 +1010,7 @@ process_overlaid_node: # if HASFDESCFS==1 else -# endif /* HASFDESFS==1 */ +# endif /* HASFDESCFS==1 */ # endif /* defined(HASFDLINK) */ # if HASFDESCFS==1 @@ -972,7 +1023,7 @@ process_overlaid_node: devs = Lf->inp_ty = 1; } } -# endif /* HASFDESFS==1 */ +# endif /* HASFDESCFS==1 */ } #endif /* defined(HASFDESCFS) && (defined(HASFDLINK) || HASFDESCFS==1) */ @@ -984,6 +1035,13 @@ process_overlaid_node: } #endif /* defined(HAS9660FS) */ +#if defined(HASFUSEFS) + else if (fuse_stat && fuse_dev_def) { + dev = fuse_dev; + devs = Lf->inp_ty = 1; + } +#endif /* defined(HASFUSEFS) */ + #if FREEBSDV>=5000 else if (d) { if (vfs) { @@ -1074,6 +1132,13 @@ process_overlaid_node: } #endif /* defined(HAS9660FS) */ +#if defined(HASFUSEFS) + else if (fuse_stat) { + Lf->inode = fuse_ino; + Lf->inp_ty = 1; + } +#endif /* defined(HASFUSEFS) */ + #if defined(HASPROCFS) # if FREEBSDV>=2000 else if (p) { @@ -1205,8 +1270,16 @@ process_overlaid_node: Lf->sz = (SZOFFTYPE)iso_sz; Lf->sz_def = 1; } + #endif /* defined(HAS9660FS) */ +#if defined(HASFUSEFS) + else if (fuse_stat) { + Lf->sz = (SZOFFTYPE)fuse_sz; + Lf->sz_def = 1; + } +#endif /* defined(HASFUSEFS) */ + } else if ((type == VCHR || type == VBLK) && !Fsize) Lf->off_def = 1; @@ -1265,6 +1338,13 @@ process_overlaid_node: } #endif /* defined(HAS9660FS) */ +#if defined(HASFUSEFS) + else if (fuse_stat) { + Lf->nlink = fuse_links; + Lf->nlink_def = 1; + } +#endif /* defined(HASFUSEFS) */ + #if FREEBSDV>=5000 else if (d) { Lf->nlink = d->de_links; @@ -1577,3 +1657,58 @@ process_pipe(pa) enter_nm(Namech); } #endif /* FREEBSDV>=2020 */ + + +#if defined(HASPTSFN) && defined(DTYPE_PTS) +/* + * process_pts - process a file structure whose type is DTYPE_PTS + */ + +void process_pts(tp) + KA_T tp; /* f_data pointer to tty structure */ +{ + dev_t dev; /* IFCHR device number */ + struct tty t; /* tty structure */ + + (void) snpf(Lf->type, sizeof(Lf->type), "PTS"); +/* + * Read the tty structure. Quit if it can't be read. + */ + if (!tp || kread(tp, (char *)&t, sizeof(t))) { + (void) snpf(Namech, Namechl, + "can't read DTYPE_PTS tty struct: %s", + print_kptr((KA_T)tp, (char *)NULL, 0)); + enter_nm(Namech); + return; + } +/* + * Convert the tty's cdev from kernel to user form. + * + * Set the device number to DevDev, the device number of /dev. + * + * Set the inode number to the device number. + * + * Set the file type to N_CHR for a character device (That's what a PTS is.) + * + * Force the use of offset from file structure. + * + * Set rdev to the converted device. + * + * Force the reloading of the device cache. + */ + if ((dev = Dev2Udev((KA_T)t.t_dev)) == NODEV) { + (void) snpf(Namech, Namechl, + "can't convert device in DTYPE_PTS tty struct: %s", + print_kptr((KA_T)tp, (char *)NULL, 0)); + enter_nm(Namech); + return; + } + Lf->dev = DevDev; + Lf->inode = (INODETYPE)dev; + Lf->inp_ty = Lf->dev_def = Lf->rdev_def = 1; + Lf->ntype = N_CHR; + Lf->off_def = 1; + Lf->rdev = dev; + DCunsafe = 1; +} +#endif /* defined(HASPTSFN) && defined(DTYPE_PTS) */ diff --git a/dialects/freebsd/dnode1.c b/dialects/freebsd/dnode1.c index a5fa225..f78b9f8 100644 --- a/dialects/freebsd/dnode1.c +++ b/dialects/freebsd/dnode1.c @@ -35,7 +35,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dnode1.c,v 1.10 2008/10/21 16:16:06 abe Exp abe $"; +static char *rcsid = "$Id: dnode1.c,v 1.11 2018/02/14 14:26:03 abe Exp $"; #endif @@ -142,3 +142,33 @@ read_iso_node(v, d, dd, ino, nl, sz) return(0); } #endif /* defined(HAS9660FS) */ + + +#if defined(HASFUSEFS) +#include <fs/fuse/fuse_node.h> +/* + * read_fuse_node() -- read FUSE file system fuse_node + */ + +int +read_fuse_node(v, d, dd, ino, nl, sz) + struct vnode *v; /* containing vnode */ + dev_t *d; /* returned device number */ + int *dd; /* returned device-defined flag */ + INODETYPE *ino; /* returned inode number */ + long *nl; /* returned number of links */ + SZOFFTYPE *sz; /* returned size */ +{ + struct fuse_vnode_data fn; /* FUSE node */ + + if (!v->v_data + || kread((KA_T)v->v_data, (char *)&fn, sizeof(fn))) + return(1); + *d = fn.cached_attrs.va_fsid; + *dd = 1; + *ino = (INODETYPE)fn.cached_attrs.va_fileid; + *nl = (long)fn.cached_attrs.va_nlink; + *sz = (SZOFFTYPE)fn.cached_attrs.va_size; + return(0); +} +#endif /* defined(HASFUSEFS) */ diff --git a/dialects/freebsd/dnode2.c b/dialects/freebsd/dnode2.c index 4b6cf9a..d8c9b87 100644 --- a/dialects/freebsd/dnode2.c +++ b/dialects/freebsd/dnode2.c @@ -35,7 +35,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 2008 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dnode2.c,v 1.6 2015/07/07 20:23:43 abe Exp $"; +static char *rcsid = "$Id: dnode2.c,v 1.7 2018/02/14 14:26:03 abe Exp $"; #endif @@ -52,6 +52,7 @@ static char *rcsid = "$Id: dnode2.c,v 1.6 2015/07/07 20:23:43 abe Exp $"; #define VOP_UNLOCK(vp, f) ((void)0) # endif /* defined(__clang__) */ +#define KLD_MODULE /* for ARM: prevent "ARM_NARCH is 0 " error */ #include <sys/zfs_znode.h> #undef _KERNEL diff --git a/dialects/freebsd/dproc.c b/dialects/freebsd/dproc.c index e2b2d0c..0185686 100644 --- a/dialects/freebsd/dproc.c +++ b/dialects/freebsd/dproc.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dproc.c,v 1.19 2015/07/07 20:23:43 abe Exp $"; +static char *rcsid = "$Id: dproc.c,v 1.20 2018/02/14 14:26:03 abe Exp $"; #endif #include "lsof.h" @@ -190,7 +190,7 @@ gather_proc_info() * If only ORed process selection options have been specified, * enable conditional file skipping and socket file only checking. */ - if ((Selflags & SELFILE) || !(Selflags & SELPROC)) + if ((Selflags & SELFILE) || !(Selflags & SelProc)) cckreg = ckscko = 0; else cckreg = ckscko = 1; @@ -324,7 +324,7 @@ gather_proc_info() * socket file only checking, based on the process' selection * status. */ - ckscko = (sf & SELPROC) ? 0 : 1; + ckscko = (sf & SelProc) ? 0 : 1; } alloc_lproc(p->P_PID, pgid, ppid, (UID_ARG)uid, p->P_COMM, (int)pss, (int)sf); @@ -565,6 +565,17 @@ get_kernel_access() Exit(1); } +#if defined(X_BADFILEOPS) +/* + * Get kernel's badfileops address (for process_file()). + */ + if (get_Nl_value(X_BADFILEOPS, (struct drive_Nl *)NULL, &X_bfopsa) < 0 + || !X_bfopsa) + { + X_bfopsa = (KA_T)0; + } +#endif /* defined(X_BADFILEOPS) */ + #if defined(WILLDROPGID) /* * Drop setgid permission, if necessary. diff --git a/dialects/freebsd/dproto.h b/dialects/freebsd/dproto.h index cc23cf7..ca05356 100644 --- a/dialects/freebsd/dproto.h +++ b/dialects/freebsd/dproto.h @@ -33,7 +33,7 @@ /* - * $Id: dproto.h,v 1.14 2009/03/25 19:23:06 abe Exp $ + * $Id: dproto.h,v 1.15 2018/02/14 14:26:03 abe Exp $ */ @@ -53,6 +53,10 @@ _PROTOTYPE(extern int is_file_named,(char *p, int cd)); _PROTOTYPE(extern void process_socket,(KA_T sa)); _PROTOTYPE(extern struct l_vfs *readvfs,(KA_T vm)); +#if defined(HASPTSFN) +_PROTOTYPE(extern void process_pts,(KA_T ta)); +#endif /* defined(HASPTSFN) */ + #if defined(HASKQUEUE) _PROTOTYPE(extern void process_kqueue,(KA_T ka)); #endif /* defined(HASKQUEUE) */ @@ -61,6 +65,10 @@ _PROTOTYPE(extern void process_kqueue,(KA_T ka)); _PROTOTYPE(extern void process_pipe,(KA_T pa)); #endif /* FREEBSDV>=2020 */ +#if defined(HASFUSEFS) +_PROTOTYPE(extern int read_fuse_node,(struct vnode *v, dev_t *d, int *dd, INODETYPE *ino, long *nl, SZOFFTYPE *sz)); +#endif /* defined(HASFUSEFS) */ + #if defined(HAS9660FS) _PROTOTYPE(extern int read_iso_node,(struct vnode *v, dev_t *d, int *dd, INODETYPE *ino, long *nl, SZOFFTYPE *sz)); #endif /* defined(HAS9660FS) */ diff --git a/dialects/freebsd/dsock.c b/dialects/freebsd/dsock.c index d942602..ee8ced7 100644 --- a/dialects/freebsd/dsock.c +++ b/dialects/freebsd/dsock.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dsock.c,v 1.30 2015/07/07 20:23:43 abe Exp $"; +static char *rcsid = "$Id: dsock.c,v 1.31 2018/02/14 14:26:03 abe Exp $"; #endif @@ -79,7 +79,7 @@ static char *rcsid = "$Id: dsock.c,v 1.30 2015/07/07 20:23:43 abe Exp $"; * Local function prototypes */ -_PROTOTYPE(static int ckstate,(KA_T ta, struct tcpcb *t, int fam)); +_PROTOTYPE(static int ckstate,(KA_T pcb, KA_T ta, struct tcpcb *t, int fam)); /* @@ -91,7 +91,8 @@ _PROTOTYPE(static int ckstate,(KA_T ta, struct tcpcb *t, int fam)); */ static int -ckstate(ta, t, fam) +ckstate(pcb, ta, t, fam) + KA_T pcb; /* PCB address */ KA_T ta; /* TCP control block address */ struct tcpcb *t; /* TCP control block receptor */ int fam; /* protocol family */ @@ -100,14 +101,18 @@ ckstate(ta, t, fam) /* * Read TCP control block. */ - if (kread(ta, (char *)t, sizeof(struct tcpcb))) + if (kread(ta, (char *)t, sizeof(struct tcpcb)) + || (KA_T)t->t_inpcb != pcb) + { return(-1); + } if (TcpStXn || TcpStIn) { /* * If there are TCP state inclusions or exclusions, check them. */ - tsnx = (int)t->t_state + TcpStOff; + if ((tsnx = (int)t->t_state + TcpStOff) >= TcpNstates) + return(0); if (TcpStXn) { if (TcpStX[tsnx]) { Lf->sf &= ~SELNET; @@ -236,22 +241,43 @@ process_socket(sa) #if defined(HASSOOPT) Lf->lts.ltm = (unsigned int)s.so_linger; Lf->lts.opt = (unsigned int)s.so_options; + +# if __FreeBSD_version>=1200027 + if (s.so_options & SO_ACCEPTCONN) { + Lf->lts.pqlen = (unsigned int)s.sol_incqlen; + Lf->lts.qlen = (unsigned int)s.sol_qlen; + Lf->lts.qlim = (unsigned int)s.sol_qlimit; + } else { + Lf->lts.rbsz = (unsigned long)s.so_rcv.sb_mbmax; + Lf->lts.sbsz = (unsigned long)s.so_snd.sb_mbmax; + +# if defined(HASSBSTATE) + Lf->lts.sbs_rcv = s.so_rcv.sb_state; + Lf->lts.sbs_snd = s.so_snd.sb_state; +# endif /* defined(HASSBSTATE) */ + + } + +# else /* __FreeBSD_version<1200027 */ Lf->lts.pqlen = (unsigned int)s.so_incqlen; Lf->lts.qlen = (unsigned int)s.so_qlen; Lf->lts.qlim = (unsigned int)s.so_qlimit; Lf->lts.rbsz = (unsigned long)s.so_rcv.sb_mbmax; Lf->lts.sbsz = (unsigned long)s.so_snd.sb_mbmax; + +# if defined(HASSBSTATE) + Lf->lts.sbs_rcv = s.so_rcv.sb_state; + Lf->lts.sbs_snd = s.so_snd.sb_state; +# endif /* defined(HASSBSTATE) */ +# endif /*__FreeBSD_version>=1200027 */ + Lf->lts.pqlens = Lf->lts.qlens = Lf->lts.qlims = Lf->lts.rbszs = Lf->lts.sbszs = (unsigned char)1; -#endif /* defined(HASSOOPT) */ -#if defined(HASSOSTATE) +# if defined(HASSOSTATE) Lf->lts.ss = (unsigned int)s.so_state; -# if defined(HASSBSTATE) - Lf->lts.sbs_rcv = s.so_rcv.sb_state; - Lf->lts.sbs_snd = s.so_snd.sb_state; -# endif /* defined(HASSBSTATE) */ -#endif /* defined(HASSOSTATE) */ +# endif /* defined(HASSOSTATE) */ +#endif /* defined(HASSOPT) */ /* * Process socket by the associated domain family. @@ -306,8 +332,11 @@ process_socket(sa) */ if (p.pr_protocol == IPPROTO_TCP) { if (in6p.in6p_ppcb) { - if ((ts = ckstate((KA_T)in6p.in6p_ppcb, &t, fam)) == 1) + if ((ts = ckstate((KA_T)s.so_pcb, (KA_T)in6p.in6p_ppcb, + &t, fam)) == 1) + { return; + } } } enter_dev_ch(print_kptr((KA_T)(in6p.in6p_ppcb ? in6p.in6p_ppcb @@ -357,8 +386,11 @@ process_socket(sa) } if (p.pr_protocol == IPPROTO_TCP) { if (inp.inp_ppcb) { - if ((ts = ckstate((KA_T)inp.inp_ppcb, &t, fam)) == 1) + if ((ts = ckstate((KA_T)s.so_pcb, (KA_T)inp.inp_ppcb, + &t, fam)) == 1) + { return; + } } } enter_dev_ch(print_kptr((KA_T)(inp.inp_ppcb ? inp.inp_ppcb diff --git a/dialects/freebsd/dstore.c b/dialects/freebsd/dstore.c index 99239bd..0de224a 100644 --- a/dialects/freebsd/dstore.c +++ b/dialects/freebsd/dstore.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1994 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dstore.c,v 1.8 2008/04/15 13:31:47 abe Exp $"; +static char *rcsid = "$Id: dstore.c,v 1.9 2018/02/14 14:26:03 abe Exp $"; #endif @@ -48,6 +48,8 @@ struct file *Cfp; /* curent file's file struct pointer */ struct drive_Nl Drive_Nl[] = { + { X_BADFILEOPS, "badfileops" }, + #if FREEBSDV<2005 { X_NCACHE, "_nchhead" }, #else /* FREEBSDV>=2005 */ @@ -129,3 +131,10 @@ struct pff_tab Pof_tab[] = { { (long)0, NULL } }; #endif /* defined(HASFSTRUCT) */ + + +/* + * Kernel's bad file operations address + */ + +KA_T X_bfopsa; /* badfileops kernel address */ diff --git a/dialects/freebsd/machine.h b/dialects/freebsd/machine.h index be1485a..d47de0c 100644 --- a/dialects/freebsd/machine.h +++ b/dialects/freebsd/machine.h @@ -31,7 +31,7 @@ /* - * $Id: machine.h,v 1.39 2015/07/07 20:23:43 abe Exp $ + * $Id: machine.h,v 1.40 2018/02/14 14:26:03 abe Exp $ */ @@ -441,6 +441,17 @@ typedef _Bool bool; /* + * HASPTSFN is defined for dialects that have a DTYPE_PTS file descriptor + * type. The definition names the function that processes the type. + * + * + * NOTE: don't forget to define a prototype for this function in dproto.h. + */ + +#define HASPTSFN process_pts + + +/* * HASRNODE is defined for those dialects that have rnodes. */ diff --git a/dialects/hpux/pstat/dproc.c b/dialects/hpux/pstat/dproc.c index fb0c8e4..a592301 100644 --- a/dialects/hpux/pstat/dproc.c +++ b/dialects/hpux/pstat/dproc.c @@ -212,7 +212,7 @@ gather_proc_info() * If only ORed process selection options have been specified, * enable conditional file skipping and socket file only checking. */ - if ((Selflags & SELFILE) || !(Selflags & SELPROC)) + if ((Selflags & SELFILE) || !(Selflags & SelProc)) cckreg = ckscko = 0; else cckreg = ckscko = 1; @@ -247,7 +247,7 @@ gather_proc_info() * socket file only checking, based on the process' selection * status. */ - ckscko = (sf & SELPROC) ? 0 : 1; + ckscko = (sf & SelProc) ? 0 : 1; } alloc_lproc((int)p->pst_pid, (int)p->pst_pgrp, (int)p->pst_ppid, (UID_ARG)p->pst_uid, p->pst_ucomm, (int)pss, (int)sf); diff --git a/dialects/linux/dmnt.c b/dialects/linux/dmnt.c index 3bbdd37..87e63db 100644 --- a/dialects/linux/dmnt.c +++ b/dialects/linux/dmnt.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dmnt.c,v 1.20 2015/07/07 19:47:31 abe Exp $"; +static char *rcsid = "$Id: dmnt.c,v 1.21 2018/02/14 14:26:38 abe Exp $"; #endif @@ -535,6 +535,8 @@ readmnt() if ((nfs = strcasecmp(fp[2], "nfs3"))) nfs = strcasecmp(fp[2], "nfs4"); } + if (!nfs && !HasNFS) + HasNFS = 1; if (mp) { /* diff --git a/dialects/linux/dnode.c b/dialects/linux/dnode.c index b2cd77e..ce80b5d 100644 --- a/dialects/linux/dnode.c +++ b/dialects/linux/dnode.c @@ -32,12 +32,16 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dnode.c,v 1.25 2015/07/07 19:46:33 abe Exp $"; +static char *rcsid = "$Id: dnode.c,v 1.26 2018/02/14 14:26:38 abe Exp $"; #endif #include "lsof.h" +#if defined(HASEPTOPTS) && defined(HASPTYEPT) +#include <linux/major.h> +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + /* * Local definitions @@ -88,7 +92,11 @@ _PROTOTYPE(static void enter_pinfo,(void)); */ #if defined(HASEPTOPTS) -static pxinfo_t **Pinfo = (pxinfo_t **)NULL; +static pxinfo_t **Pinfo = (pxinfo_t **)NULL; /* pipe endpoint hash buckets */ +# if defined(HASPTYEPT) +static pxinfo_t **PtyInfo = (pxinfo_t **)NULL; /* pseudoterminal endpoint hash + * buckets */ +# endif /* defined(HASPTYEPT) */ #endif /* defined(HASEPTOPTS) */ @@ -202,12 +210,180 @@ enter_pinfo() } +#if defined(HASPTYEPT) + + +/* + * clear_ptyinfo() -- clear allocated pseudoterminal info + */ + +void +clear_ptyinfo() +{ + int h; /* hash index */ + pxinfo_t *pi, *pp; /* temporary pointers */ + + if (!PtyInfo) + return; + for (h = 0; h < PINFOBUCKS; h++) { + if ((pi = PtyInfo[h])) { + do { + pp = pi->next; + (void) free((FREE_P *)pi); + pi = pp; + } while (pi); + PtyInfo[h] = (pxinfo_t *)NULL; + } + } +} + + +/* + * enter_ptmxi() -- enter pty info + * + * entry Lf = local file structure pointer + * Lp = local process structure pointer + */ + +void +enter_ptmxi(mn) + int mn; /* minor number of device */ +{ + int h; /* hash result */ + struct lfile *lf; /* local file structure pointer */ + struct lproc *lp; /* local proc structure pointer */ + pxinfo_t *np, *pi, *pe; /* inode hash pointers */ + + if (!PtyInfo) { + + /* + * Allocate pipe info hash buckets (but used for pty). + */ + if (!(PtyInfo = (pxinfo_t **)calloc(PINFOBUCKS, + sizeof(pxinfo_t *)))) + { + (void) fprintf(stderr, + "%s: no space for %d pty info buckets\n", Pn, PINFOBUCKS); + Exit(1); + } + } + /* + * Make sure this is a unique entry. + */ + for (h = HASHPINFO(mn), pi = PtyInfo[h], pe = (pxinfo_t *)NULL; + pi; + pe = pi, pi = pi->next + ) { + lf = pi->lf; + lp = &Lproc[pi->lpx]; + if (pi->ino == mn) { + if ((lp->pid == Lp->pid) && !strcmp(lf->fd, Lf->fd)) + return; + } + } + /* + * Allocate, fill and link a new pipe info structure used for pty + * to the end of the pty device hash chain. + */ + if (!(np = (pxinfo_t *)malloc(sizeof(pxinfo_t)))) { + (void) fprintf(stderr, + "%s: no space for pipeinfo for pty, PID %d, FD %s\n", + Pn, Lp->pid, Lf->fd); + Exit(1); + } + np->ino = mn; + np->lf = Lf; + np->lpx = Lp - Lproc; + np->next = (pxinfo_t *)NULL; + if (pe) + pe->next = np; + else + PtyInfo[h] = np; +} + + +/* + * find_ptyepti() -- find pseudoterminal end point info + */ + +pxinfo_t * +find_ptyepti(lf, m, pp) + 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) */ +{ + struct lfile *ef; /* pseudoterminal end local file */ + int h; /* hash result */ + INODETYPE mn; /* minor number */ + pxinfo_t *pi; /* pseudoterminal info pointer */ + + + mn = m ? GET_MIN_DEV(lf->rdev) : lf->tty_index; + if (PtyInfo) { + if (pp) + pi = pp; + else { + h = HASHPINFO(mn); + pi = PtyInfo[h]; + } + while (pi) { + if (pi->ino == mn) { + ef = pi->lf; + if (((m && is_pty_ptmx(ef->rdev)) + || ((!m) && is_pty_slave(GET_MAJ_DEV(ef->rdev)))) + && strcmp(lf->fd, ef->fd) + ) { + return(pi); + } + } + pi = pi->next; + } + } + return((pxinfo_t *)NULL); +} + + /* - * find_pendinfo() -- find pipe end info + * is_pty_slave() -- is a pseudoterminal a slave device + */ + +int +is_pty_slave(sm) + int sm; /* slave major device number */ +{ + if ((UNIX98_PTY_SLAVE_MAJOR <= sm) + && (sm < (UNIX98_PTY_SLAVE_MAJOR + UNIX98_PTY_SLAVE_MAJOR)) + ) { + return 1; + } + return 0; +} + + +/* + * is_pty_ptmx() -- is a pseudoterminal a master clone device + */ + +int +is_pty_ptmx(dev) + dev_t dev; /* device number */ +{ + if ((GET_MAJ_DEV(dev) == TTYAUX_MAJOR) && (GET_MIN_DEV(dev) == 2)) + return 1; + return 0; +} +#endif /* defined(HASPTYEPT) */ + + +/* + * find_pepti() -- find pipe end point info */ pxinfo_t * -find_pendinfo(lf, pp) +find_pepti(lf, pp) struct lfile *lf; /* pipe's lfile */ pxinfo_t *pp; /* previous pipe info (NULL == none) */ { @@ -559,6 +735,16 @@ process_proc_node(p, pbr, s, ss, l, ls) if (ss & SB_RDEV) { Lf->rdev = s->st_rdev; Lf->rdev_def = 1; + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) + if ((Ntype == N_CHR) + && is_pty_slave(GET_MAJ_DEV(Lf->rdev)) + ) { + enter_ptmxi(GET_MIN_DEV(Lf->rdev)); + Lf->sf |= SELPTYINFO; + } +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + } } if (Ntype == N_REGLR && (HasNFS == 2)) { diff --git a/dialects/linux/dproc.c b/dialects/linux/dproc.c index c250fcd..5c10c4f 100644 --- a/dialects/linux/dproc.c +++ b/dialects/linux/dproc.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dproc.c,v 1.29 2015/07/07 19:46:33 abe Exp $"; +static char *rcsid = "$Id: dproc.c,v 1.30 2018/02/14 14:26:38 abe Exp $"; #endif #include "lsof.h" @@ -44,7 +44,17 @@ static char *rcsid = "$Id: dproc.c,v 1.29 2015/07/07 19:46:33 abe Exp $"; #define FDINFO_FLAGS 1 /* fdinfo flags available */ #define FDINFO_POS 2 /* fdinfo position available */ -#define FDINFO_ALL (FDINFO_FLAGS | FDINFO_POS) + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) +#define FDINFO_TTY_INDEX 4 /* fdinfo tty-index available */ +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) +#define FDINFO_ALL (FDINFO_FLAGS | FDINFO_POS | FDINFO_TTY_INDEX) +#else /* !(defined(HASEPTOPTS) && defined(HASPTYEPT)) */ +#define FDINFO_ALL (FDINFO_FLAGS | FDINFO_POS ) +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + #define LSTAT_TEST_FILE "/" #define LSTAT_TEST_SEEK 1 @@ -60,6 +70,11 @@ static char *rcsid = "$Id: dproc.c,v 1.29 2015/07/07 19:46:33 abe Exp $"; struct l_fdinfo { int flags; /* flags: line value */ off_t pos; /* pos: line value */ + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) + int tty_index; /* pty line index */ +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + }; @@ -81,7 +96,7 @@ static short Ckscko; /* socket file only checking status: */ _PROTOTYPE(static MALLOC_S alloc_cbf,(MALLOC_S len, char **cbf, MALLOC_S cbfa)); -_PROTOTYPE(static int get_fdinfo,(char *p, struct l_fdinfo *fi)); +_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)); @@ -90,7 +105,8 @@ _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)); + int pid, int ppid, int pgid, int tid, + char *tcmd)); _PROTOTYPE(static int statEx,(char *p, struct stat *s, int *ss)); @@ -182,9 +198,10 @@ void gather_proc_info() { char *cmd, *tcmd; + char cmdbuf[MAXPATHLEN]; struct dirent *dp; unsigned char ht, pidts; - int n, nl, pgid, pid, ppid, rv, tid, tpgid, tppid, tx; + int n, nl, pgid, pid, ppid, prv, rv, tid, tpgid, tppid, tx; static char *path = (char *)NULL; static int pathl = 0; static char *pidpath = (char *)NULL; @@ -252,7 +269,7 @@ gather_proc_info() * If only ORed process selection options have been specified, * enable conditional file skipping and socket file only checking. */ - if ((Selflags & SELFILE) || !(Selflags & SELPROC)) + if ((Selflags & SELFILE) || !(Selflags & SelProc)) Cckreg = Ckscko = 0; else Cckreg = Ckscko = 1; @@ -301,13 +318,26 @@ gather_proc_info() continue; uid = (UID_ARG)sb.st_uid; ht = pidts = 0; + /* + * 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) + cmd = "(unknown)"; #if defined(HASTASKS) /* - * If task reporting is selected, check the tasks of the process first, - * so that the "-p<PID> -aK" options work properly. + * Task reporting has been selected, so save the process' command + * string, so that task processing won't change it in the buffer of + * read_id_stat(). + * + * Check the tasks of the process first, so that the "-p<PID> -aK" + * options work properly. */ - if ((Selflags & SELTASK)) { + else if (!IgnTasks && (Selflags & SELTASK)) { + strncpy(cmdbuf, cmd, sizeof(cmdbuf) - 1); + cmdbuf[sizeof(cmdbuf) - 1] = '\0'; + cmd = cmdbuf; (void) make_proc_path(pidpath, n, &taskpath, &taskpathl, "task"); tx = n + 4; @@ -361,8 +391,8 @@ gather_proc_info() /* * Attempt to record the task. */ - if (!process_id(tidpath, (tx + 1 + nl+ 1), tcmd, uid, - pid, tppid, tpgid, tid)) + if (!process_id(tidpath, (tx + 1 + nl+ 1), cmd, uid, + pid, tppid, tpgid, tid, tcmd)) { ht = 1; } @@ -375,15 +405,14 @@ gather_proc_info() /* * If the main process is a task and task selection has been specified * along with option ANDing, enter the main process temporarily as a - * task, so that the "-aK" option set lists the main process along + * task, so that the "-aK" option set lists the main process along * with its tasks. */ - (void) make_proc_path(pidpath, n, &path, &pathl, "stat"); - if (((rv = read_id_stat(path, pid, &cmd, &ppid, &pgid)) >= 0) - && (rv != 1)) - { - tid = (Fand && ht && pidts && (Selflags & SELTASK)) ? pid : 0; - if ((!process_id(pidpath, n, cmd, uid, pid, ppid, pgid, tid)) + if ((prv >= 0) && (prv != 1)) { + tid = (Fand && ht && pidts && !IgnTasks && (Selflags & SELTASK)) + ? pid : 0; + if ((!process_id(pidpath, n, cmd, uid, pid, ppid, pgid, tid, + (char *)NULL)) && tid) { Lp->tid = 0; @@ -398,8 +427,10 @@ gather_proc_info() */ static int -get_fdinfo(p, fi) +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 */ { @@ -414,6 +445,11 @@ get_fdinfo(p, fi) */ if (!fi) return(0); + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) + fi->tty_index = -1; +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + if (!p || !*p || !(fs = fopen(p, "r"))) return(0); /* @@ -434,7 +470,7 @@ get_fdinfo(p, fi) || !ep || *ep) continue; fi->flags = (unsigned int)ul; - if ((rv |= FDINFO_FLAGS) == FDINFO_ALL) + if ((rv |= FDINFO_FLAGS) == msk) break; } else if (!strcmp(fp[0], "pos:")) { @@ -448,6 +484,29 @@ get_fdinfo(p, fi) fi->pos = (off_t)ull; if ((rv |= FDINFO_POS) == FDINFO_ALL) break; + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) + } else if (!strcmp(fp[0], "tty-index:")) { + + /* + * Process a "tty-index:" line. + */ + ep = (char *)NULL; + if ((ul = strtoul(fp[1], &ep, 0)) == ULONG_MAX + || !ep || *ep) + continue; + fi->tty_index = (int)ul; + if (fi->tty_index < 0) { + + /* + * Oops! If integer overflow occurred, reset the field. + */ + fi->tty_index = -1; + } + if ((rv |= FDINFO_TTY_INDEX) == msk) + break; +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + } } fclose(fs); @@ -534,7 +593,7 @@ initialize() if (!OffType) { (void) snpf(path, sizeof(path), "%s/%d/fdinfo/%d", PROCFS, Mypid, fd); - if (get_fdinfo(path, &fi) & FDINFO_POS) { + if (get_fdinfo(path, FDINFO_POS, &fi) & FDINFO_POS) { if (fi.pos == (off_t)LSTAT_TEST_SEEK) OffType = 2; } @@ -797,7 +856,7 @@ open_proc_stream(p, m, buf, sz, act) */ static int -process_id(idp, idpl, cmd, uid, pid, ppid, pgid, tid) +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 */ @@ -806,8 +865,9 @@ process_id(idp, idpl, cmd, uid, pid, ppid, pgid, tid) int ppid; /* parent PID */ int pgid; /* parent GID */ int tid; /* task ID, if non-zero */ + char *tcmd; /* task command, if non-NULL) */ { - int av; + int av = 0; static char *dpath = (char *)NULL; static int dpathl = 0; short efs, enls, enss, lnk, oty, pn, pss, sf; @@ -854,11 +914,27 @@ process_id(idp, idpl, cmd, uid, pid, ppid, pgid, tid) * socket file only checking, based on the process' selection * status. */ - Ckscko = (sf & SELPROC) ? 0 : 1; + Ckscko = (sf & SelProc) ? 0 : 1; } alloc_lproc(pid, pgid, ppid, uid, cmd, (int)pss, (int)sf); - Lp->tid = tid; Plf = (struct lfile *)NULL; + +#if defined(HASTASKS) +/* + * Enter task information. + */ + Lp->tid = tid; + if (tid && tcmd) { + if (!(Lp->tcmd = mkstrcpy(tcmd, (MALLOC_S *)NULL))) { + (void) fprintf(stderr, + "%s: PID %d, TID %d, no space for task name: ", + Pn, pid, tid); + safestrprt(tcmd, stderr, 1); + Exit(1); + } + } +#endif /* defined(HASTASKS) */ + /* * Process the ID's current working directory info. */ @@ -1149,7 +1225,7 @@ process_id(idp, idpl, cmd, uid, pid, ppid, pgid, tid) if (oty) { (void) make_proc_path(ipath, j, &pathi, &pathil, fp->d_name); - if ((av = get_fdinfo(pathi, &fi)) & FDINFO_POS) { + if ((av = get_fdinfo(pathi,FDINFO_ALL,&fi)) & FDINFO_POS) { if (efs) { if (Foffset) { lfr->off = (SZOFFTYPE)fi.pos; @@ -1180,6 +1256,18 @@ process_id(idp, idpl, cmd, uid, pid, ppid, pgid, tid) ls); if ((Lf->ntype == N_ANON_INODE) && rest && *rest) enter_nm(rest); + +#if defined(HASEPTOPTS) && defined(HASPTYEPT) + else if (Lf->rdev_def + && is_pty_ptmx(Lf->rdev) + && (av & FDINFO_TTY_INDEX) + ) { + enter_ptmxi(fi.tty_index); + Lf->tty_index = fi.tty_index; + Lf->sf |= SELPTYINFO; + } +#endif /* defined(HASEPTOPTS) && defined(HASPTYEPT) */ + if (Lf->sf) link_lfile(); } @@ -1434,7 +1522,7 @@ read_id_stat(p, id, cmd, ppid, pgid) * type */ { char buf[MAXPATHLEN], *cp, *cp1, **fp; - int ch, cx, es, nf; + int ch, cx, es, nf, pc; static char *cbf = (char *)NULL; static MALLOC_S cbfa = 0; FILE *fs; @@ -1474,11 +1562,14 @@ read_id_stat_exit: if (!cp || (*cp != '(')) goto read_id_stat_exit; cp++; + pc = 1; /* start the parenthesis balance count at 1 */ /* * Enter the command characters safely. Supply them from the initial read * of the stat file line, a '\n' if the initial read didn't yield a ')' * command closure, or by reading the rest of the command a character at - * a time from the stat file. + * a time from the stat file. Count embedded '(' characters and balance + * them with embedded ')' characters. The opening '(' starts the balance + * count at one. */ for (cx = es = 0;;) { if (!es) @@ -1487,8 +1578,18 @@ read_id_stat_exit: if ((ch = fgetc(fs)) == EOF) goto read_id_stat_exit; } - if (ch == ')') /* ')' closes the command */ - break; + if (ch == '(') /* a '(' advances the balance count */ + pc++; + if (ch == ')') { + + /* + * Balance parentheses when a closure is encountered. When + * they are balanced, this is the end of the command. + */ + pc--; + if (!pc) + break; + } if ((cx + 2) > cbfa) cbfa = alloc_cbf((cx + 2), &cbf, cbfa); cbf[cx] = ch; diff --git a/dialects/linux/dsock.c b/dialects/linux/dsock.c index b3b45c4..6e6e449 100644 --- a/dialects/linux/dsock.c +++ b/dialects/linux/dsock.c @@ -32,7 +32,7 @@ #ifndef lint static char copyright[] = "@(#) Copyright 1997 Purdue Research Foundation.\nAll rights reserved.\n"; -static char *rcsid = "$Id: dsock.c,v 1.41 2015/07/07 19:46:33 abe Exp $"; +static char *rcsid = "$Id: dsock.c,v 1.42 2018/02/14 14:26:38 abe Exp $"; #endif @@ -572,6 +572,31 @@ check_unix(i) /* + * clear_uxsinfo -- clear allocated UNIX socket info + */ + +void +clear_uxsinfo() +{ + int h; /* hash index */ + uxsin_t *ui, *up; /* remporary pointers */ + + if (!Uxsin) + return; + for (h = 0; h < INOBUCKS; h++) { + if ((ui = Uxsin[h])) { + do { + up = ui->next; + (void) free((FREE_P *)ui); + ui = up; + } while (ui); + Uxsin[h] = (uxsin_t *)NULL; + } + } +} + + +/* * get_ax25() - get /proc/net/ax25 info */ diff --git a/dialects/sun/machine.h b/dialects/sun/machine.h index 1264a09..f02eff5 100644 --- a/dialects/sun/machine.h +++ b/dialects/sun/machine.h @@ -31,7 +31,7 @@ /* - * $Id: machine.h,v 1.47 2011/09/07 19:16:00 abe Exp $ + * $Id: machine.h,v 1.48 2018/02/14 14:24:07 abe Exp $ */ #if !defined(LSOF_MACHINE_H) @@ -50,13 +50,21 @@ # if solaris>=100000 +# if !defined(HAS_AIO_REQ_STRUCT) /* - * Define a dummy aio_req structure for Solaris >= 10, because #include'ing - * <sys/aio_req.h> with _KERNEL defined creates too many problems. + * When <sys.aio_req.h> lacks one, define a dummy aio_req structure for + * Solaris >= 10 systems. + * + * If this definition causes compilation errors for <sys/vnode.h>, especially + * with Solaris 11, it may be necessary to comment out the following structure + * definition. I don't know a test that will determine the possibility of + * compilation errors. */ typedef struct aio_req { int dummy; } aio_req_t; +# endif /* !defined(HAS_AIO_REQ_STRUCT) */ + /* * Include <sys/utsname.h> so it won't be corrupted for 32 bit compilations * when _KERNEL is defined for some include files in dlsof.h. |