Re: [bugfix] xterm(1) needs "cpath" pledge(2)

2018-07-29 Thread Sebastien Marie
On Sun, Jul 29, 2018 at 08:43:22AM +0200, Matthieu Herrb wrote:
> On Sun, Jul 29, 2018 at 07:28:19AM +0200, Sebastien Marie wrote:
> > 
> > but to decide, we should know *what* triggered this behaviour.
> 
> Hi,
> 
> After digging a bit, there is at least the 'Print All Immediatly'
> function from button 1 menu that will trigger the creation of a file
> and violate  the pledge.
> 
> see xtermPrintImmediately() in print.c:789. The fopen() itself appears
> in charToPrinter() on line 498 of the same file.

Hi Matthieu and Lauri,

I didn't expected someone else did the homework of Leonid so quickly :)
but thanks for digging in this problem.

> Should this feature be disabled in xterm ?

As xterm has an external upstream, just disabling the feature could be
annoying for future merges. And such feature could be legitimate too. I
would like to hear what others think about it.

The problem is this command doesn't have switch we could use to decide
if we add "cpath" in pledge(2) or not ; as we have already done for
exec-formated or exec-selectable commands and "exec" promise.


I wonder if unveil(2) could help here: unveiling for "cpath" only the
directory where file creation could occurs ? But I need to check some
points on unveil(2) first...

Thanks.
-- 
Sebastien Marie



pfctl: Simplify host()

2018-07-29 Thread Klemens Nanni
This gets rid of the `cont' flag and squashes the code a bit. `host_*()'
are pretty self explanatory so I zapped the comments as well.

Regress tests pass, no issues in production use.

Feedback? OK?

Index: pfctl_parser.c
===
RCS file: /cvs/src/sbin/pfctl/pfctl_parser.c,v
retrieving revision 1.324
diff -u -p -r1.324 pfctl_parser.c
--- pfctl_parser.c  28 Jul 2018 23:36:54 -  1.324
+++ pfctl_parser.c  29 Jul 2018 10:26:29 -
@@ -1628,7 +1628,7 @@ struct node_host *
 host(const char *s, int opts)
 {
struct node_host*h = NULL, *n;
-   int  mask = -1, v4mask = 32, v6mask = 128, cont = 1;
+   int  mask = -1, v4mask = 32, v6mask = 128;
char*p, *r, *ps, *if_name;
const char  *errstr;
 
@@ -1646,48 +1646,34 @@ host(const char *s, int opts)
mask = strtonum(p+1, 0, v6mask, &errstr);
if (errstr) {
fprintf(stderr, "netmask is %s: %s\n", errstr, p);
-   free(r);
-   free(ps);
-   return (NULL);
+   goto error;
}
p[0] = '\0';
v4mask = v6mask = mask;
} else
r = ps;
 
-   /* interface with this name exists? */
-   if (cont && (h = host_if(ps, mask)) != NULL)
-   cont = 0;
-
-   /* IPv4 address? */
-   if (cont && (h = host_v4(r, mask)) != NULL)
-   cont = 0;
-   if (r != ps)
-   free(r);
-
-   /* IPv6 address? */
-   if (cont && (h = host_v6(ps, v6mask)) != NULL)
-   cont = 0;
-
-   /* dns lookup */
-   if (cont && (h = host_dns(ps, v4mask, v6mask,
-   (opts & PF_OPT_NODNS))) != NULL)
-   cont = 0;
+   if ((h = host_if(ps, mask)) == NULL &&
+   (h = host_v4(r, mask)) == NULL &&
+   (h = host_v6(ps, v6mask)) == NULL &&
+   (h = host_dns(ps, v4mask, v6mask, (opts & PF_OPT_NODNS))) == NULL) {
+   fprintf(stderr, "no IP address found for %s\n", s);
+   goto error;
+   }
 
if (if_name && if_name[0])
for (n = h; n != NULL; n = n->next)
if ((n->ifname = strdup(if_name)) == NULL)
err(1, "host: strdup");
-
-   free(ps);   /* after we copy the name out */
-   if (h == NULL || cont == 1) {
-   fprintf(stderr, "no IP address found for %s\n", s);
-   return (NULL);
-   }
for (n = h; n != NULL; n = n->next) {
n->addr.type = PF_ADDR_ADDRMASK;
n->weight = 0;
}   
+
+error:
+   if (r != ps)
+   free(r);
+   free(ps);
return (h);
 }
===
Stats: --- 28 lines 649 chars
Stats: +++ 14 lines 371 chars
Stats: -14 lines
Stats: -278 chars
 



Re: [bugfix] xterm(1) needs "cpath" pledge(2)

2018-07-29 Thread Theo de Raadt
Matthieu Herrb  wrote:

> > but to decide, we should know *what* triggered this behaviour.
> 
> Hi,
> 
> After digging a bit, there is at least the 'Print All Immediatly'
> function from button 1 menu that will trigger the creation of a file
> and violate  the pledge.
> 
> see xtermPrintImmediately() in print.c:789. The fopen() itself appears
> in charToPrinter() on line 498 of the same file.
> 
> Should this feature be disabled in xterm ?

that's probably the best approach.

Our goal is to have the safest xterm possible, rather than an xterm with
features used by less than 0.001% of people, perhaps once every few
months (I am estimating).



Re: [bugfix] xterm(1) needs "cpath" pledge(2)

2018-07-29 Thread Leonid Bobrov
Lauri, Matthieu, thank you for saving me the trouble having to read and
understand the code of this big fat hippopotamus.

So, that means somehow I actually accidentally pressed annoying touchpad
and was lucky enough to click "Print-All Immediately" without noticing
that... I regret that I've sent previous messages (I had a feeling it's
a mistake to send them from the beginning), especially Theo's reaction
made me irritated. I am happy to realise I don't use coloured cursors. I
hope starting thread about this problem didn't hurt anyone besides Theo.

(sarcasm): My mails explicitly show that I am asshole which uses
community as unpaid workforce, today Matthieu and Lauri have made
everything for me.



Re: stop using WSMOUSE_TYPE_ELANTECH in other drivers (xenocara)

2018-07-29 Thread Ulf Brosziewski
It's still possible to use synaptics as alternative to ws.  The
new type would break such a configuration for ubcmtp, iatp, and
hidmt.  I think as long as it doesn't take too much efforts, we
should keep synaptics up to date and add the diff below to this
one.  However, I don't insist on that, so

ok bru@ (either way)


On 07/27/2018 10:00 PM, joshua stein wrote:
> And here is the xenocara part.
> 
> Index: xserver/config/wscons.c
> ===
> RCS file: /cvs/xenocara/xserver/config/wscons.c,v
> retrieving revision 1.21
> diff -u -p -u -p -r1.21 wscons.c
> --- xserver/config/wscons.c   8 Dec 2017 15:02:00 -   1.21
> +++ xserver/config/wscons.c   27 Jul 2018 19:54:17 -
> @@ -239,6 +239,7 @@ wscons_add_pointers(void)
>case WSMOUSE_TYPE_ALPS:
>case WSMOUSE_TYPE_ELANTECH:
>case WSMOUSE_TYPE_SYNAP_SBTN:
> +  case WSMOUSE_TYPE_TOUCHPAD:
>  wscons_add_pointer(devnam, "ws",
> ATTR_TOUCHPAD);
>  break;
> 
> 

Index: driver/xf86-input-synaptics/src/wsconscomm.c
===
RCS file: /cvs/xenocara/driver/xf86-input-synaptics/src/wsconscomm.c,v
retrieving revision 1.17
diff -u -p -r1.17 wsconscomm.c
--- driver/xf86-input-synaptics/src/wsconscomm.c7 Mar 2017 19:07:56 
-   1.17
+++ driver/xf86-input-synaptics/src/wsconscomm.c29 Jul 2018 12:25:48 
-
@@ -71,7 +71,8 @@ WSConsIsTouchpad(InputInfoPtr pInfo, con
 if (wsmouse_type == WSMOUSE_TYPE_SYNAPTICS ||
 wsmouse_type == WSMOUSE_TYPE_SYNAP_SBTN ||
 wsmouse_type == WSMOUSE_TYPE_ALPS ||
-wsmouse_type == WSMOUSE_TYPE_ELANTECH)
+wsmouse_type == WSMOUSE_TYPE_ELANTECH ||
+wsmouse_type == WSMOUSE_TYPE_TOUCHPAD)
 rc = TRUE;

 out:
@@ -357,6 +358,8 @@ WSConsReadDevDimensions(InputInfoPtr pIn
 priv->has_double = FALSE;
 priv->has_triple = FALSE;
 break;
+case WSMOUSE_TYPE_TOUCHPAD:
+/* Use Elantech settings for the generic type. */
 case WSMOUSE_TYPE_ELANTECH:
 priv->model = MODEL_ELANTECH;
 priv->has_width = TRUE;



Re: stop using WSMOUSE_TYPE_ELANTECH in other drivers

2018-07-29 Thread Ulf Brosziewski
ok bru@ (but please see my comments on the second diff)

On 07/27/2018 09:59 PM, joshua stein wrote:
> Back when touchpad drivers were using the synaptics Xorg driver, 
> they had to pretend to be Elantech devices in order to get 
> particular packet processing.
> 
> Since Ulf switched us to wstpad and xf86-input-ws a while ago, these 
> drivers can stop claiming to be WSMOUSE_TYPE_ELANTECH devices and 
> use a common WSMOUSE_TYPE_TOUCHPAD.
> 
> This also makes the WSMOUSEIO_GTYPE ioctl in those drivers respond 
> with whatever is stored in the softc to avoid repeating ourselves 
> (or possibly responding incorrectly).
> 
> There's also a corresponding xenocara diff coming after this.
> 
> 
> Index: sys/dev/hid/hidmt.c
> ===
> RCS file: /cvs/src/sys/dev/hid/hidmt.c,v
> retrieving revision 1.6
> diff -u -p -u -p -r1.6 hidmt.c
> --- sys/dev/hid/hidmt.c   10 Oct 2017 20:31:50 -  1.6
> +++ sys/dev/hid/hidmt.c   27 Jul 2018 19:53:59 -
> @@ -235,7 +235,7 @@ hidmt_configure(struct hidmt *mt)
>   return;
>  
>   hw = wsmouse_get_hw(mt->sc_wsmousedev);
> - hw->type = WSMOUSE_TYPE_ELANTECH;   /* see hidmt_ioctl */
> + hw->type = WSMOUSE_TYPE_TOUCHPAD;
>   hw->hw_type = (mt->sc_clickpad
>   ? WSMOUSEHW_CLICKPAD : WSMOUSEHW_TOUCHPAD);
>   hw->x_min = mt->sc_minx;
> @@ -468,13 +468,11 @@ hidmt_ioctl(struct hidmt *mt, u_long cmd
>   int wsmode;
>  
>   switch (cmd) {
> - case WSMOUSEIO_GTYPE:
> - /*
> -  * So we can specify our own finger/w values to the
> -  * xf86-input-synaptics driver like pms(4)
> -  */
> - *(u_int *)data = WSMOUSE_TYPE_ELANTECH;
> + case WSMOUSEIO_GTYPE: {
> + struct wsmousehw *hw = wsmouse_get_hw(mt->sc_wsmousedev);
> + *(u_int *)data = hw->type;
>   break;
> + }
>  
>   case WSMOUSEIO_GCALIBCOORDS:
>   wsmc->minx = mt->sc_minx;
> Index: sys/dev/i2c/iatp.c
> ===
> RCS file: /cvs/src/sys/dev/i2c/iatp.c,v
> retrieving revision 1.5
> diff -u -p -u -p -r1.5 iatp.c
> --- sys/dev/i2c/iatp.c22 Jun 2018 15:58:26 -  1.5
> +++ sys/dev/i2c/iatp.c27 Jul 2018 19:53:59 -
> @@ -325,7 +325,7 @@ iatp_configure(struct iatp_softc *sc)
>  
>   hw = wsmouse_get_hw(sc->sc_wsmousedev);
>   if (sc->sc_touchpad) {
> - hw->type = WSMOUSE_TYPE_SYNAPTICS;
> + hw->type = WSMOUSE_TYPE_TOUCHPAD;
>   hw->hw_type = WSMOUSEHW_CLICKPAD;
>   } else {
>   hw->type = WSMOUSE_TYPE_TPANEL;
> @@ -415,12 +415,11 @@ iatp_ioctl(void *v, u_long cmd, caddr_t 
>   wsmc->resy = sc->sc_tsscale.resy;
>   break;
>  
> - case WSMOUSEIO_GTYPE:
> - if (sc->sc_touchpad)
> - *(u_int *)data = WSMOUSE_TYPE_SYNAPTICS;
> - else
> - *(u_int *)data = WSMOUSE_TYPE_TPANEL;
> + case WSMOUSEIO_GTYPE: {
> + struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
> + *(u_int *)data = hw->type;
>   break;
> + }
>  
>   case WSMOUSEIO_SETMODE:
>   if (!sc->sc_touchpad)
> Index: sys/dev/usb/ubcmtp.c
> ===
> RCS file: /cvs/src/sys/dev/usb/ubcmtp.c,v
> retrieving revision 1.17
> diff -u -p -u -p -r1.17 ubcmtp.c
> --- sys/dev/usb/ubcmtp.c  6 Jun 2017 21:53:07 -   1.17
> +++ sys/dev/usb/ubcmtp.c  27 Jul 2018 19:53:59 -
> @@ -521,7 +521,7 @@ ubcmtp_configure(struct ubcmtp_softc *sc
>  {
>   struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
>  
> - hw->type = WSMOUSE_TYPE_ELANTECH;   /* see ubcmtp_ioctl */
> + hw->type = WSMOUSE_TYPE_TOUCHPAD;
>   hw->hw_type = (IS_CLICKPAD(sc->dev_type->type)
>   ? WSMOUSEHW_CLICKPAD : WSMOUSEHW_TOUCHPAD);
>   hw->x_min = sc->dev_type->l_x.min;
> @@ -601,11 +601,11 @@ ubcmtp_ioctl(void *v, unsigned long cmd,
>   cmd);
>  
>   switch (cmd) {
> - case WSMOUSEIO_GTYPE:
> - /* so we can specify our own finger/w values to the
> -  * xf86-input-synaptics driver like pms(4) */
> - *(u_int *)data = WSMOUSE_TYPE_ELANTECH;
> + case WSMOUSEIO_GTYPE: {
> + struct wsmousehw *hw = wsmouse_get_hw(sc->sc_wsmousedev);
> + *(u_int *)data = hw->type;
>   break;
> + }
>  
>   case WSMOUSEIO_GCALIBCOORDS:
>   wsmc->minx = sc->dev_type->l_x.min;
> Index: sys/dev/wscons/wsconsio.h
> ===
> RCS file: /cvs/src/sys/dev/wscons/wsconsio.h,v
> retrieving revision 1.88
> diff -u -p -u -p -r1.88 wsconsio.h
> --- sys/dev/wscons/wsconsio.h 7 May 2018 21:58:42 -   1.88
> +++ sys/dev/wscons/wsconsio.h 27 Jul 2018 19

remove uaudio_id_name()

2018-07-29 Thread Michael W. Bombardieri
Hello,

The function uaudio_id_name() was used once for formatting a string
and its return value was used to format a second string. By rolling
the prepended letter "i" into the outer snprintf() the function can
be removed entirely. Does this look correct?

- Michael


Index: uaudio.c
===
RCS file: /cvs/src/sys/dev/usb/uaudio.c,v
retrieving revision 1.130
diff -u -p -u -r1.130 uaudio.c
--- uaudio.c27 Jul 2018 05:48:59 -  1.130
+++ uaudio.c29 Jul 2018 13:22:04 -
@@ -314,8 +314,6 @@ const usb_interface_descriptor_t *uaudio
(const char *, int, int *, int, int);
 
 void   uaudio_mixer_add_ctl(struct uaudio_softc *, struct mixerctl *);
-char   *uaudio_id_name
-   (struct uaudio_softc *, const struct io_terminal *, int);
 uByte  uaudio_get_cluster_nchan
(int, const struct io_terminal *);
 void   uaudio_add_input
@@ -672,14 +670,6 @@ uaudio_mixer_add_ctl(struct uaudio_softc
 #endif
 }
 
-char *
-uaudio_id_name(struct uaudio_softc *sc, const struct io_terminal *iot, int id)
-{
-   static char buf[32];
-   snprintf(buf, sizeof(buf), "i%d", id);
-   return (buf);
-}
-
 uByte
 uaudio_get_cluster_nchan(int id, const struct io_terminal *iot)
 {
@@ -805,9 +795,8 @@ uaudio_add_mixer(struct uaudio_softc *sc
mix.wValue[k++] =
MAKE(p+c+1, o+1);
}
-   snprintf(mix.ctlname, sizeof(mix.ctlname), "mix%d-%s",
-   d->bUnitId, uaudio_id_name(sc, iot,
-   d->baSourceId[i]));
+   snprintf(mix.ctlname, sizeof(mix.ctlname), "mix%d-i%d",
+   d->bUnitId, d->baSourceId[i]);
mix.nchan = chs;
uaudio_mixer_add_ctl(sc, &mix);
} else {



Re: remove uaudio_id_name()

2018-07-29 Thread Klemens Nanni
On Sun, Jul 29, 2018 at 09:31:51PM +0800, Michael W. Bombardieri wrote:
> The function uaudio_id_name() was used once for formatting a string
> and its return value was used to format a second string. By rolling
> the prepended letter "i" into the outer snprintf() the function can
> be removed entirely. Does this look correct?
No other users, `*sc' and `*iot' are already unused... looks good to me.



Re: paste(1): use getline instead of fgetln

2018-07-29 Thread Ingo Schwarze
Hi,

Lauri Tirkkonen wrote on Tue, Jul 17, 2018 at 09:14:29PM +0300:

> In the same vein as my previous diff for join(1),
> make paste(1) use getline instead of fgetln.

I think it's correct, but i tweaked it a bit for simplicity.

In sequential(), the double loop with double getline(), both with
error handling etc. etc. really felt too ugly to me, so i reduced
it to one simple loop with one call to getline().

In parallel(), tweaks are minimal:

 * sorted declarations
 * print the filename in case of I/O errors, unless it's stdin
 * simplify printf(3) to fputs(3)

So i'd like to commit the following version.

OK?
  Ingo

P.S.
Final diff is -44 +31 (-5% of the whole program).
I love make stuff better and smaller at the same time.


Index: paste.c
===
RCS file: /cvs/src/usr.bin/paste/paste.c,v
retrieving revision 1.23
diff -u -p -r1.23 paste.c
--- paste.c 2 Jan 2018 06:56:41 -   1.23
+++ paste.c 29 Jul 2018 15:21:02 -
@@ -104,11 +104,11 @@ parallel(char **argv)
 {
SIMPLEQ_HEAD(, list) head = SIMPLEQ_HEAD_INITIALIZER(head);
struct list *lp;
+   char *line, *p;
+   size_t len, linesize;
int cnt;
-   char ch, *p;
int opencnt, output;
-   char *buf, *lbuf;
-   size_t len;
+   char ch;
 
for (cnt = 0; (p = *argv); ++argv, ++cnt) {
if (!(lp = malloc(sizeof(struct list
@@ -123,17 +123,22 @@ parallel(char **argv)
SIMPLEQ_INSERT_TAIL(&head, lp, entries);
}
 
+   line = NULL;
+   linesize = 0;
+
for (opencnt = cnt; opencnt;) {
output = 0;
SIMPLEQ_FOREACH(lp, &head, entries) {
-   lbuf = NULL;
if (!lp->fp) {
if (output && lp->cnt &&
(ch = delim[(lp->cnt - 1) % delimcnt]))
putchar(ch);
continue;
}
-   if (!(buf = fgetln(lp->fp, &len))) {
+   if ((len = getline(&line, &linesize, lp->fp)) == -1) {
+   if (ferror(lp->fp))
+   err(1, "%s", lp->fp == stdin ?
+   "getline" : lp->name);
if (!--opencnt)
break;
if (lp->fp != stdin)
@@ -144,15 +149,8 @@ parallel(char **argv)
putchar(ch);
continue;
}
-   if (buf[len - 1] == '\n')
-   buf[len - 1] = '\0';
-   else {
-   if ((lbuf = malloc(len + 1)) == NULL)
-   err(1, "malloc");
-   memcpy(lbuf, buf, len);
-   lbuf[len] = '\0';
-   buf = lbuf;
-   }
+   if (line[len - 1] == '\n')
+   line[len - 1] = '\0';
/*
 * make sure that we don't print any delimiters
 * unless there's a non-empty file.
@@ -164,59 +162,49 @@ parallel(char **argv)
putchar(ch);
} else if ((ch = delim[(lp->cnt - 1) % delimcnt]))
putchar(ch);
-   (void)printf("%s", buf);
-   if (lbuf)
-   free(lbuf);
+   fputs(line, stdout);
}
if (output)
putchar('\n');
}
+   free(line);
 }
 
 void
 sequential(char **argv)
 {
FILE *fp;
+   char *line, *p;
+   size_t len, linesize;
int cnt;
-   char ch, *p, *dp;
-   char *buf, *lbuf;
-   size_t len;
 
+   line = NULL;
+   linesize = 0;
for (; (p = *argv); ++argv) {
-   lbuf = NULL;
if (p[0] == '-' && !p[1])
fp = stdin;
else if (!(fp = fopen(p, "r"))) {
warn("%s", p);
continue;
}
-   if ((buf = fgetln(fp, &len))) {
-   for (cnt = 0, dp = delim;;) {
-   if (buf[len - 1] == '\n')
-   buf[len - 1] = '\0';
-   else {
-   if ((lbuf = malloc(len + 1)) == NULL)
-   err(1, "malloc");
-   memcpy(lbuf, buf, len);
-   lbuf[len] = '\0';
- 

Re: [bugfix] xterm(1) needs "cpath" pledge(2)

2018-07-29 Thread lists
Sun, 29 Jul 2018 15:46:20 +0300 (EEST) Leonid Bobrov 
> Lauri, Matthieu, thank you for saving me the trouble having to read and
> understand the code of this big fat hippopotamus.
> 
> So, that means somehow I actually accidentally pressed annoying touchpad
> and was lucky enough to click "Print-All Immediately" without noticing
> that... I regret that I've sent previous messages (I had a feeling it's
> a mistake to send them from the beginning), especially Theo's reaction
> made me irritated. I am happy to realise I don't use coloured cursors. I
> hope starting thread about this problem didn't hurt anyone besides Theo.

Hi Leonid,

It's very appropriate for chat sessions obviously debug one this is not.
Hope you can leave your sarcasm out for the next round of ports testing.

Kind regards,
Anton Lazarov

> (sarcasm): My mails explicitly show that I am asshole which uses
> community as unpaid workforce, today Matthieu and Lauri have made
> everything for me.
> 




[diff] acme-client - clean up main.c

2018-07-29 Thread Ross L Richardson


[This diff is very similar to one I sent previously off-list to a few.]

Just some style(9) and simple cleanup:
- order getopt string and switch cases
- add space between "if" and "("
- wrap a long line
- return rather than exit() from main()
- move chngdir == NULL test to where it belongs


Questions:

- is there any reason
   404  /* Jail: sandbox, file-system, user. */
   405  
   406  if (pledge("stdio", NULL) == -1) {
   407  warn("pledge");
   408  exit(EXIT_FAILURE);
   409  }
   410  
  shouldn't just use err() ?
  If so, then the exit() should still be return, shouldn't it?

- should the exit() calls from the various forked child processes
  be _exit()?



Index: main.c
===
RCS file: /cvs/src/usr.sbin/acme-client/main.c,v
retrieving revision 1.36
diff -u -p -r1.36 main.c
--- main.c  27 Nov 2017 01:58:52 -  1.36
+++ main.c  30 Jul 2018 01:12:45 -
@@ -56,21 +56,24 @@ main(int argc, char *argv[])
struct domain_c *domain = NULL;
struct altname_c*ac;
 
-   while ((c = getopt(argc, argv, "FADrvnf:")) != -1)
+   while ((c = getopt(argc, argv, "ADFf:nrv")) != -1)
switch (c) {
-   case 'f':
-   if ((conffile = strdup(optarg)) == NULL)
-   err(EXIT_FAILURE, "strdup");
-   break;
-   case 'F':
-   force = 1;
-   break;
case 'A':
popts |= ACME_OPT_NEWACCT;
break;
case 'D':
popts |= ACME_OPT_NEWDKEY;
break;
+   case 'F':
+   force = 1;
+   break;
+   case 'f':
+   if ((conffile = strdup(optarg)) == NULL)
+   err(EXIT_FAILURE, "strdup");
+   break;
+   case 'n':
+   popts |= ACME_OPT_CHECK;
+   break;
case 'r':
revocate = 1;
break;
@@ -78,9 +81,6 @@ main(int argc, char *argv[])
verbose = verbose ? 2 : 1;
popts |= ACME_OPT_VERBOSE;
break;
-   case 'n':
-   popts |= ACME_OPT_CHECK;
-   break;
default:
goto usage;
}
@@ -90,7 +90,7 @@ main(int argc, char *argv[])
 
/* parse config file */
if ((conf = parse_config(conffile, popts)) == NULL)
-   exit(EXIT_FAILURE);
+   return EXIT_FAILURE;
 
argc -= optind;
argv += optind;
@@ -127,7 +127,7 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "basename");
}
 
-   if(domain->chain != NULL) {
+   if (domain->chain != NULL) {
if ((chainfile = basename(domain->chain)) != NULL) {
if ((chainfile = strdup(chainfile)) == NULL)
err(EXIT_FAILURE, "strdup");
@@ -135,7 +135,7 @@ main(int argc, char *argv[])
err(EXIT_FAILURE, "basename");
}
 
-   if(domain->fullchain != NULL) {
+   if (domain->fullchain != NULL) {
if ((fullchainfile = basename(domain->fullchain)) != NULL) {
if ((fullchainfile = strdup(fullchainfile)) == NULL)
err(EXIT_FAILURE, "strdup");
@@ -160,14 +160,12 @@ main(int argc, char *argv[])
/* XXX replace with existance check in parse.y */
err(EXIT_FAILURE, "no account key in config?");
}
-   if (domain->challengedir == NULL)
-   chngdir = strdup(WWW_DIR);
-   else
+   if (domain->challengedir == NULL) {
+   if ((chngdir = strdup(WWW_DIR)) == NULL)
+   err(EXIT_FAILURE, "strdup");
+   } else
chngdir = domain->challengedir;
 
-   if (chngdir == NULL)
-   err(EXIT_FAILURE, "strdup");
-
/*
 * Do some quick checks to see if our paths exist.
 * This will be done in the children, but we might as well check
@@ -185,7 +183,8 @@ main(int argc, char *argv[])
if (!(popts & ACME_OPT_NEWDKEY) && access(domain->key, R_OK) == -1) {
warnx("%s: domain key file must exist", domain->key);
ne++;
-   } else if ((popts & ACME_OPT_NEWDKEY) && access(domain->key, R_OK) != 
-1) {
+   } else if ((popts & ACME_OPT_NEWDKEY) && access(domain->key, R_OK)
+   != -1) {
dodbg("%s: domain key exists (not creating)", domain->key);
popts &= ~ACME_OPT_NEWDKEY;
}
@@ -204,10 +203,10 @@ main(int argc, char *argv[])
   

Re: Make systat(1) more human readable

2018-07-29 Thread Martijn van Duren
Just got some positive user feedback off-list.
Any takers?

On 02/11/18 13:48, Martijn van Duren wrote:
> Some documentation nits found by jmc.
> 
> On 02/11/18 12:31, Martijn van Duren wrote:
>> Hello tech@,
>>
>> Since my brain is incapable of quickly processing numbers larger than a
>> million (even with the thousand separators enabled), I would like to
>> introduce the -h flag to systat.
>> In order not to loose too much information I do the rollover at values  
>> from 10. up.
>> I didn't use fmt_scaled, because it's intended for bytecounts and it's
>> inside libutil, which isn't linked to systat.
>>
>> It's possible to toggle it at runtime via the "human" command, but I
>> didn't add a single letter switch, since that space is already quite
>> crammed.
>>
>> OK?
>>
>> martijn@
>>
> 
> Index: engine.c
> ===
> RCS file: /cvs/src/usr.bin/systat/engine.c,v
> retrieving revision 1.22
> diff -u -p -r1.22 engine.c
> --- engine.c  8 Feb 2018 07:00:33 -   1.22
> +++ engine.c  11 Feb 2018 12:46:19 -
> @@ -52,6 +52,7 @@ struct view_ent {
>  
>  useconds_t udelay = 500;
>  int dispstart = 0;
> +int humanreadable = 0;
>  int interactive = 1;
>  int averageonly = 0;
>  int maxprint = 0;
> @@ -717,6 +718,8 @@ void
>  print_fld_sdiv(field_def *fld, u_int64_t size, int d)
>  {
>   int len;
> + char *mult = "KMGTPE";
> + int i = -1;
>  
>   if (fld == NULL)
>   return;
> @@ -726,35 +729,21 @@ print_fld_sdiv(field_def *fld, u_int64_t
>   return;
>  
>   tb_start();
> - if (tbprintft("%llu", size) <= len)
> - goto ok;
> -
> - tb_start();
> - size /= d;
> - if (tbprintft("%lluK", size) <= len)
> - goto ok;
> - if (size == 0)
> - goto err;
> -
> - tb_start();
> - size /= d;
> - if (tbprintft("%lluM", size) <= len)
> - goto ok;
> - if (size == 0)
> - goto err;
> -
> - tb_start();
> - size /= d;
> - if (tbprintft("%lluG", size) <= len)
> - goto ok;
> - if (size == 0)
> - goto err;
> -
> - tb_start();
> - size /= d;
> - if (tbprintft("%lluT", size) <= len)
> - goto ok;
> - 
> + if (humanreadable) {
> + while (size >= 1 && sizeof(mult) >= i + 1) {
> + i++;
> + size /= d;
> + }
> + if (tbprintft("%llu%.1s", size, i == -1 ? "" : mult + i) <= len)
> + goto ok;
> + }
> + while (size != 0 && sizeof(mult) >= i + 1) {
> + tb_start();
> + if (tbprintft("%llu%.1s", size, i == -1 ? "" : mult + i) <= len)
> + goto ok;
> + i++;
> + size /= d;
> + }
>  err:
>   print_fld_str(fld, "*");
>   tb_end();
> Index: engine.h
> ===
> RCS file: /cvs/src/usr.bin/systat/engine.h,v
> retrieving revision 1.9
> diff -u -p -r1.9 engine.h
> --- engine.h  8 Feb 2018 07:00:33 -   1.9
> +++ engine.h  11 Feb 2018 12:46:19 -
> @@ -148,6 +148,7 @@ void foreach_view(void (*callback)(field
>  extern int sortdir;
>  extern useconds_t udelay;
>  extern int dispstart;
> +extern int humanreadable;
>  extern int interactive;
>  extern int averageonly;
>  extern int maxprint;
> Index: main.c
> ===
> RCS file: /cvs/src/usr.bin/systat/main.c,v
> retrieving revision 1.67
> diff -u -p -r1.67 main.c
> --- main.c8 Feb 2018 07:00:33 -   1.67
> +++ main.c11 Feb 2018 12:46:19 -
> @@ -212,7 +212,7 @@ void
>  usage(void)
>  {
>   extern char *__progname;
> - fprintf(stderr, "usage: %s [-aBbiNn] [-d count] "
> + fprintf(stderr, "usage: %s [-aBbhiNn] [-d count] "
>   "[-s delay] [-w width] [view] [delay]\n", __progname);
>   exit(1);
>  }
> @@ -305,6 +305,10 @@ cmd_compat(const char *buf)
>   need_update = 1;
>   return;
>   }
> + if (strncasecmp(buf, "human", 5) == 0) {
> + humanreadable = !humanreadable;
> + return;
> + }
>  
>   for (s = buf; *s && strchr("0123456789+-.eE", *s) != NULL; s++)
>   ;
> @@ -437,7 +441,7 @@ main(int argc, char *argv[])
>   if (setresgid(gid, gid, gid) == -1)
>   err(1, "setresgid");
>  
> - while ((ch = getopt(argc, argv, "BNabd:ins:w:")) != -1) {
> + while ((ch = getopt(argc, argv, "BNabd:hins:w:")) != -1) {
>   switch (ch) {
>   case 'a':
>   maxlines = -1;
> @@ -455,6 +459,9 @@ main(int argc, char *argv[])
>   countmax = strtonum(optarg, 1, INT_MAX, &errstr);
>   if (errstr)
>   errx(1, "-d %s: %s", optarg, errstr);
> + break;
> + case 'h':
> + 

Re: pfctl: Simplify host()

2018-07-29 Thread Alexandr Nedvedicky
Hello,

On Sun, Jul 29, 2018 at 12:35:22PM +0200, Klemens Nanni wrote:
> This gets rid of the `cont' flag and squashes the code a bit. `host_*()'
> are pretty self explanatory so I zapped the comments as well.
> 
> Regress tests pass, no issues in production use.
> 
> Feedback? OK?

reads OK to me.

regards
sashan