File: 40strerror.patch

package info (click to toggle)
speedy-cgi-perl 2.22-13
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,144 kB
  • ctags: 884
  • sloc: ansic: 4,487; perl: 958; sh: 806; makefile: 91
file content (47 lines) | stat: -rw-r--r-- 1,356 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Author: Niko Tyni <ntyni@iki.fi>
Description: Don't crash while printing a fatal error.
--- a/src/speedy_util.c
+++ b/src/speedy_util.c
@@ -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