Re: CPU_LIDSUSPEND in init(8) and reboot(8)

2017-06-13 Thread Martin Natano
ping?


On Sun, May 21, 2017 at 09:46:45AM +0200, Martin Natano wrote:
> While switching init and reboot to CPU_LIDACTION, I forgot about the
> #ifdef's. Ok?
> 
> natano
> 
> 
> Index: init/init.c
> ===
> RCS file: /cvs/src/sbin/init/init.c,v
> retrieving revision 1.64
> diff -u -p -r1.64 init.c
> --- init/init.c   3 May 2017 09:51:39 -   1.64
> +++ init/init.c   21 May 2017 07:25:07 -
> @@ -1325,7 +1325,7 @@ f_nice_death(void)
>   static const int death_sigs[3] = { SIGHUP, SIGTERM, SIGKILL };
>   int status;
>  
> -#ifdef CPU_LIDSUSPEND
> +#ifdef CPU_LIDACTION
>   int mib[] = {CTL_MACHDEP, CPU_LIDACTION};
>   int lidaction = 0;
>  
> Index: reboot/reboot.c
> ===
> RCS file: /cvs/src/sbin/reboot/reboot.c,v
> retrieving revision 1.36
> diff -u -p -r1.36 reboot.c
> --- reboot/reboot.c   2 Mar 2017 10:38:09 -   1.36
> +++ reboot/reboot.c   21 May 2017 07:25:31 -
> @@ -112,7 +112,7 @@ main(int argc, char *argv[])
>   if (geteuid())
>   errx(1, "%s", strerror(EPERM));
>  
> -#ifdef CPU_LIDSUSPEND
> +#ifdef CPU_LIDACTION
>   if (howto & RB_POWERDOWN) {
>   /* Disable suspending on laptop lid close */
>   int mib[] = {CTL_MACHDEP, CPU_LIDACTION};
> @@ -122,7 +122,7 @@ main(int argc, char *argv[])
>   sizeof(lidaction)) == -1 && errno != EOPNOTSUPP)
>   warn("sysctl");
>   }
> -#endif /* CPU_LIDSUSPEND */
> +#endif /* CPU_LIDACTION */
>  
>   if (qflag) {
>   reboot(howto);



Re: ping: Style fixes/cleanups

2017-06-13 Thread Martin Natano
On Tue, Jun 13, 2017 at 08:02:13PM +0200, Klemens Nanni wrote:
> Unify option checking and simply logic.
> 
> F_HDRINCL and F_ROUTE are mutually exclusive, thus check the latter only
> if the former one is not set.
> 
> Index: ping.c
> ===
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.218
> diff -u -p -r1.218 ping.c
> --- ping.c22 Feb 2017 13:43:35 -  1.218
> +++ ping.c13 Jun 2017 17:38:22 -
> @@ -562,17 +562,17 @@ main(int argc, char *argv[])
>   (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, ,
>   sizeof(optval));
> 
> - if ((options & F_FLOOD) && (options & F_INTERVAL))
> + if (options & (F_FLOOD | F_INTERVAL))
>   errx(1, "-f and -i options are incompatible");
> 
> - if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS)))
> + if (options & (F_FLOOD | F_AUD_RECV | F_AUD_MISS))
>   warnx("No audible output for flood pings");

Did you try to compile and run this?

if (options & (F_FLOOD | F_INTERVAL))

is equivalent to

if ((options & F_FLOOD) || (options & F_INTERVAL))
^^
so this changes behaviour and is most likely wrong.


natano



Re: pool cpu caches and a systat view of them

2017-06-13 Thread David Gwynne

> On 14 Jun 2017, at 13:50, David Gwynne  wrote:
> 
> i have a few things left to do in the pools per cpu caches, one of
> which is make their activity visibile. to that end, here's a diff
> provides a way for userland to request stats from the per cpu caches,
> and uses that in systat so you can watch them.
> 
> there are two added pool sysctls. one copies an array of stats from
> each cpus cache. the interesting bits in those stats are how many
> items each cpu handled, and how many list operations the cpu did
> against the global pool cache.
> 
> the second sysctl reports stats about the global pool cache. currently
> this is the target for the list length the cpus build is, how many
> lists its holding, and how many times the gc has moved a list of
> items back into the pool for recovery.
> 
> these are used by sysctl for a new view which ive called pcaches,
> short for pool caches.
> 
> ksh: Fmt: not found

har. this was supposed to say that an example of the output is below. this is 
an 8 way box after running tcpbench for a bit.

> 
>   2 users Load 1.42 0.78 0.35 (1-88 of 158)   v880.embarrassm.net 13:48:40
> 
> NAME LEN   NL  NGC  CPU REQREL   LREQ   
> LREL
> mbufpl 8   7200  9559672622839794 
> 209151
>  1  907108 362300  88367  
> 20266
>  2  915933 356927  90031  
> 20155
>  3  878324 339160  86646  
> 19250
>  4   30620   7851   3301
> 454
>  51401885117 
> 52
>  6  56 57  0  > 0
>  7  37 45  0  > 0
> mtagpl 8000   0  0  0 
>  0
>  1   0  0  0  > 0
>  2   0  0  0  > 0
>  3   0  0  0  > 0
>  4   0  0  0  > 0
>  5   0  0  0  > 0
>  6   0  0  0  > 0
>  7   0  0  0  > 0
> mcl2k  8   3200  944634   7776 117605
> 497
>  1 122 318421  0  
> 39786
>  2 114 313498  0  
> 39171
>  3 105 298051  0  
> 37242
>  4  22   6834  0
> 850
>  5   0744  0 
> 91
>  6   0  1  0  > 0
>  7   1  3  0  > 0
> mcl2k2 8000   0  0  0 
>  0
>  1   0  0  0  > 0
>  2   0  0  0  > 0
>  3   0  0  0  > 0
>  4   0  0  0  > 0
>  5   0  0  0  > 0
>  6   0  0  0  > 0
>  7   0  0  0  > 0
> mcl4k  8200  20 44  1 
>  2
>  11978   2072 85 
> 96
>  22100   1988 97 
> 83
>  31910   1986 83 
> 91
>  4  87 61  6  
> 2
>  5   1  9  0  > 0
>  6   0  0  0  > 0
>  7   0  0  0  > 0
> mcl8k  8   1700  97956 11
> 117
>  1   19517  20418   2254   
> 2366
>  2   20934  20704   2441   
> 2412
>  3   20294  19734   2347   
> 2275
>  

pool cpu caches and a systat view of them

2017-06-13 Thread David Gwynne
i have a few things left to do in the pools per cpu caches, one of
which is make their activity visibile. to that end, here's a diff
provides a way for userland to request stats from the per cpu caches,
and uses that in systat so you can watch them.

there are two added pool sysctls. one copies an array of stats from
each cpus cache. the interesting bits in those stats are how many
items each cpu handled, and how many list operations the cpu did
against the global pool cache.

the second sysctl reports stats about the global pool cache. currently
this is the target for the list length the cpus build is, how many
lists its holding, and how many times the gc has moved a list of
items back into the pool for recovery.

these are used by sysctl for a new view which ive called pcaches,
short for pool caches.

ksh: Fmt: not found

   2 users Load 1.42 0.78 0.35 (1-88 of 158)   v880.embarrassm.net 13:48:40

NAME LEN   NL  NGC  CPU REQREL   LREQ   LREL
mbufpl 8   7200  9559672622839794 209151
  1  907108 362300  88367  20266
  2  915933 356927  90031  20155
  3  878324 339160  86646  19250
  4   30620   7851   3301454
  51401885117 52
  6  56 57  0  0
  7  37 45  0  0
mtagpl 8000   0  0  0  0
  1   0  0  0  0
  2   0  0  0  0
  3   0  0  0  0
  4   0  0  0  0
  5   0  0  0  0
  6   0  0  0  0
  7   0  0  0  0
mcl2k  8   3200  944634   7776 117605497
  1 122 318421  0  39786
  2 114 313498  0  39171
  3 105 298051  0  37242
  4  22   6834  0850
  5   0744  0 91
  6   0  1  0  0
  7   1  3  0  0
mcl2k2 8000   0  0  0  0
  1   0  0  0  0
  2   0  0  0  0
  3   0  0  0  0
  4   0  0  0  0
  5   0  0  0  0
  6   0  0  0  0
  7   0  0  0  0
mcl4k  8200  20 44  1  2
  11978   2072 85 96
  22100   1988 97 83
  31910   1986 83 91
  4  87 61  6  2
  5   1  9  0  0
  6   0  0  0  0
  7   0  0  0  0
mcl8k  8   1700  97956 11117
  1   19517  20418   2254   2366
  2   20934  20704   2441   2412
  3   20294  19734   2347   2275
  41234399150 45
  5   0 54  0  5
  6   0  0  0  0
  7   0  0  0  0
mcl9k  8000   1  5  0  0

Re: htpasswd: use crypt_newhash instead of bcrypt API

2017-06-13 Thread Ted Unangst
Michal Mazurek wrote:
> On 15:31:50, 10.06.17, Ted Unangst wrote:
> > > @@ -58,17 +58,29 @@ The provided
> > >  .Fa password
> > >  is randomly salted and hashed and stored in
> > >  .Fa hash .
> > > +.Fa hash
> > > +must already be allocated, and
> > > +.Fa hashsize
> > > +must contain its size, which cannot be less than 61 bytes.
> > 
> > that's an implementation detail. if we're advising a limit, i think we
> > should say 128 or so.
> 
> How come? Tracing the code of crypt_newhash() we end up in
> bcrypt_hashpass(), which has the following check:
> 
> if (encryptedlen < BCRYPT_HASHSPACE)
>   goto inval;
> 
> BCRYPT_HASHSPACE is defined thus:
> libc/crypt/bcrypt.c:#define   BCRYPT_HASHSPACE61

Part of the design criteria for the crypt_newhash function is that it support
other hashes as well. We happen to only support bcrypt (and that's unlikely to
change) but there's no reason to hardcode that assumption into an interface
designed to abstract away such concerns.

PASS_MAX (_PASSWORD_LEN) is 128, though it suffers from nul not included
disease, so I don't know if we want to specify the limit in terms of that
constant. In practice, however, if you look at encrypt/encrypt.c it uses
char buffer[_PASSWORD_LEN];

which is missing the nul, but nevertheless 128. passwd does the same.

so we can use the constant, or just say 128.



Re: install.sub: Fix scrambled address list in v6_defroute()

2017-06-13 Thread Klemens Nanni

On Wed, Jun 14, 2017 at 03:00:11AM +0200, Klemens Nanni wrote:

Installing -current the other day showed a broken list when picking
the IPv6 default route just like reported on bugs@ five days ago[1].

Missed the link.

1:  http://marc.info/?l=openbsd-bugs=149704197715791



install.sub: Fix scrambled address list in v6_defroute()

2017-06-13 Thread Klemens Nanni

Installing -current the other day showed a broken list when picking
the IPv6 default route just like reported on bugs@ five days ago[1].

This behaviour can be reproduced manually running the code from
v6_defroute():

$ # source/define bsort()
$ _if=trunk0
$ bsort $(ping6 -n -c 2 ff02::2%$_if 2>/dev/null |
sed -n '/bytes from/{s/^.*from //;s/,.*$//;p;}' |
sed -n 'G;s/\n/&&/;/^\(.*\n\).*\n\1/d;h;P')
fe80:::__ff:fe__:___%trunk0: hlim=64 icmp_seq=0 icmp_seq=1 ms 
time=0.431 time=0.802

The first sed filters for those lines containing the router addresses
and does two things:
1. strip leading text up to the address
2. strip trailing text after the first ','

However, as far as i can see 'ping6 -nc2' will never output lines that
would match the second criteria thus making this part of the command
obsolete.

The second sed removes duplicate addresses (not neccessarily consecutive
ones). This works fine for itself, but as seen above its input contains
more than just addresses. Besides that, sorting through sed just before
having bsort() cleaning the list is duplicate effort here.

With this patch bsort() gets passed possibly duplicate IPv6 addresses
one per line so _routers will eventually contain a sorted list of unique
router addresses; this fixes the list shown during the installer.


While debugging this, I noticed that stopping after two echo replies
would sometimes show only one router; increasing this limit to three
made both of my network's routers reply/show up reliably.


Feedback/OK?

Index: install.sub
===
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1014
diff -u -p -r1.1014 install.sub
--- install.sub 3 Jun 2017 22:27:41 -   1.1014
+++ install.sub 14 Jun 2017 00:59:28 -
@@ -997,9 +997,8 @@ v6_defroute() {

route -n show -inet6 | egrep -q '^default[[:space:]]' && return

-   _routers=$(bsort $(ping6 -n -c 2 ff02::2%$_if 2>/dev/null |
-   sed -n '/bytes from/{s/^.*from //;s/,.*$//;p;}' |
-   sed -n 'G;s/\n/&&/;/^\(.*\n\).*\n\1/d;h;P'))
+   _routers=$(bsort $(ping6 -n -c 3 ff02::2%$_if 2>/dev/null |
+   sed -n 's/^.*from \(.*\): .*$/\1/p'))

_prompt="IPv6 default router?"




Re: update logging in ifstated

2017-06-13 Thread Rob Pierce
On Tue, Jun 13, 2017 at 08:44:46AM +0200, Sebastian Benoit wrote:
> Rob Pierce(r...@2keys.ca) on 2017.06.11 18:04:31 -0400:
> > This minimizes differences with the latest log.c.
> > 
> > I was not sure how to handle verbosity, as the current implementation is
> > verbose by default in debug mode. The diff below requires actually
> > requesting (double) verbosity on the command line in order to retain the
> > same behaviour (in debug mode).
> 
> Thanks.
> 
> can you redo this with the log.c from bgpd/ospfd/... ?
> The difference is exactly in the handling of verbose, and that way we dont
> change the -v semantics right now.
> 
> I havent unified the verbose handling yet, but if you diff them you'll see
> its only a small difference now. My plan is to narrow all the log.c users
> down to this small difference and then fix that in all of them in one go.
> 
> Also please add a log.h with the declarations just like in bgpd/ospfd/...
> 
> /Benno

Ah yes, thank you for the pointer. How is this?

log.[ch] are now identical to bgpd and ospfd.

Rob

cvs server: Diffing .
Index: ifstated.c
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
retrieving revision 1.41
diff -u -p -r1.41 ifstated.c
--- ifstated.c  30 May 2013 19:22:48 -  1.41
+++ ifstated.c  13 Jun 2017 23:09:05 -
@@ -36,12 +36,14 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
 #include "ifstated.h"
+#include "log.h"
 
 struct  ifsd_config *conf = NULL, *newconf = NULL;
 
@@ -88,7 +90,8 @@ main(int argc, char *argv[])
int ch;
int debug = 0;
 
-   log_init(1);
+   log_init(1, LOG_DAEMON);/* log to stderr until daemonized */
+   log_setverbose(1);
 
while ((ch = getopt(argc, argv, "dD:f:hniv")) != -1) {
switch (ch) {
@@ -138,7 +141,8 @@ main(int argc, char *argv[])
daemon(1, 0);
 
event_init();
-   log_init(debug);
+   log_init(debug, LOG_DAEMON);
+   log_setverbose(opts & IFSD_OPT_VERBOSE);
 
signal_set(_ev, SIGCHLD, sigchld_handler, NULL);
signal_add(_ev, NULL);
@@ -169,12 +173,12 @@ startup_handler(int fd, short event, voi
rtfilter = ROUTE_FILTER(RTM_IFINFO);
if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
, sizeof(rtfilter)) == -1) /* not fatal */
-   log_warn("startup_handler: setsockopt msgfilter");
+   log_warn("%s: setsockopt msgfilter", __func__);
 
rtfilter = RTABLE_ANY;
if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
, sizeof(rtfilter)) == -1) /* not fatal */
-   log_warn("startup_handler: setsockopt tablefilter");
+   log_warn("%s: setsockopt tablefilter", __func__);

event_set(_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL);
event_add(_msg_ev, NULL);
@@ -580,7 +584,7 @@ do_action(struct ifsd_action *action)
}
break;
default:
-   log_debug("do_action: unknown action %d", action->type);
+   log_debug("%s: unknown action %d", __func__, action->type);
break;
}
 }
Index: ifstated.h
===
RCS file: /cvs/src/usr.sbin/ifstated/ifstated.h,v
retrieving revision 1.10
diff -u -p -r1.10 ifstated.h
--- ifstated.h  19 Jul 2016 08:04:53 -  1.10
+++ ifstated.h  13 Jun 2017 23:09:05 -
@@ -135,20 +135,3 @@ enum   { IFSD_EVTIMER_ADD, IFSD_EVTIMER_DE
 struct ifsd_config *parse_config(char *, int);
 intcmdline_symset(char *);
 void   clear_config(struct ifsd_config *);
-
-/* log.c */
-void   log_init(int);
-void   log_warn(const char *, ...)
-   __attribute__((__format__ (printf, 1, 2)));
-void   log_warnx(const char *, ...)
-   __attribute__((__format__ (printf, 1, 2)));
-void   log_info(const char *, ...)
-   __attribute__((__format__ (printf, 1, 2)));
-void   log_debug(const char *, ...)
-   __attribute__((__format__ (printf, 1, 2)));
-void   vlog(int, const char *, va_list)
-   __attribute__((__format__ (printf, 2, 0)));
-void   logit(int, const char *, ...)
-   __attribute__((__format__ (printf, 2, 3)));
-void fatal(const char *) __dead;
-void fatalx(const char *) __dead;
Index: log.c
===
RCS file: /cvs/src/usr.sbin/ifstated/log.c,v
retrieving revision 1.4
diff -u -p -r1.4 log.c
--- log.c   21 Mar 2017 12:06:55 -  1.4
+++ log.c   13 Jun 2017 23:09:05 -
@@ -16,40 +16,55 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include 
-#include 
 #include 
 #include 
+#include 
 #include 
 #include 
+#include 
 #include 
 
-voidlog_init(int);
-voidlog_warn(const char *, ...);
-voidlog_warnx(const 

Re: m4(1): add -E flag support

2017-06-13 Thread Todd C. Miller
On Tue, 13 Jun 2017 17:05:56 -0400, Brian Callahan wrote:

> Whoops, that was unintentional. Fixed.

Looks good to me.

 - todd



Re: m4(1): add -E flag support

2017-06-13 Thread Brian Callahan
Hi --

Whoops, that was unintentional. Fixed.

~Brian

Index: usr.bin/m4/eval.c
===
RCS file: /cvs/src/usr.bin/m4/eval.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 eval.c
--- usr.bin/m4/eval.c   5 Feb 2015 12:59:57 -   1.74
+++ usr.bin/m4/eval.c   13 Jun 2017 21:03:15 -
@@ -269,6 +269,12 @@ expand_builtin(const char *argv[], int a
warn("%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, 
argv[2]);
exit_code = 1;
+   /* exit immediately if multiple -E flags
+*/
+   if (fatal_warns == 2) {
+   killdiv();
+   exit(exit_code);
+   }
} else
err(1, "%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, 
argv[2]);
Index: usr.bin/m4/extern.h
===
RCS file: /cvs/src/usr.bin/m4/extern.h,v
retrieving revision 1.54
diff -u -p -u -p -r1.54 extern.h
--- usr.bin/m4/extern.h 12 May 2014 19:11:19 -  1.54
+++ usr.bin/m4/extern.h 13 Jun 2017 21:03:15 -
@@ -58,6 +58,8 @@ extern void doesyscmd(const char *);
 extern void getdivfile(const char *);
 extern void doformat(const char *[], int);
 
+extern void m4_warnx(const char *, ...);
+
 /* look.c */
 
 #define FLAG_UNTRACED 0
@@ -175,4 +177,5 @@ extern int  synch_lines;/* line synchro
 
 extern int mimic_gnu;  /* behaves like gnu-m4 */
 extern int prefix_builtins;/* prefix builtin macros with m4_ */
+extern int fatal_warns;/* make warnings fatal */
 
Index: usr.bin/m4/gnum4.c
===
RCS file: /cvs/src/usr.bin/m4/gnum4.c,v
retrieving revision 1.50
diff -u -p -u -p -r1.50 gnum4.c
--- usr.bin/m4/gnum4.c  29 Apr 2015 00:13:26 -  1.50
+++ usr.bin/m4/gnum4.c  13 Jun 2017 21:03:15 -
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -234,7 +235,7 @@ addchar(int c)
 }
 
 static char *
-getstring()
+getstring(void)
 {
addchar('\0');
current = 0;
@@ -255,11 +256,35 @@ exit_regerror(int er, regex_t *re, const
m4errx(1, "regular expression error in %s: %s.", source, errbuf);
 }
 
+/* warnx() plus check to see if we need to change exit code or exit.
+ * -E flag functionality.
+ */
+void
+m4_warnx(const char *fmt, ...)
+{
+   va_list ap;
+
+   va_start(ap, fmt);
+   vwarnx(fmt, ap);
+   va_end(ap);
+
+   /* Do nothing if no -E flags, set exit_code > 0 but keep going
+* if one -E flag, exit immediately with exit status > 0 if
+* two or more -E flags.
+*/
+   if (fatal_warns == 0)
+   return;
+   else if (fatal_warns == 1)
+   exit_code = 1;
+   else
+   exit(1);
+}
+
 static void
 add_sub(int n, const char *string, regex_t *re, regmatch_t *pm)
 {
if (n > re->re_nsub)
-   warnx("No subexpression %d", n);
+   m4_warnx("No subexpression %d", n);
/* Subexpressions that did not match are
 * not an error.  */
else if (pm[n].rm_so != -1 &&
@@ -442,7 +467,7 @@ void
 dopatsubst(const char *argv[], int argc)
 {
if (argc <= 3) {
-   warnx("Too few arguments to patsubst");
+   m4_warnx("Too few arguments to patsubst");
return;
}
/* special case: empty regexp */
@@ -494,7 +519,7 @@ doregexp(const char *argv[], int argc)
const char *source;
 
if (argc <= 3) {
-   warnx("Too few arguments to regexp");
+   m4_warnx("Too few arguments to regexp");
return;
}
/* special gnu case */
Index: usr.bin/m4/m4.1
===
RCS file: /cvs/src/usr.bin/m4/m4.1,v
retrieving revision 1.63
diff -u -p -u -p -r1.63 m4.1
--- usr.bin/m4/m4.1 14 Sep 2015 20:06:58 -  1.63
+++ usr.bin/m4/m4.1 13 Jun 2017 21:03:15 -
@@ -38,7 +38,7 @@
 .Nd macro language processor
 .Sh SYNOPSIS
 .Nm
-.Op Fl gPs
+.Op Fl EgPs
 .Oo
 .Sm off
 .Fl D Ar name Op No = Ar value
@@ -127,6 +127,19 @@ turn on all options.
 .Pp
 By default, trace is set to
 .Qq eq .
+.It Fl E
+Set warnings to be fatal.
+When a single
+.Fl E
+flag is specified, if warnings are issued, execution continues but
+.Nm
+will exit with a non-zero exit status.
+When multiple
+.Fl E
+flags are specified, execution will halt upon issuing the first warning and
+.Nm
+will exit with a non-zero exit status.
+This behaviour matches 

Re: m4(1): add -E flag support

2017-06-13 Thread Brian Callahan
Hi --

Updated diff attached. Wrapped everything up in an m4_warnx() call
and added a regress test for single -E. Thanks!

The one fatal_warns check in eval.c seems like a special case, so
I left that one as it was.

~Brian

Index: usr.bin/m4/eval.c
===
RCS file: /cvs/src/usr.bin/m4/eval.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 eval.c
--- usr.bin/m4/eval.c   5 Feb 2015 12:59:57 -   1.74
+++ usr.bin/m4/eval.c   13 Jun 2017 20:22:09 -
@@ -269,6 +269,12 @@ expand_builtin(const char *argv[], int a
warn("%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, 
argv[2]);
exit_code = 1;
+   /* exit immediately if multiple -E flags
+*/
+   if (fatal_warns == 2) {
+   killdiv();
+   exit(exit_code);
+   }
} else
err(1, "%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, 
argv[2]);
Index: usr.bin/m4/extern.h
===
RCS file: /cvs/src/usr.bin/m4/extern.h,v
retrieving revision 1.54
diff -u -p -u -p -r1.54 extern.h
--- usr.bin/m4/extern.h 12 May 2014 19:11:19 -  1.54
+++ usr.bin/m4/extern.h 13 Jun 2017 20:22:09 -
@@ -58,6 +58,8 @@ extern void doesyscmd(const char *);
 extern void getdivfile(const char *);
 extern void doformat(const char *[], int);
 
+extern void m4_warnx(const char *, ...);
+
 /* look.c */
 
 #define FLAG_UNTRACED 0
@@ -175,4 +177,5 @@ extern int  synch_lines;/* line synchro
 
 extern int mimic_gnu;  /* behaves like gnu-m4 */
 extern int prefix_builtins;/* prefix builtin macros with m4_ */
+extern int fatal_warns;/* make warnings fatal */
 
Index: usr.bin/m4/gnum4.c
===
RCS file: /cvs/src/usr.bin/m4/gnum4.c,v
retrieving revision 1.50
diff -u -p -u -p -r1.50 gnum4.c
--- usr.bin/m4/gnum4.c  29 Apr 2015 00:13:26 -  1.50
+++ usr.bin/m4/gnum4.c  13 Jun 2017 20:22:09 -
@@ -35,6 +35,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -234,7 +235,7 @@ addchar(int c)
 }
 
 static char *
-getstring()
+getstring(void)
 {
addchar('\0');
current = 0;
@@ -255,11 +256,35 @@ exit_regerror(int er, regex_t *re, const
m4errx(1, "regular expression error in %s: %s.", source, errbuf);
 }
 
+/* warnx() plus check to see if we need to change exit code or exit.
+ * -E flag functionality.
+ */
+void
+m4_warnx(const char *fmt, ...)
+{
+   va_list ap;
+
+   va_start(ap, fmt);
+   vwarnx(fmt, ap);
+   va_end(ap);
+
+   /* Do nothing if no -E flags, set exit_code > 0 but keep going
+* if one -E flag, exit immediately with exit status > 0 if
+* two or more -E flags.
+*/
+   if (fatal_warns == 0)
+   return;
+   else if (fatal_warns == 1)
+   exit_code = 1;
+   else
+   exit(1);
+}
+
 static void
 add_sub(int n, const char *string, regex_t *re, regmatch_t *pm)
 {
if (n > re->re_nsub)
-   warnx("No subexpression %d", n);
+   m4_warnx("No subexpression %d", n);
/* Subexpressions that did not match are
 * not an error.  */
else if (pm[n].rm_so != -1 &&
@@ -442,7 +467,7 @@ void
 dopatsubst(const char *argv[], int argc)
 {
if (argc <= 3) {
-   warnx("Too few arguments to patsubst");
+   m4_warnx("Too few arguments to patsubst");
return;
}
/* special case: empty regexp */
@@ -494,7 +519,7 @@ doregexp(const char *argv[], int argc)
const char *source;
 
if (argc <= 3) {
-   warnx("Too few arguments to regexp");
+   m4_warnx("Too few arguments to regexp");
return;
}
/* special gnu case */
Index: usr.bin/m4/m4.1
===
RCS file: /cvs/src/usr.bin/m4/m4.1,v
retrieving revision 1.63
diff -u -p -u -p -r1.63 m4.1
--- usr.bin/m4/m4.1 14 Sep 2015 20:06:58 -  1.63
+++ usr.bin/m4/m4.1 13 Jun 2017 20:22:09 -
@@ -38,7 +38,7 @@
 .Nd macro language processor
 .Sh SYNOPSIS
 .Nm
-.Op Fl gPs
+.Op Fl EgPs
 .Oo
 .Sm off
 .Fl D Ar name Op No = Ar value
@@ -127,6 +127,19 @@ turn on all options.
 .Pp
 By default, trace is set to
 .Qq eq .
+.It Fl E
+Set warnings to be fatal.
+When a single
+.Fl E
+flag is specified, if warnings are issued, execution continues but
+.Nm
+will exit with a non-zero exit status.

Re: m4(1): add -E flag support

2017-06-13 Thread Anton Lindqvist
On Tue, Jun 13, 2017 at 03:35:54PM -0400, Brian Callahan wrote:
> This diff comes with man page additions explaining the new flag,
> as well as a regress test for -E -E behavior. I could not figure
> out how to write a regress test that checks for exit status, so
> there is no test for single -E behavior.

You could use the following pattern to test the exit code:

  if ${M4} -E -E -g ${.CURDIR}/fatalwarnings.m4 >/dev/null 2>&1 || test $$? -ne 
1; then false; fi



Re: m4(1): add -E flag support

2017-06-13 Thread Todd C. Miller
I don't have an objection to this but wouldn't it be less error-prone
to include the check_fatal_warns() checks in a warnx() wrapper?

There are some fprintf() calls in tokenizer.l that would need to
be converted but that still seems simpler than requiring callers
of warnx() or the equivalent to also call check_fatal_warns().

 - todd



Re: tcpdump: drop atalk support

2017-06-13 Thread Michal Mazurek
Let's not support loading addresses from /etc/appletalk.names.

There are two points to consider:
* tcpdump uses just one file now (/etc/pf.os) which means we can probably
simplify priv_getlines(), but let's not right now.
* there is some lookup code left, but let's remove it later.
removing is not as simple, as the hnametable[] array is used even
when printing a numerical address.

Comments? OK?

Index: usr.sbin/tcpdump/print-atalk.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/print-atalk.c,v
retrieving revision 1.31
diff -u -p -r1.31 print-atalk.c
--- usr.sbin/tcpdump/print-atalk.c  28 Oct 2016 12:54:05 -  1.31
+++ usr.sbin/tcpdump/print-atalk.c  13 Jun 2017 19:32:10 -
@@ -554,51 +554,13 @@ struct hnamemem {
 
 static struct hnamemem hnametable[HASHNAMESIZE];
 
-/*
- * see if there's an AppleTalk number to name map file.
- */
-static void
-init_atalk(void)
-{
-   struct hnamemem *tp;
-   char nambuf[HOST_NAME_MAX+1 + 20];
-   char line[BUFSIZ];
-   int i1, i2, i3;
-
-   priv_getlines(FTAB_APPLETALK);
-   while (priv_getline(line, sizeof(line)) > 0) {
-   if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
-   continue;
-   if (sscanf(line, "%d.%d.%d %255s", , , , nambuf) == 4)
-   /* got a hostname. */
-   i3 |= ((i1 << 8) | i2) << 8;
-   else if (sscanf(line, "%d.%d %255s", , , nambuf) == 3)
-   /* got a net name */
-   i3 = (((i1 << 8) | i2) << 8) | 255;
-   else
-   continue;
-   
-   for (tp = [i3 & (HASHNAMESIZE-1)];
-tp->nxt; tp = tp->nxt)
-   ;
-   tp->addr = i3;
-   tp->nxt = newhnamemem();
-   tp->name = savestr(nambuf);
-   }
-}
-
 static const char *
 ataddr_string(u_short atnet, u_char athost)
 {
struct hnamemem *tp, *tp2;
int i = (atnet << 8) | athost;
char nambuf[HOST_NAME_MAX+1 + 20];
-   static int first = 1;
 
-   if (first) {
-   first = 0;
-   init_atalk();
-   }
for (tp = [i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
if (tp->addr == i)
return (tp->name);
Index: usr.sbin/tcpdump/privsep.c
===
RCS file: /cvs/src/usr.sbin/tcpdump/privsep.c,v
retrieving revision 1.44
diff -u -p -r1.44 privsep.c
--- usr.sbin/tcpdump/privsep.c  23 Jan 2017 04:25:05 -  1.44
+++ usr.sbin/tcpdump/privsep.c  13 Jun 2017 19:32:10 -
@@ -101,8 +101,7 @@ struct ftab {
int count;
 };
 
-static struct ftab file_table[] = {{"/etc/appletalk.names", 1, 0},
-  {PF_OSFP_FILE, 1, 0}};
+static struct ftab file_table[] = {{PF_OSFP_FILE, 1, 0}};
 
 #define NUM_FILETAB (sizeof(file_table) / sizeof(struct ftab))
 
Index: usr.sbin/tcpdump/privsep.h
===
RCS file: /cvs/src/usr.sbin/tcpdump/privsep.h,v
retrieving revision 1.8
diff -u -p -r1.8 privsep.h
--- usr.sbin/tcpdump/privsep.h  14 Jul 2015 20:23:40 -  1.8
+++ usr.sbin/tcpdump/privsep.h  13 Jun 2017 19:32:10 -
@@ -22,8 +22,7 @@
 #define TCPDUMP_MAGIC 0xa1b2c3d4
 
 /* file ids used by priv_getlines */
-#define FTAB_APPLETALK 0
-#define FTAB_PFOSFP1
+#define FTAB_PFOSFP0
 
 enum cmd_types {
PRIV_OPEN_BPF,  /* open a bpf descriptor */


-- 
Michal Mazurek



Re: m4(1): add -E flag support

2017-06-13 Thread Theo de Raadt
The decisions taken seem correct.  I'll let m4 people judge the rest of it.



m4(1): add -E flag support

2017-06-13 Thread Brian Callahan
Hi tech --

I've shared this with a few developers, and have been advised to
share now with a wider audience.

This diff adds -E flag functionality to m4(1). I wrote this diff
after noticing a patch in ports/devel/scons by jasper@ with the
comment:
XXX: OpenBSD's m4(1) lacks the -E option (needs to be implemented though).

The -E flag causes warnings to become fatal. It appears to be a
GNU extension. Unfortunately, the GNU people have multiple
definitions of what fatal is, so I will outline the situation and
my approach to this diff.

The -E flag was first introduced to GNU m4 in 1994, version 1.2.
The flag, when set, caused m4 to exit with an exit status > 0
immediately upon issuing its first warning.

In GNU m4 1.4.9, released in 2007, this behavior was changed to
do the following:
1. If a single -E flag is given, still change the exit status of
   m4 to be > 0, but otherwise continue as normal.
2. If 2 or more -E flags are given, do the old -E behavior, that
   is, exit with an exit status > 0 immediately upon issuing the
   first warning.
This is the current behavior of all later GNU m4 releases.

I have chosen the 1.4.9 and later behavior for our m4, as it has
been now 10 years since the new behavior was introduced.

I also looked to see if there is an upstream for m4. There is not
as far as I can tell. So we are our own upstream. In fact, we are
upstream for other projects as well.

Here's that situation:
1. FreeBSD (and DragonFly) sync their m4(1) to ours. They do not
   have an -E flag because we don't.
2. NetBSD added -E flag support in January 2016. However, NetBSD
   opted to implement the old pre-GNU m4 1.4.9 -E flag behavior.
   Additionally, NetBSD's implementation does not error out for
   all warnings: only warnings for functions contained within
   gm4.c got the -E flag treatment. Therefore, it is possible to
   run NetBSD's m4(1) with the -E flag, receive a warning, and
   not error out (and the -E flag does absolutely nothing in the
   NetBSD implementation if the -g flag is not also given).
   My implementation was written entirely independently from the
   NetBSD implementation, as I did not even know they had added
   -E flag support until this diff was written and sent off for
   early review.
3. Solaris and AIX implementations of m4(1) don't have -E flag
   support.
4. Mac OS X (tested on 10.12.5) has GNU m4 1.4.6 as the version
   that comes with the base system, meaning that anyone who
   uses that version will get the old pre-1.4.9 behavior.

This diff comes with man page additions explaining the new flag,
as well as a regress test for -E -E behavior. I could not figure
out how to write a regress test that checks for exit status, so
there is no test for single -E behavior.

Comments appreciated.

~Brian

Index: usr.bin/m4/eval.c
===
RCS file: /cvs/src/usr.bin/m4/eval.c,v
retrieving revision 1.74
diff -u -p -u -p -r1.74 eval.c
--- usr.bin/m4/eval.c   5 Feb 2015 12:59:57 -   1.74
+++ usr.bin/m4/eval.c   11 Jun 2017 22:52:08 -
@@ -269,6 +269,12 @@ expand_builtin(const char *argv[], int a
warn("%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, 
argv[2]);
exit_code = 1;
+   /* exit immediately if multiple -E flags
+*/
+   if (fatal_warns == 2) {
+   killdiv();
+   exit(exit_code);
+   }
} else
err(1, "%s at line %lu: include(%s)",
CURRENT_NAME, CURRENT_LINE, 
argv[2]);
Index: usr.bin/m4/extern.h
===
RCS file: /cvs/src/usr.bin/m4/extern.h,v
retrieving revision 1.54
diff -u -p -u -p -r1.54 extern.h
--- usr.bin/m4/extern.h 12 May 2014 19:11:19 -  1.54
+++ usr.bin/m4/extern.h 11 Jun 2017 22:52:08 -
@@ -58,6 +58,8 @@ extern void doesyscmd(const char *);
 extern void getdivfile(const char *);
 extern void doformat(const char *[], int);
 
+extern void check_fatal_warns(void);
+
 /* look.c */
 
 #define FLAG_UNTRACED 0
@@ -175,4 +177,5 @@ extern int  synch_lines;/* line synchro
 
 extern int mimic_gnu;  /* behaves like gnu-m4 */
 extern int prefix_builtins;/* prefix builtin macros with m4_ */
+extern int fatal_warns;/* make warnings fatal */
 
Index: usr.bin/m4/gnum4.c
===
RCS file: /cvs/src/usr.bin/m4/gnum4.c,v
retrieving revision 1.50
diff -u -p -u -p -r1.50 gnum4.c
--- usr.bin/m4/gnum4.c  29 Apr 2015 00:13:26 -  1.50
+++ usr.bin/m4/gnum4.c  11 Jun 2017 22:52:08 

Re: wsfont: remove iso7/pcvt encoding macros and entries

2017-06-13 Thread Mike Larkin
On Tue, Jun 13, 2017 at 11:00:52AM +0200, Frederic Cambus wrote:
> Hi tech@,
> 
> We do not support iso7 nor pcvt encoding, so remove macro definitions
> and commented entries.
> 
> Comments? OK?
> 

ok mlarkin

also see what miod said in a later reply, maybe more "-" for you :)

> Index: sys/dev/wscons/wsconsio.h
> ===
> RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
> retrieving revision 1.82
> diff -u -p -r1.82 wsconsio.h
> --- sys/dev/wscons/wsconsio.h 13 Jun 2017 08:00:24 -  1.82
> +++ sys/dev/wscons/wsconsio.h 13 Jun 2017 08:41:20 -
> @@ -506,8 +506,6 @@ struct wsdisplay_font {
>   int encoding;
>  #define WSDISPLAY_FONTENC_ISO 0
>  #define WSDISPLAY_FONTENC_IBM 1
> -#define WSDISPLAY_FONTENC_PCVT 2
> -#define WSDISPLAY_FONTENC_ISO7 3 /* greek */
>   u_int fontwidth, fontheight, stride;
>  #define WSDISPLAY_MAXFONTSZ  (512*1024)
>   int bitorder, byteorder;
> Index: usr.sbin/wsfontload/wsfontload.c
> ===
> RCS file: /cvs/src/usr.sbin/wsfontload/wsfontload.c,v
> retrieving revision 1.16
> diff -u -p -r1.16 wsfontload.c
> --- usr.sbin/wsfontload/wsfontload.c  6 Sep 2015 20:07:46 -   1.16
> +++ usr.sbin/wsfontload/wsfontload.c  13 Jun 2017 08:41:21 -
> @@ -75,10 +75,6 @@ static const struct {
>  } encodings[] = {
>   {"iso",  WSDISPLAY_FONTENC_ISO},
>   {"ibm",  WSDISPLAY_FONTENC_IBM},
> -#if 0
> - {"pcvt", WSDISPLAY_FONTENC_PCVT},
> - {"iso7", WSDISPLAY_FONTENC_ISO7},
> -#endif
>  };
>  
>  int
> 



Re: ping: Style fixes/cleanups

2017-06-13 Thread Theo de Raadt
Sorry I don't see the point of (void)printf.

It makes code unreadable, and only cleans up pointless false positives
from tools.

Any such effort is wasted.  No bugs are being fixed.  Imagine doing it
to the entire source tree.  The work would never get finished because
it is largely pointless to churn code without fixing exerciseable
bugs.

> printf's return value is ignored allmost all the times so do the same
> for the rest of them as well for consistency.
> 
> Subsequent calls got merged where I think is appropiate and readability
> improves.
> 
> The usage format string now looks like it's actual put.
> 
> Index: ping.c
> ===
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.218
> diff -u -p -r1.218 ping.c
> --- ping.c22 Feb 2017 13:43:35 -  1.218
> +++ ping.c13 Jun 2017 18:08:42 -
> @@ -756,10 +756,10 @@ main(int argc, char *argv[])
>   arc4random_buf(_offset, sizeof(tv64_offset));
>   arc4random_buf(_key, sizeof(mac_key));
>  
> - printf("PING %s (", hostname);
> + (void)printf("PING %s (", hostname);
>   if (options & F_VERBOSE)
> - printf("%s --> ", pr_addr(from, from->sa_len));
> - printf("%s): %d data bytes\n", pr_addr(dst, dst->sa_len), datalen);
> + (void)printf("%s --> ", pr_addr(from, from->sa_len));
> + (void)printf("%s): %d data bytes\n", pr_addr(dst, dst->sa_len), 
> datalen);
>  
>   smsghdr.msg_name = dst;
>   smsghdr.msg_namelen = dst->sa_len;
> @@ -862,7 +862,7 @@ main(int argc, char *argv[])
>*/
>   if ((mtu = get_pathmtu(, )) > 0) {
>   if ((options & F_VERBOSE) != 0) {
> - printf("new path MTU (%d) is "
> + (void)printf("new path MTU (%d) is "
>   "notified\n", mtu);
>   }
>   }
> @@ -926,28 +926,28 @@ fill(char *bp, char *patp)
>  void
>  summary(void)
>  {
> - printf("\n--- %s ping statistics ---\n", hostname);
> - printf("%lld packets transmitted, ", ntransmitted);
> - printf("%lld packets received, ", nreceived);
> + (void)printf("\n--- %s ping statistics ---\n"
> + "%lld packets transmitted, %lld packets received, ",
> + hostname, ntransmitted, nreceived);
>  
>   if (nrepeats)
> - printf("%lld duplicates, ", nrepeats);
> + (void)printf("%lld duplicates, ", nrepeats);
>   if (ntransmitted) {
>   if (nreceived > ntransmitted)
> - printf("-- somebody's duplicating packets!");
> + (void)printf("-- somebody's duplicating packets!");
>   else
> - printf("%.1f%% packet loss",
> - double)ntransmitted - nreceived) * 100) /
> - ntransmitted));
> + (void)printf("%.1f%% packet loss",
> + (double)(ntransmitted - nreceived)
> + * 100 / ntransmitted);
>   }
> - printf("\n");
> + (void)printf("\n");
>   if (timinginfo) {
>   /* Only display average to microseconds */
>   double num = nreceived + nrepeats;
>   double avg = tsum / num;
>   double dev = sqrt(fmax(0, tsumsq / num - avg * avg));
> - printf("round-trip min/avg/max/std-dev = %.3f/%.3f/%.3f/%.3f 
> ms\n",
> - tmin, avg, tmax, dev);
> + (void)printf("round-trip min/avg/max/std-dev = "
> + "%.3f/%.3f/%.3f/%.3f ms\n", tmin, avg, tmax, dev);
>   }
>  }
>  
> @@ -1092,7 +1092,7 @@ pinger(int s)
>   if (i < 0 || i != cc) {
>   if (i < 0)
>   warn("sendmsg");
> - printf("ping: wrote %s %d chars, ret=%d\n", hostname, cc, i);
> + (void)printf("ping: wrote %s %d chars, ret=%d\n", hostname, cc, 
> i);
>   }
>   if (!(options & F_QUIET) && options & F_FLOOD)
>   (void)write(STDOUT_FILENO, , 1);
> @@ -1278,11 +1278,9 @@ pr_pack(u_char *buf, int cc, struct msgh
>   cp = (u_char *)
>   >icmp_data[0];
>   for (i = ECHOLEN; i < cc && i < datalen;
> - ++i, ++cp) {
> - if ((i % 32) == 8)
> - (void)printf("\n\t");
> - (void)printf("%x ", *cp);
> - }
> + ++i, ++cp)
> + (void)printf(i % 32 == 8 ?
> + "\n\t%x " : "%x ", *cp);
>

Re: ping: Style fixes/cleanups

2017-06-13 Thread Klemens Nanni

printf's return value is ignored allmost all the times so do the same
for the rest of them as well for consistency.

Subsequent calls got merged where I think is appropiate and readability
improves.

The usage format string now looks like it's actual put.

Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.218
diff -u -p -r1.218 ping.c
--- ping.c  22 Feb 2017 13:43:35 -  1.218
+++ ping.c  13 Jun 2017 18:08:42 -
@@ -756,10 +756,10 @@ main(int argc, char *argv[])
arc4random_buf(_offset, sizeof(tv64_offset));
arc4random_buf(_key, sizeof(mac_key));

-   printf("PING %s (", hostname);
+   (void)printf("PING %s (", hostname);
if (options & F_VERBOSE)
-   printf("%s --> ", pr_addr(from, from->sa_len));
-   printf("%s): %d data bytes\n", pr_addr(dst, dst->sa_len), datalen);
+   (void)printf("%s --> ", pr_addr(from, from->sa_len));
+   (void)printf("%s): %d data bytes\n", pr_addr(dst, dst->sa_len), 
datalen);

smsghdr.msg_name = dst;
smsghdr.msg_namelen = dst->sa_len;
@@ -862,7 +862,7 @@ main(int argc, char *argv[])
 */
if ((mtu = get_pathmtu(, )) > 0) {
if ((options & F_VERBOSE) != 0) {
-   printf("new path MTU (%d) is "
+   (void)printf("new path MTU (%d) is "
"notified\n", mtu);
}
}
@@ -926,28 +926,28 @@ fill(char *bp, char *patp)
void
summary(void)
{
-   printf("\n--- %s ping statistics ---\n", hostname);
-   printf("%lld packets transmitted, ", ntransmitted);
-   printf("%lld packets received, ", nreceived);
+   (void)printf("\n--- %s ping statistics ---\n"
+   "%lld packets transmitted, %lld packets received, ",
+   hostname, ntransmitted, nreceived);

if (nrepeats)
-   printf("%lld duplicates, ", nrepeats);
+   (void)printf("%lld duplicates, ", nrepeats);
if (ntransmitted) {
if (nreceived > ntransmitted)
-   printf("-- somebody's duplicating packets!");
+   (void)printf("-- somebody's duplicating packets!");
else
-   printf("%.1f%% packet loss",
-   double)ntransmitted - nreceived) * 100) /
-   ntransmitted));
+   (void)printf("%.1f%% packet loss",
+   (double)(ntransmitted - nreceived)
+   * 100 / ntransmitted);
}
-   printf("\n");
+   (void)printf("\n");
if (timinginfo) {
/* Only display average to microseconds */
double num = nreceived + nrepeats;
double avg = tsum / num;
double dev = sqrt(fmax(0, tsumsq / num - avg * avg));
-   printf("round-trip min/avg/max/std-dev = %.3f/%.3f/%.3f/%.3f 
ms\n",
-   tmin, avg, tmax, dev);
+   (void)printf("round-trip min/avg/max/std-dev = "
+   "%.3f/%.3f/%.3f/%.3f ms\n", tmin, avg, tmax, dev);
}
}

@@ -1092,7 +1092,7 @@ pinger(int s)
if (i < 0 || i != cc) {
if (i < 0)
warn("sendmsg");
-   printf("ping: wrote %s %d chars, ret=%d\n", hostname, cc, i);
+   (void)printf("ping: wrote %s %d chars, ret=%d\n", hostname, cc, 
i);
}
if (!(options & F_QUIET) && options & F_FLOOD)
(void)write(STDOUT_FILENO, , 1);
@@ -1278,11 +1278,9 @@ pr_pack(u_char *buf, int cc, struct msgh
cp = (u_char *)
>icmp_data[0];
for (i = ECHOLEN; i < cc && i < datalen;
-   ++i, ++cp) {
-   if ((i % 32) == 8)
-   (void)printf("\n\t");
-   (void)printf("%x ", *cp);
-   }
+   ++i, ++cp)
+   (void)printf(i % 32 == 8 ?
+   "\n\t%x " : "%x ", *cp);
break;
}
}
@@ -1560,8 +1558,7 @@ pr_icmph(struct icmp *icp)
(void)printf("Redirect, Unknown Code: %d", 
icp->icmp_code);
break;
}
-   (void)printf("(New addr: %s)\n",
-   inet_ntoa(icp->icmp_gwaddr));
+   (void)printf("(New 

Re: ping: Style fixes/cleanups

2017-06-13 Thread Klemens Nanni

Unify option checking and simply logic.

F_HDRINCL and F_ROUTE are mutually exclusive, thus check the latter only
if the former one is not set.

Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.218
diff -u -p -r1.218 ping.c
--- ping.c  22 Feb 2017 13:43:35 -  1.218
+++ ping.c  13 Jun 2017 17:38:22 -
@@ -562,17 +562,17 @@ main(int argc, char *argv[])
(void)setsockopt(s, SOL_SOCKET, SO_DEBUG, ,
sizeof(optval));

-   if ((options & F_FLOOD) && (options & F_INTERVAL))
+   if (options & (F_FLOOD | F_INTERVAL))
errx(1, "-f and -i options are incompatible");

-   if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS)))
+   if (options & (F_FLOOD | F_AUD_RECV | F_AUD_MISS))
warnx("No audible output for flood pings");

if (datalen >= sizeof(struct payload))   /* can we time transfer */
timing = 1;

if (v6flag) {
-   /* in F_VERBOSE case, we may get non-echoreply packets*/
+   /* in F_VERBOSE case, we may get non-echoreply packets */
if (options & F_VERBOSE && datalen < 2048) /* XXX 2048? */
packlen = 2048 + IP6LEN + ECHOLEN + EXTRA;
else
@@ -621,7 +621,7 @@ main(int argc, char *argv[])
 * let the kernel pass extension headers of incoming packets,
 * for privileged socket options
 */
-   if ((options & F_VERBOSE) != 0) {
+   if (options & F_VERBOSE) {
int opton = 1;

if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVHOPOPTS,
@@ -696,7 +696,7 @@ main(int argc, char *argv[])
options |= F_HDRINCL;
}

-   if (options & F_RROUTE && options & F_HDRINCL)
+   if (options & (F_RROUTE | F_HDRINCL))
errx(1, "-R option and -D or -T, or -t to unicast"
" destinations are incompatible");

@@ -717,10 +717,8 @@ main(int argc, char *argv[])
else
ip->ip_src.s_addr = INADDR_ANY;
ip->ip_dst = dst4.sin_addr;
-   }
-
/* record route option */
-   if (options & F_RROUTE) {
+   } else if (options & F_RROUTE) {
if (IN_MULTICAST(ntohl(dst4.sin_addr.s_addr)))
errx(1, "record route not valid to multicast"
" destinations");
@@ -773,7 +771,7 @@ main(int argc, char *argv[])
(void)signal(SIGINT, onsignal);
(void)signal(SIGINFO, onsignal);

-   if ((options & F_FLOOD) == 0) {
+   if (!(options & F_FLOOD)) {
(void)signal(SIGALRM, onsignal);
itimer.it_interval = interval;
itimer.it_value = interval;
@@ -861,8 +859,8 @@ main(int argc, char *argv[])
 * a path MTU notification.)
 */
if ((mtu = get_pathmtu(, )) > 0) {
-   if ((options & F_VERBOSE) != 0) {
-   printf("new path MTU (%d) is "
+   if (options & F_VERBOSE) {
+   (void)printf("new path MTU (%d) is "
"notified\n", mtu);
}
}
@@ -961,7 +959,7 @@ pr_addr(struct sockaddr *addr, socklen_t
static char buf[NI_MAXHOST];
int flag = 0;

-   if ((options & F_HOSTNAME) == 0)
+   if (!(options & F_HOSTNAME))
flag |= NI_NUMERICHOST;

if (getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, flag) == 0)
@@ -1892,7 +1890,7 @@ get_pathmtu(struct msghdr *mhdr, struct 
			dst->sin6_scope_id &&

mtuctl->ip6m_addr.sin6_scope_id !=
dst->sin6_scope_id)) {
-   if ((options & F_VERBOSE) != 0) {
+   if (options & F_VERBOSE) {
printf("path MTU for %s is notified. "
"(ignored)\n",
pr_addr((struct sockaddr *)



Re: ping: Style fixes/cleanups

2017-06-13 Thread Klemens Nanni

The intent here is to get the highest multiple of four smaller or equal
than i + 3. Instead of relying on integer division to get rid of the
remainder just to "undo" everything, simply clear the lowest two bits
(0b11 = 3) leaving multiples of four.

Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.218
diff -u -p -r1.218 ping.c
--- ping.c  22 Feb 2017 13:43:35 -  1.218
+++ ping.c  13 Jun 2017 17:29:19 -
@@ -1379,7 +1379,7 @@ pr_ipopt(int hlen, u_char *buf)
!memcmp(cp, old_rr, i) &&
!(options & F_FLOOD)) {
(void)printf("\t(same route)");
-   i = ((i + 3) / 4) * 4;
+   i = (i + 3) & ~0x3;
hlen -= i;
cp += i;
break;



Re: ping: Style fixes/cleanups

2017-06-13 Thread Klemens Nanni

Do not clear the unneeded dst[46] structure.

Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.218
diff -u -p -r1.218 ping.c
--- ping.c  22 Feb 2017 13:43:35 -  1.218
+++ ping.c  13 Jun 2017 17:32:13 -
@@ -434,8 +434,10 @@ main(int argc, char *argv[])
if (argc != 1)
usage();

-   memset(, 0, sizeof(dst4));
-   memset(, 0, sizeof(dst6));
+   if (v6flag)
+   memset(, 0, sizeof(dst6));
+   else
+   memset(, 0, sizeof(dst4));

target = *argv;




Re: ping: Style fixes/cleanups

2017-06-13 Thread Klemens Nanni

On Tue, Jun 13, 2017 at 10:45:57AM -0600, Theo de Raadt wrote:

Sorry, but that type of diff is a no-go.  You've made a large variety
of different decisions on your own and mixed them up with ones which
are personal taste, and then touched so many lines of the code that
future study of historical changes in the code will be confusing.

Points taken.


The right approach is seperate changes into seperate catagories with
seperate explanations.  So I suggest you start with the ones of most
importance, and don't mix it with fluff (that's what we call it).

Each of the following patches applies cleanly on its own.

Starting with this one replacing perror(3) with err(1).


Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.218
diff -u -p -r1.218 ping.c
--- ping.c  22 Feb 2017 13:43:35 -  1.218
+++ ping.c  13 Jun 2017 17:28:46 -
@@ -729,10 +729,8 @@ main(int argc, char *argv[])
rspace[IPOPT_OLEN] = sizeof(rspace)-1;
rspace[IPOPT_OFFSET] = IPOPT_MINOFF;
if (setsockopt(s, IPPROTO_IP, IP_OPTIONS, rspace,
-   sizeof(rspace)) < 0) {
-   perror("ping: record route");
-   exit(1);
-   }
+   sizeof(rspace)) < 0)
+   err(1, "record route");
}

if ((moptions & MULTICAST_NOLOOP) &&



Re: ping: Style fixes/cleanups

2017-06-13 Thread Theo de Raadt
Sorry, but that type of diff is a no-go.  You've made a large variety
of different decisions on your own and mixed them up with ones which
are personal taste, and then touched so many lines of the code that
future study of historical changes in the code will be confusing.

And you've changed the logic at least once:

> - if (options & F_RROUTE) {
> + } else if (options & F_RROUTE) {

The right approach is seperate changes into seperate catagories with
seperate explanations.  So I suggest you start with the ones of most
importance, and don't mix it with fluff (that's what we call it).

> Ignore return status of all printf calls consistently, merge
> subsequent ones where appropiate, do not memset unneeded dst structure,
> simplify/unify option checks, use err not perror, break lines at 80
> chars, remove unnecessary parentheses, avoid unobvious integer divsion,
> make usage format string and output look alike.
> 
> Feedback/OK?
> 
> Index: ping.c
> ===
> RCS file: /cvs/src/sbin/ping/ping.c,v
> retrieving revision 1.218
> diff -u -p -r1.218 ping.c
> --- ping.c22 Feb 2017 13:43:35 -  1.218
> +++ ping.c13 Jun 2017 16:35:03 -
> @@ -182,10 +182,10 @@ int ident;  /* process id to 
> identify o
>  int v6flag = 0;  /* are we ping6? */
>  
>  /* counters */
> -int64_t npackets;/* max packets to transmit */
> +int64_t npackets;/* max # of packets to transmit */
>  int64_t nreceived;   /* # of packets we got back */
> -int64_t nrepeats;/* number of duplicates */
> -int64_t ntransmitted;/* sequence # for outbound packets = 
> #sent */
> +int64_t nrepeats;/* # of duplicates */
> +int64_t ntransmitted;/* sequence # for outbound packets = # 
> sent */
>  int64_t nmissedmax = 1;  /* max value of ntransmitted - 
> nreceived - 1 */
>  struct timeval interval = {1, 0}; /* interval between packets */
>  
> @@ -208,34 +208,34 @@ volatile sig_atomic_t seenalrm;
>  volatile sig_atomic_t seenint;
>  volatile sig_atomic_t seeninfo;
>  
> -void  fill(char *, char *);
> -void  summary(void);
> -void  onsignal(int);
> -void  retransmit(int);
> -int   pinger(int);
> -const char   *pr_addr(struct sockaddr *, socklen_t);
> -void  pr_pack(u_char *, int, struct msghdr *);
> -__dead void   usage(void);
> +void  fill(char *, char *);
> +void  summary(void);
> +void  onsignal(int);
> +void  retransmit(int);
> +int   pinger(int);
> +const char   *pr_addr(struct sockaddr *, socklen_t);
> +void  pr_pack(u_char *, int, struct msghdr *);
> +__dead void   usage(void);
>  
>  /* IPv4 specific functions */
> -void  pr_ipopt(int, u_char *);
> -int   in_cksum(u_short *, int);
> -void  pr_icmph(struct icmp *);
> -void  pr_retip(struct ip *);
> -void  pr_iph(struct ip *);
> +void  pr_ipopt(int, u_char *);
> +int   in_cksum(u_short *, int);
> +void  pr_icmph(struct icmp *);
> +void  pr_retip(struct ip *);
> +void  pr_iph(struct ip *);
>  #ifndef SMALL
> -int   map_tos(char *, int *);
> +int   map_tos(char *, int *);
>  #endif   /* SMALL */
>  
>  /* IPv6 specific functions */
> -int   get_hoplim(struct msghdr *);
> -int   get_pathmtu(struct msghdr *, struct sockaddr_in6 *);
> -void  pr_icmph6(struct icmp6_hdr *, u_char *);
> -void  pr_iph6(struct ip6_hdr *);
> -void  pr_exthdrs(struct msghdr *);
> -void  pr_ip6opt(void *);
> -void  pr_rthdr(void *);
> -void  pr_retip6(struct ip6_hdr *, u_char *);
> +int   get_hoplim(struct msghdr *);
> +int   get_pathmtu(struct msghdr *, struct sockaddr_in6 *);
> +void  pr_icmph6(struct icmp6_hdr *, u_char *);
> +void  pr_iph6(struct ip6_hdr *);
> +void  pr_exthdrs(struct msghdr *);
> +void  pr_ip6opt(void *);
> +void  pr_rthdr(void *);
> +void  pr_retip6(struct ip6_hdr *, u_char *);
>  
>  int
>  main(int argc, char *argv[])
> @@ -434,8 +434,10 @@ main(int argc, char *argv[])
>   if (argc != 1)
>   usage();
>  
> - memset(, 0, sizeof(dst4));
> - memset(, 0, sizeof(dst6));
> + if (v6flag)
> + memset(, 0, sizeof(dst6));
> + else
> + memset(, 0, sizeof(dst4));
>  
>   target = *argv;
>  
> @@ -562,17 +564,17 @@ main(int argc, char *argv[])
>   (void)setsockopt(s, SOL_SOCKET, SO_DEBUG, ,
>   sizeof(optval));
>  
> - if ((options & F_FLOOD) && (options & F_INTERVAL))
> + if (options & (F_FLOOD | 

Re: htpasswd: use crypt_newhash instead of bcrypt API

2017-06-13 Thread Michal Mazurek
On 15:31:50, 10.06.17, Ted Unangst wrote:
> > @@ -58,17 +58,29 @@ The provided
> >  .Fa password
> >  is randomly salted and hashed and stored in
> >  .Fa hash .
> > +.Fa hash
> > +must already be allocated, and
> > +.Fa hashsize
> > +must contain its size, which cannot be less than 61 bytes.
> 
> that's an implementation detail. if we're advising a limit, i think we
> should say 128 or so.

How come? Tracing the code of crypt_newhash() we end up in
bcrypt_hashpass(), which has the following check:

if (encryptedlen < BCRYPT_HASHSPACE)
goto inval;

BCRYPT_HASHSPACE is defined thus:
libc/crypt/bcrypt.c:#define   BCRYPT_HASHSPACE61

-- 
Michal Mazurek



ping: Style fixes/cleanups

2017-06-13 Thread Klemens Nanni

Ignore return status of all printf calls consistently, merge
subsequent ones where appropiate, do not memset unneeded dst structure,
simplify/unify option checks, use err not perror, break lines at 80
chars, remove unnecessary parentheses, avoid unobvious integer divsion,
make usage format string and output look alike.

Feedback/OK?

Index: ping.c
===
RCS file: /cvs/src/sbin/ping/ping.c,v
retrieving revision 1.218
diff -u -p -r1.218 ping.c
--- ping.c  22 Feb 2017 13:43:35 -  1.218
+++ ping.c  13 Jun 2017 16:35:03 -
@@ -182,10 +182,10 @@ int ident;/* process id to 
identify o
int v6flag = 0; /* are we ping6? */

/* counters */
-int64_t npackets;  /* max packets to transmit */
+int64_t npackets;  /* max # of packets to transmit */
int64_t nreceived;  /* # of packets we got back */
-int64_t nrepeats;  /* number of duplicates */
-int64_t ntransmitted;  /* sequence # for outbound packets = #sent */
+int64_t nrepeats;  /* # of duplicates */
+int64_t ntransmitted;  /* sequence # for outbound packets = # sent */
int64_t nmissedmax = 1; /* max value of ntransmitted - nreceived - 1 */
struct timeval interval = {1, 0}; /* interval between packets */

@@ -208,34 +208,34 @@ volatile sig_atomic_t seenalrm;
volatile sig_atomic_t seenint;
volatile sig_atomic_t seeninfo;

-voidfill(char *, char *);
-voidsummary(void);
-voidonsignal(int);
-voidretransmit(int);
-int pinger(int);
-const char *pr_addr(struct sockaddr *, socklen_t);
-voidpr_pack(u_char *, int, struct msghdr *);
-__dead void usage(void);
+voidfill(char *, char *);
+voidsummary(void);
+voidonsignal(int);
+voidretransmit(int);
+int pinger(int);
+const char *pr_addr(struct sockaddr *, socklen_t);
+voidpr_pack(u_char *, int, struct msghdr *);
+__dead void usage(void);

/* IPv4 specific functions */
-voidpr_ipopt(int, u_char *);
-int in_cksum(u_short *, int);
-voidpr_icmph(struct icmp *);
-voidpr_retip(struct ip *);
-voidpr_iph(struct ip *);
+voidpr_ipopt(int, u_char *);
+int in_cksum(u_short *, int);
+voidpr_icmph(struct icmp *);
+voidpr_retip(struct ip *);
+voidpr_iph(struct ip *);
#ifndef SMALL
-int map_tos(char *, int *);
+int map_tos(char *, int *);
#endif  /* SMALL */

/* IPv6 specific functions */
-int get_hoplim(struct msghdr *);
-int get_pathmtu(struct msghdr *, struct sockaddr_in6 *);
-voidpr_icmph6(struct icmp6_hdr *, u_char *);
-voidpr_iph6(struct ip6_hdr *);
-voidpr_exthdrs(struct msghdr *);
-voidpr_ip6opt(void *);
-voidpr_rthdr(void *);
-voidpr_retip6(struct ip6_hdr *, u_char *);
+int get_hoplim(struct msghdr *);
+int get_pathmtu(struct msghdr *, struct sockaddr_in6 *);
+voidpr_icmph6(struct icmp6_hdr *, u_char *);
+voidpr_iph6(struct ip6_hdr *);
+voidpr_exthdrs(struct msghdr *);
+voidpr_ip6opt(void *);
+voidpr_rthdr(void *);
+voidpr_retip6(struct ip6_hdr *, u_char *);

int
main(int argc, char *argv[])
@@ -434,8 +434,10 @@ main(int argc, char *argv[])
if (argc != 1)
usage();

-   memset(, 0, sizeof(dst4));
-   memset(, 0, sizeof(dst6));
+   if (v6flag)
+   memset(, 0, sizeof(dst6));
+   else
+   memset(, 0, sizeof(dst4));

target = *argv;

@@ -562,17 +564,17 @@ main(int argc, char *argv[])
(void)setsockopt(s, SOL_SOCKET, SO_DEBUG, ,
sizeof(optval));

-   if ((options & F_FLOOD) && (options & F_INTERVAL))
+   if (options & (F_FLOOD | F_INTERVAL))
errx(1, "-f and -i options are incompatible");

-   if ((options & F_FLOOD) && (options & (F_AUD_RECV | F_AUD_MISS)))
+   if (options & (F_FLOOD | F_AUD_RECV | F_AUD_MISS))
warnx("No audible output for flood pings");

if (datalen >= sizeof(struct payload))   /* can we time transfer */
timing = 1;

if (v6flag) {
-   /* in F_VERBOSE case, we may get non-echoreply packets*/
+   /* in F_VERBOSE case, we may get non-echoreply packets */
if (options & F_VERBOSE && datalen < 2048) /* XXX 2048? */
packlen = 2048 + IP6LEN + ECHOLEN + EXTRA;
else
@@ -621,7 +623,7 @@ main(int argc, char 

Re: games/hunt: /usr/games/lib doesn't exist

2017-06-13 Thread Michal Mazurek
As tb@ pointed out, /usr/man/man6 also doesn't exist. Let's remove
the whole "Installation" section.

OK?

Index: games/hunt//README
===
RCS file: /cvs/src/games/hunt/README,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 README
--- games/hunt//README  21 Jan 1999 05:33:37 -  1.1.1.1
+++ games/hunt//README  13 Jun 2017 16:27:43 -
@@ -43,59 +43,6 @@ Words of Warning:
hunt abusers.  Hunt may also be addictive, and the
withdrawal symptoms are not pretty :-)
 
-Installation:
-
-   1. Edit file "Makefile" and make sure the options selected are
-   reasonable.  There are four "make" variables that you
-   should check: GAME_PARAM, SYSCFLAGS, SYSLDFLAGS, and DEFS.
-   GAME_PARAM controls what features of the game will be
-   compiled in (e.g. reflecting walls).  The optional features
-   are listed in comments above where GAME_PARAM is defined.
-   If you want to try them, just add the ones you want to the 
-   GAME_PARAM definition.
-
-   DEFS is where most system configuration is described.
-   If your system is 4.3BSD, Sun, Ultrix, Convex, HPUX
-   v6.0.1, or SGI, you're in luck.  We provide the
-   appropriate definitions for these systems and you just
-   need to select one of them (e.g. if you have an Ultrix
-   system, just change the line
-   DEFS=   $(GAME_PARAM) $(DEFS_43)
-   to
-   DEFS=   $(GAME_PARAM) $(DEFS_ULTRIX)
-   ).  If your system is *not* listed above, then you may
-   need to do some experiments.  All of the options are
-   documented in the Makefile, be brave.
-
-   SYSCFLAGS and SYSLDFLAGS are used for "unusual" systems
-   and you probably won't need to deal with it.  An
-   example of an unusual system is the Silicon Graphics
-   IRIS, which keeps the network socket code in a BSD
-   emulation library that is in -lbsd.  Edit these only if
-   you *know* your system is "different."
-
-   2. Edit file "Makefile" and look at the "install:" target.  By
-   default, files are installed in /usr/games,
-   /usr/games/lib, and /usr/man/man6, which are "standard"
-   locations for games.  If your system has a local games
-   directory, you'll need to change these.
-   3. Edit file "pathname.c" and make sure the file names and port
-   numbers are reasonable.  You can ignore the first set
-   of variables as they are used only for debugging
-   purposes.  The second set is used in the installed
-   version of hunt.  The important variables are "Driver"
-   (where the server is kept), "Test_port" (the Internet
-   UDP port number that new players should use to contact
-   the server), and "Stat_file" (where scoring statistics
-   and body counts are written).  The only tricky variable
-   here is "Test_port".  The default value is chosen so
-   that it is unlikely to conflict with other service port
-   numbers, but you can change it if you want to.
-   4. Type "make install", which will compile and install the
-   programs and manual pages.  Now you're almost ready to
-   go (see next section).  There may be some warnings during
-   compilation.  Ignore them.
-
 Setting up the network:
 
Hunt may be set up in one of three modes: standalone, inetd, or
@@ -121,12 +68,12 @@ Setting up the network:
server machine.  THERE SHOULD ONLY BE ONE SERVER MACHINE!
 
# start up the hunt daemon if present
-   if [ -f /usr/games/lib/huntd ]; then
-   /usr/games/lib/huntd -s & (echo -n ' huntd')>/dev/console
+   if [ -f /usr/games/huntd ]; then
+   /usr/games/huntd -s & (echo -n ' huntd')>/dev/console
fi
 
Also, you should start one up (on the off chance that you will
-   want to test this mess :-) by typing "/usr/games/lib/hunt -s".
+   want to test this mess :-) by typing "/usr/games/hunt -s".
 
-
 
@@ -140,7 +87,7 @@ Setting up the network:
that variable, then you should put whatever value you used here
as well.  In /etc/inetd.conf, add the line
 
-   huntdgram   udp waitnobody  /usr/games/lib/huntdhuntd
+   huntdgram   udp waitnobody  /usr/games/huntdhuntd
 
This works for 4.3BSD.  I don't remember the configuration file
format for 4.2BSD inetd.

-- 
Michal Mazurek



Re: wsfont: remove iso7/pcvt encoding macros and entries

2017-06-13 Thread Miod Vallat

> Hi tech@,
>
> We do not support iso7 nor pcvt encoding, so remove macro definitions
> and commented entries.

If you do that, then you can probably optimize away
vga_valid_primary_font() in sys/dev/ic/vga.c as well.



Re: sed(1): missing NUL in pattern space

2017-06-13 Thread kshe
On Sat, 10 Jun 2017 10:25:27 +, Otto Moerbeek wrote:
> Thanks for the analysis and diff, I hope to get a chanche to think
> about this soon. At least I'll make sure this diff is not forgotten,
> -Otto

I have seen the tests that you recently added to the tree; in the mean
time, however, while I continued experimenting and reading the source, I
discovered more bugs (as expected), as well as other trivial issues
which might be worthy of note before committing any real fixes.

First of all, my comprehension of the `c' command has slightly changed
since my last message: I now think its behaviour should be aligned with
that of `p', `P', `w' and others, all of which produce no output after
`c', treating a deleted pattern space as truly inexistent, and not
merely as an empty one.  It would hence appear more coherent to add

if (pd)
break;

before calling lputs(), as is done in many other places.  This would
then change the expected output of one of the newly added tests.

In general though, that `c' command is a big mess.  It is supposed to
delete the pattern space: in other implementations of sed that I have
tested, that means it will essentially behave like `i' followed by `d'.
In BSD's sed, however, it continues processing commands...  Here's one
of the many bugs that arise because of that:

$ echo abc | sed 'c\
> text
> s/.*/x/
> p
> s/.*/y/
> p'
text
x

So why isn't `y' printed too?  In comparison, using flags instead of
standalone commands:

$ echo abc | sed 'c\
> text
> s/.*/x/p
> s/.*/y/p'
text
x
y

Here, we do get a `y', but only one (there should be two given that `-n'
has not been supplied to suppress normal output).  Since at least `p' as
a flag given to `s' appears to work, let us try the same with `w':

$ echo abc | sed 'c\
> text
> s/.*/x/w /tmp/sed.out
> s/.*/y/w /tmp/sed.out'
text
$ cat /tmp/sed.out
x

But this time it doesn't work.  Now add a third `s' command...

$ echo abc | sed 'c\
> text
> s/.*/x/w /tmp/sed.out
> s/.*/y/w /tmp/sed.out
> s/.*/z/w /tmp/sed.out'
text
z
$ cat /tmp/sed.out
x
z

And it works.  Well, not really: we do see a `z', but still no `y'.
Indeed, this does not make any sense.

The reason for this strange behaviour is nevertheless easy to figure out
when looking at how `s' is implemented, keeping in mind that the
substitute space is globally defined.  In any case, even if one was to
fix that particular bug, I would probably be able to find more.  This is
why I believe that the only sane solution is that, just like `d', `c'
should simply

goto new;

which would, at the same time, obviate the need for the `deleted' field
of the SPACE structure, subsequently allowing for substantial cleanups.

Also, aside of that `c' mess, there is still the fact that NUL bytes
originally present in the input are not well handled at all.  Of course,
`l' cannot print past them (whereas `p' can), which is a shame; but
significantly worse is the inconsistent behaviour of `s' in that case.
At first, it seems to work well (in the output, `^@' represents a NUL):

$ printf 'x\0y' | sed 's/x/_/'
_^@y

It can even handle some empty matches perfectly:

$ printf 'x\0y' | sed 's/[[:<:]]/_/' # pattern space survives
_x^@y

But not all of them:

$ printf 'x\0y' | sed 's/[[:>:]]/_/' # pattern space is cut off
x_
$ printf 'x\0y' | sed 's/[[:>:]]/_/2' # likewise
x

One might argue that NUL bytes are not supposed to happen in textual
input, so that these examples are irrelevant; the real problem however
is that it also affects newlines, thus perfectly valid text:

$ printf 'x\ny' | sed 'N;s/[[:<:]]/_/'
_x
y
$ printf 'x\ny' | sed 'N;s/[[:>:]]/_/'
x_
$ printf 'x\ny' | sed 'N;s/[[:>:]]/_/2'
x

So maybe substitute() should test for (slen == 0) instead of the
questionable (*s == '\0' || *s == '\n').  That would seem more correct
to me, but this is only a guess since I must admit that I don't fully
understand that part of the code yet.  Here is a diff, for instance,
that fixes all the above issues.

--- a/src/usr.bin/sed/process.c Wed Jun  7 09:56:20 2017
+++ b/src/usr.bin/sed/process.c Tue Jun 13 07:21:59 2017
@@ -387,14 +388,11 @@ substitute(struct s_command *cp)
 * and at the end of the line, terminate.
 */
if (match[0].rm_so == match[0].rm_eo) {
-   if (*s == '\0' || *s == '\n')
-   slen = -1;
-   else
-   slen--;
-   if (*s != '\0') {
-   cspace(, s++, 1, APPEND);
-   le++;
-  

wsfont: remove iso7/pcvt encoding macros and entries

2017-06-13 Thread Frederic Cambus
Hi tech@,

We do not support iso7 nor pcvt encoding, so remove macro definitions
and commented entries.

Comments? OK?

Index: sys/dev/wscons/wsconsio.h
===
RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
retrieving revision 1.82
diff -u -p -r1.82 wsconsio.h
--- sys/dev/wscons/wsconsio.h   13 Jun 2017 08:00:24 -  1.82
+++ sys/dev/wscons/wsconsio.h   13 Jun 2017 08:41:20 -
@@ -506,8 +506,6 @@ struct wsdisplay_font {
int encoding;
 #define WSDISPLAY_FONTENC_ISO 0
 #define WSDISPLAY_FONTENC_IBM 1
-#define WSDISPLAY_FONTENC_PCVT 2
-#define WSDISPLAY_FONTENC_ISO7 3 /* greek */
u_int fontwidth, fontheight, stride;
 #define WSDISPLAY_MAXFONTSZ(512*1024)
int bitorder, byteorder;
Index: usr.sbin/wsfontload/wsfontload.c
===
RCS file: /cvs/src/usr.sbin/wsfontload/wsfontload.c,v
retrieving revision 1.16
diff -u -p -r1.16 wsfontload.c
--- usr.sbin/wsfontload/wsfontload.c6 Sep 2015 20:07:46 -   1.16
+++ usr.sbin/wsfontload/wsfontload.c13 Jun 2017 08:41:21 -
@@ -75,10 +75,6 @@ static const struct {
 } encodings[] = {
{"iso",  WSDISPLAY_FONTENC_ISO},
{"ibm",  WSDISPLAY_FONTENC_IBM},
-#if 0
-   {"pcvt", WSDISPLAY_FONTENC_PCVT},
-   {"iso7", WSDISPLAY_FONTENC_ISO7},
-#endif
 };
 
 int



Re: Copying a file on msdos FS (fat32) changes content

2017-06-13 Thread Martijn Rijkeboer
On 06/12/17 21:41, Stefan Fritsch wrote:
> On Mon, 12 Jun 2017, Martijn Rijkeboer wrote:
>> After upgrading to the latest snapshot there seems to be something wrong
>> with the msdos filesystem driver. When I copy a binary file on a msdos 
>> (fat32)
>> mounted partition the content changes e.g.:
>>
>>   # cp refind_x64.efi bootx64.efi
>>   # ls -l refind_x64.efi bootx64.efi
>>   -rw-r--r--  1 root  wheel  230856 Jun 12 10:47 bootx64.efi
>>   -rw-r--r--  1 root  wheel  230856 Mar  9 11:09 refind_x64.efi
>>   # sha256 refind_x64.efi bootx64.efi
>>   SHA256 (refind_x64.efi) =
>>   9c9a38f168fed270c158ff5a68d3fa5172eb15bcb41662abf69faa13d2abc418
>>   SHA256 (bootx64.efi) =
>>   26f7350143cc897d53b0257dbf5d9f1d84eace4746cbd9f2ff95a033ee0c577f
> 
> Sigh.
> 
> Please try if the attached patch fixes the problem. It reverts a likely 
> culprit.

Yes, this patch fixes the problem.

Kind regards,


Martijn Rijkeboer


> 
> Cheers,
> Stefan
> 
> diff --git sys/msdosfs/denode.h sys/msdosfs/denode.h
> index efa8192a06d..cdca90500ab 100644
> --- sys/msdosfs/denode.h
> +++ sys/msdosfs/denode.h
> @@ -1,4 +1,4 @@
> -/*   $OpenBSD: denode.h,v 1.31 2017/05/29 13:48:12 sf Exp $  */
> +/*   $OpenBSD: denode.h,v 1.30 2016/08/30 19:47:23 sf Exp $  */
>  /*   $NetBSD: denode.h,v 1.24 1997/10/17 11:23:39 ws Exp $   */
>  
>  /*-
> @@ -142,6 +142,7 @@ struct denode {
>   struct vnode *de_devvp; /* vnode of blk dev we live on */
>   uint32_t de_flag;   /* flag bits */
>   dev_t de_dev;   /* device where direntry lives */
> + daddr_t de_lastr;
>   uint32_t de_dirclust;   /* cluster of the directory file containing 
> this entry */
>   uint32_t de_diroffset;  /* offset of this entry in the directory 
> cluster */
>   uint32_t de_fndoffset;  /* offset of found dir entry */
> diff --git sys/msdosfs/msdosfs_vnops.c sys/msdosfs/msdosfs_vnops.c
> index 61b45af6185..39c60044df5 100644
> --- sys/msdosfs/msdosfs_vnops.c
> +++ sys/msdosfs/msdosfs_vnops.c
> @@ -1,4 +1,4 @@
> -/*   $OpenBSD: msdosfs_vnops.c,v 1.114 2017/05/29 13:48:12 sf Exp $  */
> +/*   $OpenBSD: msdosfs_vnops.c,v 1.113 2016/08/30 19:47:23 sf Exp $  */
>  /*   $NetBSD: msdosfs_vnops.c,v 1.63 1997/10/17 11:24:19 ws Exp $*/
>  
>  /*-
> @@ -77,13 +77,13 @@
>  
>  static uint32_t fileidhash(uint64_t);
>  
> -int msdosfs_bmaparray(struct vnode *, daddr_t, daddr_t *, int *);
>  int msdosfs_kqfilter(void *);
>  int filt_msdosfsread(struct knote *, long);
>  int filt_msdosfswrite(struct knote *, long);
>  int filt_msdosfsvnode(struct knote *, long);
>  void filt_msdosfsdetach(struct knote *);
>  
> +
>  /*
>   * Some general notes:
>   *
> @@ -509,14 +509,18 @@ int
>  msdosfs_read(void *v)
>  {
>   struct vop_read_args *ap = v;
> + int error = 0;
> + uint32_t diff;
> + int blsize;
> + int isadir;
> + uint32_t n;
> + long on;
> + daddr_t lbn, rablock, rablkno;
> + struct buf *bp;
>   struct vnode *vp = ap->a_vp;
>   struct denode *dep = VTODE(vp);
>   struct msdosfsmount *pmp = dep->de_pmp;
>   struct uio *uio = ap->a_uio;
> - int isadir, error = 0;
> - uint32_t n, diff, size, on;
> - struct buf *bp;
> - daddr_t cn, bn;
>  
>   /*
>* If they didn't ask for any data, then we are done.
> @@ -531,8 +535,7 @@ msdosfs_read(void *v)
>   if (uio->uio_offset >= dep->de_FileSize)
>   return (0);
>  
> - cn = de_cluster(pmp, uio->uio_offset);
> - size = pmp->pm_bpcluster;
> + lbn = de_cluster(pmp, uio->uio_offset);
>   on = uio->uio_offset & pmp->pm_crbomask;
>   n = ulmin(pmp->pm_bpcluster - on, uio->uio_resid);
>  
> @@ -545,22 +548,31 @@ msdosfs_read(void *v)
>   if (diff < n)
>   n = diff;
>  
> + /* convert cluster # to block # if a directory */
> + if (isadir) {
> + error = pcbmap(dep, lbn, , 0, );
> + if (error)
> + return (error);
> + }
>   /*
>* If we are operating on a directory file then be sure to
>* do i/o with the vnode for the filesystem instead of the
>* vnode for the directory.
>*/
>   if (isadir) {
> - error = pcbmap(dep, cn, , 0, );
> - if (error)
> - return (error);
> - error = bread(pmp->pm_devvp, cn, size, );
> + error = bread(pmp->pm_devvp, lbn, blsize, );
>   } else {
> - bn = de_cn2bn(pmp, cn);
> - if (de_cn2off(pmp, cn + 1) >= dep->de_FileSize)
> - error = bread(vp, bn, size, );
> + rablock = lbn + 1;
> + rablkno = de_cn2bn(pmp, rablock);
> + if (dep->de_lastr + 1 == lbn &&
> + 

Re: update logging in ifstated

2017-06-13 Thread Sebastian Benoit
Rob Pierce(r...@2keys.ca) on 2017.06.11 18:04:31 -0400:
> This minimizes differences with the latest log.c.
> 
> I was not sure how to handle verbosity, as the current implementation is
> verbose by default in debug mode. The diff below requires actually
> requesting (double) verbosity on the command line in order to retain the
> same behaviour (in debug mode).

Thanks.

can you redo this with the log.c from bgpd/ospfd/... ?
The difference is exactly in the handling of verbose, and that way we dont
change the -v semantics right now.

I havent unified the verbose handling yet, but if you diff them you'll see
its only a small difference now. My plan is to narrow all the log.c users
down to this small difference and then fix that in all of them in one go.

Also please add a log.h with the declarations just like in bgpd/ospfd/...

/Benno

> 
> Rob
> 
> Index: ifstated.c
> ===
> RCS file: /cvs/src/usr.sbin/ifstated/ifstated.c,v
> retrieving revision 1.41
> diff -u -p -r1.41 ifstated.c
> --- ifstated.c30 May 2013 19:22:48 -  1.41
> +++ ifstated.c11 Jun 2017 21:51:16 -
> @@ -32,10 +32,11 @@
>  #include 
>  #include 
>  
> +#include 
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -86,14 +87,12 @@ main(int argc, char *argv[])
>  {
>   struct timeval tv;
>   int ch;
> - int debug = 0;
> -
> - log_init(1);
> + int debug = 0, verbose = 0;
>  
>   while ((ch = getopt(argc, argv, "dD:f:hniv")) != -1) {
>   switch (ch) {
>   case 'd':
> - debug = 1;
> + debug = 2;
>   break;
>   case 'D':
>   if (cmdline_symset(optarg) < 0)
> @@ -113,6 +112,7 @@ main(int argc, char *argv[])
>   opt_inhibit = 1;
>   break;
>   case 'v':
> + verbose++;
>   if (opts & IFSD_OPT_VERBOSE)
>   opts |= IFSD_OPT_VERBOSE2;
>   opts |= IFSD_OPT_VERBOSE;
> @@ -122,6 +122,9 @@ main(int argc, char *argv[])
>   }
>   }
>  
> + /* log to stderr until daemonized */
> + log_init(debug ? debug : 1, LOG_DAEMON);
> +
>   argc -= optind;
>   argv += optind;
>   if (argc > 0)
> @@ -138,7 +141,8 @@ main(int argc, char *argv[])
>   daemon(1, 0);
>  
>   event_init();
> - log_init(debug);
> + log_init(debug, LOG_DAEMON);
> + log_setverbose(verbose);
>  
>   signal_set(_ev, SIGCHLD, sigchld_handler, NULL);
>   signal_add(_ev, NULL);
> @@ -169,12 +173,12 @@ startup_handler(int fd, short event, voi
>   rtfilter = ROUTE_FILTER(RTM_IFINFO);
>   if (setsockopt(rt_fd, PF_ROUTE, ROUTE_MSGFILTER,
>   , sizeof(rtfilter)) == -1) /* not fatal */
> - log_warn("startup_handler: setsockopt msgfilter");
> + log_warn("%s: setsockopt msgfilter", __func__);
>  
>   rtfilter = RTABLE_ANY;
>   if (setsockopt(rt_fd, PF_ROUTE, ROUTE_TABLEFILTER,
>   , sizeof(rtfilter)) == -1) /* not fatal */
> - log_warn("startup_handler: setsockopt tablefilter");
> + log_warn("%s: setsockopt tablefilter", __func__);
>   
>   event_set(_msg_ev, rt_fd, EV_READ|EV_PERSIST, rt_msg_handler, NULL);
>   event_add(_msg_ev, NULL);
> @@ -580,7 +584,7 @@ do_action(struct ifsd_action *action)
>   }
>   break;
>   default:
> - log_debug("do_action: unknown action %d", action->type);
> + log_debug("%s: unknown action %d", __func__, action->type);
>   break;
>   }
>  }
> Index: ifstated.h
> ===
> RCS file: /cvs/src/usr.sbin/ifstated/ifstated.h,v
> retrieving revision 1.10
> diff -u -p -r1.10 ifstated.h
> --- ifstated.h19 Jul 2016 08:04:53 -  1.10
> +++ ifstated.h11 Jun 2017 21:51:16 -
> @@ -137,7 +137,10 @@ int  cmdline_symset(char *);
>  void clear_config(struct ifsd_config *);
>  
>  /* log.c */
> -void log_init(int);
> +void log_init(int, int);
> +void log_procinit(const char *);
> +void log_setverbose(int);
> +int  log_getverbose(void);
>  void log_warn(const char *, ...)
>   __attribute__((__format__ (printf, 1, 2)));
>  void log_warnx(const char *, ...)
> @@ -146,9 +149,11 @@ void log_info(const char *, ...)
>   __attribute__((__format__ (printf, 1, 2)));
>  void log_debug(const char *, ...)
>   __attribute__((__format__ (printf, 1, 2)));
> -void vlog(int, const char *, va_list)
> - __attribute__((__format__ (printf, 2, 0)));
>  void logit(int, const char *, ...)
>   __attribute__((__format__ (printf, 2, 3)));
> -void fatal(const char *) __dead;
> -void fatalx(const char *) __dead;
>