From 390acba226dd2bce2335ffed2318a79d554861da Mon Sep 17 00:00:00 2001 From: Ralph Corderoy Date: Wed, 19 Oct 2016 13:04:12 +0100 Subject: [PATCH] Don't recurse in advertise() on writev(2) error, just write(2). Some errors, e.g. EPIPE, cause the advise()'s call to another advertise() to fail again, ad segvinitum when stack busts. Instead, snprintf(3) and write(2) that single string, ignoring any error. --- sbr/error.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sbr/error.c b/sbr/error.c index c23c3dfa..beb4ba6d 100644 --- a/sbr/error.c +++ b/sbr/error.c @@ -107,6 +107,10 @@ advertise (const char *what, char *tail, const char *fmt, va_list ap) iov->iov_len = strlen (iov->iov_base = "\n"); iov++; if (writev (fileno (stderr), iob, iov - iob) < 0) { - advise ("stderr", "writev"); + snprintf(buffer, sizeof buffer, "%s: write stderr failed: %d\n", + invo_name && *invo_name ? invo_name : "nmh", errno); + if (write(2, buffer, strlen(buffer)) == -1) { + /* Ignore. if-statement needed to shut up compiler. */ + } } } -- 2.56.0