On 22/04/21(Thu) 20:19, Alexander Bluhm wrote:
> Hi,
> 
> sysctl witnesswatch gives an error message if the feature is not
> compiled into the kernel.  I think dt(4) allowdt should do the same.
> 
> sysctl: kern.allowdt: value is not available
> 
> This removes a bit of unused code from ramdisk kernel.
> The variable allowdt should be in the device, not in sysctl source.
> We don't need #ifdef for extern and prototypes, without it code is
> more readable.
> Put the unneeded sysctl code into an #if NDT > 0.
> 
> ok?

ok mpi@

> By the way, can we enable dt(4) in GENERIC?  I use it quite often
> and it is handy to have it is avaiable.  Missuse is prevented by
> securelevel sysctl.  Any downside?

I don't see any reason to not do it.

> Index: dev/dt/dt_dev.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/dev/dt/dt_dev.c,v
> retrieving revision 1.12
> diff -u -p -r1.12 dt_dev.c
> --- dev/dt/dt_dev.c   26 Mar 2021 21:17:10 -0000      1.12
> +++ dev/dt/dt_dev.c   22 Apr 2021 17:38:22 -0000
> @@ -109,6 +109,8 @@ SIMPLEQ_HEAD(, dt_probe)  dt_probe_list;  
>  struct rwlock                        dt_lock = RWLOCK_INITIALIZER("dtlk");
>  volatile uint32_t            dt_tracing = 0; /* [K] # of processes tracing */
>  
> +int allowdt;
> +
>  void dtattach(struct device *, struct device *, void *);
>  int  dtopen(dev_t, int, int, struct proc *);
>  int  dtclose(dev_t, int, int, struct proc *);
> @@ -145,7 +147,6 @@ dtopen(dev_t dev, int flags, int mode, s
>  {
>       struct dt_softc *sc;
>       int unit = minor(dev);
> -     extern int allowdt;
>  
>       if (!allowdt)
>               return EPERM;
> Index: kern/kern_sysctl.c
> ===================================================================
> RCS file: /data/mirror/openbsd/cvs/src/sys/kern/kern_sysctl.c,v
> retrieving revision 1.389
> diff -u -p -r1.389 kern_sysctl.c
> --- kern/kern_sysctl.c        8 Feb 2021 10:51:02 -0000       1.389
> +++ kern/kern_sysctl.c        22 Apr 2021 17:38:22 -0000
> @@ -114,24 +114,21 @@
>  #endif
>  
>  #include "audio.h"
> -#include "video.h"
> +#include "dt.h"
>  #include "pf.h"
> +#include "video.h"
>  
>  extern struct forkstat forkstat;
>  extern struct nchstats nchstats;
>  extern int nselcoll, fscale;
>  extern struct disklist_head disklist;
>  extern fixpt_t ccpu;
> -extern  long numvnodes;
> -#if NAUDIO > 0
> +extern long numvnodes;
> +extern int allowdt;
>  extern int audio_record_enable;
> -#endif
> -#if NVIDEO > 0
>  extern int video_record_enable;
> -#endif
>  
>  int allowkmem;
> -int allowdt;
>  
>  int sysctl_diskinit(int, struct proc *);
>  int sysctl_proc_args(int *, u_int, void *, size_t *, struct proc *);
> @@ -142,12 +139,8 @@ int sysctl_proc_vmmap(int *, u_int, void
>  int sysctl_intrcnt(int *, u_int, void *, size_t *);
>  int sysctl_sensors(int *, u_int, void *, size_t *, void *, size_t);
>  int sysctl_cptime2(int *, u_int, void *, size_t *, void *, size_t);
> -#if NAUDIO > 0
>  int sysctl_audio(int *, u_int, void *, size_t *, void *, size_t);
> -#endif
> -#if NVIDEO > 0
>  int sysctl_video(int *, u_int, void *, size_t *, void *, size_t);
> -#endif
>  int sysctl_cpustats(int *, u_int, void *, size_t *, void *, size_t);
>  int sysctl_utc_offset(void *, size_t *, void *, size_t);
>  
> @@ -479,10 +472,12 @@ kern_sysctl(int *name, u_int namelen, vo
>                       return (EPERM);
>               securelevel = level;
>               return (0);
> +#if NDT > 0
>       case KERN_ALLOWDT:
>               if (securelevel > 0)
>                       return (sysctl_rdint(oldp, oldlenp, newp, allowdt));
>               return (sysctl_int(oldp, oldlenp, newp, newlen,  &allowdt));
> +#endif
>       case KERN_ALLOWKMEM:
>               if (securelevel > 0)
>                       return (sysctl_rdint(oldp, oldlenp, newp, allowkmem));
> 

Reply via email to