moonbridge
changeset 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 |
files | moonbridge.c moonbridge_io.c |
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 {
2.1 --- a/moonbridge_io.c Mon Jun 22 22:19:41 2015 +0200 2.2 +++ b/moonbridge_io.c Mon Jun 22 22:26:55 2015 +0200 2.3 @@ -37,8 +37,9 @@ 2.4 2.5 #define MOONBR_IO_LISTEN_BACKLOG 1024 2.6 2.7 +#define MOONBR_IO_STRERROR_R_MSG "Error detail unavailable due to noncompliant strerror_r() implementation" 2.8 #define moonbr_io_errmsg() \ 2.9 - char errmsg[MOONBR_IO_MAXSTRERRORLEN]; \ 2.10 + char errmsg[MOONBR_IO_MAXSTRERRORLEN] = MOONBR_IO_STRERROR_R_MSG; \ 2.11 strerror_r(errno, errmsg, MOONBR_IO_MAXSTRERRORLEN) 2.12 2.13 #define MOONBR_IO_HANDLE_MT_REGKEY "moonbridge_io_handle" 2.14 @@ -1253,7 +1254,7 @@ 2.15 int i, argc; 2.16 int sockin[2], sockout[2], sockerr[2]; 2.17 volatile int errorcond = 0; 2.18 - volatile char errmsgbuf[MOONBR_IO_MAXSTRERRORLEN]; 2.19 + volatile char errmsgbuf[MOONBR_IO_MAXSTRERRORLEN] = MOONBR_IO_STRERROR_R_MSG; 2.20 moonbr_io_child_t *child; 2.21 argc = lua_gettop(L); 2.22 argv = lua_newuserdata(L, (argc + 1) * sizeof(char *));