Re: umidi(4) jack count

2018-09-06 Thread Alexandre Ratchov
On Fri, Sep 07, 2018 at 12:40:49AM +0800, Michael Mikonos wrote:
> Hello,
> 
> The umidi(4) driver has three different endpoint allocation
> functions, which are called by alloc_all_endpoints(). The
> initial jack count can be moved here because it is zero
> no matter which allocation function is used.
> Also when we eventually free the jacks the count can
> be reset. Does this look OK?
> 

ok ratchov@



Re: umidi(4) jack count

2018-09-06 Thread Stefan Sperling
On Fri, Sep 07, 2018 at 12:40:49AM +0800, Michael Mikonos wrote:
> Hello,
> 
> The umidi(4) driver has three different endpoint allocation
> functions, which are called by alloc_all_endpoints(). The
> initial jack count can be moved here because it is zero
> no matter which allocation function is used.
> Also when we eventually free the jacks the count can
> be reset. Does this look OK?

Yes, it does.

> 
> - Michael
> 
> 
> Index: umidi.c
> ===
> RCS file: /cvs/src/sys/dev/usb/umidi.c,v
> retrieving revision 1.47
> diff -u -p -u -r1.47 umidi.c
> --- umidi.c   6 Sep 2018 09:48:23 -   1.47
> +++ umidi.c   6 Sep 2018 16:24:22 -
> @@ -387,6 +387,8 @@ alloc_all_endpoints(struct umidi_softc *
>   struct umidi_endpoint *ep;
>   int i;
>  
> + sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
> +
>   if (UMQ_ISTYPE(sc, UMQ_TYPE_FIXED_EP))
>   err = alloc_all_endpoints_fixed_ep(sc);
>   else if (UMQ_ISTYPE(sc, UMQ_TYPE_YAMAHA))
> @@ -436,8 +438,6 @@ alloc_all_endpoints_fixed_ep(struct umid
>  
>   fp = umidi_get_quirk_data_from_type(sc->sc_quirk,
>   UMQ_TYPE_FIXED_EP);
> - sc->sc_out_num_jacks = 0;
> - sc->sc_in_num_jacks = 0;
>   sc->sc_out_num_endpoints = fp->num_out_ep;
>   sc->sc_in_num_endpoints = fp->num_in_ep;
>   sc->sc_endpoints = mallocarray(sc->sc_out_num_endpoints +
> @@ -521,7 +521,6 @@ alloc_all_endpoints_yamaha(struct umidi_
>   int out_addr, in_addr, in_packetsize, i, dir;
>   size_t remain, descsize;
>  
> - sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
>   out_addr = in_addr = 0;
>  
>   /* detect endpoints */
> @@ -627,7 +626,6 @@ alloc_all_endpoints_genuine(struct umidi
>   if (!p)
>   return USBD_NOMEM;
>  
> - sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
>   sc->sc_out_num_endpoints = sc->sc_in_num_endpoints = 0;
>   epaddr = -1;
>  
> @@ -780,6 +778,7 @@ free_all_jacks(struct umidi_softc *sc)
>   if (sc->sc_out_jacks) {
>   free(sc->sc_jacks, M_USBDEV, jacks * sizeof(*sc->sc_out_jacks));
>   sc->sc_jacks = sc->sc_in_jacks = sc->sc_out_jacks = NULL;
> + sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
>   }
>   splx(s);
>  }
> 



Re: cp(1) Fix incomplete -i behaviour [1/3]

2018-09-06 Thread Stefan Sperling
On Fri, Aug 31, 2018 at 09:40:19AM +0200, Martijn van Duren wrote:
> Hello tech@,
> 
> While working on fixing the -iv behaviour yesterday I noticed that the  
> -i verification isn't implemented for the special copies and thus
> allowing to overwrite a file.
> I did some archaeology and found it was introduced by bostic in 1990,
> so the behaviour is here for over 28 years!
> 
> Since this is cp I split the diff in the smallest possible chunks for
> easier review. These diffs go on top of my diff send in yesterday[0].
> 
> 1) Implements the copy_overwrite function so we can reuse it in all
> functions.
> 2) Add the copy_overwrite function to copy_{link,fifo,special}
> 3) Change dne variable to exists for copy_file to be consistent with
> the naming in the other copy_* functions.
> 
> OK?

ok stsp@

> 
> martijn@
> 
> [0] https://marc.info/?l=openbsd-tech=153565590700590=2
> 
> diff --git utils.c utils.c
> index fdbf5a0..3a8d6b4 100644
> --- utils.c
> +++ utils.c
> @@ -47,13 +47,15 @@
>  
>  #include "extern.h"
>  
> +int copy_overwrite(void);
> +
>  int
>  copy_file(FTSENT *entp, int dne)
>  {
>   static char *buf;
>   static char *zeroes;
>   struct stat to_stat, *fs;
> - int ch, checkch, from_fd, rcount, rval, to_fd, wcount;
> + int from_fd, rcount, rval, to_fd, wcount;
>  #ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
>   char *p;
>  #endif
> @@ -84,7 +86,6 @@ copy_file(FTSENT *entp, int dne)
>   (void)unlink(to.p_path);
>  
>   /*
> -  * If the file exists and we're interactive, verify with the user.
>* If the file DNE, set the mode to be the from file, minus setuid
>* bits, modified by the umask; arguably wrong, but it makes copying
>* executables work right and it's been that way forever.  (The
> @@ -92,16 +93,10 @@ copy_file(FTSENT *entp, int dne)
>* modified by the umask.)
>*/
>   if (!dne && !fflag) {
> - if (iflag) {
> - (void)fprintf(stderr, "overwrite %s? ", to.p_path);
> - checkch = ch = getchar();
> - while (ch != '\n' && ch != EOF)
> - ch = getchar();
> - if (checkch != 'y' && checkch != 'Y') {
> - (void)close(from_fd);
> - return (2);
> - }
> - }
> + if (!copy_overwrite()) {
> + (void)close(from_fd);
> + return 2;
> + }
>   to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
>   } else
>   to_fd = open(to.p_path, O_WRONLY | O_TRUNC | O_CREAT,
> @@ -248,6 +243,24 @@ copy_special(struct stat *from_stat, int exists)
>   return (pflag ? setfile(from_stat, -1) : 0);
>  }
>  
> +/*
> + * If the file exists and we're interactive, verify with the user.
> + */
> +int
> +copy_overwrite(void)
> +{
> + int ch, checkch;
> +
> + if (iflag) {
> + (void)fprintf(stderr, "overwrite %s? ", to.p_path);
> + checkch = ch = getchar();
> + while (ch != '\n' && ch != EOF)
> + ch = getchar();
> + if (checkch != 'y' && checkch != 'Y')
> + return (0);
> + }
> + return 1;
> +}
>  
>  int
>  setfile(struct stat *fs, int fd)
> 



Re: cp(1) Fix incomplete -i behaviour [2/3]

2018-09-06 Thread Stefan Sperling
On Fri, Aug 31, 2018 at 09:42:08AM +0200, Martijn van Duren wrote:
> part 2
> 
> OK?

ok stsp@

> 
> martijn@
> 
> diff --git cp.c cp.c
> index 321e82f..fbf924c 100644
> --- cp.c
> +++ cp.c
> @@ -395,9 +395,9 @@ copy(char *argv[], enum op type, int fts_options)
>  
>   switch (curr->fts_statp->st_mode & S_IFMT) {
>   case S_IFLNK:
> - if (copy_link(curr, !fts_dne(curr)))
> + if ((cval = copy_link(curr, !fts_dne(curr))) == 1)
>   rval = 1;
> - else if (vflag)
> + if (!cval && vflag)
>   (void)fprintf(stdout, "%s -> %s\n",
>   curr->fts_path, to.p_path);
>   break;
> @@ -430,8 +430,8 @@ copy(char *argv[], enum op type, int fts_options)
>   case S_IFBLK:
>   case S_IFCHR:
>   if (Rflag) {
> - if (copy_special(curr->fts_statp,
> - !fts_dne(curr)))
> + if ((cval = copy_special(curr->fts_statp,
> + !fts_dne(curr))) == 1)
>   rval = 1;
>   } else {
>   cval = copy_file(curr, fts_dne(curr));
> @@ -445,7 +445,8 @@ copy(char *argv[], enum op type, int fts_options)
>   break;
>   case S_IFIFO:
>   if (Rflag) {
> - if (copy_fifo(curr->fts_statp, !fts_dne(curr)))
> + if ((cval = copy_fifo(curr->fts_statp,
> + !fts_dne(curr))) == 1)
>   rval = 1;
>   } else {
>   cval = copy_file(curr, fts_dne(curr));
> diff --git utils.c utils.c
> index 3a8d6b4..4a9219c 100644
> --- utils.c
> +++ utils.c
> @@ -199,6 +199,8 @@ copy_link(FTSENT *p, int exists)
>   int len;
>   char name[PATH_MAX];
>  
> + if (exists && !copy_overwrite())
> + return (2);
>   if ((len = readlink(p->fts_path, name, sizeof(name)-1)) == -1) {
>   warn("readlink: %s", p->fts_path);
>   return (1);
> @@ -218,6 +220,8 @@ copy_link(FTSENT *p, int exists)
>  int
>  copy_fifo(struct stat *from_stat, int exists)
>  {
> + if (exists && !copy_overwrite())
> + return (2);
>   if (exists && unlink(to.p_path)) {
>   warn("unlink: %s", to.p_path);
>   return (1);
> @@ -232,6 +236,8 @@ copy_fifo(struct stat *from_stat, int exists)
>  int
>  copy_special(struct stat *from_stat, int exists)
>  {
> + if (exists && !copy_overwrite())
> + return (2);
>   if (exists && unlink(to.p_path)) {
>   warn("unlink: %s", to.p_path);
>   return (1);
> 



Re: cp(1) Fix incomplete -i behaviour [3/3]

2018-09-06 Thread Stefan Sperling
On Fri, Aug 31, 2018 at 09:43:03AM +0200, Martijn van Duren wrote:
> part 3
> 
> OK?

ok stsp@

> 
> martijn@
> 
> diff --git cp.c cp.c
> index fbf924c..2ccef08 100644
> --- cp.c
> +++ cp.c
> @@ -434,7 +434,7 @@ copy(char *argv[], enum op type, int fts_options)
>   !fts_dne(curr))) == 1)
>   rval = 1;
>   } else {
> - cval = copy_file(curr, fts_dne(curr));
> + cval = copy_file(curr, !fts_dne(curr));
>   if (cval == 1)
>   rval = 1;
>   }
> @@ -449,7 +449,7 @@ copy(char *argv[], enum op type, int fts_options)
>   !fts_dne(curr))) == 1)
>   rval = 1;
>   } else {
> - cval = copy_file(curr, fts_dne(curr));
> + cval = copy_file(curr, !fts_dne(curr));
>   if (cval == 1)
>   rval = 1;
>   }
> @@ -462,7 +462,7 @@ copy(char *argv[], enum op type, int fts_options)
>   warnc(EOPNOTSUPP, "%s", curr->fts_path);
>   break;
>   default:
> - if ((cval = copy_file(curr, fts_dne(curr))) == 1)
> + if ((cval = copy_file(curr, !fts_dne(curr))) == 1)
>   rval = 1;
>   if (!cval && vflag)
>   (void)fprintf(stdout, "%s -> %s\n",
> diff --git utils.c utils.c
> index 4a9219c..0f44bbf 100644
> --- utils.c
> +++ utils.c
> @@ -50,7 +50,7 @@
>  int copy_overwrite(void);
>  
>  int
> -copy_file(FTSENT *entp, int dne)
> +copy_file(FTSENT *entp, int exists)
>  {
>   static char *buf;
>   static char *zeroes;
> @@ -82,7 +82,7 @@ copy_file(FTSENT *entp, int dne)
>* In -f (force) mode, we always unlink the destination first
>* if it exists.  Note that -i and -f are mutually exclusive.
>*/
> - if (!dne && fflag)
> + if (exists && fflag)
>   (void)unlink(to.p_path);
>  
>   /*
> @@ -92,7 +92,7 @@ copy_file(FTSENT *entp, int dne)
>* other choice is 666 or'ed with the execute bits on the from file
>* modified by the umask.)
>*/
> - if (!dne && !fflag) {
> + if (exists && !fflag) {
>   if (!copy_overwrite()) {
>   (void)close(from_fd);
>   return 2;
> @@ -174,7 +174,7 @@ copy_file(FTSENT *entp, int dne)
>*/
>  #define  RETAINBITS \
>   (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
> - if (!pflag && dne &&
> + if (!pflag && !exists &&
>   fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
>   if (fstat(to_fd, _stat)) {
>   warn("%s", to.p_path);
> 



Re: cp(1) Don't trigger -v if -i causes a skip

2018-09-06 Thread Stefan Sperling
On Thu, Aug 30, 2018 at 09:02:22PM +0200, Martijn van Duren wrote:
> Hello tech@,
> 
> Don't know if this is too much magic numbers for copy_file, but this 
> "fixes" the case where we print the verbose line, even if we don't copy 
> it. This doesn't not happen in mv or rm.
> 
> Note that the current implementation also doesn't show a successful
> copy of a fifo or special if a prior copy failed:
> $ touch /tmp/test1
> $ mkfifo /tmp/test2
> $ chmod 0 /tmp/test1
> $ cp -Rv /tmp/test* /tmp/tmp/
> cp: /tmp/test1: Permission denied
> $ ls /tmp/tmp
> test2
> $ ./obj/cp -Rv /tmp/test* /tmp/tmp/
> cp: /tmp/test1: Permission denied
> /tmp/test2 -> /tmp/tmp/test2
> 
> OK?

ok stsp@

> 
> martijn@
> 
> Index: cp.c
> ===
> RCS file: /cvs/src/bin/cp/cp.c,v
> retrieving revision 1.46
> diff -u -p -r1.46 cp.c
> --- cp.c  27 Jun 2017 21:49:47 -  1.46
> +++ cp.c  30 Aug 2018 18:43:26 -
> @@ -264,7 +264,7 @@ copy(char *argv[], enum op type, int fts
>   struct stat to_stat;
>   FTS *ftsp;
>   FTSENT *curr;
> - int base, nlen, rval;
> + int base, cval, nlen, rval;
>   char *p, *target_mid;
>   base = 0;
>  
> @@ -434,32 +434,35 @@ copy(char *argv[], enum op type, int fts
>   !fts_dne(curr)))
>   rval = 1;
>   } else
> - if (copy_file(curr, fts_dne(curr)))
> + if ((cval = copy_file(curr, fts_dne(curr))) == 
> 1)
>   rval = 1;
> - if (!rval && vflag)
> + if (!cval && vflag)
>   (void)fprintf(stdout, "%s -> %s\n",
>   curr->fts_path, to.p_path);
> + cval = 0;
>   break;
>   case S_IFIFO:
>   if (Rflag) {
>   if (copy_fifo(curr->fts_statp, !fts_dne(curr)))
>   rval = 1;
>   } else
> - if (copy_file(curr, fts_dne(curr)))
> + if ((cval = copy_file(curr, fts_dne(curr))) == 
> 1)
>   rval = 1;
> - if (!rval && vflag)
> + if (!cval && vflag)
>   (void)fprintf(stdout, "%s -> %s\n",
>   curr->fts_path, to.p_path);
> + cval = 0;
>   break;
>   case S_IFSOCK:
>   warnc(EOPNOTSUPP, "%s", curr->fts_path);
>   break;
>   default:
> - if (copy_file(curr, fts_dne(curr)))
> + if ((cval = copy_file(curr, fts_dne(curr))) == 1)
>   rval = 1;
> - else if (vflag)
> + if (!cval && vflag)
>   (void)fprintf(stdout, "%s -> %s\n",
>   curr->fts_path, to.p_path);
> + cval = 0;
>   break;
>   }
>   }
> Index: utils.c
> ===
> RCS file: /cvs/src/bin/cp/utils.c,v
> retrieving revision 1.40
> diff -u -p -r1.40 utils.c
> --- utils.c   27 Jun 2017 21:43:46 -  1.40
> +++ utils.c   30 Aug 2018 18:43:26 -
> @@ -99,7 +99,7 @@ copy_file(FTSENT *entp, int dne)
>   ch = getchar();
>   if (checkch != 'y' && checkch != 'Y') {
>   (void)close(from_fd);
> - return (0);
> + return (2);
>   }
>   }
>   to_fd = open(to.p_path, O_WRONLY | O_TRUNC, 0);
> 



Re: httpd: block return with a contentless status

2018-09-06 Thread Florian Obser
Disregard for now.
Carlin pointed out that this (unintentionally) stopped sending content length 
for head requests. While the RFC has content length optional (according to 
Carlin, didn't have time to check myself) we probably shouldn't just change 
behavior

On September 6, 2018 6:39:18 PM GMT+02:00, Florian Obser  
wrote:
>On Fri, Sep 07, 2018 at 03:08:53AM +1200, Carlin Bingham wrote:
>> If httpd is configured to do "block return" with a 1xx or 204 status,
>it
>> sends a response with a Content-Length header and a body, which per
>RFC
>> 7230 it must not.
>> 
>> The use case for this is a webapp which wants the webserver itself to
>be
>> configured to return a 204 response for certain requests. I'm running
>> httpd behind relayd, and relayd doesn't accept the 204 responses
>httpd
>> returns.
>> 
>> Here's a possible patch.
>> 
>> 
>> --
>> Carlin
>
>How about this one? That way we list all the reasons not to have a
>body up front.
>
>diff --git server_http.c server_http.c
>index 4c91dea2d16..72c67c46890 100644
>--- server_http.c
>+++ server_http.c
>@@ -846,9 +846,10 @@ server_abort_http(struct client *clt, unsigned int
>code, const char *msg)
>   const char  *httperr = NULL, *style;
>   char*httpmsg, *body = NULL, *extraheader = NULL;
>   char tmbuf[32], hbuf[128], *hstsheader = NULL;
>+  char*clenheader = NULL;
>   char buf[IBUF_READ_SIZE];
>   char*escapedmsg = NULL;
>-  int  bodylen;
>+  int  bodylen = -1;
> 
>   if (code == 0) {
>   server_close(clt, "dropped");
>@@ -924,29 +925,34 @@ server_abort_http(struct client *clt, unsigned
>int code, const char *msg)
> 
>   free(escapedmsg);
> 
>-  /* A CSS stylesheet allows minimal customization by the user */
>-  style = "body { background-color: white; color: black; font-family: "
>-  "'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n"
>-  "hr { border: 0; border-bottom: 1px dashed; }\n";
>-
>-  /* Generate simple HTML error document */
>-  if ((bodylen = asprintf(,
>-  "\n"
>-  "\n"
>-  "\n"
>-  "-  "charset=utf-8\"/>\n"
>-  "%03d %s\n"
>-  "\n"
>-  "\n"
>-  "\n"
>-  "%03d %s\n"
>-  "\n%s\n"
>-  "\n"
>-  "\n",
>-  code, httperr, style, code, httperr, HTTPD_SERVERNAME)) == -1) {
>-  body = NULL;
>-  goto done;
>+  if (code >= 200 && code != 204 && desc->http_method !=
>+  HTTP_METHOD_HEAD) {
>+  /* A CSS stylesheet allows minimal customization by the user */
>+  style = "body { background-color: white; color: black; "
>+  "font-family: 'Comic Sans MS', 'Chalkboard SE', "
>+  "'Comic Neue', sans-serif; }\n"
>+  "hr { border: 0; border-bottom: 1px dashed; }\n";
>+
>+  /* Generate simple HTML error document */
>+  if ((bodylen = asprintf(,
>+  "\n"
>+  "\n"
>+  "\n"
>+  "+  "charset=utf-8\"/>\n"
>+  "%03d %s\n"
>+  "\n"
>+  "\n"
>+  "\n"
>+  "%03d %s\n"
>+  "\n%s\n"
>+  "\n"
>+  "\n",
>+  code, httperr, style, code, httperr, HTTPD_SERVERNAME)) ==
>+  -1) {
>+  body = NULL;
>+  goto done;
>+  }
>   }
> 
>   if (srv_conf->flags & SRVFLAG_SERVER_HSTS) {
>@@ -961,6 +967,14 @@ server_abort_http(struct client *clt, unsigned int
>code, const char *msg)
>   }
>   }
> 
>+  if (bodylen != -1) {
>+  if (asprintf(, "Content-Length: %d\r\n",
>+  bodylen) == -1) {
>+  clenheader = NULL;
>+  goto done;
>+  }
>+  }
>+
>   /* Add basic HTTP headers */
>   if (asprintf(,
>   "HTTP/1.0 %03d %s\r\n"
>@@ -968,15 +982,16 @@ server_abort_http(struct client *clt, unsigned
>int code, const char *msg)
>   "Server: %s\r\n"
>   "Connection: close\r\n"
>   "Content-Type: text/html\r\n"
>-  "Content-Length: %d\r\n"
>+  "%s"
>   "%s"
>   "%s"
>   "\r\n"
>   "%s",
>-  code, httperr, tmbuf, HTTPD_SERVERNAME, bodylen,
>+  code, httperr, tmbuf, HTTPD_SERVERNAME,
>+  bodylen == -1 ? "" : clenheader,
>   extraheader == NULL ? "" : extraheader,
>   hstsheader == NULL ? "" : hstsheader,
>-  desc->http_method == HTTP_METHOD_HEAD ? "" : body) == -1)
>+  bodylen == -1 ? "" : body) == -1)
>   goto done;
> 
>   /* Dump the message 

umidi(4) jack count

2018-09-06 Thread Michael Mikonos
Hello,

The umidi(4) driver has three different endpoint allocation
functions, which are called by alloc_all_endpoints(). The
initial jack count can be moved here because it is zero
no matter which allocation function is used.
Also when we eventually free the jacks the count can
be reset. Does this look OK?

- Michael


Index: umidi.c
===
RCS file: /cvs/src/sys/dev/usb/umidi.c,v
retrieving revision 1.47
diff -u -p -u -r1.47 umidi.c
--- umidi.c 6 Sep 2018 09:48:23 -   1.47
+++ umidi.c 6 Sep 2018 16:24:22 -
@@ -387,6 +387,8 @@ alloc_all_endpoints(struct umidi_softc *
struct umidi_endpoint *ep;
int i;
 
+   sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
+
if (UMQ_ISTYPE(sc, UMQ_TYPE_FIXED_EP))
err = alloc_all_endpoints_fixed_ep(sc);
else if (UMQ_ISTYPE(sc, UMQ_TYPE_YAMAHA))
@@ -436,8 +438,6 @@ alloc_all_endpoints_fixed_ep(struct umid
 
fp = umidi_get_quirk_data_from_type(sc->sc_quirk,
UMQ_TYPE_FIXED_EP);
-   sc->sc_out_num_jacks = 0;
-   sc->sc_in_num_jacks = 0;
sc->sc_out_num_endpoints = fp->num_out_ep;
sc->sc_in_num_endpoints = fp->num_in_ep;
sc->sc_endpoints = mallocarray(sc->sc_out_num_endpoints +
@@ -521,7 +521,6 @@ alloc_all_endpoints_yamaha(struct umidi_
int out_addr, in_addr, in_packetsize, i, dir;
size_t remain, descsize;
 
-   sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
out_addr = in_addr = 0;
 
/* detect endpoints */
@@ -627,7 +626,6 @@ alloc_all_endpoints_genuine(struct umidi
if (!p)
return USBD_NOMEM;
 
-   sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
sc->sc_out_num_endpoints = sc->sc_in_num_endpoints = 0;
epaddr = -1;
 
@@ -780,6 +778,7 @@ free_all_jacks(struct umidi_softc *sc)
if (sc->sc_out_jacks) {
free(sc->sc_jacks, M_USBDEV, jacks * sizeof(*sc->sc_out_jacks));
sc->sc_jacks = sc->sc_in_jacks = sc->sc_out_jacks = NULL;
+   sc->sc_out_num_jacks = sc->sc_in_num_jacks = 0;
}
splx(s);
 }



Re: httpd: block return with a contentless status

2018-09-06 Thread Florian Obser
On Fri, Sep 07, 2018 at 03:08:53AM +1200, Carlin Bingham wrote:
> If httpd is configured to do "block return" with a 1xx or 204 status, it
> sends a response with a Content-Length header and a body, which per RFC
> 7230 it must not.
> 
> The use case for this is a webapp which wants the webserver itself to be
> configured to return a 204 response for certain requests. I'm running
> httpd behind relayd, and relayd doesn't accept the 204 responses httpd
> returns.
> 
> Here's a possible patch.
> 
> 
> --
> Carlin

How about this one? That way we list all the reasons not to have a
body up front.

diff --git server_http.c server_http.c
index 4c91dea2d16..72c67c46890 100644
--- server_http.c
+++ server_http.c
@@ -846,9 +846,10 @@ server_abort_http(struct client *clt, unsigned int code, 
const char *msg)
const char  *httperr = NULL, *style;
char*httpmsg, *body = NULL, *extraheader = NULL;
char tmbuf[32], hbuf[128], *hstsheader = NULL;
+   char*clenheader = NULL;
char buf[IBUF_READ_SIZE];
char*escapedmsg = NULL;
-   int  bodylen;
+   int  bodylen = -1;
 
if (code == 0) {
server_close(clt, "dropped");
@@ -924,29 +925,34 @@ server_abort_http(struct client *clt, unsigned int code, 
const char *msg)
 
free(escapedmsg);
 
-   /* A CSS stylesheet allows minimal customization by the user */
-   style = "body { background-color: white; color: black; font-family: "
-   "'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }\n"
-   "hr { border: 0; border-bottom: 1px dashed; }\n";
-
-   /* Generate simple HTML error document */
-   if ((bodylen = asprintf(,
-   "\n"
-   "\n"
-   "\n"
-   "\n"
-   "%03d %s\n"
-   "\n"
-   "\n"
-   "\n"
-   "%03d %s\n"
-   "\n%s\n"
-   "\n"
-   "\n",
-   code, httperr, style, code, httperr, HTTPD_SERVERNAME)) == -1) {
-   body = NULL;
-   goto done;
+   if (code >= 200 && code != 204 && desc->http_method !=
+   HTTP_METHOD_HEAD) {
+   /* A CSS stylesheet allows minimal customization by the user */
+   style = "body { background-color: white; color: black; "
+   "font-family: 'Comic Sans MS', 'Chalkboard SE', "
+   "'Comic Neue', sans-serif; }\n"
+   "hr { border: 0; border-bottom: 1px dashed; }\n";
+
+   /* Generate simple HTML error document */
+   if ((bodylen = asprintf(,
+   "\n"
+   "\n"
+   "\n"
+   "\n"
+   "%03d %s\n"
+   "\n"
+   "\n"
+   "\n"
+   "%03d %s\n"
+   "\n%s\n"
+   "\n"
+   "\n",
+   code, httperr, style, code, httperr, HTTPD_SERVERNAME)) ==
+   -1) {
+   body = NULL;
+   goto done;
+   }
}
 
if (srv_conf->flags & SRVFLAG_SERVER_HSTS) {
@@ -961,6 +967,14 @@ server_abort_http(struct client *clt, unsigned int code, 
const char *msg)
}
}
 
+   if (bodylen != -1) {
+   if (asprintf(, "Content-Length: %d\r\n",
+   bodylen) == -1) {
+   clenheader = NULL;
+   goto done;
+   }
+   }
+
/* Add basic HTTP headers */
if (asprintf(,
"HTTP/1.0 %03d %s\r\n"
@@ -968,15 +982,16 @@ server_abort_http(struct client *clt, unsigned int code, 
const char *msg)
"Server: %s\r\n"
"Connection: close\r\n"
"Content-Type: text/html\r\n"
-   "Content-Length: %d\r\n"
+   "%s"
"%s"
"%s"
"\r\n"
"%s",
-   code, httperr, tmbuf, HTTPD_SERVERNAME, bodylen,
+   code, httperr, tmbuf, HTTPD_SERVERNAME,
+   bodylen == -1 ? "" : clenheader,
extraheader == NULL ? "" : extraheader,
hstsheader == NULL ? "" : hstsheader,
-   desc->http_method == HTTP_METHOD_HEAD ? "" : body) == -1)
+   bodylen == -1 ? "" : body) == -1)
goto done;
 
/* Dump the message without checking for success */
@@ -987,6 +1002,7 @@ server_abort_http(struct client *clt, unsigned int code, 
const char *msg)
free(body);
free(extraheader);
free(hstsheader);
+   free(clenheader);
if (msg == NULL)
msg = "\"\"";
if (asprintf(, "%s (%03d %s)", msg, code, httperr) == -1) {


-- 
I'm not entirely sure you are real.



httpd: block return with a contentless status

2018-09-06 Thread Carlin Bingham
If httpd is configured to do "block return" with a 1xx or 204 status, it
sends a response with a Content-Length header and a body, which per RFC
7230 it must not.

The use case for this is a webapp which wants the webserver itself to be
configured to return a 204 response for certain requests. I'm running
httpd behind relayd, and relayd doesn't accept the 204 responses httpd
returns.

Here's a possible patch.


--
Carlin


Index: usr.sbin/httpd/server_http.c
===
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.122
diff -u -p -u -r1.122 server_http.c
--- usr.sbin/httpd/server_http.c20 Jun 2018 16:43:05 -  1.122
+++ usr.sbin/httpd/server_http.c5 Sep 2018 16:37:35 -
@@ -846,6 +846,7 @@ server_abort_http(struct client *clt, un
const char  *httperr = NULL, *style;
char*httpmsg, *body = NULL, *extraheader = NULL;
char tmbuf[32], hbuf[128], *hstsheader = NULL;
+   char*clenheader = NULL;
char buf[IBUF_READ_SIZE];
char*escapedmsg = NULL;
int  bodylen;
@@ -961,6 +962,16 @@ server_abort_http(struct client *clt, un
}
}
 
+   if ((code >= 100 && code < 200) || code == 204)
+   clenheader = NULL;
+   else {
+   if (asprintf(,
+   "Content-Length: %d\r\n", bodylen) == -1) {
+   clenheader = NULL;
+   goto done;
+   }
+   }
+
/* Add basic HTTP headers */
if (asprintf(,
"HTTP/1.0 %03d %s\r\n"
@@ -968,15 +979,17 @@ server_abort_http(struct client *clt, un
"Server: %s\r\n"
"Connection: close\r\n"
"Content-Type: text/html\r\n"
-   "Content-Length: %d\r\n"
+   "%s"
"%s"
"%s"
"\r\n"
"%s",
-   code, httperr, tmbuf, HTTPD_SERVERNAME, bodylen,
+   code, httperr, tmbuf, HTTPD_SERVERNAME,
+   clenheader == NULL ? "" : clenheader,
extraheader == NULL ? "" : extraheader,
hstsheader == NULL ? "" : hstsheader,
-   desc->http_method == HTTP_METHOD_HEAD ? "" : body) == -1)
+   desc->http_method == HTTP_METHOD_HEAD || clenheader == NULL ?
+   "" : body) == -1)
goto done;
 
/* Dump the message without checking for success */
@@ -987,6 +1000,7 @@ server_abort_http(struct client *clt, un
free(body);
free(extraheader);
free(hstsheader);
+   free(clenheader);
if (msg == NULL)
msg = "\"\"";
if (asprintf(, "%s (%03d %s)", msg, code, httperr) == -1) {



Re: umidi(4) alloc_all_endpoints_fixed_ep()

2018-09-06 Thread Martin Pieuchot
On 06/09/18(Thu) 23:01, Michael Mikonos wrote:
> Hello,
> 
> In the umidi(4) driver the function alloc_all_endpoints_fixed_ep()
> returns USBD_NOMEM if mallocarray() fails, but the return value is
> always USBD_INVAL when 'goto error' happens. OK?

Note that it'd be better to *not* use `usbd_status' for indicating
generic failures.  It would be great if `usbd_status' could be only
used for code related to transfer (xfer) error/status.
In that particular case alloc_all_endpoints() & friends could use
normal errnos values.  But that's a different issue ;)

Since you're here, adding sizes to free(9) is also a nice possible
cleanup :D

Anyway, your diff is ok mpi@

> Index: umidi.c
> ===
> RCS file: /cvs/src/sys/dev/usb/umidi.c,v
> retrieving revision 1.47
> diff -u -p -u -r1.47 umidi.c
> --- umidi.c   6 Sep 2018 09:48:23 -   1.47
> +++ umidi.c   6 Sep 2018 14:28:21 -
> @@ -428,7 +428,6 @@ free_all_endpoints(struct umidi_softc *s
>  static usbd_status
>  alloc_all_endpoints_fixed_ep(struct umidi_softc *sc)
>  {
> - usbd_status err;
>   struct umq_fixed_ep_desc *fp;
>   struct umidi_endpoint *ep;
>   usb_endpoint_descriptor_t *epd;
> @@ -458,14 +457,12 @@ alloc_all_endpoints_fixed_ep(struct umid
>   if (!epd) {
>   DPRINTF(("%s: cannot get endpoint descriptor(out:%d)\n",
>  sc->sc_dev.dv_xname, fp->out_ep[i].ep));
> - err = USBD_INVAL;
>   goto error;
>   }
>   if (UE_GET_XFERTYPE(epd->bmAttributes)!=UE_BULK ||
>   UE_GET_DIR(epd->bEndpointAddress)!=UE_DIR_OUT) {
>   printf("%s: illegal endpoint(out:%d)\n",
>  sc->sc_dev.dv_xname, fp->out_ep[i].ep);
> - err = USBD_INVAL;
>   goto error;
>   }
>   ep->sc = sc;
> @@ -485,14 +482,12 @@ alloc_all_endpoints_fixed_ep(struct umid
>   if (!epd) {
>   DPRINTF(("%s: cannot get endpoint descriptor(in:%d)\n",
>  sc->sc_dev.dv_xname, fp->in_ep[i].ep));
> - err = USBD_INVAL;
>   goto error;
>   }
>   if (UE_GET_XFERTYPE(epd->bmAttributes)!=UE_BULK ||
>   UE_GET_DIR(epd->bEndpointAddress)!=UE_DIR_IN) {
>   printf("%s: illegal endpoint(in:%d)\n",
>  sc->sc_dev.dv_xname, fp->in_ep[i].ep);
> - err = USBD_INVAL;
>   goto error;
>   }
>   ep->sc = sc;
> @@ -509,7 +504,7 @@ alloc_all_endpoints_fixed_ep(struct umid
>  error:
>   free(sc->sc_endpoints, M_USBDEV, 0);
>   sc->sc_endpoints = NULL;
> - return err;
> + return USBD_INVAL;
>  }
>  
>  static usbd_status
> 



umidi(4) alloc_all_endpoints_fixed_ep()

2018-09-06 Thread Michael Mikonos
Hello,

In the umidi(4) driver the function alloc_all_endpoints_fixed_ep()
returns USBD_NOMEM if mallocarray() fails, but the return value is
always USBD_INVAL when 'goto error' happens. OK?

- Michael


Index: umidi.c
===
RCS file: /cvs/src/sys/dev/usb/umidi.c,v
retrieving revision 1.47
diff -u -p -u -r1.47 umidi.c
--- umidi.c 6 Sep 2018 09:48:23 -   1.47
+++ umidi.c 6 Sep 2018 14:28:21 -
@@ -428,7 +428,6 @@ free_all_endpoints(struct umidi_softc *s
 static usbd_status
 alloc_all_endpoints_fixed_ep(struct umidi_softc *sc)
 {
-   usbd_status err;
struct umq_fixed_ep_desc *fp;
struct umidi_endpoint *ep;
usb_endpoint_descriptor_t *epd;
@@ -458,14 +457,12 @@ alloc_all_endpoints_fixed_ep(struct umid
if (!epd) {
DPRINTF(("%s: cannot get endpoint descriptor(out:%d)\n",
   sc->sc_dev.dv_xname, fp->out_ep[i].ep));
-   err = USBD_INVAL;
goto error;
}
if (UE_GET_XFERTYPE(epd->bmAttributes)!=UE_BULK ||
UE_GET_DIR(epd->bEndpointAddress)!=UE_DIR_OUT) {
printf("%s: illegal endpoint(out:%d)\n",
   sc->sc_dev.dv_xname, fp->out_ep[i].ep);
-   err = USBD_INVAL;
goto error;
}
ep->sc = sc;
@@ -485,14 +482,12 @@ alloc_all_endpoints_fixed_ep(struct umid
if (!epd) {
DPRINTF(("%s: cannot get endpoint descriptor(in:%d)\n",
   sc->sc_dev.dv_xname, fp->in_ep[i].ep));
-   err = USBD_INVAL;
goto error;
}
if (UE_GET_XFERTYPE(epd->bmAttributes)!=UE_BULK ||
UE_GET_DIR(epd->bEndpointAddress)!=UE_DIR_IN) {
printf("%s: illegal endpoint(in:%d)\n",
   sc->sc_dev.dv_xname, fp->in_ep[i].ep);
-   err = USBD_INVAL;
goto error;
}
ep->sc = sc;
@@ -509,7 +504,7 @@ alloc_all_endpoints_fixed_ep(struct umid
 error:
free(sc->sc_endpoints, M_USBDEV, 0);
sc->sc_endpoints = NULL;
-   return err;
+   return USBD_INVAL;
 }
 
 static usbd_status



bgpd, fast as number lookups using as-set

2018-09-06 Thread Claudio Jeker
This diff implements as-set. Similar to prefix-set this allows to reduce
large lists of AS numbers to a single set.

To define an as-set:
as-set "AS_SET_AS_PCH" {
27 42 187 297 715 3856 10886 11893 13202 16327 16668 19281 20539 21312 
21556 24999 25505 27678 32978 32979 35160 38052 42530 44876 45170 45494 
48892 50843 51874 51972 52234 52304 52306 54145 54390 60313 197058 
}

To match against an as-set:
match from any source-as as-set "AS_SET_AS_PCH" set localpref 1000

OK?
-- 
:wq Claudio


Index: Makefile
===
RCS file: /cvs/src/usr.sbin/bgpd/Makefile,v
retrieving revision 1.32
diff -u -p -r1.32 Makefile
--- Makefile21 Aug 2017 14:43:33 -  1.32
+++ Makefile9 Aug 2018 20:35:53 -
@@ -4,7 +4,7 @@ PROG=   bgpd
 SRCS=  bgpd.c session.c log.c logmsg.c parse.y config.c \
rde.c rde_rib.c rde_decide.c rde_prefix.c mrt.c kroute.c \
control.c pfkey.c rde_update.c rde_attr.c printconf.c \
-   rde_filter.c pftable.c name2id.c util.c carp.c timer.c
+   rde_filter.c rde_sets.c pftable.c name2id.c util.c carp.c timer.c
 CFLAGS+= -Wall -I${.CURDIR}
 CFLAGS+= -Wstrict-prototypes -Wmissing-prototypes
 CFLAGS+= -Wmissing-declarations
Index: bgpd.c
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.194
diff -u -p -r1.194 bgpd.c
--- bgpd.c  14 Jul 2018 12:32:35 -  1.194
+++ bgpd.c  29 Aug 2018 16:25:43 -
@@ -519,6 +519,12 @@ reconfigure(char *conffile, struct bgpd_
free(ps);
}
 
+   /* as-sets for filters in the RDE */
+   if (as_sets_send(ibuf_rde, conf->as_sets) == -1)
+   return (-1);
+   as_sets_free(conf->as_sets);
+   conf->as_sets = NULL;
+
/* filters for the RDE */
while ((r = TAILQ_FIRST(conf->filters)) != NULL) {
TAILQ_REMOVE(conf->filters, r, entry);
Index: bgpd.conf.5
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.conf.5,v
retrieving revision 1.171
diff -u -p -r1.171 bgpd.conf.5
--- bgpd.conf.5 11 Jul 2018 14:08:46 -  1.171
+++ bgpd.conf.5 5 Sep 2018 18:12:07 -
@@ -144,6 +144,20 @@ or as a large number (ASPLAIN format), f
 AS 196618
 .Ed
 .Pp
+.Pp
+.It Xo
+.Ic as-set Ar name
+.Ic { Ar as-number ... Ic }
+.Xc
+A
+.Ic as-set
+holds a collection of AS numbers and can be used with the AS specific
+parameter in
+.Sx FILTER
+rules.
+Lookups against as-sets are more efficient than a large number of rules
+which differ only in the AS number.
+.Pp
 .It Ic connect-retry Ar seconds
 Set the number of seconds before retrying to open a connection.
 This timer should be sufficiently large in EBGP configurations.
@@ -,21 +1125,25 @@ If a parameter is specified, the rule on
 matching attributes.
 .Pp
 .Bl -tag -width Ds -compact
-.It Xo
+.It Xo 
 .Ar as-type Op Ar operator
 .Ar as-number
 .Xc
+.It Ar as-type Ic as-set Ar name
 This rule applies only to
 .Em UPDATES
 where the
 .Em AS path
 matches.
 The
-.Ar as-number
-is matched against a part of the
+part of the
 .Em AS path
 specified by the
-.Ar as-type :
+.Ar as-type
+is matched against the
+.Ar as-number
+or the
+.Ic as-set Ar name :
 .Pp
 .Bl -tag -width transmit-as -compact
 .It Ic AS
@@ -1146,6 +1164,10 @@ It may be set to
 which is expanded to the current neighbor remote AS number, or
 .Ic local-as ,
 which is expanded to the locally assigned AS number.
+.Pp
+When specifying an
+.Ic as-set Ar name
+the AS path will instead be matched against all the AS numbers in the set.
 .Pp
 The
 .Ar operator
Index: bgpd.h
===
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.333
diff -u -p -r1.333 bgpd.h
--- bgpd.h  5 Sep 2018 09:49:57 -   1.333
+++ bgpd.h  6 Sep 2018 13:31:46 -
@@ -43,7 +43,7 @@
 #defineTCP_MD5_KEY_LEN 80
 #defineIPSEC_ENC_KEY_LEN   32
 #defineIPSEC_AUTH_KEY_LEN  20
-#definePREFIXSET_NAME_LEN  32
+#defineSET_NAME_LEN64
 
 #defineMAX_PKTSIZE 4096
 #defineMIN_HOLDTIME3
@@ -213,6 +213,9 @@ TAILQ_HEAD(network_head, network);
 struct prefixset;
 SIMPLEQ_HEAD(prefixset_head, prefixset);
 
+struct as_set;
+SIMPLEQ_HEAD(as_set_head, as_set);
+
 struct filter_rule;
 TAILQ_HEAD(filter_head, filter_rule);
 
@@ -223,6 +226,7 @@ struct bgpd_config {
struct listen_addrs *listen_addrs;
struct mrt_head *mrt;
struct prefixset_head   *prefixsets;
+   struct as_set_head  *as_sets;
char*csock;
char*rcsock;
int   

Re: [patch] Fix closing socket twice bug in netcat program

2018-09-06 Thread Nan Xiao
Hi bluhm,

Very sorry for my remiss! Updated, thanks!

Index: netcat.c
===
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.192
diff -u -p -r1.192 netcat.c
--- netcat.c10 Aug 2018 17:15:22 -  1.192
+++ netcat.c6 Sep 2018 10:10:07 -
@@ -564,8 +564,11 @@ main(int argc, char *argv[])
}
/* Allow only one connection at a time, but stay alive. */
for (;;) {
-   if (family != AF_UNIX)
+   if (family != AF_UNIX) {
+   if (s != -1)
+   close(s);
s = local_listen(host, uport, hints);
+   }
if (s < 0)
err(1, NULL);
if (uflag && kflag) {
@@ -622,9 +625,7 @@ main(int argc, char *argv[])
}
close(connfd);
}
-   if (family != AF_UNIX)
-   close(s);
-   else if (uflag) {
+   if (family == AF_UNIX && uflag) {
if (connect(s, NULL, 0) < 0)
err(1, "connect");
}


On 9/6/2018 8:53 PM, Alexander Bluhm wrote:
> On Thu, Sep 06, 2018 at 06:27:15PM +0800, Nan Xiao wrote:
>> @@ -564,8 +564,11 @@ main(int argc, char *argv[])
>>  }
>>  /* Allow only one connection at a time, but stay alive. */
>>  for (;;) {
>> -if (family != AF_UNIX)
>> +if (family != AF_UNIX) {
>> +if (s == -1)
> 
> This has to be (s != -1).
> 
>> +close(s);
>>  s = local_listen(host, uport, hints);
>> +}
>>  if (s < 0)
>>  err(1, NULL);
>>  if (uflag && kflag) {
>> @@ -622,9 +625,7 @@ main(int argc, char *argv[])
>>  }
>>  close(connfd);
>>  }
>> -if (family != AF_UNIX)
>> -close(s);
>> -else if (uflag) {
>> +if (family == AF_UNIX && uflag) {
>>  if (connect(s, NULL, 0) < 0)
>>  err(1, "connect");
>>  }
> 
> otherwise OK bluhm@
> 

-- 
Best Regards
Nan Xiao(肖楠)



Re: [patch] Fix closing socket twice bug in netcat program

2018-09-06 Thread Alexander Bluhm
On Thu, Sep 06, 2018 at 06:27:15PM +0800, Nan Xiao wrote:
> @@ -564,8 +564,11 @@ main(int argc, char *argv[])
>   }
>   /* Allow only one connection at a time, but stay alive. */
>   for (;;) {
> - if (family != AF_UNIX)
> + if (family != AF_UNIX) {
> + if (s == -1)

This has to be (s != -1).

> + close(s);
>   s = local_listen(host, uport, hints);
> + }
>   if (s < 0)
>   err(1, NULL);
>   if (uflag && kflag) {
> @@ -622,9 +625,7 @@ main(int argc, char *argv[])
>   }
>   close(connfd);
>   }
> - if (family != AF_UNIX)
> - close(s);
> - else if (uflag) {
> + if (family == AF_UNIX && uflag) {
>   if (connect(s, NULL, 0) < 0)
>   err(1, "connect");
>   }

otherwise OK bluhm@



Re: [patch] Fix closing socket twice bug in netcat program

2018-09-06 Thread Nan Xiao
Hi bluhm,

Thanks for your reply! I think your method is better, and I update the
patch:

Index: netcat.c
===
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.192
diff -u -p -r1.192 netcat.c
--- netcat.c10 Aug 2018 17:15:22 -  1.192
+++ netcat.c6 Sep 2018 10:10:07 -
@@ -564,8 +564,11 @@ main(int argc, char *argv[])
}
/* Allow only one connection at a time, but stay alive. */
for (;;) {
-   if (family != AF_UNIX)
+   if (family != AF_UNIX) {
+   if (s == -1)
+   close(s);
s = local_listen(host, uport, hints);
+   }
if (s < 0)
err(1, NULL);
if (uflag && kflag) {
@@ -622,9 +625,7 @@ main(int argc, char *argv[])
}
close(connfd);
}
-   if (family != AF_UNIX)
-   close(s);
-   else if (uflag) {
+   if (family == AF_UNIX && uflag) {
if (connect(s, NULL, 0) < 0)
err(1, "connect");
}

Thanks!

On 9/6/2018 5:07 AM, Alexander Bluhm wrote:
> On Tue, Sep 04, 2018 at 01:01:38PM +0800, Nan Xiao wrote:
>> Before netcat program exits, it will check whether s is -1, and close
>> socket if s is not -1:
>>
>>  if (s != -1)
>>  close(s);
>>
>> The following patch fixes the issue that netcat will close socket twice
>> if it works as a server:
> 
> I think it is a bug, but should be fixed differently.  The netstat
> code has a lot of if and else for all the use cases.  Adding a s =
> -1 at one place makes it even more confusing.
> 
> In general main() does not reset s to -1, it isets it at the
> beginning.  Look at the client side.  There we close at the beginning
> of the loop:
> 
>   /* Cycle through portlist, connecting to each port. */
>   for (s = -1, i = 0; portlist[i] != NULL; i++) {
>   if (s != -1)
>   close(s);
> 
> So on the server side we should do the same, otherwise the code
> will get more and more messy.  Use the same concept everywhere.
> I think this would be better:
> 
>   /* Allow only one connection at a time, but stay alive. */
>   for (;;) {
>   if (family != AF_UNIX) {
>   if (s != -1)
>   close(s);
>   s = local_listen(host, uport, hints);
>   }
> 
> bluhm
> 

-- 
Best Regards
Nan Xiao(肖楠)



Re: Mention errno in printf(3) man

2018-09-06 Thread Otto Moerbeek
On Wed, Sep 05, 2018 at 12:01:59PM -0700, ge...@geoffhill.org wrote:

> Right now the printf(3) family of manpages make no reference to errno.
> Glancing at __vfprintf, it appears that most of the erroneous paths do
> set errno.

Most, but not all. Stating it will set errno in all error cases is
not right.

-Otto


> 
> Should the manual be amended to reflect this behavior, so that users
> have a documented way to determine the cause of failure in such cases?
> 
> Note this is a smaller concession than a full ERRORS section to
> enumerate error codes, which would pin down the error API, making it
> hard to change without user breakage. errno is still useful without
> this section thanks to libc functions like strerror(3) and err(3).
> 
> The intended effect on userspace developers is to encourage picking
> warn(3) over warnx(3) when logging, and other similar choices.
> 
> 
> Index: lib/libc/stdio/printf.3
> ===
> RCS file: /cvs/src/lib/libc/stdio/printf.3,v
> retrieving revision 1.74
> diff -u -p -u -r1.74 printf.3
> --- lib/libc/stdio/printf.3   13 Oct 2015 12:25:04 -  1.74
> +++ lib/libc/stdio/printf.3   5 Sep 2018 18:28:33 -
> @@ -642,7 +642,9 @@ a field; if the result of a conversion i
>  field is expanded to contain the conversion result.
>  .Sh RETURN VALUES
>  For all these functions if an output or encoding error occurs, a value
> -less than 0 is returned.
> +less than 0 is returned and the global variable
> +.Va errno
> +is set to indicate the error.
>  .Pp
>  The
>  .Fn printf ,