summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2021-05-21 22:42:09 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2021-08-27 02:16:52 -0400
commit0286bdef0c503bfccd658e0cca1101d51947fdaa (patch)
treed9d24e67330656c2264fc14d6ed6f6520ba39b85
parent86c39754f215ec00186a649c09cf0b2eea21c872 (diff)
downloadlighttpd-git-0286bdef0c503bfccd658e0cca1101d51947fdaa.tar.gz
[multiple] use thread-safe strerror where avail
use ck_strerror_s() to use strerror_s() or strerror_r() thread-safe and constraint-checking interfaces, where available.
-rw-r--r--src/CMakeLists.txt7
-rw-r--r--src/Makefile.am14
-rw-r--r--src/gw_backend.c6
-rw-r--r--src/log.c17
-rw-r--r--src/meson.build7
-rw-r--r--src/mod_openssl.c5
-rw-r--r--src/mod_wolfssl.c5
7 files changed, 43 insertions, 18 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f0356646..8c7b8e38 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -883,6 +883,7 @@ add_executable(test_configfile
vector.c
log.c
sock_addr.c
+ ck.c
)
add_test(NAME test_configfile COMMAND test_configfile)
@@ -893,6 +894,7 @@ add_executable(test_keyvalue
base64.c
array.c
log.c
+ ck.c
)
add_test(NAME test_keyvalue COMMAND test_keyvalue)
@@ -901,6 +903,7 @@ add_executable(test_mod_access
buffer.c
array.c
log.c
+ ck.c
)
add_test(NAME test_mod_access COMMAND test_mod_access)
@@ -909,6 +912,7 @@ add_executable(test_mod_evhost
buffer.c
array.c
log.c
+ ck.c
)
add_test(NAME test_mod_evhost COMMAND test_mod_evhost)
@@ -917,6 +921,7 @@ add_executable(test_mod_simple_vhost
buffer.c
array.c
log.c
+ ck.c
)
add_test(NAME test_mod_simple_vhost COMMAND test_mod_simple_vhost)
@@ -925,6 +930,7 @@ add_executable(test_mod_userdir
buffer.c
array.c
log.c
+ ck.c
)
add_test(NAME test_mod_userdir COMMAND test_mod_userdir)
@@ -938,6 +944,7 @@ add_executable(test_request
http_kv.c
log.c
sock_addr.c
+ ck.c
)
add_test(NAME test_request COMMAND test_request)
diff --git a/src/Makefile.am b/src/Makefile.am
index 4fb228fe..8886a83b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -636,25 +636,25 @@ t_test_base64_LDADD = $(LIBUNWIND_LIBS)
t_test_burl_SOURCES = t/test_burl.c burl.c buffer.c base64.c
t_test_burl_LDADD = $(LIBUNWIND_LIBS)
-t_test_configfile_SOURCES = t/test_configfile.c buffer.c array.c data_config.c http_header.c http_kv.c vector.c log.c sock_addr.c
+t_test_configfile_SOURCES = t/test_configfile.c buffer.c array.c data_config.c http_header.c http_kv.c vector.c log.c sock_addr.c ck.c
t_test_configfile_LDADD = $(PCRE_LIB) $(LIBUNWIND_LIBS)
-t_test_keyvalue_SOURCES = t/test_keyvalue.c burl.c buffer.c base64.c array.c log.c
+t_test_keyvalue_SOURCES = t/test_keyvalue.c burl.c buffer.c base64.c array.c log.c ck.c
t_test_keyvalue_LDADD = $(PCRE_LIB) $(LIBUNWIND_LIBS)
-t_test_mod_access_SOURCES = t/test_mod_access.c buffer.c array.c log.c
+t_test_mod_access_SOURCES = t/test_mod_access.c buffer.c array.c log.c ck.c
t_test_mod_access_LDADD = $(LIBUNWIND_LIBS)
-t_test_mod_evhost_SOURCES = t/test_mod_evhost.c buffer.c array.c log.c
+t_test_mod_evhost_SOURCES = t/test_mod_evhost.c buffer.c array.c log.c ck.c
t_test_mod_evhost_LDADD = $(LIBUNWIND_LIBS)
-t_test_mod_simple_vhost_SOURCES = t/test_mod_simple_vhost.c buffer.c array.c log.c
+t_test_mod_simple_vhost_SOURCES = t/test_mod_simple_vhost.c buffer.c array.c log.c ck.c
t_test_mod_simple_vhost_LDADD = $(LIBUNWIND_LIBS)
-t_test_mod_userdir_SOURCES = t/test_mod_userdir.c buffer.c array.c log.c
+t_test_mod_userdir_SOURCES = t/test_mod_userdir.c buffer.c array.c log.c ck.c
t_test_mod_userdir_LDADD = $(LIBUNWIND_LIBS)
-t_test_request_SOURCES = t/test_request.c base64.c buffer.c burl.c array.c http_header.c http_kv.c log.c sock_addr.c
+t_test_request_SOURCES = t/test_request.c base64.c buffer.c burl.c array.c http_header.c http_kv.c log.c sock_addr.c ck.c
t_test_request_LDADD = $(LIBUNWIND_LIBS)
noinst_HEADERS = $(hdr)
diff --git a/src/gw_backend.c b/src/gw_backend.c
index 896aafe1..9c532e2d 100644
--- a/src/gw_backend.c
+++ b/src/gw_backend.c
@@ -248,9 +248,8 @@ __attribute_cold__
static void gw_proc_connect_error(request_st * const r, gw_host *host, gw_proc *proc, pid_t pid, int errnum, int debug) {
const time_t cur_ts = log_monotonic_secs;
log_error_st * const errh = r->conf.errh;
- log_error(errh, __FILE__, __LINE__,
- "establishing connection failed: socket: %s: %s",
- proc->connection_name->ptr, strerror(errnum));
+ log_perror(errh, __FILE__, __LINE__, /*(caller should set errno = errnum)*/
+ "establishing connection failed: socket: %s", proc->connection_name->ptr);
if (!proc->is_local) {
proc->disabled_until = cur_ts + host->disable_time;
@@ -1919,6 +1918,7 @@ static handler_t gw_write_request(gw_handler_ctx * const hctx, request_st * cons
if (hctx->state == GW_STATE_CONNECT_DELAYED) { /*(not GW_STATE_INIT)*/
int socket_error = fdevent_connect_status(hctx->fd);
if (socket_error != 0) {
+ errno = socket_error; /*(for log_perror())*/
gw_proc_connect_error(r, hctx->host, hctx->proc, hctx->pid,
socket_error, hctx->conf.debug);
return HANDLER_ERROR;
diff --git a/src/log.c b/src/log.c
index 99f91e8b..64debdef 100644
--- a/src/log.c
+++ b/src/log.c
@@ -5,6 +5,7 @@
#include "first.h"
+#include "ck.h"
#include "log.h"
#include <sys/types.h>
@@ -166,6 +167,16 @@ log_buffer_vprintf (buffer * const b,
}
+__attribute_noinline__
+static void
+log_error_append_strerror (buffer * const b, const int errnum)
+{
+ char buf[1024];
+ errno_t rc = ck_strerror_s(buf, sizeof(buf), errnum);
+ if (0 == rc || rc == ERANGE)
+ buffer_append_str2(b, CONST_STR_LEN(": "), buf, strlen(buf));
+}
+
__attribute_format__((__printf__, 4, 0))
static void
log_error_va_list_impl (log_error_st * const errh,
@@ -178,10 +189,8 @@ log_error_va_list_impl (log_error_st * const errh,
buffer * const b = &errh->b;
if (-1 == log_buffer_prepare(errh, filename, line, b)) return;
log_buffer_vprintf(b, fmt, ap);
- if (perr) {
- buffer_append_string_len(b, CONST_STR_LEN(": "));
- buffer_append_string(b, strerror(errnum));
- }
+ if (perr)
+ log_error_append_strerror(b, errnum);
log_write(errh, b);
errno = errnum;
}
diff --git a/src/meson.build b/src/meson.build
index b3ab283e..9c1210fb 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -896,6 +896,7 @@ test('test_configfile', executable('test_configfile',
'vector.c',
'log.c',
'sock_addr.c',
+ 'ck.c',
],
dependencies: common_flags + libpcre + libunwind,
build_by_default: false,
@@ -909,6 +910,7 @@ test('test_keyvalue', executable('test_keyvalue',
'base64.c',
'array.c',
'log.c',
+ 'ck.c',
],
dependencies: common_flags + libpcre + libunwind,
build_by_default: false,
@@ -920,6 +922,7 @@ test('test_mod_access', executable('test_mod_access',
'buffer.c',
'array.c',
'log.c',
+ 'ck.c',
],
dependencies: common_flags + libunwind,
build_by_default: false,
@@ -931,6 +934,7 @@ test('test_mod_evhost', executable('test_mod_evhost',
'buffer.c',
'array.c',
'log.c',
+ 'ck.c',
],
dependencies: common_flags + libunwind,
build_by_default: false,
@@ -942,6 +946,7 @@ test('test_mod_simple_vhost', executable('test_mod_simple_vhost',
'buffer.c',
'array.c',
'log.c',
+ 'ck.c',
],
dependencies: common_flags + libunwind,
build_by_default: false,
@@ -953,6 +958,7 @@ test('test_mod_userdir', executable('test_mod_userdir',
'buffer.c',
'array.c',
'log.c',
+ 'ck.c',
],
dependencies: common_flags + libunwind,
build_by_default: false,
@@ -969,6 +975,7 @@ test('test_request', executable('test_request',
'http_kv.c',
'log.c',
'sock_addr.c',
+ 'ck.c',
],
dependencies: common_flags + libunwind,
build_by_default: false,
diff --git a/src/mod_openssl.c b/src/mod_openssl.c
index 27a8874e..a476547a 100644
--- a/src/mod_openssl.c
+++ b/src/mod_openssl.c
@@ -3182,8 +3182,9 @@ connection_read_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes)
if (0==oerrno && 0==cq->bytes_in && !hctx->conf.ssl_log_noise)
break;
- log_error(hctx->errh, __FILE__, __LINE__,
- "SSL: %d %d %d %s", len, rc, oerrno, strerror(oerrno));
+ errno = oerrno; /*(for log_perror())*/
+ log_perror(hctx->errh, __FILE__, __LINE__,
+ "SSL: %d %d %d", len, rc, oerrno);
break;
}
diff --git a/src/mod_wolfssl.c b/src/mod_wolfssl.c
index 907fc74b..d879336b 100644
--- a/src/mod_wolfssl.c
+++ b/src/mod_wolfssl.c
@@ -2944,8 +2944,9 @@ connection_read_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes)
if (0==oerrno && 0==cq->bytes_in && !hctx->conf.ssl_log_noise)
break;
- log_error(hctx->errh, __FILE__, __LINE__,
- "SSL: %d %d %d %s", len, rc, oerrno, strerror(oerrno));
+ errno = oerrno; /*(for log_perror())*/
+ log_perror(hctx->errh, __FILE__, __LINE__,
+ "SSL: %d %d %d", len, rc, oerrno);
break;
}