look(1): drop "rpath" promise after open(2)/fstat(2)

2022-02-08 Thread Scott Cheloha
The look(1) program needs to open(2) and fstat(2) exactly one file
during its runtime.  Using unveil(2) seems like overkill here.

This seems closer to what we want:

- pledge(2) initially with "stdio rpath" at the top of main().
  We know we need to read a file at this point but don't yet
  know which one.

- pledge(2) down to "stdio" after we have opened the file
  in question and called fstat(2) to get its size.  The rest
  of the program is computation and stdio.

- Remove the unveil(2) call.  We don't need it if we're only
  working with one file and it's already open.

Unless I have misunderstood something, we don't need "rpath" to
mmap(2) the descriptor into memory after opening it, so drop "rpath"
before the mmap(2) call.

ok?

Index: look.c
===
RCS file: /cvs/src/usr.bin/look/look.c,v
retrieving revision 1.25
diff -u -p -r1.25 look.c
--- look.c  24 Oct 2021 21:24:16 -  1.25
+++ look.c  9 Feb 2022 01:26:38 -
@@ -77,6 +77,9 @@ main(int argc, char *argv[])
int ch, fd, termchar;
char *back, *file, *front, *string, *p;
 
+   if (pledge("stdio rpath", NULL) == -1)
+   err(2, "pledge");
+
file = _PATH_WORDS;
termchar = '\0';
while ((ch = getopt(argc, argv, "dft:")) != -1)
@@ -110,11 +113,6 @@ main(int argc, char *argv[])
usage();
}
 
-   if (unveil(file, "r") == -1)
-   err(2, "unveil %s", file);
-   if (pledge("stdio rpath", NULL) == -1)
-   err(2, "pledge");
-
if (termchar != '\0' && (p = strchr(string, termchar)) != NULL)
*++p = '\0';
 
@@ -122,6 +120,10 @@ main(int argc, char *argv[])
err(2, "%s", file);
if (sb.st_size > SIZE_MAX)
errc(2, EFBIG, "%s", file);
+
+   if (pledge("stdio", NULL) == -1)
+   err(2, "pledge");
+
if ((front = mmap(NULL,
(size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0)) == 
MAP_FAILED)
err(2, "%s", file);



Re: ps STAT sorted

2022-02-08 Thread Bryan Steele
On Tue, Feb 08, 2022 at 08:39:35PM +0100, Alexander Bluhm wrote:
> Hi,
> 
> Sort the ps(1) STAT characters alphabetically like in the man page.
> Note that the 'else' I have removed is redundant.
> 
> ok?
> 
> bluhm
> 
> Index: bin/ps/print.c
> ===
> RCS file: /data/mirror/openbsd/cvs/src/bin/ps/print.c,v
> retrieving revision 1.80
> diff -u -p -r1.80 print.c
> --- bin/ps/print.c7 Feb 2022 22:57:47 -   1.80
> +++ bin/ps/print.c8 Feb 2022 19:21:07 -
> @@ -262,35 +262,35 @@ printstate(const struct kinfo_proc *kp, 
>   }
>   cp++;
>  
> + if ((kp->p_psflags & PS_CONTROLT) && kp->p__pgid == kp->p_tpgid)
> + *cp++ = '+';
>   if (kp->p_nice < NZERO)
>   *cp++ = '<';
> - else if (kp->p_nice > NZERO)
> - *cp++ = 'N';
> - if (kp->p_psflags & PS_TRACED)
> - *cp++ = 'X';
> + if ((flag & P_SYSTEM) == 0 &&
> + kp->p_rlim_rss_cur / 1024 < pgtok(kp->p_vm_rssize))
> + *cp++ = '>';
> + if (kp->p_eflag & EPROC_CHROOT)
> + *cp++ = 'c';
>   if ((kp->p_psflags & (PS_EXITING | PS_ZOMBIE)) == PS_EXITING)
>   *cp++ = 'E';
> - if (kp->p_psflags & PS_ISPWAIT)
> - *cp++ = 'V';
>   if (flag & P_SYSTEM)
>   *cp++ = 'K';
> - if ((flag & P_SYSTEM) == 0 &&
> - kp->p_rlim_rss_cur / 1024 < pgtok(kp->p_vm_rssize))
> - *cp++ = '>';
> - if (kp->p_eflag & EPROC_SLEADER)
> - *cp++ = 's';
> - if ((kp->p_psflags & PS_CONTROLT) && kp->p__pgid == kp->p_tpgid)
> - *cp++ = '+';
> + if (kp->p_nice > NZERO)
> + *cp++ = 'N';
>   if (kp->p_psflags & PS_PLEDGE)
>   *cp++ = 'p';
> + if (kp->p_eflag & EPROC_SLEADER)
> + *cp++ = 's';
>   if (kp->p_eflag & EPROC_UNVEIL) {
>   if (kp->p_eflag & EPROC_LKUNVEIL)
>   *cp++ = 'U';
>   else
>   *cp++ = 'u';
>   }
> - if (kp->p_eflag & EPROC_CHROOT)
> - *cp++ = 'c';
> + if (kp->p_psflags & PS_ISPWAIT)
> + *cp++ = 'V';
> + if (kp->p_psflags & PS_TRACED)
> + *cp++ = 'X';
>   *cp = '\0';
>  
>   if (state == 'R' && kp->p_cpuid != KI_NOCPU)

I feel like shuffling the order these are printed has a higher chance of
causing confusion than additional characters. But maybe it's worth it
for new users, hmm.

-Bryan.



ps STAT sorted

2022-02-08 Thread Alexander Bluhm
Hi,

Sort the ps(1) STAT characters alphabetically like in the man page.
Note that the 'else' I have removed is redundant.

ok?

bluhm

Index: bin/ps/print.c
===
RCS file: /data/mirror/openbsd/cvs/src/bin/ps/print.c,v
retrieving revision 1.80
diff -u -p -r1.80 print.c
--- bin/ps/print.c  7 Feb 2022 22:57:47 -   1.80
+++ bin/ps/print.c  8 Feb 2022 19:21:07 -
@@ -262,35 +262,35 @@ printstate(const struct kinfo_proc *kp, 
}
cp++;
 
+   if ((kp->p_psflags & PS_CONTROLT) && kp->p__pgid == kp->p_tpgid)
+   *cp++ = '+';
if (kp->p_nice < NZERO)
*cp++ = '<';
-   else if (kp->p_nice > NZERO)
-   *cp++ = 'N';
-   if (kp->p_psflags & PS_TRACED)
-   *cp++ = 'X';
+   if ((flag & P_SYSTEM) == 0 &&
+   kp->p_rlim_rss_cur / 1024 < pgtok(kp->p_vm_rssize))
+   *cp++ = '>';
+   if (kp->p_eflag & EPROC_CHROOT)
+   *cp++ = 'c';
if ((kp->p_psflags & (PS_EXITING | PS_ZOMBIE)) == PS_EXITING)
*cp++ = 'E';
-   if (kp->p_psflags & PS_ISPWAIT)
-   *cp++ = 'V';
if (flag & P_SYSTEM)
*cp++ = 'K';
-   if ((flag & P_SYSTEM) == 0 &&
-   kp->p_rlim_rss_cur / 1024 < pgtok(kp->p_vm_rssize))
-   *cp++ = '>';
-   if (kp->p_eflag & EPROC_SLEADER)
-   *cp++ = 's';
-   if ((kp->p_psflags & PS_CONTROLT) && kp->p__pgid == kp->p_tpgid)
-   *cp++ = '+';
+   if (kp->p_nice > NZERO)
+   *cp++ = 'N';
if (kp->p_psflags & PS_PLEDGE)
*cp++ = 'p';
+   if (kp->p_eflag & EPROC_SLEADER)
+   *cp++ = 's';
if (kp->p_eflag & EPROC_UNVEIL) {
if (kp->p_eflag & EPROC_LKUNVEIL)
*cp++ = 'U';
else
*cp++ = 'u';
}
-   if (kp->p_eflag & EPROC_CHROOT)
-   *cp++ = 'c';
+   if (kp->p_psflags & PS_ISPWAIT)
+   *cp++ = 'V';
+   if (kp->p_psflags & PS_TRACED)
+   *cp++ = 'X';
*cp = '\0';
 
if (state == 'R' && kp->p_cpuid != KI_NOCPU) {



Re: mandoc.1: update example to reflect current options

2022-02-08 Thread Ingo Schwarze
Hello Anders,

Anders Damsgaard wrote on Tue, Feb 08, 2022 at 08:36:11AM +0100:

> The mandoc(1) option alias -l for -a was removed from the documentation
> in revision 1.107:
> 
> https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/mandoc/mandoc.1.diff?r1=1.106=1.107
> 
> The -l option still works, but this diff makes the example consistent
> with the current option description.

Thanks, committed.

Both are correct and reliable, but i agree -a is easier to understand
whereas understanding why -l works is a bit convoluted.

Yours,
  Ingo



Log message:
In the first example, use "mandoc -a" directly rather "mandoc -l".

It feels more natural to me to use -a directly when asking mandoc(1)
to use a pager.  The reason that "mandoc -l" does exactly the same
as "mandoc -a" is that "mandoc" is essentially "man -lc", so the -a
implied by -l negates the -c and the -l has no effect because it is
already the default for mandoc(1).

The more usual command for doing the same is "man -l foo.1 bar.1 ..."
but that's off-topic for the mandoc(1) manual page.

Patch on tech@ from Anders Damsgaard .


> Index: usr.bin/mandoc/mandoc.1
> ===
> RCS file: /cvs/src/usr.bin/mandoc/mandoc.1,v
> retrieving revision 1.180
> diff -u -p -u -p -r1.180 mandoc.1
> --- usr.bin/mandoc/mandoc.1   6 Feb 2022 00:29:03 -   1.180
> +++ usr.bin/mandoc/mandoc.1   8 Feb 2022 07:33:42 -
> @@ -735,7 +735,7 @@ output mode implies
>   .Sh EXAMPLES
>   To page manuals to the terminal:
>   .Pp
> -.Dl $ mandoc -l mandoc.1 man.1 apropos.1 makewhatis.8
> +.Dl $ mandoc -a mandoc.1 man.1 apropos.1 makewhatis.8
>   .Pp
>   To produce HTML manuals with
>   .Pa /usr/share/misc/mandoc.css



Re: wskbd_set_mixervolume

2022-02-08 Thread Anton Lindqvist
On Tue, Feb 08, 2022 at 07:32:38AM +0100, Alexandre Ratchov wrote:
> On Mon, Feb 07, 2022 at 06:55:21PM +0100, Anton Lindqvist wrote:
> > On Mon, Feb 07, 2022 at 11:21:43AM +0100, Alexandre Ratchov wrote:
> > > On Sun, Feb 06, 2022 at 08:40:35AM +0100, Anton Lindqvist wrote:
> > > > 
> > > > Polished diff. I'm omitting a necessary refactoring commit making
> > > > audio_attach_mi() accept a new cookie argument.
> > > > 
> > > 
> > > I'm not sure to understand the need for the wskbd_audio structure.
> > > Couldn't we just store the cookie in audio and wskbd softc structures,
> > > then pass it in the wskbd_set_mixervolume_sc() calls ?
> > 
> > Due to the device caching the data must be stored in either the audio or
> > wskbd softc and I don't want to expose the softc structures so I ended
> > up introducing wskbd_audio. Dropping the caching would probably make it
> > possible to only pass down the cookie to wskbd_set_mixervolume_sc() and
> > always do the audio device lookup.
> > 
> > Is anyone in favor of this approach? I achieves the expected behavior in
> > my opinion.
> 
> IMHO, handling the volume keys this way won't work in the general
> case. But for the short term we've no other options, have we?
> 
> AFAICS, you're fixing a concrete use-case by tweaking what already
> exists, this won't make things more broken than they already are. I'm
> OK with it.

Here's the complete diff including adding a cookie argument to
audio_attach_mi().
diff --git sys/arch/hppa/gsc/harmony.c sys/arch/hppa/gsc/harmony.c
index 033a3d2c356..d5748fac4b1 100644
--- sys/arch/hppa/gsc/harmony.c
+++ sys/arch/hppa/gsc/harmony.c
@@ -249,7 +249,7 @@ harmony_attach(parent, self, aux)
if ((rev & CS4215_REV_VER) >= CS4215_REV_VER_E)
sc->sc_hasulinear8 = 1;
 
-   audio_attach_mi(_sa_hw_if, sc, >sc_dv);
+   audio_attach_mi(_sa_hw_if, sc, NULL, >sc_dv);
 
timeout_set(>sc_acc_tmo, harmony_acc_tmo, sc);
sc->sc_acc_num = 0xa5a5a5a5;
diff --git sys/arch/luna88k/cbus/nec86.c sys/arch/luna88k/cbus/nec86.c
index b6516cc4888..dc4e2069ddd 100644
--- sys/arch/luna88k/cbus/nec86.c
+++ sys/arch/luna88k/cbus/nec86.c
@@ -237,7 +237,7 @@ nec86_attachsubr(struct nec86_softc *sc)
 
if (sc->sc_attached == 0) {
printf(": %s\n", boardname[ysc->model]);
-   audio_attach_mi(_hw_if, ysc, >sc_dev);
+   audio_attach_mi(_hw_if, ysc, NULL, >sc_dev);
sc->sc_attached = 1;
}
 }
diff --git sys/arch/macppc/dev/aoa.c sys/arch/macppc/dev/aoa.c
index a2ca8e10a95..638da4b1669 100644
--- sys/arch/macppc/dev/aoa.c
+++ sys/arch/macppc/dev/aoa.c
@@ -134,7 +134,7 @@ aoa_defer(struct device *dev)
 {
struct aoa_softc *sc = (struct aoa_softc *)dev;
 
-   audio_attach_mi(_hw_if, sc, >sc_dev);
+   audio_attach_mi(_hw_if, sc, NULL, >sc_dev);
deq_reset(sc);
 }
 
diff --git sys/arch/macppc/dev/awacs.c sys/arch/macppc/dev/awacs.c
index 8ea7d4869a0..adcafcf79fb 100644
--- sys/arch/macppc/dev/awacs.c
+++ sys/arch/macppc/dev/awacs.c
@@ -340,7 +340,7 @@ awacs_attach(struct device *parent, struct device *self, 
void *aux)
awacs_halt_input(sc);
printf("\n");
 
-   audio_attach_mi(_hw_if, sc, >sc_dev);
+   audio_attach_mi(_hw_if, sc, NULL, >sc_dev);
 }
 
 u_int
diff --git sys/arch/macppc/dev/daca.c sys/arch/macppc/dev/daca.c
index 070b839c99a..91b078dd254 100644
--- sys/arch/macppc/dev/daca.c
+++ sys/arch/macppc/dev/daca.c
@@ -154,7 +154,7 @@ daca_defer(struct device *dev)
 
/* XXX If i2c has failed to attach, what should we do? */
 
-   audio_attach_mi(_hw_if, sc, >sc_dev);
+   audio_attach_mi(_hw_if, sc, NULL, >sc_dev);
 
daca_init(sc);
 }
diff --git sys/arch/macppc/dev/onyx.c sys/arch/macppc/dev/onyx.c
index c279258f091..9252d1c7376 100644
--- sys/arch/macppc/dev/onyx.c
+++ sys/arch/macppc/dev/onyx.c
@@ -165,7 +165,7 @@ onyx_defer(struct device *dev)
 
/* XXX If i2c has failed to attach, what should we do? */
 
-   audio_attach_mi(_hw_if, sc, >sc_dev);
+   audio_attach_mi(_hw_if, sc, NULL, >sc_dev);
 
deq_reset(sc);
onyx_set_volume(sc, 192, 192);
diff --git sys/arch/macppc/dev/snapper.c sys/arch/macppc/dev/snapper.c
index 3fbf58aec0f..13784f6d207 100644
--- sys/arch/macppc/dev/snapper.c
+++ sys/arch/macppc/dev/snapper.c
@@ -486,7 +486,7 @@ snapper_defer(struct device *dev)
 
/* XXX If i2c has failed to attach, what should we do? */
 
-   audio_attach_mi(_hw_if, sc, >sc_dev);
+   audio_attach_mi(_hw_if, sc, NULL, >sc_dev);
 
/* kiic_setmode(sc->sc_i2c, I2C_STDSUBMODE); */
snapper_init(sc);
diff --git sys/arch/macppc/dev/tumbler.c sys/arch/macppc/dev/tumbler.c
index 6c522a10585..4e2b1fc321a 100644
--- sys/arch/macppc/dev/tumbler.c
+++ sys/arch/macppc/dev/tumbler.c
@@ -299,7 +299,7 @@ tumbler_defer(struct device *dev)
 
/* XXX If i2c has failed to attach, what should we do? */
 
-   audio_attach_mi(_hw_if, sc, >sc_dev);
+   

Unify f_modify and f_process event filter callbacks for pipes

2022-02-08 Thread Visa Hankala
The current code pattern used with MP-safe event filters is verbose.
I would like to find a more concise form before making more event
filters MP-safe.

Of struct filterops callbacks, f_modify and f_process essentially
use f_event. By utilizing the f_event function pointer, a subsystem
can have unified modify and process callbacks that are shared between
the filter types.

The diff below does the unification for pipes. The gist might become
clearer by comparing the resulting code to r1.128 of sys_pipe.c

The use of indirection might obfuscate the code a little bit. However,
the reduction in code size should outweigh this.

Indirect function calls involve retpolines on certain architectures
and consequently take more time than direct calls. The patch does not
change the big picture. Function pointers are used throughout the
kernel.

I wrote a test program where one process writes bytes through a pipe
to another process that uses poll(2) and read(2). On a relatively recent
Ryzen 5000 series processor, about 0.17% of syscall samples where spent
in a retpoline handler, scattered in various parts of the kernel.
None of these retpoline samples happened to involve filt_pipemodify() or
filt_pipeprocess().

In sum, I think the patch is an improvement.

OK?

Index: kern/sys_pipe.c
===
RCS file: src/sys/kern/sys_pipe.c,v
retrieving revision 1.133
diff -u -p -r1.133 sys_pipe.c
--- kern/sys_pipe.c 13 Dec 2021 14:56:55 -  1.133
+++ kern/sys_pipe.c 8 Feb 2022 15:47:27 -
@@ -78,25 +78,18 @@ static const struct fileops pipeops = {
 
 void   filt_pipedetach(struct knote *kn);
 intfilt_piperead(struct knote *kn, long hint);
-intfilt_pipereadmodify(struct kevent *kev, struct knote *kn);
-intfilt_pipereadprocess(struct knote *kn, struct kevent *kev);
-intfilt_piperead_common(struct knote *kn, struct pipe *rpipe);
 intfilt_pipewrite(struct knote *kn, long hint);
-intfilt_pipewritemodify(struct kevent *kev, struct knote *kn);
-intfilt_pipewriteprocess(struct knote *kn, struct kevent *kev);
-intfilt_pipewrite_common(struct knote *kn, struct pipe *rpipe);
 intfilt_pipeexcept(struct knote *kn, long hint);
-intfilt_pipeexceptmodify(struct kevent *kev, struct knote *kn);
-intfilt_pipeexceptprocess(struct knote *kn, struct kevent *kev);
-intfilt_pipeexcept_common(struct knote *kn, struct pipe *rpipe);
+intfilt_pipemodify(struct kevent *kev, struct knote *kn);
+intfilt_pipeprocess(struct knote *kn, struct kevent *kev);
 
 const struct filterops pipe_rfiltops = {
.f_flags= FILTEROP_ISFD | FILTEROP_MPSAFE,
.f_attach   = NULL,
.f_detach   = filt_pipedetach,
.f_event= filt_piperead,
-   .f_modify   = filt_pipereadmodify,
-   .f_process  = filt_pipereadprocess,
+   .f_modify   = filt_pipemodify,
+   .f_process  = filt_pipeprocess,
 };
 
 const struct filterops pipe_wfiltops = {
@@ -104,8 +97,8 @@ const struct filterops pipe_wfiltops = {
.f_attach   = NULL,
.f_detach   = filt_pipedetach,
.f_event= filt_pipewrite,
-   .f_modify   = filt_pipewritemodify,
-   .f_process  = filt_pipewriteprocess,
+   .f_modify   = filt_pipemodify,
+   .f_process  = filt_pipeprocess,
 };
 
 const struct filterops pipe_efiltops = {
@@ -113,8 +106,8 @@ const struct filterops pipe_efiltops = {
.f_attach   = NULL,
.f_detach   = filt_pipedetach,
.f_event= filt_pipeexcept,
-   .f_modify   = filt_pipeexceptmodify,
-   .f_process  = filt_pipeexceptprocess,
+   .f_modify   = filt_pipemodify,
+   .f_process  = filt_pipeprocess,
 };
 
 /*
@@ -954,9 +947,9 @@ filt_pipedetach(struct knote *kn)
 }
 
 int
-filt_piperead_common(struct knote *kn, struct pipe *rpipe)
+filt_piperead(struct knote *kn, long hint)
 {
-   struct pipe *wpipe;
+   struct pipe *rpipe = kn->kn_fp->f_data, *wpipe;
 
rw_assert_wrlock(rpipe->pipe_lock);
 
@@ -975,49 +968,9 @@ filt_piperead_common(struct knote *kn, s
 }
 
 int
-filt_piperead(struct knote *kn, long hint)
-{
-   struct pipe *rpipe = kn->kn_fp->f_data;
-
-   return (filt_piperead_common(kn, rpipe));
-}
-
-int
-filt_pipereadmodify(struct kevent *kev, struct knote *kn)
-{
-   struct pipe *rpipe = kn->kn_fp->f_data;
-   int active;
-
-   rw_enter_write(rpipe->pipe_lock);
-   knote_modify(kev, kn);
-   active = filt_piperead_common(kn, rpipe);
-   rw_exit_write(rpipe->pipe_lock);
-
-   return (active);
-}
-
-int
-filt_pipereadprocess(struct knote *kn, struct kevent *kev)
-{
-   struct pipe *rpipe = kn->kn_fp->f_data;
-   int active;
-
-   rw_enter_write(rpipe->pipe_lock);
-   if (kev != NULL && (kn->kn_flags & EV_ONESHOT))
-   active = 1;
-   else
-   active = filt_piperead_common(kn, 

Re: Increase armv7 ramdisk size

2022-02-08 Thread Theo de Raadt
Fine.

Visa Hankala  wrote:

> On Mon, Feb 07, 2022 at 09:35:21AM -0700, Theo de Raadt wrote:
> > Please don't do such a small increase, because it is likely we'll need to
> > do it again the near future.
> > 
> > I suggest taking ns#600 to ns#650 or ns#700, and adjusting all the numbers.
> 
> Here is a diff that uses ns#700.
> 
> OK?
> 
> Index: etc/etc.armv7/disktab
> ===
> RCS file: src/etc/etc.armv7/disktab,v
> retrieving revision 1.13
> diff -u -p -r1.13 disktab
> --- etc/etc.armv7/disktab 12 Oct 2021 16:39:22 -  1.13
> +++ etc/etc.armv7/disktab 8 Feb 2022 15:35:00 -
> @@ -2,9 +2,9 @@
>  
>  # Leave nc=16; adjust size using: ns
>  rdroot|ramdiskroot|RAM-disk root FS image:\
> - :dt=rdroot:se#512:nc#16:nt#2:ns#600:\
> - :ta=4.2BSD:oa#0:pa#19200:fa#512:ba#4096:\
> - :ob#0:pb#0:oc#0:pc#19200:
> + :dt=rdroot:se#512:nc#16:nt#2:ns#700:\
> + :ta=4.2BSD:oa#0:pa#22400:fa#512:ba#4096:\
> + :ob#0:pb#0:oc#0:pc#22400:
>  
>  miniroot:\
>   :dt=rdroot:se#512:nc#9:nt#16:ns#496:\
> Index: sys/arch/armv7/conf/RAMDISK
> ===
> RCS file: src/sys/arch/armv7/conf/RAMDISK,v
> retrieving revision 1.127
> diff -u -p -r1.127 RAMDISK
> --- sys/arch/armv7/conf/RAMDISK   9 Oct 2021 01:01:09 -   1.127
> +++ sys/arch/armv7/conf/RAMDISK   8 Feb 2022 15:35:00 -
> @@ -11,7 +11,7 @@ option  SMALL_KERNEL
>  option   NO_PROPOLICE
>  option   BOOT_CONFIG
>  
> -option   MINIROOTSIZE=19200
> +option   MINIROOTSIZE=22400
>  option   RAMDISK_HOOKS
>  
>  option   FFS
> 



Re: tr(1): improve table names

2022-02-08 Thread Scott Cheloha
On Sun, Jan 30, 2022 at 10:23:43AM -0600, Scott Cheloha wrote:
> In tr(1), we have these two global arrays, "string1" and "string2".
> 
> I have a few complaints:
> 
> 1. They are not strings.  They are lookup tables.  The names are
>misleading.
> 
> 2. The arguments given to tr(1) in argv[] are indeed called "string1"
>and "string2".  These are the names used in the standard, the manpage,
>and the usage printout.
> 
>However, the lookup tables are merely *described* by these arguments.
>They are not the arguments themselves.
> 
> 3. The meaning of the contents of these lookup tables changes depending
>on which of the five different operating modes tr(1) is running in.
> 
>string1[i] might mean "delete byte i" or "squeeze byte i" or
>"replace byte i with the value string1[i]" depending on how
>tr(1) was invoked.
> 
> Given this, I think it'd be a lot nicer if we named the tables to
> indicate which transformation operation they correspond to.
> 
> We have three such operations: "delete", "squeeze", and "translate".
> So we ought to have a table for each.  And in setup() we should call
> the table a "table", not a "string".
> 
> Now when you look at the loops in main() you can immediately
> understand which operation is happening without needing to consult the
> manpage or the comments.  (Seriously, look.)
> 
> I have more cleanup I want to do here in tr.c, but I think renaming
> these tables first is going to make the rest of it a lot easier to
> review.
> 
> ok?

1 week bump.

ok?

Index: tr.c
===
RCS file: /cvs/src/usr.bin/tr/tr.c,v
retrieving revision 1.20
diff -u -p -r1.20 tr.c
--- tr.c2 Nov 2021 15:45:52 -   1.20
+++ tr.c30 Jan 2022 16:14:21 -
@@ -40,7 +40,8 @@
 
 #include "extern.h"
 
-static int string1[NCHARS] = {
+int delete[NCHARS], squeeze[NCHARS];
+int translate[NCHARS] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ASCII */
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
@@ -73,7 +74,7 @@ static int string1[NCHARS] = {
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
-}, string2[NCHARS];
+};
 
 STR s1 = { STRING1, NORMAL, 0, OOBCH, { 0, OOBCH }, NULL, NULL };
 STR s2 = { STRING2, NORMAL, 0, OOBCH, { 0, OOBCH }, NULL, NULL };
@@ -122,11 +123,11 @@ main(int argc, char *argv[])
if (argc != 2)
usage();
 
-   setup(string1, argv[0], , cflag);
-   setup(string2, argv[1], , 0);
+   setup(delete, argv[0], , cflag);
+   setup(squeeze, argv[1], , 0);
 
for (lastch = OOBCH; (ch = getchar()) != EOF;)
-   if (!string1[ch] && (!string2[ch] || lastch != ch)) {
+   if (!delete[ch] && (!squeeze[ch] || lastch != ch)) {
lastch = ch;
(void)putchar(ch);
}
@@ -141,10 +142,10 @@ main(int argc, char *argv[])
if (argc != 1)
usage();
 
-   setup(string1, argv[0], , cflag);
+   setup(delete, argv[0], , cflag);
 
while ((ch = getchar()) != EOF)
-   if (!string1[ch])
+   if (!delete[ch])
(void)putchar(ch);
exit(0);
}
@@ -154,10 +155,10 @@ main(int argc, char *argv[])
 * Squeeze all characters (or complemented characters) in string1.
 */
if (sflag && argc == 1) {
-   setup(string1, argv[0], , cflag);
+   setup(squeeze, argv[0], , cflag);
 
for (lastch = OOBCH; (ch = getchar()) != EOF;)
-   if (!string1[ch] || lastch != ch) {
+   if (!squeeze[ch] || lastch != ch) {
lastch = ch;
(void)putchar(ch);
}
@@ -177,7 +178,7 @@ main(int argc, char *argv[])
s2.str = (unsigned char *)argv[1];
 
if (cflag)
-   for (cnt = NCHARS, p = string1; cnt--;)
+   for (cnt = NCHARS, p = translate; cnt--;)
*p++ = OOBCH;
 
if (!next())
@@ -187,45 +188,45 @@ main(int argc, char *argv[])
ch = s2.lastch;
if (sflag)
while (next()) {
-   string1[s1.lastch] = ch = s2.lastch;
-   string2[ch] = 1;
+   translate[s1.lastch] = ch = s2.lastch;
+   squeeze[ch] = 1;
(void)next();
}
else
while (next()) {
-   string1[s1.lastch] = ch = s2.lastch;
+   

Re: rev(1): drop "rpath" promise in no-file branch

2022-02-08 Thread Todd C . Miller
On Tue, 08 Feb 2022 10:40:00 -0600, Scott Cheloha wrote:

> We don't need "rpath" if we're only processing the standard input.

Sure.  OK millert@

 - todd



rev(1): drop "rpath" promise in no-file branch

2022-02-08 Thread Scott Cheloha
We don't need "rpath" if we're only processing the standard input.

ok?

Index: rev.c
===
RCS file: /cvs/src/usr.bin/rev/rev.c,v
retrieving revision 1.15
diff -u -p -r1.15 rev.c
--- rev.c   29 Jan 2022 00:11:54 -  1.15
+++ rev.c   8 Feb 2022 16:38:46 -
@@ -68,6 +68,9 @@ main(int argc, char *argv[])
 
rval = 0;
if (argc == 0) {
+   if (pledge("stdio", NULL) == -1)
+   err(1, "pledge");
+
rval = rev_file(NULL);
} else {
for (; *argv != NULL; argv++)



Re: Increase armv7 ramdisk size

2022-02-08 Thread Visa Hankala
On Mon, Feb 07, 2022 at 09:35:21AM -0700, Theo de Raadt wrote:
> Please don't do such a small increase, because it is likely we'll need to
> do it again the near future.
> 
> I suggest taking ns#600 to ns#650 or ns#700, and adjusting all the numbers.

Here is a diff that uses ns#700.

OK?

Index: etc/etc.armv7/disktab
===
RCS file: src/etc/etc.armv7/disktab,v
retrieving revision 1.13
diff -u -p -r1.13 disktab
--- etc/etc.armv7/disktab   12 Oct 2021 16:39:22 -  1.13
+++ etc/etc.armv7/disktab   8 Feb 2022 15:35:00 -
@@ -2,9 +2,9 @@
 
 # Leave nc=16; adjust size using: ns
 rdroot|ramdiskroot|RAM-disk root FS image:\
-   :dt=rdroot:se#512:nc#16:nt#2:ns#600:\
-   :ta=4.2BSD:oa#0:pa#19200:fa#512:ba#4096:\
-   :ob#0:pb#0:oc#0:pc#19200:
+   :dt=rdroot:se#512:nc#16:nt#2:ns#700:\
+   :ta=4.2BSD:oa#0:pa#22400:fa#512:ba#4096:\
+   :ob#0:pb#0:oc#0:pc#22400:
 
 miniroot:\
:dt=rdroot:se#512:nc#9:nt#16:ns#496:\
Index: sys/arch/armv7/conf/RAMDISK
===
RCS file: src/sys/arch/armv7/conf/RAMDISK,v
retrieving revision 1.127
diff -u -p -r1.127 RAMDISK
--- sys/arch/armv7/conf/RAMDISK 9 Oct 2021 01:01:09 -   1.127
+++ sys/arch/armv7/conf/RAMDISK 8 Feb 2022 15:35:00 -
@@ -11,7 +11,7 @@ optionSMALL_KERNEL
 option NO_PROPOLICE
 option BOOT_CONFIG
 
-option MINIROOTSIZE=19200
+option MINIROOTSIZE=22400
 option RAMDISK_HOOKS
 
 option FFS



Re: perl clang -Wcompound-token-split-by-macro

2022-02-08 Thread Marc Espie
On Tue, Feb 08, 2022 at 01:59:51PM +, Stuart Henderson wrote:
> > > I think we should start updating Devel::PPPort in base.  Then we
> > > can regenerate other ppport.h in base and ports.  Note that some ports
> > > need newer Devel::PPPort than we have now.  So updating seems
> > > unavoidable.
> 
> I do worry a bit that if we regenerate in ports, that some ports might
> want an *older* version. (At least the regen might need to be made optional).
> 
> Anyone know if FreeBSD has done anything for this?
> 

That's funny, because basically that glue is supposed to make things *more
portable*... so having it not work with a newer version would definitely
mean we need to ask upstream to fix their software.

eventually, it should settle down. Putting the blame in the right location
so that it gets fixed for everyone looks to me to be the best course of
action, unless it proves too time-consuming.



Re: perl clang -Wcompound-token-split-by-macro

2022-02-08 Thread Stuart Henderson
> > I think we should start updating Devel::PPPort in base.  Then we
> > can regenerate other ppport.h in base and ports.  Note that some ports
> > need newer Devel::PPPort than we have now.  So updating seems
> > unavoidable.

I do worry a bit that if we regenerate in ports, that some ports might
want an *older* version. (At least the regen might need to be made optional).

Anyone know if FreeBSD has done anything for this?



Re: fix active scan on iwm and iwx

2022-02-08 Thread Mark Kettenis
> Date: Tue, 8 Feb 2022 14:21:52 +0100
> From: Stefan Sperling 
> 
> On Tue, Jan 25, 2022 at 11:22:45AM +0100, Mark Kettenis wrote:
> > > The KASSERT triggers but for the wrong reason: We don't have outstanding
> > > tasks, we have a bad reference counter. Only setting the ref counter to 1 
> > > if
> > > we are about to launch a task during resume should fix it, and this 
> > > matches
> > > what iwx(4) is doing:
> > 
> > Running this now.  May take some time to reproduce the issue though.
> 
> Any news?  I would like to commit this patch.

Been running a kernel with this since January 25th without triggering
the issue that made me want to ifconfig down/up the interface.

The diff looks good to me though.  I think you should just commit it.

ok kettenis@

> > > diff d26399562c831a7212cebc57463cc9931ff8aff2 /usr/src
> > > blob - 937f2cc28f6c85502031e4c9efa0a02c75fd1a6d
> > > file + sys/dev/pci/if_iwm.c
> > > --- sys/dev/pci/if_iwm.c
> > > +++ sys/dev/pci/if_iwm.c
> > > @@ -11719,8 +11719,6 @@ iwm_wakeup(struct iwm_softc *sc)
> > >   struct ifnet *ifp = >sc_ic.ic_if;
> > >   int err;
> > >  
> > > - refcnt_init(>task_refs);
> > > -
> > >   err = iwm_start_hw(sc);
> > >   if (err)
> > >   return err;
> > > @@ -11729,6 +11727,7 @@ iwm_wakeup(struct iwm_softc *sc)
> > >   if (err)
> > >   return err;
> > >  
> > > + refcnt_init(>task_refs);
> > >   ifq_clr_oactive(>if_snd);
> > >   ifp->if_flags |= IFF_RUNNING;
> > >  
> > > 
> > 
> 



iked restart clean entry tcpmd5 of bgpd

2022-02-08 Thread Breno Silveira Soares

Hi,

When iked restart, the daemon cleans tcpmd5 entries (SAD entries) of bgpd.
Then de daemon bgpd stop working properly.

Thanks in advance.

Best Regards,
Breno.





Re: fix active scan on iwm and iwx

2022-02-08 Thread Stefan Sperling
On Tue, Jan 25, 2022 at 11:22:45AM +0100, Mark Kettenis wrote:
> > The KASSERT triggers but for the wrong reason: We don't have outstanding
> > tasks, we have a bad reference counter. Only setting the ref counter to 1 if
> > we are about to launch a task during resume should fix it, and this matches
> > what iwx(4) is doing:
> 
> Running this now.  May take some time to reproduce the issue though.

Any news?  I would like to commit this patch.

> > diff d26399562c831a7212cebc57463cc9931ff8aff2 /usr/src
> > blob - 937f2cc28f6c85502031e4c9efa0a02c75fd1a6d
> > file + sys/dev/pci/if_iwm.c
> > --- sys/dev/pci/if_iwm.c
> > +++ sys/dev/pci/if_iwm.c
> > @@ -11719,8 +11719,6 @@ iwm_wakeup(struct iwm_softc *sc)
> > struct ifnet *ifp = >sc_ic.ic_if;
> > int err;
> >  
> > -   refcnt_init(>task_refs);
> > -
> > err = iwm_start_hw(sc);
> > if (err)
> > return err;
> > @@ -11729,6 +11727,7 @@ iwm_wakeup(struct iwm_softc *sc)
> > if (err)
> > return err;
> >  
> > +   refcnt_init(>task_refs);
> > ifq_clr_oactive(>if_snd);
> > ifp->if_flags |= IFF_RUNNING;
> >  
> > 
> 



Make pipes and sockets use KNOTE() instead of selwakeup()

2022-02-08 Thread Visa Hankala
Now that poll(2) is based on kqueue, the old, non-MP-safe poll backend
is not used any longer. Event sources can call KNOTE() directly instead
of selwakeup().

This diff does the KNOTE() conversion for pipes and sockets, removing
a kernel-locked section from a frequently used code path. The related
event filters do not use the hint value, hence passing 0 rather than
NOTE_SUBMIT.

I will not convert selwakeup() calls en masse yet as it might be a bit
too early to do so.

Please test.

Index: kern/sys_pipe.c
===
RCS file: src/sys/kern/sys_pipe.c,v
retrieving revision 1.133
diff -u -p -r1.133 sys_pipe.c
--- kern/sys_pipe.c 13 Dec 2021 14:56:55 -  1.133
+++ kern/sys_pipe.c 8 Feb 2022 08:59:05 -
@@ -381,12 +381,7 @@ pipeselwakeup(struct pipe *cpipe)
 {
rw_assert_wrlock(cpipe->pipe_lock);
 
-   if (cpipe->pipe_state & PIPE_SEL) {
-   cpipe->pipe_state &= ~PIPE_SEL;
-   selwakeup(>pipe_sel);
-   } else {
-   KNOTE(>pipe_sel.si_note, 0);
-   }
+   KNOTE(>pipe_sel.si_note, 0);
 
if (cpipe->pipe_state & PIPE_ASYNC)
pgsigio(>pipe_sigio, SIGIO, 0);
Index: kern/uipc_socket.c
===
RCS file: src/sys/kern/uipc_socket.c,v
retrieving revision 1.271
diff -u -p -r1.271 uipc_socket.c
--- kern/uipc_socket.c  24 Dec 2021 06:50:16 -  1.271
+++ kern/uipc_socket.c  8 Feb 2022 08:59:05 -
@@ -2049,7 +2049,7 @@ void
 sohasoutofband(struct socket *so)
 {
pgsigio(>so_sigio, SIGURG, 0);
-   selwakeup(>so_rcv.sb_sel);
+   KNOTE(>so_rcv.sb_sel.si_note, 0);
 }
 
 int
Index: kern/uipc_socket2.c
===
RCS file: src/sys/kern/uipc_socket2.c,v
retrieving revision 1.116
diff -u -p -r1.116 uipc_socket2.c
--- kern/uipc_socket2.c 6 Nov 2021 05:26:33 -   1.116
+++ kern/uipc_socket2.c 8 Feb 2022 08:59:06 -
@@ -423,7 +423,7 @@ sowakeup(struct socket *so, struct sockb
}
if (sb->sb_flags & SB_ASYNC)
pgsigio(>so_sigio, SIGIO, 0);
-   selwakeup(>sb_sel);
+   KNOTE(>sb_sel.si_note, 0);
 }
 
 /*



mandoc.1: update example to reflect current options

2022-02-08 Thread Anders Damsgaard

Hello,

The mandoc(1) option alias -l for -a was removed from the documentation
in revision 1.107:

https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/usr.bin/mandoc/mandoc.1.diff?r1=1.106=1.107

The -l option still works, but this diff makes the example consistent
with the current option description.

Cheers, Anders


Index: usr.bin/mandoc/mandoc.1
===
RCS file: /cvs/src/usr.bin/mandoc/mandoc.1,v
retrieving revision 1.180
diff -u -p -u -p -r1.180 mandoc.1
--- usr.bin/mandoc/mandoc.1 6 Feb 2022 00:29:03 -   1.180
+++ usr.bin/mandoc/mandoc.1 8 Feb 2022 07:33:42 -
@@ -735,7 +735,7 @@ output mode implies
 .Sh EXAMPLES
 To page manuals to the terminal:
 .Pp
-.Dl $ mandoc -l mandoc.1 man.1 apropos.1 makewhatis.8
+.Dl $ mandoc -a mandoc.1 man.1 apropos.1 makewhatis.8
 .Pp
 To produce HTML manuals with
 .Pa /usr/share/misc/mandoc.css