From: Ralph Corderoy Date: Wed, 19 Oct 2016 12:04:12 +0000 (+0100) Subject: Don't recurse in advertise() on writev(2) error, just write(2). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/390acba226dd2bce2335ffed2318a79d554861da?ds=sidebyside;hp=86b1fbb19b287c67f43fd280a13c81eea72583a3 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. --- 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. */ + } } }