allows use of system libwebsockets instead of bundled one (#9984)
* allows usage of system libwebsockets * fixes problems that were preventing ACLK to work with LWS `4.1.` * add LWS info to buildinfo Co-authored-by: Austin S. Hemmelgarn <austin@netdata.cloud>
Timotej S committed
Oct 30, 2020 at 10:28 UTC
593e1b6dbc6c979955e503d431d32c0dce1a2e09
5 files changed
+56
-14
Makefile.am
+1
-1
@@ -712,8 +712,8 @@ netdata_SOURCES = $(NETDATA_FILES)
712
if ENABLE_ACLK
713
netdata_LDADD = \
714
externaldeps/mosquitto/libmosquitto.a \
715
- externaldeps/libwebsockets/libwebsockets.a \
715
$(OPTIONAL_LIBCAP_LIBS) \
716
+ $(OPTIONAL_LWS_LIBS) \
717
$(NETDATA_COMMON_LIBS) \
718
$(NULL)
719
else
aclk/aclk_lws_https_client.c
+9
-3
@@ -12,6 +12,8 @@
12
struct simple_hcc_data {
13
char *data;
14
size_t data_size;
15
+ size_t written;
16
+ char lws_work_buffer[1024 + LWS_PRE];
17
char *payload;
18
int response_code;
19
int done;
@@ -28,6 +30,10 @@ static int simple_https_client_callback(struct lws *wsi, enum lws_callback_reaso
30
switch (reason) {
31
case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ:
32
debug(D_ACLK, "LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ");
33
+ if (perconn_data->data_size - 1 - perconn_data->written < len)
34
+ return 1;
35
+ memcpy(&perconn_data->data[perconn_data->written], in, len);
36
+ perconn_data->written += len;
37
return 0;
38
case LWS_CALLBACK_RECEIVE_CLIENT_HTTP:
39
debug(D_ACLK, "LWS_CALLBACK_RECEIVE_CLIENT_HTTP");
@@ -35,11 +41,11 @@ static int simple_https_client_callback(struct lws *wsi, enum lws_callback_reaso
41
error("Missing Per Connect Data");
42
return -1;
43
}
38
- ptr = perconn_data->data;
39
- n = perconn_data->data_size - 1;
44
+ n = sizeof(perconn_data->lws_work_buffer) - LWS_PRE;
45
+ ptr = perconn_data->lws_work_buffer + LWS_PRE;
46
if (lws_http_client_read(wsi, &ptr, &n) < 0)
47
return -1;
42
- ptr[n] = '\0';
48
+ perconn_data->data[perconn_data->written] = '\0';
49
return 0;
50
case LWS_CALLBACK_WSI_DESTROY:
51
debug(D_ACLK, "LWS_CALLBACK_WSI_DESTROY");
configure.ac
+30
-8
@@ -172,6 +172,15 @@ AC_ARG_ENABLE(
172
,
173
[enable_ebpf="detect"]
174
)
175
+AC_ARG_WITH(
176
+ [bundled-lws],
177
+ [AS_HELP_STRING([--with-bundled-lws=DIR], [Use a specific Libwebsockets static library @<:@default use system library@:>@])],
178
+ [
179
+ with_bundled_lws="yes"
180
+ bundled_lws_dir="${withval}"
181
+ ],
182
+ [with_bundled_lws="no"]
183
+)
184
185
# -----------------------------------------------------------------------------
186
# Enforce building with C99, bail early if we can't.
@@ -651,15 +660,27 @@ if test "$enable_cloud" != "no"; then
660
fi
661
AC_MSG_RESULT([${HAVE_libmosquitto_a}])
662
654
- AC_MSG_CHECKING([if libwebsockets static lib is present])
655
- if test -f "externaldeps/libwebsockets/libwebsockets.a"; then
656
- LWS_CFLAGS="-I externaldeps/libwebsockets/include"
657
- HAVE_libwebsockets_a="yes"
663
+ if test "${with_bundled_lws}" = "yes"; then
664
+ AC_MSG_CHECKING([if libwebsockets static lib is present])
665
+ if test -f "${bundled_lws_dir}/libwebsockets.a"; then
666
+ LWS_CFLAGS="-I ${bundled_lws_dir}/include"
667
+ OPTIONAL_LWS_LIBS="${bundled_lws_dir}/libwebsockets.a"
668
+ AC_MSG_RESULT([yes])
669
+ AC_DEFINE([BUNDLED_LWS], [1], [using statically linked libwebsockets])
670
+ else
671
+ AC_DEFINE([ACLK_NO_LWS], [1], [libwebsockets.a was not found during build.])
672
+ # this should be error if installer ever changes default to system
673
+ # as currently this is default we prefer building netdata without ACLK
674
+ # instead of error fail
675
+ AC_MSG_RESULT([no])
676
+ AC_MSG_WARN([You required static libwebsockets to be used but we can't use it. Disabling ACLK])
677
+ fi
678
else
659
- HAVE_libwebsockets_a="no"
660
- AC_DEFINE([ACLK_NO_LWS], [1], [libwebsockets.a was not found during build.])
679
+ AC_CHECK_LIB([websockets],
680
+ [lws_get_vhost_by_name],
681
+ [OPTIONAL_LWS_LIBS="-lwebsockets"],
682
+ [AC_DEFINE([ACLK_NO_LWS], [1], [usable system libwebsockets was not found during build.])])
683
fi
662
- AC_MSG_RESULT([${HAVE_libwebsockets_a}])
684
685
if test "${build_target}" = "linux" -a "${enable_cloud}" != "no"; then
686
if test "${have_libcap}" = "yes" -a "${with_libcap}" = "no"; then
@@ -678,7 +699,7 @@ if test "$enable_cloud" != "no"; then
699
AC_MSG_ERROR([You have asked for ACLK to be built but no json-c available. ACLK requires json-c])
700
701
AC_MSG_CHECKING([if netdata agent-cloud-link can be enabled])
681
- if test "${HAVE_libmosquitto_a}" = "yes" -a "${HAVE_libwebsockets_a}" = "yes" -a -n "${SSL_LIBS}" -a "${enable_jsonc}" = "yes"; then
702
+ if test "${HAVE_libmosquitto_a}" = "yes" -a -n "${OPTIONAL_LWS_LIBS}" -a -n "${SSL_LIBS}" -a "${enable_jsonc}" = "yes"; then
703
can_enable_aclk="yes"
704
else
705
can_enable_aclk="no"
@@ -1452,6 +1473,7 @@ AC_SUBST([OPTIONAL_PROMETHEUS_REMOTE_WRITE_CFLAGS])
1473
AC_SUBST([OPTIONAL_PROMETHEUS_REMOTE_WRITE_LIBS])
1474
AC_SUBST([OPTIONAL_MONGOC_CFLAGS])
1475
AC_SUBST([OPTIONAL_MONGOC_LIBS])
1476
+AC_SUBST([OPTIONAL_LWS_LIBS])
1477
1478
# -----------------------------------------------------------------------------
1479
# Check if cmocka is available - needed for unit testing
daemon/buildinfo.c
+12
-1
@@ -68,7 +68,14 @@
68
#ifdef ACLK_NO_LWS
69
#define FEAT_LWS "NO"
70
#else
71
-#define FEAT_LWS "YES"
71
+#ifdef ENABLE_ACLK
72
+#include <libwebsockets.h>
73
+#endif
74
+#ifdef BUNDLED_LWS
75
+#define FEAT_LWS "YES static"
76
+#else
77
+#define FEAT_LWS "YES shared-lib"
78
+#endif
79
#endif
80
81
#ifdef NETDATA_WITH_ZLIB
@@ -193,7 +200,11 @@ void print_build_info(void) {
200
printf(" libcap: %s\n", FEAT_LIBCAP);
201
printf(" libcrypto: %s\n", FEAT_CRYPTO);
202
printf(" libm: %s\n", FEAT_LIBM);
203
+#if defined(ENABLE_ACLK)
204
+ printf(" LWS: %s v%d.%d.%d\n", FEAT_LWS, LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH);
205
+#else
206
printf(" LWS: %s\n", FEAT_LWS);
207
+#endif
208
printf(" mosquitto: %s\n", FEAT_MOSQUITTO);
209
printf(" tcalloc: %s\n", FEAT_TCMALLOC);
210
printf(" zlib: %s\n", FEAT_ZLIB);
netdata-installer.sh
+4
-1
@@ -234,6 +234,7 @@ USAGE: ${PROGRAM} [options]
234
--enable-lto Enable Link-Time-Optimization. Default: enabled
235
--disable-lto
236
--disable-x86-sse Disable SSE instructions. By default SSE optimizations are enabled.
237
+ --use-system-lws Use a system copy of libwebsockets instead of bundling our own (default is to use the bundled copy).
238
--zlib-is-really-here or
239
--libs-are-really-here If you get errors about missing zlib or libuuid but you know it is available, you might
240
have a broken pkg-config. Use this option to proceed without checking pkg-config.
@@ -275,6 +276,7 @@ while [ -n "${1}" ]; do
276
case "${1}" in
277
"--zlib-is-really-here") LIBS_ARE_HERE=1 ;;
278
"--libs-are-really-here") LIBS_ARE_HERE=1 ;;
279
+ "--use-system-lws") USE_SYSTEM_LWS=1 ;;
280
"--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;;
281
"--dont-start-it") DONOTSTART=1 ;;
282
"--dont-wait") DONOTWAIT=1 ;;
@@ -641,7 +643,7 @@ copy_libwebsockets() {
643
}
644
645
bundle_libwebsockets() {
644
- if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then
646
+ if [ -n "${NETDATA_DISABLE_CLOUD}" ] || [ -n "${USE_SYSTEM_LWS}" ]; then
647
return 0
648
fi
649
@@ -668,6 +670,7 @@ bundle_libwebsockets() {
670
copy_libwebsockets "${tmp}/libwebsockets-${LIBWEBSOCKETS_PACKAGE_VERSION}" &&
671
rm -rf "${tmp}"; then
672
run_ok "libwebsockets built and prepared."
673
+ NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-lws=externaldeps/libwebsockets"
674
else
675
run_failed "Failed to build libwebsockets."
676
if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then