]> diplodocus.org Git - nmh/commitdiff
Don't recurse in advertise() on writev(2) error, just write(2).
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 19 Oct 2016 12:04:12 +0000 (13:04 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 19 Oct 2016 12:04:12 +0000 (13:04 +0100)
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

index c23c3dfa3072cb996757bb6a7f140714447c65ea..beb4ba6d2213e77937e9ac61c116a8ccdea47987 100644 (file)
@@ -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. */
+        }
     }
 }