Re: Automatic configuration of /etc/ttys in installer

2018-05-28 Thread Theo Buehler
On Sat, May 26, 2018 at 10:39:57PM +0200, Mark Kettenis wrote:
> > Date: Tue, 8 May 2018 08:51:14 +0200 (CEST)
> > From: Mark Kettenis 
> > 
> > After my recent changes to armv7 and arm64 the installer and
> > single-user mode are usable with a non-standard serial console speed.
> > However, the installer will still install an /etc/ttys file with
> > std.115200 in it.  This means that getty(8) will change the speed
> > which means you get garbage or nothing on your serial connections.
> > 
> > Here is an attempt to make the installer modify the console entry in
> > /etc/ttys to reflect the correct speed.  This uses some of the same
> > code that we use to offer i386/amd64 users to switch the console to
> > serial.  But it doesn't ask the question since we don't have to guess
> > what the console will be.  I restricted the patching to the set of
> > speeds that we actually support.
> > 
> > Is there a better way to do this?
> 
> Ping?

The diff reads fine to me, but I can't actually test it.

ok tb@

> 
> > Index: distrib/arm64/ramdisk/install.md
> > ===
> > RCS file: /cvs/src/distrib/arm64/ramdisk/install.md,v
> > retrieving revision 1.9
> > diff -u -p -r1.9 install.md
> > --- distrib/arm64/ramdisk/install.md23 Mar 2018 05:02:27 -  
> > 1.9
> > +++ distrib/arm64/ramdisk/install.md8 May 2018 06:40:44 -
> > @@ -150,4 +150,12 @@ md_congrats() {
> >  }
> >  
> >  md_consoleinfo() {
> > +   CTTY=console
> > +   DEFCONS=y
> > +   case $CSPEED in
> > +   9600|19200|38400|57600|115200|150)
> > +   ;;
> > +   *)
> > +   CSPEED=115200;;
> > +   esac
> >  }
> > Index: distrib/miniroot/install.sub
> > ===
> > RCS file: /cvs/src/distrib/miniroot/install.sub,v
> > retrieving revision 1.1067
> > diff -u -p -r1.1067 install.sub
> > --- distrib/miniroot/install.sub7 May 2018 10:44:01 -   1.1067
> > +++ distrib/miniroot/install.sub8 May 2018 06:40:44 -
> > @@ -2637,6 +2637,7 @@ apply() {
> > if [[ $DEFCONS == y ]]; then
> > cp /mnt/etc/ttys /tmp/i/ttys
> > sed -e "/^$CTTY/s/std.9600/std.${CSPEED}/" \
> > +   -e "/^$CTTY/s/std.115200/std.${CSPEED}/" \
> > -e "/^$CTTY/s/unknown/vt220 /" \
> > -e "/$CTTY/s/off.*/on secure/" /tmp/i/ttys 
> > >/mnt/etc/ttys
> > [[ -n $CPROM ]] &&
> > 
> > 
> 



Re: IPL_VM for `f_mtx'

2018-05-28 Thread Mark Kettenis
> Date: Mon, 28 May 2018 12:24:22 +0200
> From: Mathieu - 
> 
> Mark Kettenis wrote:
> > > Date: Mon, 28 May 2018 11:23:47 +0200
> > > From: Martin Pieuchot 
> > > 
> > > As found by tb@ and visa@, `f_mtx' need to block interrupts as long as
> > > it can be taken w/ and w/o the KERNEL_LOCK().  Otherwise a deadlock is
> > > possible if an interrupt tries to grab the KERNEL_LOCK().
> > > 
> > > I'm not switching to a rwlock because code paths are short, I don't
> > > want to introduce new sleeping points and in the long run we should
> > > be using SRPs or atomic operations for reference counts.
> > > 
> > > ok?
> > 
> > I suppose IPL_VM is the most sensible default for mutexes that need to
> > block all interrupts that might need the kernel lock.
> > 
> > ok kettenis@
> 
> 
> Hello,
> 
> Wouldn't IPL_MPFLOOR be more appropriate? After all mutexes are already
> raising the ipl level to IPL_MPFLOOR (expect for IPL_NONE and above).

The problem is that IPL_MPFLOOR doesn't exist on all platforms.  Maybe
it should...

> > > Index: kern/kern_descrip.c
> > > ===
> > > RCS file: /cvs/src/sys/kern/kern_descrip.c,v
> > > retrieving revision 1.158
> > > diff -u -p -r1.158 kern_descrip.c
> > > --- kern/kern_descrip.c   8 May 2018 09:03:58 -   1.158
> > > +++ kern/kern_descrip.c   28 May 2018 09:23:31 -
> > > @@ -957,7 +957,11 @@ restart:
> > >*/
> > >   numfiles++;
> > >   fp = pool_get(_pool, PR_WAITOK|PR_ZERO);
> > > - mtx_init(>f_mtx, IPL_NONE);
> > > + /*
> > > +  * We need to block interrupts as long as `f_mtx' is being taken
> > > +  * with and without the KERNEL_LOCK().
> > > +  */
> > > + mtx_init(>f_mtx, IPL_VM);
> > >   fp->f_iflags = FIF_LARVAL;
> > >   if ((fq = p->p_fd->fd_ofiles[0]) != NULL) {
> > >   LIST_INSERT_AFTER(fq, fp, f_list);
> > > 
> > > 
> > 
> 



Drop comcnspeed

2018-05-28 Thread Mark Kettenis
This variable is unused on arm64.  Inherited from armv7 where it still
functions somewhat.  I suppose this used to set the speed of the
serial console but nowadays it only sets the default speed that we use
when the device tree doesn't set it.  I propose to remove it on armv7
too.  Using 115200 as a default like we do on arm64 should work just
fine.  I've not seen any armv7 or arm64 hardware that uses 9600 by
default.  If we want a mechanism to set the default speed we should
have the bootloader tweak the device tree instead.

ok?


Index: arch/arm64/arm64/machdep.c
===
RCS file: /cvs/src/sys/arch/arm64/arm64/machdep.c,v
retrieving revision 1.34
diff -u -p -r1.34 machdep.c
--- arch/arm64/arm64/machdep.c  28 May 2018 19:39:15 -  1.34
+++ arch/arm64/arm64/machdep.c  28 May 2018 19:43:19 -
@@ -1135,7 +1135,6 @@ remap_efi_runtime(EFI_PHYSICAL_ADDRESS s
printf("SetVirtualAddressMap failed: %lu\n", status);
 }
 
-int comcnspeed = B115200;
 char bootargs[256];
 
 void
@@ -1194,12 +1193,6 @@ process_kernel_args(void)
break;
case 's':
fl |= RB_SINGLE;
-   break;
-   case '1':
-   comcnspeed = B115200;
-   break;
-   case '9':
-   comcnspeed = B9600;
break;
default:
printf("unknown option `%c'\n", *cp);



add const to the return value of BIO_s_file()

2018-05-28 Thread Theo Buehler
This is the first trivial part of the last batch of diffs catching up
with OpenSSL's const additions.

As usual, sthen kindly ran the whole diff through a ports bulk build.

Only this small change caused some fallout, namely devel/ptlib.
Of course, I'll commit a fix for the port at the same time as this diff.

Index: lib/libcrypto/bio/bio.h
===
RCS file: /var/cvs/src/lib/libcrypto/bio/bio.h,v
retrieving revision 1.43
diff -u -p -r1.43 bio.h
--- lib/libcrypto/bio/bio.h 12 May 2018 18:51:59 -  1.43
+++ lib/libcrypto/bio/bio.h 28 May 2018 20:07:41 -
@@ -597,7 +597,7 @@ BIO_asn1_get_suffix(BIO *b, asn1_ps_func
 asn1_ps_func **psuffix_free);
 
 int BIO_get_new_index(void);
-BIO_METHOD *BIO_s_file(void );
+const BIO_METHOD *BIO_s_file(void);
 BIO *BIO_new_file(const char *filename, const char *mode);
 BIO *BIO_new_fp(FILE *stream, int close_flag);
 # define BIO_s_file_internal   BIO_s_file
Index: lib/libcrypto/bio/bss_file.c
===
RCS file: /var/cvs/src/lib/libcrypto/bio/bss_file.c,v
retrieving revision 1.32
diff -u -p -r1.32 bss_file.c
--- lib/libcrypto/bio/bss_file.c29 Jan 2017 17:49:22 -  1.32
+++ lib/libcrypto/bio/bss_file.c28 May 2018 20:07:41 -
@@ -98,7 +98,7 @@ static long file_ctrl(BIO *h, int cmd, l
 static int file_new(BIO *h);
 static int file_free(BIO *data);
 
-static BIO_METHOD methods_filep = {
+static const BIO_METHOD methods_filep = {
.type = BIO_TYPE_FILE,
.name = "FILE pointer",
.bwrite = file_write,
@@ -148,7 +148,7 @@ BIO_new_fp(FILE *stream, int close_flag)
return (ret);
 }
 
-BIO_METHOD *
+const BIO_METHOD *
 BIO_s_file(void)
 {
return (_filep);



Re: arm64/disksubr.c

2018-05-28 Thread Dale Rahn
ok drahn@
On Mon, May 28, 2018 at 03:57:58PM +0200, Mark Kettenis wrote:
> This has a hand-rolled readdisksector.  Replace it with a function
> call like we do on other architectures.  Also remove an include that
> isn't needed and isn't present on other architectures.
> 
> ok?
> 
> 
> Index: arch/arm64/arm64/disksubr.c
> ===
> RCS file: /cvs/src/sys/arch/arm64/arm64/disksubr.c,v
> retrieving revision 1.2
> diff -u -p -r1.2 disksubr.c
> --- arch/arm64/arm64/disksubr.c   28 Feb 2017 10:49:37 -  1.2
> +++ arch/arm64/arm64/disksubr.c   28 May 2018 13:55:31 -
> @@ -32,7 +32,6 @@
>   */
>  
>  #include 
> -#include 
>  #include 
>  #include 
>  #include 
> @@ -110,15 +109,11 @@ writedisklabel(dev_t dev, void (*strat)(
>   goto done;
>  
>   /* Read it in, slap the new label in, and write it back out */
> - bp->b_blkno = DL_BLKTOSEC(lp, partoff + DOS_LABELSECTOR) *
> - DL_BLKSPERSEC(lp);
> - offset = DL_BLKOFFSET(lp, partoff + DOS_LABELSECTOR);
> - bp->b_bcount = lp->d_secsize;
> - CLR(bp->b_flags, B_READ | B_WRITE | B_DONE);
> - SET(bp->b_flags, B_BUSY | B_READ | B_RAW);
> - (*strat)(bp);
> - if ((error = biowait(bp)) != 0)
> + error = readdisksector(bp, strat, lp, DL_BLKTOSEC(lp, partoff +
> + DOS_LABELSECTOR));
> + if (error)
>   goto done;
> + offset = DL_BLKOFFSET(lp, partoff + DOS_LABELSECTOR);
>  
>   dlp = (struct disklabel *)(bp->b_data + offset);
>   *dlp = *lp;
> 
Dale Rahn   dr...@dalerahn.com



[Patch] mg(1): Experimental UTF-8 support

2018-05-28 Thread Leonid Bobrov
Hi!

Diff is taken from here:
https://github.com/hboetes/mg/compare/display-wide-characters
with minor modifications (didn't patch some files and updated mg.1)

I got two not critical cursor movement bugs
(like I have to press C-f twice or M-f moves cursor subword forward)
Index: basic.c
===
RCS file: /cvs/src/usr.bin/mg/basic.c,v
retrieving revision 1.47
diff -u -p -u -p -r1.47 basic.c
--- basic.c 10 Oct 2015 09:13:14 -  1.47
+++ basic.c 28 May 2018 18:08:10 -
@@ -18,6 +18,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "def.h"
 
@@ -269,12 +270,25 @@ setgoal(void)
 int
 getgoal(struct line *dlp)
 {
-   int c, i, col = 0;
-   char tmp[5];
+   return getbyteofcol(dlp, 0, curgoal);
+}
 
+/*
+ * Return the byte offset within lp that is targetcol columns beyond
+ * startbyte
+ */
+size_t
+getbyteofcol(const struct line *lp, const size_t startbyte,
+ const size_t targetcol)
+{
+   int c;
+   size_t i, col = 0;
+   char tmp[5];
+   size_t advance_by = 1;
 
-   for (i = 0; i < llength(dlp); i++) {
-   c = lgetc(dlp, i);
+   for (i = startbyte; i < llength(lp); i += advance_by) {
+   advance_by = 1;
+   c = lgetc(lp, i);
if (c == '\t'
 #ifdef NOTAB
&& !(curbp->b_flag & BFNOTAB)
@@ -284,16 +298,84 @@ getgoal(struct line *dlp)
col++;
} else if (ISCTRL(c) != FALSE) {
col += 2;
-   } else if (isprint(c))
+   } else if (isprint(c)) {
col++;
-   else {
+   } else if (!(curbp->b_flag & BFSHOWRAW)) {
+   mbstate_t mbs = { 0 };
+   wchar_t wc = 0;
+   size_t consumed = mbrtowc(, >l_text[i],
+ llength(lp) - i, );
+   int width = -1;
+   if (consumed < (size_t) -2) {
+   width = wcwidth(wc);
+   }
+   if (width >= 0) {
+   col += width;
+   advance_by = consumed;
+   } else {
+   col += snprintf(tmp, sizeof(tmp), "\\%o", c);
+   }
+   } else {
col += snprintf(tmp, sizeof(tmp), "\\%o", c);
}
-   if (col > curgoal)
+   if (col > targetcol)
break;
}
return (i);
 }
+
+/*
+ * Return the column at which specified offset byte would appear, if
+ * this were part of a longer string printed by vtputs, starting at
+ * intial_col
+ */
+size_t
+getcolofbyte(const struct line *lp, const size_t startbyte,
+ const size_t initial_col, const size_t targetoffset)
+{
+   int c;
+   size_t i, col = initial_col;
+   char tmp[5];
+   size_t advance_by = 1;
+
+   for (i = startbyte; i < llength(lp); i += advance_by) {
+   if (i >= targetoffset)
+   break;
+   advance_by = 1;
+   c = lgetc(lp, i);
+   if (c == '\t'
+#ifdef NOTAB
+   && !(curbp->b_flag & BFNOTAB)
+#endif
+   ) {
+   col |= 0x07;
+   col++;
+   } else if (ISCTRL(c) != FALSE) {
+   col += 2;
+   } else if (isprint(c)) {
+   col++;
+   } else if (!(curbp->b_flag & BFSHOWRAW)) {
+   mbstate_t mbs = { 0 };
+   wchar_t wc = 0;
+   size_t consumed = mbrtowc(, >l_text[i],
+ llength(lp) - i, );
+   int width = -1;
+   if (consumed < (size_t) -2) {
+   width = wcwidth(wc);
+   }
+   if (width >= 0) {
+   col += width;
+   advance_by = consumed;
+   } else {
+   col += snprintf(tmp, sizeof(tmp), "\\%o", c);
+   }
+   } else {
+   col += snprintf(tmp, sizeof(tmp), "\\%o", c);
+   }
+   }
+   return (col);
+}
+
 
 /*
  * Scroll forward by a specified number
Index: cmode.c
===
RCS file: /cvs/src/usr.bin/mg/cmode.c,v
retrieving revision 1.16
diff -u -p -u -p -r1.16 cmode.c
--- cmode.c 26 Sep 2015 21:51:58 -  1.16
+++ cmode.c 28 May 2018 18:08:10 -
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "def.h"
 #include "funmap.h"
@@ -419,10 +420,25 @@ findcolpos(const 

Re: [markup] manual page HTML validation

2018-05-28 Thread Ingo Schwarze
Hi Anton,

li...@wrant.com wrote on Mon, May 28, 2018 at 06:04:50PM +0300:

> Thanks for applying the fixes,
> can we have HTML 4.01 * web manual pages?

No, you can't.

> I'll understand if the answer is no,
> short listed explanation would do..

While i often advocate using well-established, seasoned standards
rather than the latest whim, HTML5 is a very significant improvement
over HTML4.01 for several reasons which i'm not going to list, has
been a public standard since 2014, and the features we use are well
supported by browsers.

Until 2014, mandoc did emit HTML4.01.  Kristaps upgraded it to emit
HTML5 instead, and the upgrade was first released with mandoc 1.13.2
on Dec 13, 2014.  The upgrade allowed significant simplifications
including getting rid of the -Txhtml output mode, cleaner C source
code, cleaner HTML output, and better eqn(7) support by using MathML.
It was the most important step forward with HTML output in mandoc,
ever.

No, we are not going back.

Yours,
  Ingo



Re: [markup] manual page HTML validation

2018-05-28 Thread lists
Mon, 28 May 2018 16:35:22 +0200 Ingo Schwarze 
> Hi Anton,
> 
> li...@wrant.com wrote on Mon, May 28, 2018 at 12:39:05PM +0300:
> 
> > https://validator.w3.org/nu/?doc=http%3A%2F%2Fman.openbsd.org%2Fpf.conf
> > https://validator.w3.org/nu/?doc=http%3A%2F%2Fman.openbsd.org%2Fifconfig  
> 
> Thanks for spotting these errors.
> I just fixed them with the commit below,
> and i also installed the fix on man.openbsd.org.
> 

Hi Ingo,

Thanks for applying the fixes, can we have HTML 4.01 * web manual pages?
I'll understand if the answer is no, short listed explanation would do..

Kind regards,
Anton Lazarov



Re: [markup] manual page HTML validation

2018-05-28 Thread Ingo Schwarze
Hi Anton,

li...@wrant.com wrote on Mon, May 28, 2018 at 12:39:05PM +0300:

> https://validator.w3.org/nu/?doc=http%3A%2F%2Fman.openbsd.org%2Fpf.conf
> https://validator.w3.org/nu/?doc=http%3A%2F%2Fman.openbsd.org%2Fifconfig

Thanks for spotting these errors.
I just fixed them with the commit below,
and i also installed the fix on man.openbsd.org.

> Obviously it is good to have a doctype declaration or conform to generic
> strict declarations.  I'm only interested in the anchor id elements now.
> 
> The interest is provoked by the useful pointing to portion of the pages,
> exactly similar to view and reference same in terminal pagers e.g. less.

I understand none of that.  It doesn't sound like English text.

> Hope this does not interfere much with the work flow and is appropriate.

Sure, bugs can be reported at any time, in particular bugs
that are not yet known and, like this one, not yet listed on:
  http://mandoc.bsd.lv/cgi-bin/cvsweb/TODO?rev=HEAD

For general OpenBSD bugs, if you don't include a patch fixing the
bug, bugs@ is more appropriate than tech@, though.  And for mandoc
bugs in particular, t...@mandoc.bsd.lv is more appropriate than the
general OpenBSD lists.  But if a report points out a genuine bug
and results in a commit, it no longer matters all that much whether
it was reported to the ideal place, or instead to a place that
merely worked, too.  Improving the system is what ultimately matters
more than formal processes.

Yours,
  Ingo


Log Message:
---
URL-fragment strings can only contain certain characters.
Fixing HTML syntax violations e.g. in pf.conf(5) and ifconfig(8)
reported by Anton Lazarov .

Modified Files:
--
mandoc:
html.c

Revision Data
-
Index: html.c
===
RCS file: /home/cvs/mandoc/mandoc/html.c,v
retrieving revision 1.229
retrieving revision 1.230
diff -Lhtml.c -Lhtml.c -u -p -r1.229 -r1.230
--- html.c
+++ html.c
@@ -287,10 +287,16 @@ html_make_id(const struct roff_node *n, 
if (buf == NULL)
return NULL;
 
-   /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */
+   /*
+* In ID attributes, only use ASCII characters that are
+* permitted in URL-fragment strings according to the
+* explicit list at:
+* https://url.spec.whatwg.org/#url-fragment-string
+*/
 
for (cp = buf; *cp != '\0'; cp++)
-   if (*cp == ' ')
+   if (isalnum((unsigned char)*cp) == 0 &&
+   strchr("!$&'()*+,-./:;=?@_~", *cp) == NULL)
*cp = '_';
 
if (unique == 0)



fdinsert(), take 2

2018-05-28 Thread Martin Pieuchot
Here's a new version of my diff to remove the FIF_LARVAL flag.

Larval files still exist, but at this stage they aren't present in
`fd_ofiles[]'.  That means we don't need specific tricks in fd_getfile()
and fd_iterfile().  The idea is to put files in shared data structures
once they are properly setup. For that we use a new function: fdinsert().

This diff is rebased on top of the recent changes and it includes the
following:
  - simplification of fd_inuse() pointed by visa@
  - Add a KASSERT() in fdinsert(), also suggested by visa@
  - remove references to FIF_LARVAL
  - use fd_getfile() & fdremove() to simplify fdrelease()


This diff has been tested as part of the big "unlocking" diff I sent
last week, so I'm confident, but reviews & tests are more than welcome!

Ok?

Index: kern/kern_exec.c
===
RCS file: /cvs/src/sys/kern/kern_exec.c,v
retrieving revision 1.195
diff -u -p -r1.195 kern_exec.c
--- kern/kern_exec.c28 Apr 2018 03:13:04 -  1.195
+++ kern/kern_exec.c28 May 2018 09:41:15 -
@@ -584,7 +584,7 @@ sys_execve(struct proc *p, void *v, regi
struct vnode *vp;
int indx;
 
-   if ((error = falloc(p, 0, , )) != 0)
+   if ((error = falloc(p, , )) != 0)
break;
 #ifdef DIAGNOSTIC
if (indx != i)
@@ -607,10 +607,9 @@ sys_execve(struct proc *p, void *v, regi
fp->f_type = DTYPE_VNODE;
fp->f_ops = 
fp->f_data = (caddr_t)vp;
-   FILE_SET_MATURE(fp, p);
-   } else {
-   FRELE(fp, p);
+   fdinsert(p->p_fd, indx, 0, fp);
}
+   FRELE(fp, p);
}
fdpunlock(p->p_fd);
if (error)
Index: kern/exec_script.c
===
RCS file: /cvs/src/sys/kern/exec_script.c,v
retrieving revision 1.44
diff -u -p -r1.44 exec_script.c
--- kern/exec_script.c  2 May 2018 02:24:56 -   1.44
+++ kern/exec_script.c  28 May 2018 09:41:15 -
@@ -170,17 +170,20 @@ check_shell:
 #endif
 
fdplock(p->p_fd);
-   error = falloc(p, 0, , >ep_fd);
-   fdpunlock(p->p_fd);
-   if (error)
+   error = falloc(p, , >ep_fd);
+   if (error) {
+   fdpunlock(p->p_fd);
goto fail;
+   }
 
epp->ep_flags |= EXEC_HASFD;
fp->f_type = DTYPE_VNODE;
fp->f_ops = 
fp->f_data = (caddr_t) scriptvp;
fp->f_flag = FREAD;
-   FILE_SET_MATURE(fp, p);
+   fdinsert(p->p_fd, epp->ep_fd, 0, fp);
+   fdpunlock(p->p_fd);
+   FRELE(fp, p);
}
 
/* set up the parameters for the recursive check_exec() call */
Index: kern/kern_descrip.c
===
RCS file: /cvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.159
diff -u -p -r1.159 kern_descrip.c
--- kern/kern_descrip.c 28 May 2018 08:55:11 -  1.159
+++ kern/kern_descrip.c 28 May 2018 09:41:16 -
@@ -144,6 +144,17 @@ find_last_set(struct filedesc *fd, int l
return i;
 }
 
+static __inline int
+fd_inuse(struct filedesc *fdp, int fd)
+{
+   u_int off = fd >> NDENTRYSHIFT;
+
+   if (fdp->fd_lomap[off] & (1 << (fd & NDENTRYMASK)))
+   return 1;
+
+   return 0;
+}
+
 static __inline void
 fd_used(struct filedesc *fdp, int fd)
 {
@@ -190,7 +201,7 @@ fd_iterfile(struct file *fp, struct proc
nfp = LIST_NEXT(fp, f_list);
 
/* don't FREF when f_count == 0 to avoid race in fdrop() */
-   while (nfp != NULL && (nfp->f_count == 0 || !FILE_IS_USABLE(nfp)))
+   while (nfp != NULL && nfp->f_count == 0)
nfp = LIST_NEXT(nfp, f_list);
if (nfp != NULL)
FREF(nfp);
@@ -209,9 +220,6 @@ fd_getfile(struct filedesc *fdp, int fd)
if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
return (NULL);
 
-   if (!FILE_IS_USABLE(fp))
-   return (NULL);
-
FREF(fp);
return (fp);
 }
@@ -634,19 +642,17 @@ finishdup(struct proc *p, struct file *f
return (EDEADLK);
}
 
-   oldfp = fdp->fd_ofiles[new];
-   if (oldfp != NULL) {
-   if (!FILE_IS_USABLE(oldfp)) {
-   FRELE(fp, p);
-   return (EBUSY);
-   }
-   FREF(oldfp);
-   }
+   oldfp = fd_getfile(fdp, new);
+   if (dup2 && oldfp == NULL) {
+   if (fd_inuse(fdp, 

Re: errors in usage.c - libusbhid

2018-05-28 Thread David Bern
I was suggested off list to give an explanation on what the patch does.

So please, tell me if I need to clarify more, or make further changes to
the code.

The patch tries to fix two things.
1. Changes in hid_parse_usage_in_page() fixes problems in parsing usages
defined as:  *   Button %d

hid_parse_usage_in_page():
Previously - With input "Button:Button_1" returns -1
Now - With input "Button:Button_1" returns 589825

In the scenario of parsing Button:Button_1 we will not find a usage name
matching that string. For example Button:Button_1 is defined as
Button %d in the table.

We are still able to calculate the proper usage number in the same way we
are
able to calculate the proper usage name in hid_usage_in_page().

The first step is to identify if usage name is shortened. If it is,
usage will hold a value of -1. Then I try to locate a separator char in the
name as "_".
If a separator char is found I use it to read the value as "_%d" to get the
corresponding usage number

>+   us = pages[k].page_contents[j].usage;
>+   if (us == -1) {
>+   usage_sep = strchr(sep, '_');
>+   if (usage_sep == NULL)
>+   return -1;
>+   if (sscanf(usage_sep, "_%d", _usage))
>+   return (pages[k].usage << 16) |
>+   parsed_usage;


2. The text-string that is returned by hid_usage_in_page() misses page
information.
So the changes made in hid_usage_in_page() is to make it the inverse of
hid_parse_usage_in_page()

In details what the code previously did and now does.

hid_usage_in_page():
Previously - With input 589825 returns Button_1
Now - With input 589825 returns Button:Button_1


The change just adds a pages[k].name to the string, a format that
hid_parse_usage_in_page() expects it to have.
I make formatting in two steps when us == -1 which it is when usage is
shortened
as for example: *   Button %d.

>+   snprintf(fmt, sizeof fmt,
>+   "%%s:%s", pages[k].page_contents[j].name);
>+   snprintf(b, sizeof b, fmt, pages[k].name, i);

The first step is to create a format string that will result in something
like
 "%s:Button_%d".
The last step I use the fmt-string to create a complete string that will
result in
"Button:Button_1"




2018-05-24 18:44 GMT+02:00 David Bern :

> While I was waiting for comments and feedback I came up with some
> improvements.
> The "logic" is still the same, but the execution is hopefully more sane.
>
> Index: usage.c
> ===
> RCS file: /cvs/src/lib/libusbhid/usage.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 usage.c
> --- usage.c 8 Oct 2014 04:49:36 -   1.16
> +++ usage.c 24 May 2018 16:37:54 -
> @@ -224,6 +224,7 @@ hid_usage_in_page(unsigned int u)
>  {
> int i = HID_USAGE(u), j, k, us;
> int page = HID_PAGE(u);
> +   char fmt[100];
> static char b[100];
>
> for (k = 0; k < npages; k++)
> @@ -234,12 +235,16 @@ hid_usage_in_page(unsigned int u)
> for (j = 0; j < pages[k].pagesize; j++) {
> us = pages[k].page_contents[j].usage;
> if (us == -1) {
> -   snprintf(b, sizeof b,
> -   pages[k].page_contents[j].name, i);
> +   snprintf(fmt, sizeof fmt,
> +   "%%s:%s", pages[k].page_contents[j].name);
> +   snprintf(b, sizeof b, fmt, pages[k].name, i);
> +   return b;
> +   }
> +   if (us == i) {
> +   snprintf(b, sizeof b, "%s:%s", pages[k].name,
> +   pages[k].page_contents[j].name);
> return b;
> }
> -   if (us == i)
> -   return pages[k].page_contents[j].name;
> }
>   bad:
> snprintf(b, sizeof b, "0x%04x", i);
> @@ -265,8 +270,9 @@ int
>  hid_parse_usage_in_page(const char *name)
>  {
> const char *sep;
> +   const char *usage_sep;
> unsigned int l;
> -   int k, j;
> +   int k, j, us, parsed_usage;
>
> sep = strchr(name, ':');
> if (sep == NULL)
> @@ -278,9 +284,19 @@ hid_parse_usage_in_page(const char *name
> return -1;
>   found:
> sep++;
> -   for (j = 0; j < pages[k].pagesize; j++)
> +   for (j = 0; j < pages[k].pagesize; j++) {
> +   us = pages[k].page_contents[j].usage;
> +   if (us == -1) {
> +   usage_sep = strchr(sep, '_');
> +   if (usage_sep == NULL)
> +   return -1;
> +   if (sscanf(usage_sep, "_%d", _usage))
> +   return (pages[k].usage << 16) |
> +  

[markup] manual page HTML validation

2018-05-28 Thread lists
Sat, 26 May 2018 14:04:38 -0600 (MDT) Ingo Schwarze

> CVSROOT:  /cvs
> Module name:  src
> Changes by:   schwa...@cvs.openbsd.org2018/05/26 14:04:38
> 
> Modified files:
>   usr.bin/mandoc : mandoc.css 
> 
> Log message:
> Start with baby steps towards responsive design:
> Use a @media width query to select a set of default indentations.
> Suggested by John Gardner .
> 

Hi Ingo, tech@,

While here please see the results from validating browser Dillo as well:

[1] http://man.openbsd.org/pf.conf

HTML warning: line 773, Unexpected closing tag:  -- expected .
HTML warning: line 873, Unexpected closing tag:  -- expected .
HTML warning: line 1131, Unexpected closing tag:  -- expected .
HTML warning: line 1148, Unexpected closing tag:  -- expected .
HTML warning: line 1156, Unexpected closing tag:  -- expected .
HTML warning: line 1166, Unexpected closing tag:  -- expected .
HTML warning: line 1397, Unexpected closing tag:  -- expected .

https://validator.w3.org/nu/?doc=http%3A%2F%2Fman.openbsd.org%2Fpf.conf
http://www.htmlhelp.org/cgi-bin/validate.cgi?url=http://man.openbsd.org/pf.conf=yes

[2] http://man.openbsd.org/ifconfig

HTML warning: line 456, Unexpected closing tag:  -- expected .
HTML warning: line 935, Unexpected closing tag:  -- expected .
HTML warning: line 1146, Unexpected closing tag:  -- expected .
HTML warning: line 1235, Unexpected closing tag:  -- expected .
HTML warning: line 1462, Unexpected closing tag:  -- expected .
HTML warning: line 1470, Unexpected closing tag:  -- expected .
HTML warning: line 1600, Unexpected closing tag:  -- expected .
HTML warning: line 1938, Unexpected closing tag:  -- expected .

https://validator.w3.org/nu/?doc=http%3A%2F%2Fman.openbsd.org%2Fifconfig
http://www.htmlhelp.org/cgi-bin/validate.cgi?url=http://man.openbsd.org/ifconfig=yes

The list of HTML warnings is generated via the bug counter, bottom right
corner of the browser (left click), right click for the validating URLs.

Obviously it is good to have a doctype declaration or conform to generic
strict declarations.  I'm only interested in the anchor id elements now.

The interest is provoked by the useful pointing to portion of the pages,
exactly similar to view and reference same in terminal pagers e.g. less.

Hope this does not interfere much with the work flow and is appropriate.

Kind regards,
Anton Lazarov



IPL_VM for `f_mtx'

2018-05-28 Thread Martin Pieuchot
As found by tb@ and visa@, `f_mtx' need to block interrupts as long as
it can be taken w/ and w/o the KERNEL_LOCK().  Otherwise a deadlock is
possible if an interrupt tries to grab the KERNEL_LOCK().

I'm not switching to a rwlock because code paths are short, I don't
want to introduce new sleeping points and in the long run we should
be using SRPs or atomic operations for reference counts.

ok?

Index: kern/kern_descrip.c
===
RCS file: /cvs/src/sys/kern/kern_descrip.c,v
retrieving revision 1.158
diff -u -p -r1.158 kern_descrip.c
--- kern/kern_descrip.c 8 May 2018 09:03:58 -   1.158
+++ kern/kern_descrip.c 28 May 2018 09:23:31 -
@@ -957,7 +957,11 @@ restart:
 */
numfiles++;
fp = pool_get(_pool, PR_WAITOK|PR_ZERO);
-   mtx_init(>f_mtx, IPL_NONE);
+   /*
+* We need to block interrupts as long as `f_mtx' is being taken
+* with and without the KERNEL_LOCK().
+*/
+   mtx_init(>f_mtx, IPL_VM);
fp->f_iflags = FIF_LARVAL;
if ((fq = p->p_fd->fd_ofiles[0]) != NULL) {
LIST_INSERT_AFTER(fq, fp, f_list);



Some arm64 cleanup

2018-05-28 Thread Mark Kettenis
machine_reg.h is completely unused
swi.h is referenced from libc's SYS.h but nothing from that file is used
bootconfig.h has some junk that isn't really used

The MAX_BOOT_STRING define in bootconfig.h doesn't really serve a
purpose anymore.  Simply use a fixed-size buffer and strlcpy the
results into it using sizeof.

ok?

Index: sys/arch/arm64/include/bootconfig.h
===
RCS file: /cvs/src/sys/arch/arm64/include/bootconfig.h,v
retrieving revision 1.2
diff -u -p -r1.2 bootconfig.h
--- sys/arch/arm64/include/bootconfig.h 18 Dec 2016 14:40:25 -  1.2
+++ sys/arch/arm64/include/bootconfig.h 28 May 2018 09:03:07 -
@@ -32,9 +32,6 @@
 #ifndef _MACHINE_BOOTCONFIG_H_
 #define_MACHINE_BOOTCONFIG_H_
 
-#defineMAX_BOOT_STRING 255
-extern char bootstring[MAX_BOOT_STRING];
-
 struct arm64_bootparams {
vaddr_t modulep;
vaddr_t kern_l1pt;  /* L1 page table for the kernel */
@@ -45,14 +42,8 @@ struct arm64_bootparams {
void*arg2; // passed to kernel in R2
 };
 
-extern paddr_t physmap[];
-extern u_int physmap_idx;
-
-
 void initarm(struct arm64_bootparams *);
 
 extern char *boot_file;
 
 #endif /* _MACHINE_BOOTCONFIG_H_ */
-
-/* End of bootconfig.h */
Index: sys/arch/arm64/include/machine_reg.h
===
RCS file: sys/arch/arm64/include/machine_reg.h
diff -N sys/arch/arm64/include/machine_reg.h
--- sys/arch/arm64/include/machine_reg.h30 Apr 2017 13:04:49 -  
1.2
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,57 +0,0 @@
-/* $OpenBSD: machine_reg.h,v 1.2 2017/04/30 13:04:49 mpi Exp $ */
-
-/*
- * Copyright (c) 2002, 2003  Genetec Corporation.  All rights reserved.
- * Written by Hiroyuki Bessho for Genetec Corporation.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *notice, this list of conditions and the following disclaimer in the
- *documentation and/or other materials provided with the distribution.
- * 3. The name of Genetec Corporation may not be used to endorse or
- *promote products derived from this software without specific prior
- *written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-
-#ifndef _MACHINE_REG_H
-#define _MACHINE_REG_H
-
-/*
- * Logical mapping for onboard/integrated peripherals
- */
-#defineMACHINE_IO_AREA_VBASE   0xfd00
-#define MACHINE_GPIO_VBASE 0xfd00
-#define MACHINE_CLKMAN_VBASE   0xfd10
-#define MACHINE_INTCTL_VBASE   0xfd20
-#define MACHINE_AGPIO_VBASE0xfd30
-#define MACHINE_VBASE_FREE 0xfd40
-/* FFUART and/or BTUART are mapped to this area when
-   used for console */
-
-#define ioreg_read(a)  (*(volatile unsigned *)(a))
-#define ioreg_write(a,v)  (*(volatile unsigned *)(a)=(v))
-
-#define ioreg16_read(a)  (*(volatile uint16_t *)(a))
-#define ioreg16_write(a,v)  (*(volatile uint16_t *)(a)=(v))
-
-#define ioreg8_read(a)  (*(volatile uint8_t *)(a))
-#define ioreg8_write(a,v)  (*(volatile uint8_t *)(a)=(v))
-
-#endif /* _MACHINE_REG_H */
Index: sys/arch/arm64/include/swi.h
===
RCS file: sys/arch/arm64/include/swi.h
diff -N sys/arch/arm64/include/swi.h
--- sys/arch/arm64/include/swi.h17 Dec 2016 23:38:33 -  1.1
+++ /dev/null   1 Jan 1970 00:00:00 -
@@ -1,23 +0,0 @@
-/* $OpenBSD: swi.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */
-/* $NetBSD: swi.h,v 1.1 2002/01/13 15:03:06 bjh21 Exp $*/
-
-/*
- * This file is in the Public Domain.
- * Ben Harris, 2002.
- */
-
-#ifndef _MACHINE_SWI_H_
-#define _MACHINE_SWI_H_
-
-#define SWI_OS_MASK0xf0
-#define SWI_OS_RISCOS  0x00
-#define SWI_OS_RISCIX  0x80
-#define SWI_OS_LINUX   0x90
-#define SWI_OS_NETBSD  0xa0
-#define SWI_OS_ARM 0xf0
-
-#define SWI_IMB0xf0
-#define SWI_IMBrange   

ifconfig: Remove unused

2018-05-28 Thread Klemens Nanni
Annotations are outdated, in fact it's not used since

revision 1.348
date: 2017/08/29 21:10:20;  author: deraadt;  state: Exp;  lines: +3 -3
quarterly rescan of the tree:  remove unneccessary sys/param.h, and
annotate the ones which are needed.

revision 1.347
date: 2017/08/29 20:06:51;  author: stsp;  state: Exp;  lines: +2 -2
Don't use isset() from sys/param.h in ifconfig. Requested by deraadt


No object change with or without -DSMALL.

OK?

Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.366
diff -u -p -r1.366 ifconfig.c
--- ifconfig.c  12 May 2018 02:02:34 -  1.366
+++ ifconfig.c  28 May 2018 07:47:16 -
@@ -60,7 +60,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include  /* NBBY isset */
 #include 
 #include 
 #include 



Re: eoip(4): MikroTik Ethernet over IP support

2018-05-28 Thread Michael W. Bombardieri
On Sun, May 27, 2018 at 10:18:30AM +1000, David Gwynne wrote:
> this implements MikroTiks Ethernet over IP protocol support.
> 
> The Mikrotik protocol is basically GRE, so this is implemented as
> eoip(4) as (yet another) part of if_gre. the main differences between
> egre and eoip is that eoip uses gre version 1 (not 0) and 0x6400
> as the protocol identifier (not transparent ethernet as per rfc
> 1701), mandates a key header, but splits the key into 16bit len and
> tunnel id fields (a bit like pptp).
> 
> the keepalive semantics are also different. keepalives are just 0
> length packets, and arent echoed. each side listens for the others
> packet to see if theyre up, but doesn't relay the keepalives. theyre
> more hellos maybe?
> 
> like egre though, it still misaligns the payload, but what doesnt
> these days?
> 
> this also tweaks tcpdump to better support the protocol.

Hello,

In gre_ioctl(), mgre_ioctl(), egre_ioctl() and eoip_ioctl() the
SIOCSIFFLAGS case appears to have code that explicitly sets error=0
but it looks like error is already zero unless I'm reading it wrong.
Also, nvgre_ioctl() is different because it seems to set error=ENETRESET
in that case (i.e. IFF_UP and IFF_RUNNING are both set). Is that
difference intended?

- Michael