Skip to content

Commit 052474b

Browse files
authored
Merge pull request #363 from lsof-org/fix-netbsd
Fix NetBSD 10/11 support
2 parents 96d65e5 + 7805d7e commit 052474b

8 files changed

Lines changed: 51 additions & 21 deletions

File tree

Configure

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,10 +2662,15 @@ return(0); }
26622662
echo "!!!WARNING!!! Unsupported NetBSD version: $LSOF_VSTR"
26632663
echo "!!!WARNING!!! Configuring for NetBSD 10.0"
26642664
;;
2665+
11.*)
2666+
LSOF_VERS="11000000"
2667+
echo "!!!WARNING!!! Unsupported NetBSD version: $LSOF_VSTR"
2668+
echo "!!!WARNING!!! Configuring for NetBSD 11.0"
2669+
;;
26652670
*)
26662671
echo "Unknown NetBSD release: $LSOF_VSTR"
2667-
echo Assuming NetBSD 10.0
2668-
LSOF_VERS="10000000"
2672+
echo Assuming NetBSD 11.0
2673+
LSOF_VERS="11000000"
26692674
;;
26702675
esac # }
26712676
fi # }

configure.ac

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ AS_CASE([${host_os}],
134134
AC_MSG_WARN([Unsupported NetBSD release: $(uname -r)])
135135
AC_MSG_WARN([Configuring for NetBSD 10.0])
136136
;;
137+
11.*)
138+
LSOF_VERS="11000000"
139+
AC_MSG_WARN([Unsupported NetBSD release: $(uname -r)])
140+
AC_MSG_WARN([Configuring for NetBSD 11.0])
141+
;;
137142
*)
138143
AC_MSG_ERROR([Unknown NetBSD release: $(uname -r)])
139144
;;
@@ -466,7 +471,7 @@ AC_CHECK_DECLS([kvm_getproc2], [], [], [#include <kvm.h>])
466471
# Detect fs/ptyfs/ptyfs.h header for HASPTYFS
467472
AC_CHECK_HEADERS([fs/ptyfs/ptyfs.h])
468473

469-
# Detect fs/ptyfs/ptyfs.h header for HASPROCFS
474+
# Detect miscfs/procfs/procfs.h header for HASPROCFS
470475
AC_CHECK_HEADERS([miscfs/procfs/procfs.h])
471476

472477
# Detect PFSroot enum for HASPROCFS_PFSROOT
@@ -487,6 +492,8 @@ AS_IF([test x$LSOF_DIALECT = xnetbsd], [
487492
488493
AC_MSG_NOTICE([lockf.h creation succeeded])
489494
CFLAGS="$CFLAGS -DHAS_LOCKF_H"
495+
# Hardcode some flags for latest NetBSD versions
496+
CFLAGS="$CFLAGS -DHASPROCFS_PFSROOT"
490497
])
491498

492499
# Detect fdescfs version for HASFDESCFS

lib/dialects/netbsd/Mksrc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ L="dlsof.h dmnt.c dnode.c dnode1.c dproc.c dproto.h dsock.c dstore.c machine.h"
2626

2727
mksrc
2828

29+
D=lib
30+
L="node.c"
31+
32+
mksrc
33+
2934
D=src
30-
L="arg.c main.c node.c print.c ptti.c store.c usage.c util.c"
35+
L="arg.c main.c print.c ptti.c store.c usage.c util.c"
3136

3237
mksrc

lib/dialects/netbsd/dlsof.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ struct mounts {
498498
extern int Np; /* number of kernel processes */
499499

500500
# if defined(HASKVMGETPROC2)
501-
struct kinfo_proc2 *P; /* local process table copy */
501+
extern struct kinfo_proc2 *P; /* local process table copy */
502502
# else /* ! defined(HASKVMGETPROC2) */
503-
struct kinfo_proc *P; /* local process table copy */
503+
extern struct kinfo_proc *P; /* local process table copy */
504504
# endif /* defined(HASKVMGETPROC2) */
505505

506506
extern int pgshift; /* kernel's page shift */

lib/dialects/netbsd/dnode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ void process_node(struct lsof_context *ctx, /* context */
439439
ksb.st_ino = (ino_t)2;
440440
ksb.st_size = DEV_BSIZE;
441441
ksbs = 1;
442-
} else if (Namech[0] && statsafely(Namech, &ksb) == 0)
442+
} else if (Namech[0] && statsafely(ctx, Namech, &ksb) == 0)
443443
ksbs = 1;
444444
nty = KERNFSNODE;
445445
break;

lib/rnmt.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ struct lnc {
3939
char lnc_name[NCHNAMLEN + 1]; /* name */
4040
};
4141

42+
/* For NetBSD 10 compat */
43+
#ifndef NC_NLEN
44+
#define NC_NLEN(ncp) ((ncp)->nc_nlen)
45+
#endif
46+
4247
static const rb_tree_ops_t lnc_rbtree_ops = {
4348
.rbto_compare_nodes = lnc_compare_nodes,
4449
.rbto_compare_key = lnc_compare_key,
@@ -84,7 +89,7 @@ static struct lnc *ncache_enter_local(KA_T vp, const struct lnc *plnc,
8489
}
8590
lnc->lnc_vp = vp;
8691
lnc->lnc_plnc = plnc;
87-
lnc->lnc_nlen = nc->nc_nlen;
92+
lnc->lnc_nlen = NC_NLEN(nc);
8893
memcpy(lnc->lnc_name, nc->nc_name, lnc->lnc_nlen);
8994
lnc->lnc_name[lnc->lnc_nlen] = 0;
9095

@@ -104,13 +109,13 @@ static int sanity_check_namecache(const struct namecache *nc) {
104109
if (nc->nc_vp == NULL)
105110
return -1;
106111

107-
if (nc->nc_nlen > NCHNAMLEN)
112+
if (NC_NLEN(nc) > NCHNAMLEN)
108113
return -1;
109114

110-
if (nc->nc_nlen == 1 && nc->nc_name[0] == '.')
115+
if (NC_NLEN(nc) == 1 && nc->nc_name[0] == '.')
111116
return -1;
112117

113-
if (nc->nc_nlen == 2 && nc->nc_name[0] == '.' && nc->nc_name[1] == '.')
118+
if (NC_NLEN(nc) == 2 && nc->nc_name[0] == '.' && nc->nc_name[1] == '.')
114119
return -1;
115120

116121
return 0;
@@ -137,21 +142,21 @@ static void ncache_walk(struct lsof_context *ctx, KA_T ncp,
137142
if (sanity_check_vnode_impl(&vi) == 0 && sanity_check_namecache(&nc) == 0) {
138143
lnc = ncache_enter_local(vp, plnc, &nc);
139144
if (vi.vi_vnode.v_type == VDIR && vi.vi_nc_tree.rbt_root != NULL) {
140-
ncache_walk((KA_T)vi.vi_nc_tree.rbt_root, lnc);
145+
ncache_walk(ctx, (KA_T)vi.vi_nc_tree.rbt_root, lnc);
141146
}
142147
}
143148
if (left)
144-
ncache_walk(left, plnc);
149+
ncache_walk(ctx, left, plnc);
145150
if (right)
146-
ncache_walk(right, plnc);
151+
ncache_walk(ctx, right, plnc);
147152
}
148153

149154
void ncache_load(struct lsof_context *ctx) {
150155
KA_T rootvnode_addr;
151156
struct vnode_impl vi;
152157

153158
rootvnode_addr = (KA_T)0;
154-
if (get_Nl_value("rootvnode", (struct drive_Nl *)NULL, &rootvnode_addr) <
159+
if (get_Nl_value(ctx, "rootvnode", (struct drive_Nl *)NULL, &rootvnode_addr) <
155160
0 ||
156161
!rootvnode_addr ||
157162
kread(ctx, (KA_T)rootvnode_addr, (char *)&rootvnode_addr,
@@ -161,7 +166,7 @@ void ncache_load(struct lsof_context *ctx) {
161166
}
162167

163168
rb_tree_init(&lnc_rbtree, &lnc_rbtree_ops);
164-
ncache_walk((KA_T)vi.vi_nc_tree.rbt_root, 0);
169+
ncache_walk(ctx, (KA_T)vi.vi_nc_tree.rbt_root, 0);
165170
}
166171

167172
static void build_path(char **buf, size_t *remaining, const struct lnc *lnc) {
@@ -187,7 +192,7 @@ static void build_path(char **buf, size_t *remaining, const struct lnc *lnc) {
187192
*buf += len;
188193
}
189194

190-
char *ncache_lookup(char *buf, int blen, int *fp) {
195+
char *ncache_lookup(struct lsof_context *ctx, char *buf, int blen, int *fp) {
191196
const struct lnc *lnc;
192197
char *p;
193198
size_t remaining;

tests/LTbasic2.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,17 @@ int main(int argc, char **argv) {
117117
}
118118
} else if (f->fd_type == LSOF_FD_NUMERIC) {
119119
/* check if fd matches */
120-
if (f->fd_num == fd && f->name &&
121-
strstr(f->name, "LTbasic2-tmp")) {
120+
if (f->fd_num == fd && f->inode == tmp_stat.st_ino &&
121+
f->dev == tmp_stat.st_dev) {
122+
#ifdef NETBSDV
123+
/* on NetBSD, the file path for new created file may be
124+
* unavailable, skip validation */
122125
fd_found = 1;
126+
#else
127+
if (f->name && strstr(f->name, "LTbasic2-tmp")) {
128+
fd_found = 1;
129+
}
130+
#endif
123131
}
124132
}
125133
}
@@ -149,4 +157,4 @@ int main(int argc, char **argv) {
149157
}
150158
}
151159
return 0;
152-
}
160+
}

tests/LTsock.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,11 @@ static char *FindSock(int fn) /* function -- an LT_FBY* value */
631631
* Complete the option vector and start lsof execution.
632632
*/
633633

634+
mk_end = ti;
634635
#if defined(USE_LSOF_C_OPT)
635636
opv[ti++] = "-C";
636637
#endif /* defined(USE_LSOF_C_OPT) */
637638

638-
mk_end = ti;
639639
opv[ti] = (char *)NULL;
640640
if ((cem = ExecLsof(opv))) {
641641
for (tj = mk_start; tj < mk_end; tj++)

0 commit comments

Comments
 (0)