chiark / gitweb /
server/admin.c (a_format): Introduce `?ERR' for explicitly named errors.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 13 May 2018 11:30:06 +0000 (12:30 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 25 Jan 2019 12:10:31 +0000 (12:10 +0000)
Judging by the documentation, `?ERRNO' is supposed to take an `int'
argument and format the error it specifies; but it actually works by
examining `errno', and all the callers know this.  Changing it now seems
pointless, but I do want to be able to report errors in cases where
`errno' is or might be stale, and stuffing an error code back into
`errno' just so that it can be reported seems rather ugly.

Instead, add `?ERR' which /does/ accept an `int' argument, and fix the
documentation so that it describes reality.

server/admin.c
server/tripe.h

index 6ff141876f3976c080a1f55bc72be21d5fb44b7d..6ff0dbf3e38f78a12a3226ced3dda4f18a0e963e 100644 (file)
@@ -260,7 +260,9 @@ static void a_flush(int fd, unsigned mode, void *v)
  *
  *               * "?PEER" PEER -- peer's name
  *
- *               * "?ERRNO" ERRNO -- system error code
+ *               * "?ERR" CODE -- system error code
+ *
+ *               * "?ERRNO" -- system error code from @errno@
  *
  *               * "[!]..." ... -- @dstr_putf@-like string as single token
  */
@@ -303,7 +305,11 @@ void a_vformat(dstr *d, const char *fmt, va_list *ap)
        while (*av) u_quotify(d, *av++);
       } else if (strcmp(fmt, "?PEER") == 0)
        u_quotify(d, p_name(va_arg(*ap, peer *)));
-      else if (strcmp(fmt, "?ERRNO") == 0) {
+      else if (strcmp(fmt, "?ERR") == 0) {
+       int e = va_arg(*ap, int);
+       dstr_putf(d, " E%d", e);
+       u_quotify(d, strerror(e));
+      } else if (strcmp(fmt, "?ERRNO") == 0) {
        dstr_putf(d, " E%d", errno);
        u_quotify(d, strerror(errno));
       } else
index 059568269bd6a3c216d561c2d763050a981c6b3b..9ff54566116090697454a21718964fdb68bf70e9 100644 (file)
@@ -1233,7 +1233,9 @@ extern int c_check(const void */*m*/, size_t /*msz*/, buf */*b*/);
  *
  *               * "?PEER" PEER -- peer's name
  *
- *               * "?ERRNO" ERRNO -- system error code
+ *               * "?ERR" CODE -- system error code
+ *
+ *               * "?ERRNO" -- system error code from @errno@
  *
  *               * "[!]..." ... -- @dstr_putf@-like string as single token
  */