--- dproc.c.old 2020-03-07 23:37:36.121976000 +0000 +++ dproc.c 2020-03-07 23:40:33.913686000 +0000 @@ -37,6 +37,14 @@ #include "lsof.h" +/* + * This is not an exact version but it should not matter. At worst there + * is a small version window where this lsof does not compile on older + * -CURRENT. + */ +#if __FreeBSD_version >= 1300081 +#define HAS_PWD +#endif _PROTOTYPE(static void enter_vn_text,(KA_T va, int *n)); _PROTOTYPE(static void get_kernel_access,(void)); @@ -132,6 +140,15 @@ KA_T fa; #endif /* defined(HAS_FDESCENTTBL) */ +#if defined(HAS_PWD) + struct pwd pwd; + KA_T pwd_addr; +#endif /* defined(HAS_FDESCENTTBL) */ + + struct vnode *cdir; + struct vnode *rdir; + struct vnode *jdir; + static ofb_t *ofb = NULL; static int ofbb = 0; int pgid, pid; @@ -312,6 +329,22 @@ continue; #endif /* defined(HAS_FDESCENTTBL) */ +#if defined(HAS_PWD) + cdir = rdir = jdir = NULL; + pwd_addr = (KA_T)FILEDESC_KVM_LOAD_PWD(&fd); + if (pwd_addr != 0) { + if (!kread(pwd_addr, (char *)&pwd, sizeof(pwd))) { + cdir = pwd.pwd_cdir; + rdir = pwd.pwd_rdir; + jdir = pwd.pwd_jdir; + } + } +#else + cdir = fd.fd_cdir; + rdir = fd.fd_rdir; + jdir = fd.fd_jdir; +#endif + /* * Allocate a local process structure. */ @@ -347,20 +380,20 @@ /* * Save current working directory information. */ - if (!ckscko && fd.fd_cdir) { + if (!ckscko && cdir) { alloc_lfile(CWD, -1); Cfp = (struct file *)NULL; - process_node((KA_T)fd.fd_cdir); + process_node((KA_T)cdir); if (Lf->sf) link_lfile(); } /* * Save root directory information. */ - if (!ckscko && fd.fd_rdir) { + if (!ckscko && rdir) { alloc_lfile(RTD, -1); Cfp = (struct file *)NULL; - process_node((KA_T)fd.fd_rdir); + process_node((KA_T)rdir); if (Lf->sf) link_lfile(); } @@ -369,10 +402,10 @@ /* * Save jail directory information. */ - if (!ckscko && fd.fd_jdir) { + if (!ckscko && jdir) { alloc_lfile("jld", -1); Cfp = (struct file *)NULL; - process_node((KA_T)fd.fd_jdir); + process_node((KA_T)jdir); if (Lf->sf) link_lfile(); }