diff --git a/sysutils/lsof/Makefile b/sysutils/lsof/Makefile index af50e60e4e36..2e7f7b397e2d 100644 --- a/sysutils/lsof/Makefile +++ b/sysutils/lsof/Makefile @@ -1,8 +1,8 @@ -# $NetBSD: Makefile,v 1.140 2021/11/11 00:49:34 gutteridge Exp $ +# $NetBSD: Makefile,v 1.141 2022/05/25 09:33:37 tnn Exp $ DISTNAME= lsof_4.91 PKGNAME= ${DISTNAME:S/_/-/} -PKGREVISION= 5 +PKGREVISION= 6 CATEGORIES= sysutils MASTER_SITES= ftp://ftp.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/ MASTER_SITES+= ftp://ftp.mirrorservice.org/sites/lsof.itap.purdue.edu/pub/tools/unix/lsof/OLD/ @@ -74,6 +74,7 @@ post-extract: fi ; \ ${TOOLS_PATH.bsdtar} -xf ${SRCBALL_NAME}.tar cd ${WRKSRC} ; ${ECHO} "y" | ./Inventory || exit 1 + ${CP} ${FILESDIR}/rnmt.c ${WRKSRC}/lib/rnmt.c SPECIAL_PERMS+= ${PREFIX}/sbin/lsof ${REAL_ROOT_USER} ${REAL_GROUP} 2755 diff --git a/sysutils/lsof/distinfo b/sysutils/lsof/distinfo index c36906e7b935..e9dbdefb9f97 100644 --- a/sysutils/lsof/distinfo +++ b/sysutils/lsof/distinfo @@ -1,14 +1,15 @@ -$NetBSD: distinfo,v 1.101 2022/02/27 02:13:44 gutteridge Exp $ +$NetBSD: distinfo,v 1.102 2022/05/25 09:33:37 tnn Exp $ BLAKE2s (lsof_4.91.tar.bz2) = 77109e036c36f7d1483e69f2aae2314830dc4d2bdc3bf88a4031832f17e6afef SHA512 (lsof_4.91.tar.bz2) = 49f811941dd6303f7cb0655fddb8b1177af5d1b18f2bd1edfab09d2c128aea73daecf09c7a5375979c66ba764c88a6e70c9086b55c3634e3be01ab1aa12e9f92 Size (lsof_4.91.tar.bz2) = 791734 bytes -SHA1 (patch-aa) = 4469a5fed540e3c5635b6082efedc477ea96a382 +SHA1 (patch-aa) = 76523a6d3bdff93a835dc442114f2bd4a018f95e SHA1 (patch-ab) = 1501d8b0e6fd2c61949ba0d447c7b726655725c4 -SHA1 (patch-ac) = dac0fcdfee97d42c8f23684a4321519b9f8698d9 +SHA1 (patch-ac) = ab1dc4540452f413493c58b729c7c6de83abfb6a SHA1 (patch-ad) = 7f639e8832c2da8e498c33a38ecbc7b3d3a7430a SHA1 (patch-ae) = 3f4a7ce54c0646941fd86400f91a2d17e9d2354a SHA1 (patch-af) = 88b3d2b42c05e20c189fa00fd65f1f412fe54038 SHA1 (patch-ag) = 99ab1c616604e9775522dbc70bfd6a7294964d0a SHA1 (patch-ah) = 2de22b9a3733f958298af5e33b66c0653c320f59 SHA1 (patch-dialects_n+obsd_dnode1.c) = dc8c766760aca4eb2e7d7af3944260dd49795c09 +SHA1 (patch-lib_Makefile.skel) = abfb9d50eef60c5d43cbf4978bf179de0ebe371e diff --git a/sysutils/lsof/files/rnmt.c b/sysutils/lsof/files/rnmt.c new file mode 100644 index 000000000000..682e1be53613 --- /dev/null +++ b/sysutils/lsof/files/rnmt.c @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2022 Tobias Nygren + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +#include "../machine.h" + +#if defined(HASNCACHE) && defined(USE_LIB_RNMT) +#include +#include +#include + +#include "../lsof.h" + +/* + * rnmt.c - read NetBSD=>10-style red-black tree kernel name cache + */ + +static int lnc_compare_nodes(void *, const void *, const void *); +static int lnc_compare_key(void *, const void *, const void *); + +static rb_tree_t lnc_rbtree; + +/* local name cache entry */ +struct lnc { + struct rb_node lnc_tree; /* red-black tree */ + KA_T lnc_vp; /* vnode address */ + KA_T lnc_pvp; /* parent vnode address */ + const struct lnc *lnc_plnc; /* parent lnc address */ + int lnc_nlen; /* name length */ + char lnc_name[NCHNAMLEN + 1]; /* name */ +}; + +static const rb_tree_ops_t lnc_rbtree_ops = { + .rbto_compare_nodes = lnc_compare_nodes, + .rbto_compare_key = lnc_compare_key, + .rbto_node_offset = offsetof(struct lnc, lnc_tree), + .rbto_context = NULL +}; + +static int +lnc_compare_nodes(void *context, const void *node1, const void *node2) +{ + const struct lnc *lnc1 = node1; + const struct lnc *lnc2 = node2; + + if (lnc1->lnc_vp < lnc2->lnc_vp) { + return -1; + } + if (lnc1->lnc_vp > lnc2->lnc_vp) { + return 1; + } + + return 0; +} + +static int +lnc_compare_key(void *context, const void *node, const void *key) +{ + const struct lnc *lnc = node; + const KA_T vp = (KA_T)key; + + if (lnc->lnc_vp < vp) { + return -1; + } + if (lnc->lnc_vp > vp) { + return 1; + } + + return 0; +} + +static struct lnc * +ncache_enter_local(KA_T vp, KA_T pvp, const struct lnc *plnc, const struct namecache *nc) +{ + struct lnc *lnc; + + lnc = malloc(sizeof(*lnc)); + if (!lnc) { + errx(1, "can't allocate local name cache entry\n"); + } + lnc->lnc_vp = vp; + lnc->lnc_pvp = pvp; + lnc->lnc_plnc = plnc; + lnc->lnc_nlen = nc->nc_nlen; + memcpy(lnc->lnc_name, nc->nc_name, lnc->lnc_nlen); + lnc->lnc_name[lnc->lnc_nlen] = 0; + + rb_tree_insert_node(&lnc_rbtree, lnc); + + return lnc; +} + +static int +sanity_check_vnode_impl(const struct vnode_impl *vi) +{ + if (vi->vi_vnode.v_type >= VBAD) + return -1; + + return 0; +} + +static int +sanity_check_namecache(const struct namecache *nc) +{ + if (nc->nc_vp == NULL) + return -1; + + if (nc->nc_nlen > NCHNAMLEN) + return -1; + + if (nc->nc_nlen == 1 && nc->nc_name[0] == '.') + return -1; + + if (nc->nc_nlen == 2 && nc->nc_name[0] == '.' && nc->nc_name[1] == '.') + return -1; + + return 0; +} + +static void +ncache_walk(KA_T ncp, KA_T pvp, const struct lnc *plnc) +{ + struct l_nch *lc; + static struct vnode_impl vi; + static struct namecache nc; + struct lnc *lnc; + KA_T vp; + KA_T left, right; + + if (kread(ncp, (char *)&nc, sizeof(nc))) { + return; + } + vp = (KA_T)nc.nc_vp; + if (kread(vp, (char *)&vi, sizeof(vi))) { + vi.vi_vnode.v_type = VBAD; + } + left = (KA_T)nc.nc_tree.rb_nodes[0]; + right = (KA_T)nc.nc_tree.rb_nodes[1]; + if (sanity_check_vnode_impl(&vi) == 0 && sanity_check_namecache(&nc) == 0) { + lnc = ncache_enter_local(vp, pvp, plnc, &nc); + if (vi.vi_vnode.v_type = VDIR && vi.vi_nc_tree.rbt_root != NULL) { + ncache_walk((KA_T)vi.vi_nc_tree.rbt_root, ncp, lnc); + } + } + if (left) + ncache_walk(left, pvp, plnc); + if (right) + ncache_walk(right, pvp, plnc); +} + +void +ncache_load() +{ + KA_T rootvnode_addr; + struct vnode_impl vi; + + rootvnode_addr = (KA_T)0; + if (get_Nl_value("rootvnode", (struct drive_Nl *)NULL, &rootvnode_addr) < 0 + || !rootvnode_addr + || kread((KA_T)rootvnode_addr, (char *)&rootvnode_addr, sizeof(rootvnode_addr)) + || kread((KA_T)rootvnode_addr, (char *)&vi, sizeof(vi))) { + errx(1, "can't read rootvnode\n"); + } + + rb_tree_init(&lnc_rbtree, &lnc_rbtree_ops); + ncache_walk((KA_T)vi.vi_nc_tree.rbt_root, 0, 0); +} + +static void +build_path(char **buf, size_t *remaining, const struct lnc *lnc) +{ + size_t len; + + if (lnc == NULL) + return; + + build_path(buf, remaining, lnc->lnc_plnc); + if (remaining == 0) { + return; + } + if (lnc->lnc_plnc != NULL) { + **buf = '/'; + (*buf)++; + } + remaining--; + len = lnc->lnc_nlen; + if (*remaining < len) + len = *remaining; + memcpy(*buf, lnc->lnc_name, len); + *remaining -= len; + *buf += len; +} + +char * +ncache_lookup(char *buf, int blen, int *fp) +{ + const struct lnc *lnc; + char *p; + size_t remaining; + + *fp = 0; + lnc = rb_tree_find_node(&lnc_rbtree, (void*)Lf->na); + if (lnc != NULL) { + p = buf; + remaining = blen; + build_path(&p, &remaining, lnc); + if (remaining == 0) { + buf[blen - 1] = 0; + } else { + *p = 0; + } + *fp = 1; + return buf; + } + + return NULL; +} +#endif diff --git a/sysutils/lsof/patches/patch-aa b/sysutils/lsof/patches/patch-aa index 61f5628e9d57..1f9385d29857 100644 --- a/sysutils/lsof/patches/patch-aa +++ b/sysutils/lsof/patches/patch-aa @@ -1,7 +1,7 @@ -$NetBSD: patch-aa,v 1.28 2010/04/30 06:53:07 sbd Exp $ +$NetBSD: patch-aa,v 1.29 2022/05/25 09:33:37 tnn Exp $ ---- dialects/n+obsd/machine.h.orig 2006-03-28 16:54:17.000000000 -0500 -+++ dialects/n+obsd/machine.h 2008-05-17 18:53:29.000000000 -0400 +--- dialects/n+obsd/machine.h.orig 2010-07-29 16:02:55.000000000 +0000 ++++ dialects/n+obsd/machine.h @@ -41,6 +41,10 @@ #include @@ -13,3 +13,14 @@ $NetBSD: patch-aa,v 1.28 2010/04/30 06:53:07 sbd Exp $ /* +@@ -577,7 +581,9 @@ + /* #define USE_LIB_READMNT 1 rmnt.c */ + /* #define USE_LIB_REGEX 1 regex.c */ + +-# if (defined(OPENBSDV) && OPENBSDV>=2010) || (defined(NETBSDV) && NETBSDV>=1002000) ++#if (defined(NETBSDV) && NETBSDV>=9099000) ++#define USE_LIB_RNMT 1 /* rnmt.c */ ++# elif (defined(OPENBSDV) && OPENBSDV>=2010) || (defined(NETBSDV) && NETBSDV>=1002000) + #define USE_LIB_RNMH 1 /* rnmh.c */ + # else /* (defined(OPENBSDV) && OPENBSDV<2010) && (defined(NETBSDV) && NETBSDV<1002000) */ + #define USE_LIB_RNAM 1 /* rnam.c */ diff --git a/sysutils/lsof/patches/patch-ac b/sysutils/lsof/patches/patch-ac index ee9b0696f688..d588570ac42a 100644 --- a/sysutils/lsof/patches/patch-ac +++ b/sysutils/lsof/patches/patch-ac @@ -1,8 +1,19 @@ -$NetBSD: patch-ac,v 1.29 2008/05/17 23:53:29 christos Exp $ +$NetBSD: patch-ac,v 1.30 2022/05/25 09:33:37 tnn Exp $ ---- dialects/n+obsd/dstore.c.orig 2004-12-30 13:42:32.000000000 -0500 -+++ dialects/n+obsd/dstore.c 2008-05-17 19:35:34.000000000 -0400 -@@ -119,6 +119,8 @@ +--- dialects/n+obsd/dstore.c.orig 2004-12-30 18:42:32.000000000 +0000 ++++ dialects/n+obsd/dstore.c +@@ -48,7 +48,9 @@ struct file *Cfp; /* current file's fil + */ + + struct drive_Nl Drive_Nl[] = { +- ++#if (defined(NETBSDV) && NETBSDV>=9099000) ++ { "rootvnode", "rootvnode", }, ++#endif + #if (defined(OPENBSDV) && OPENBSDV>=2010) || (defined(NETBSDV) && NETBSDV>=1002000) + { X_NCACHE, "_nchashtbl", }, + { X_NCSIZE, "_nchash" }, +@@ -119,6 +121,8 @@ struct pff_tab Pof_tab[] = { # if defined(UF_EXCLOSE) { (long)UF_EXCLOSE, POF_CLOEXEC }, diff --git a/sysutils/lsof/patches/patch-lib_Makefile.skel b/sysutils/lsof/patches/patch-lib_Makefile.skel new file mode 100644 index 000000000000..c94ad7f60e92 --- /dev/null +++ b/sysutils/lsof/patches/patch-lib_Makefile.skel @@ -0,0 +1,24 @@ +$NetBSD: patch-lib_Makefile.skel,v 1.1 2022/05/25 09:33:37 tnn Exp $ + +--- lib/Makefile.skel.orig 2001-02-13 02:12:22.000000000 +0000 ++++ lib/Makefile.skel +@@ -13,10 +13,10 @@ INCL= ${DINC} + HDR= ../lsof.h ../proto.h ../dlsof.h ../dproto.h ../machine.h + + SRC= ckkv.c cvfs.c dvch.c fino.c isfn.c lkud.c pdvn.c prfp.c \ +- ptti.c rdev.c regex.c rmnt.c rnam.c rnch.c rnmh.c snpf.c ++ ptti.c rdev.c regex.c rmnt.c rnam.c rnch.c rnmh.c rnmt.c snpf.c + + OBJ= ckkv.o cvfs.o dvch.o fino.o isfn.o lkud.o pdvn.o prfp.o \ +- ptti.o rdev.o regex.o rmnt.o rnam.o rnch.o rnmh.o snpf.o ++ ptti.o rdev.o regex.o rmnt.o rnam.o rnch.o rnmh.o rnmt.o snpf.o + + all: ${LIB} + +@@ -59,4 +59,6 @@ rnch.o: ${HDR} rnch.c + + rnmh.o: ${HDR} rnmh.c + ++rnmt.o: ${HDR} rnmt.c ++ + snpf.o: ${HDR} snpf.c