Re: kvm_getfiles and KERN_FILE_BYFILE
On Sun, 2020-11-29 at 16:15 -0800, Philip Guenther wrote: > On Sun, Nov 29, 2020 at 12:14 PM Martijn van Duren > wrote: > > On Sat, 2020-11-28 at 16:23 -0800, Philip Guenther wrote: > > > On Thu, Nov 26, 2020 at 1:08 PM Martijn van Duren > > > wrote: > > > > I'm currently playing around a bit with kvm_getfiles and found that I > > > > couldn't use KERN_FILE_BYFILE with DTYPE_SOCKET. > > > > According to kvm_getfiles(3): > > > > For KERN_FILE_BYFILE the recognized file types are defined in > > > > : > > > > > > > > DTYPE_VNODE files and devices > > > > DTYPE_SOCKET sockets, regardless of domain > > > > DTYPE_PIPE pipes and FIFOs > > > > DTYPE_KQUEUE kqueues > > > > > > > > But these defines are under ifdef _KERNEL. > > > > > > > > So is the manpage lying here, or should the defines be hoisted out > > > > of the ifdef? > > > > > > > > > > > > > Let's go ahead and hoist them: FreeBSD and NetBSD already have. If > > > possible, the diff to do that should also simplify the #include bits in > > > these files: > > > usr.bin/netstat/inet.c > > > usr.bin/fstat/fstat.c > > > usr.bin/fstat/fuser.c > > > usr.bin/systat/netstat.c > > > > > > > > > Philip Guenther > > > > > > > The others have the #endif/#ifdef break rather low in the file. > > Personally I reckon it's better reading if the common code is more > > towards the top. > > > > OK? > > > > > ok guenther@ > > How do the userland clean up bits look? > > > Philip Guenther > Something like this? Index: fstat/fstat.c === RCS file: /cvs/src/usr.bin/fstat/fstat.c,v retrieving revision 1.101 diff -u -p -r1.101 fstat.c --- fstat/fstat.c 22 Aug 2020 18:34:29 - 1.101 +++ fstat/fstat.c 30 Nov 2020 07:17:51 - @@ -55,9 +55,7 @@ #include #include #include -#define _KERNEL /* for DTYPE_* */ #include -#undef _KERNEL #include #include Index: fstat/fuser.c === RCS file: /cvs/src/usr.bin/fstat/fuser.c,v retrieving revision 1.8 diff -u -p -r1.8 fuser.c --- fstat/fuser.c 25 Jan 2019 00:19:26 - 1.8 +++ fstat/fuser.c 30 Nov 2020 07:17:51 - @@ -45,9 +45,7 @@ #include #include #include -#define _KERNEL /* for DTYPE_VNODE */ #include -#undef _KERNEL #include #include Index: systat/netstat.c === RCS file: /cvs/src/usr.bin/systat/netstat.c,v retrieving revision 1.45 diff -u -p -r1.45 netstat.c --- systat/netstat.c12 Mar 2015 01:03:00 - 1.45 +++ systat/netstat.c30 Nov 2020 07:17:51 - @@ -38,9 +38,7 @@ #include #include #include -#define _KERNEL #include -#undef _KERNEL #include #include Index: netstat/inet.c === RCS file: /cvs/src/usr.bin/netstat/inet.c,v retrieving revision 1.168 diff -u -p -r1.168 inet.c --- netstat/inet.c 15 Jan 2020 14:02:37 - 1.168 +++ netstat/inet.c 30 Nov 2020 07:17:51 - @@ -37,9 +37,7 @@ #include #include #include -#define _KERNEL #include -#undef _KERNEL #include #include
Re: kvm_getfiles and KERN_FILE_BYFILE
On Sun, Nov 29, 2020 at 12:14 PM Martijn van Duren < openbsd+t...@list.imperialat.at> wrote: > On Sat, 2020-11-28 at 16:23 -0800, Philip Guenther wrote: > > On Thu, Nov 26, 2020 at 1:08 PM Martijn van Duren < > openbsd+t...@list.imperialat.at> wrote: > > > I'm currently playing around a bit with kvm_getfiles and found that I > > > couldn't use KERN_FILE_BYFILE with DTYPE_SOCKET. > > > According to kvm_getfiles(3): > > > For KERN_FILE_BYFILE the recognized file types are defined in > > > : > > > > > >DTYPE_VNODE files and devices > > >DTYPE_SOCKET sockets, regardless of domain > > >DTYPE_PIPEpipes and FIFOs > > >DTYPE_KQUEUE kqueues > > > > > > But these defines are under ifdef _KERNEL. > > > > > > So is the manpage lying here, or should the defines be hoisted out > > > of the ifdef? > > > > > > > > > Let's go ahead and hoist them: FreeBSD and NetBSD already have. If > possible, the diff to do that should also simplify the #include bits in > these files: > > usr.bin/netstat/inet.c > > usr.bin/fstat/fstat.c > > usr.bin/fstat/fuser.c > > usr.bin/systat/netstat.c > > > > > > Philip Guenther > > > > The others have the #endif/#ifdef break rather low in the file. > Personally I reckon it's better reading if the common code is more > towards the top. > > OK? > ok guenther@ How do the userland clean up bits look? Philip Guenther
Re: kvm_getfiles and KERN_FILE_BYFILE
On Sat, 2020-11-28 at 16:23 -0800, Philip Guenther wrote: > On Thu, Nov 26, 2020 at 1:08 PM Martijn van Duren > wrote: > > I'm currently playing around a bit with kvm_getfiles and found that I > > couldn't use KERN_FILE_BYFILE with DTYPE_SOCKET. > > According to kvm_getfiles(3): > > For KERN_FILE_BYFILE the recognized file types are defined in > > : > > > > DTYPE_VNODE files and devices > > DTYPE_SOCKET sockets, regardless of domain > > DTYPE_PIPE pipes and FIFOs > > DTYPE_KQUEUE kqueues > > > > But these defines are under ifdef _KERNEL. > > > > So is the manpage lying here, or should the defines be hoisted out > > of the ifdef? > > > > > Let's go ahead and hoist them: FreeBSD and NetBSD already have. If possible, > the diff to do that should also simplify the #include bits in these files: > usr.bin/netstat/inet.c > usr.bin/fstat/fstat.c > usr.bin/fstat/fuser.c > usr.bin/systat/netstat.c > > > Philip Guenther > The others have the #endif/#ifdef break rather low in the file. Personally I reckon it's better reading if the common code is more towards the top. OK? martijn@ Index: file.h === RCS file: /cvs/src/sys/sys/file.h,v retrieving revision 1.61 diff -u -p -r1.61 file.h --- file.h 13 Mar 2020 10:07:01 - 1.61 +++ file.h 29 Nov 2020 20:12:30 - @@ -38,7 +38,15 @@ #else /* _KERNEL */ #include #include +#endif /* _KERNEL */ +#defineDTYPE_VNODE 1 /* file */ +#defineDTYPE_SOCKET2 /* communications endpoint */ +#defineDTYPE_PIPE 3 /* pipe */ +#defineDTYPE_KQUEUE4 /* event queue */ +#defineDTYPE_DMABUF5 /* DMA buffer (for DRM) */ + +#ifdef _KERNEL struct proc; struct uio; struct knote; @@ -80,11 +88,6 @@ struct file { LIST_ENTRY(file) f_list;/* [F] list of active files */ struct mutex f_mtx; u_int f_flag; /* [a] see fcntl.h */ -#defineDTYPE_VNODE 1 /* file */ -#defineDTYPE_SOCKET2 /* communications endpoint */ -#defineDTYPE_PIPE 3 /* pipe */ -#defineDTYPE_KQUEUE4 /* event queue */ -#defineDTYPE_DMABUF5 /* DMA buffer (for DRM) */ u_int f_iflags; /* [a] internal flags */ int f_type; /* [I] descriptor type */ u_int f_count;/* [a] reference count */
Re: kvm_getfiles and KERN_FILE_BYFILE
On Thu, Nov 26, 2020 at 1:08 PM Martijn van Duren < openbsd+t...@list.imperialat.at> wrote: > I'm currently playing around a bit with kvm_getfiles and found that I > couldn't use KERN_FILE_BYFILE with DTYPE_SOCKET. > According to kvm_getfiles(3): > For KERN_FILE_BYFILE the recognized file types are defined in > : > >DTYPE_VNODE files and devices >DTYPE_SOCKET sockets, regardless of domain >DTYPE_PIPEpipes and FIFOs >DTYPE_KQUEUE kqueues > > But these defines are under ifdef _KERNEL. > > So is the manpage lying here, or should the defines be hoisted out > of the ifdef? > Let's go ahead and hoist them: FreeBSD and NetBSD already have. If possible, the diff to do that should also simplify the #include bits in these files: usr.bin/netstat/inet.c usr.bin/fstat/fstat.c usr.bin/fstat/fuser.c usr.bin/systat/netstat.c Philip Guenther
kvm_getfiles and KERN_FILE_BYFILE
I'm currently playing around a bit with kvm_getfiles and found that I couldn't use KERN_FILE_BYFILE with DTYPE_SOCKET. According to kvm_getfiles(3): For KERN_FILE_BYFILE the recognized file types are defined in : DTYPE_VNODE files and devices DTYPE_SOCKET sockets, regardless of domain DTYPE_PIPEpipes and FIFOs DTYPE_KQUEUE kqueues But these defines are under ifdef _KERNEL. So is the manpage lying here, or should the defines be hoisted out of the ifdef? martijn@