On Thu, Oct 06, 2005 at 11:10:34PM +0300, Niko Tyni wrote: > tags 292071 patch
Oops, forgot the attachment. Here it is for real. Cheers, -- Niko Tyni [EMAIL PROTECTED]
#! /bin/sh /usr/share/dpatch/dpatch-run ## strerror.dpatch by Niko Tyni <[EMAIL PROTECTED]> ## ## All lines beginning with `## DP:' are a description of the patch. ## DP: Don't crash while printing a fatal error. @DPATCH@ diff -urNad speedy-cgi-perl-2.22/src/speedy_util.c /tmp/dpep.ifgC6c/speedy-cgi-perl-2.22/src/speedy_util.c --- speedy-cgi-perl-2.22/src/speedy_util.c 2005-10-06 21:36:00.974971661 +0300 +++ /tmp/dpep.ifgC6c/speedy-cgi-perl-2.22/src/speedy_util.c 2005-10-06 21:36:41.673012983 +0300 @@ -96,13 +96,42 @@ } static void just_die(const char *fmt, va_list ap) { + /* + * All this strerror_r() stuff is here because + * including perl.h in some cases (Perl 5.8?) replaces + * strerr() with a wrapper that needs an embedded perl + * interpreter running. Otherwise we get SIGSEGV when + * accessing interpreter-specific global variables for the + * strerror buffer + * + * Furthermore, there are two implementations of + * strerror_r() out there, with different prototypes. + */ + char buf[2048]; +#ifdef HAS_STRERROR_R + char errbuf[256]; + int errsv; +#endif sprintf(buf, "%s[%u]: ", SPEEDY_PROGNAME, (int)getpid()); vsprintf(buf + strlen(buf), fmt, ap); if (errno) { strcat(buf, ": "); +#ifdef HAS_STRERROR_R +#ifdef _GNU_SOURCE + strcat(buf, strerror_r(errno, errbuf, sizeof(errbuf))); +#else /* ! _GNU_SOURCE */ + errsv = errno; + if (strerror_r(errsv, errbuf, sizeof(errbuf)) + sprintf(buf + strlen(buf), "(errno = %d)", errsv); + else + strcat(buf, errbuf); + } +#endif +#else /* ! HAS_STRERROR_R */ strcat(buf, strerror(errno)); +#endif /* HAS_STRERROR_R */ } strcat(buf, "\n"); # ifdef SPEEDY_DEBUG