From e4b47618f00dc9ae93ccc24a9271d92faec63536 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sun, 13 May 2018 12:30:06 +0100 Subject: [PATCH] server/admin.c (a_format): Introduce `?ERR' for explicitly named errors. 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 | 10 ++++++++-- server/tripe.h | 4 +++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/admin.c b/server/admin.c index 6ff14187..6ff0dbf3 100644 --- a/server/admin.c +++ b/server/admin.c @@ -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 diff --git a/server/tripe.h b/server/tripe.h index 05956826..9ff54566 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -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 */ -- 2.11.0