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
> >      <sys/file.h>:
> > 
> >            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 -0000      1.61
+++ file.h      29 Nov 2020 20:12:30 -0000
@@ -38,7 +38,15 @@
 #else /* _KERNEL */
 #include <sys/queue.h>
 #include <sys/mutex.h>
+#endif /* _KERNEL */
 
+#define        DTYPE_VNODE     1       /* file */
+#define        DTYPE_SOCKET    2       /* communications endpoint */
+#define        DTYPE_PIPE      3       /* pipe */
+#define        DTYPE_KQUEUE    4       /* event queue */
+#define        DTYPE_DMABUF    5       /* 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 */
-#define        DTYPE_VNODE     1       /* file */
-#define        DTYPE_SOCKET    2       /* communications endpoint */
-#define        DTYPE_PIPE      3       /* pipe */
-#define        DTYPE_KQUEUE    4       /* event queue */
-#define        DTYPE_DMABUF    5       /* DMA buffer (for DRM) */
        u_int   f_iflags;       /* [a] internal flags */
        int     f_type;         /* [I] descriptor type */
        u_int   f_count;        /* [a] reference count */


Reply via email to