moonbridge
diff moonbridge.c @ 213:43a077f2ab49
Safety catch for noncompliant strerror_r() implementation on GNU/Linux systems
author | jbe |
---|---|
date | Mon Jun 22 22:26:55 2015 +0200 (2015-06-22) |
parents | 453b7d1a7944 |
children | 45a425c75643 |
line diff
1.1 --- a/moonbridge.c Mon Jun 22 22:19:41 2015 +0200 1.2 +++ b/moonbridge.c Mon Jun 22 22:26:55 2015 +0200 1.3 @@ -91,6 +91,9 @@ 1.4 /* Maximum length of an error string returned by strerror() */ 1.5 #define MOONBR_MAXSTRERRORLEN 80 1.6 1.7 +/* Error message for noncompliant strerror_r() implementation on GNU systems */ 1.8 +#define MOONBR_STRERROR_R_MSG "Error detail unavailable due to noncompliant strerror_r() implementation" 1.9 + 1.10 /* Status bytes exchanged between master and child processes */ 1.11 #define MOONBR_STATUS_IDLE 'I' 1.12 #define MOONBR_COMMAND_CONNECT 'C' 1.13 @@ -670,7 +673,7 @@ 1.14 1.15 /* Logs an error in child process while appending error string for global errno variable */ 1.16 static void moonbr_child_log_errno(const char *message) { 1.17 - char errmsg[MOONBR_MAXSTRERRORLEN]; 1.18 + char errmsg[MOONBR_MAXSTRERRORLEN] = MOONBR_STRERROR_R_MSG; 1.19 strerror_r(errno, errmsg, MOONBR_MAXSTRERRORLEN); /* use thread-safe call in case child created threads */ 1.20 fprintf(stderr, "%s: %s\n", message, errmsg); 1.21 } 1.22 @@ -1978,7 +1981,7 @@ 1.23 if (errcode) { 1.24 freeaddrinfo(res); 1.25 if (errcode == EAI_SYSTEM) { 1.26 - char errmsg[MOONBR_MAXSTRERRORLEN]; 1.27 + char errmsg[MOONBR_MAXSTRERRORLEN] = MOONBR_STRERROR_R_MSG; 1.28 strerror_r(errno, errmsg, MOONBR_MAXSTRERRORLEN); /* use thread-safe call in case child created threads */ 1.29 luaL_error(L, "Could not resolve host: %s: %s", gai_strerror(errcode), errmsg); 1.30 } else {