diff options
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | aclk/aclk_lws_https_client.c | 12 | ||||
-rw-r--r-- | configure.ac | 38 | ||||
-rw-r--r-- | daemon/buildinfo.c | 13 | ||||
-rwxr-xr-x | netdata-installer.sh | 5 |
5 files changed, 56 insertions, 14 deletions
diff --git a/Makefile.am b/Makefile.am index 274f9e66ae..24de58e66f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -712,8 +712,8 @@ netdata_SOURCES = $(NETDATA_FILES) if ENABLE_ACLK netdata_LDADD = \ externaldeps/mosquitto/libmosquitto.a \ - externaldeps/libwebsockets/libwebsockets.a \ $(OPTIONAL_LIBCAP_LIBS) \ + $(OPTIONAL_LWS_LIBS) \ $(NETDATA_COMMON_LIBS) \ $(NULL) else diff --git a/aclk/aclk_lws_https_client.c b/aclk/aclk_lws_https_client.c index 5d54c79583..c1856ed2c0 100644 --- a/aclk/aclk_lws_https_client.c +++ b/aclk/aclk_lws_https_client.c @@ -12,6 +12,8 @@ struct simple_hcc_data { char *data; size_t data_size; + size_t written; + char lws_work_buffer[1024 + LWS_PRE]; char *payload; int response_code; int done; @@ -28,6 +30,10 @@ static int simple_https_client_callback(struct lws *wsi, enum lws_callback_reaso switch (reason) { case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ: debug(D_ACLK, "LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ"); + if (perconn_data->data_size - 1 - perconn_data->written < len) + return 1; + memcpy(&perconn_data->data[perconn_data->written], in, len); + perconn_data->written += len; return 0; case LWS_CALLBACK_RECEIVE_CLIENT_HTTP: 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 error("Missing Per Connect Data"); return -1; } - ptr = perconn_data->data; - n = perconn_data->data_size - 1; + n = sizeof(perconn_data->lws_work_buffer) - LWS_PRE; + ptr = perconn_data->lws_work_buffer + LWS_PRE; if (lws_http_client_read(wsi, &ptr, &n) < 0) return -1; - ptr[n] = '\0'; + perconn_data->data[perconn_data->written] = '\0'; return 0; case LWS_CALLBACK_WSI_DESTROY: debug(D_ACLK, "LWS_CALLBACK_WSI_DESTROY"); diff --git a/configure.ac b/configure.ac index 5f13b4feb0..2d5e84c490 100644 --- a/configure.ac +++ b/configure.ac @@ -172,6 +172,15 @@ AC_ARG_ENABLE( , [enable_ebpf="detect"] ) +AC_ARG_WITH( + [bundled-lws], + [AS_HELP_STRING([--with-bundled-lws=DIR], [Use a specific Libwebsockets static library @<:@default use system library@:>@])], + [ + with_bundled_lws="yes" + bundled_lws_dir="${withval}" + ], + [with_bundled_lws="no"] +) # ----------------------------------------------------------------------------- # Enforce building with C99, bail early if we can't. @@ -651,15 +660,27 @@ if test "$enable_cloud" != "no"; then fi AC_MSG_RESULT([${HAVE_libmosquitto_a}]) - AC_MSG_CHECKING([if libwebsockets static lib is present]) - if test -f "externaldeps/libwebsockets/libwebsockets.a"; then - LWS_CFLAGS="-I externaldeps/libwebsockets/include" - HAVE_libwebsockets_a="yes" + if test "${with_bundled_lws}" = "yes"; then + AC_MSG_CHECKING([if libwebsockets static lib is present]) + if test -f "${bundled_lws_dir}/libwebsockets.a"; then + LWS_CFLAGS="-I ${bundled_lws_dir}/include" + OPTIONAL_LWS_LIBS="${bundled_lws_dir}/libwebsockets.a" + AC_MSG_RESULT([yes]) + AC_DEFINE([BUNDLED_LWS], [1], [using statically linked libwebsockets]) + else + AC_DEFINE([ACLK_NO_LWS], [1], [libwebsockets.a was not found during build.]) + # this should be error if installer ever changes default to system + # as currently this is default we prefer building netdata without ACLK + # instead of error fail + AC_MSG_RESULT([no]) + AC_MSG_WARN([You required static libwebsockets to be used but we can't use it. Disabling ACLK]) + fi else - HAVE_libwebsockets_a="no" - AC_DEFINE([ACLK_NO_LWS], [1], [libwebsockets.a was not found during build.]) + AC_CHECK_LIB([websockets], + [lws_get_vhost_by_name], + [OPTIONAL_LWS_LIBS="-lwebsockets"], + [AC_DEFINE([ACLK_NO_LWS], [1], [usable system libwebsockets was not found during build.])]) fi - AC_MSG_RESULT([${HAVE_libwebsockets_a}]) if test "${build_target}" = "linux" -a "${enable_cloud}" != "no"; then if test "${have_libcap}" = "yes" -a "${with_libcap}" = "no"; then @@ -678,7 +699,7 @@ if test "$enable_cloud" != "no"; then AC_MSG_ERROR([You have asked for ACLK to be built but no json-c available. ACLK requires json-c]) AC_MSG_CHECKING([if netdata agent-cloud-link can be enabled]) - if test "${HAVE_libmosquitto_a}" = "yes" -a "${HAVE_libwebsockets_a}" = "yes" -a -n "${SSL_LIBS}" -a "${enable_jsonc}" = "yes"; then + if test "${HAVE_libmosquitto_a}" = "yes" -a -n "${OPTIONAL_LWS_LIBS}" -a -n "${SSL_LIBS}" -a "${enable_jsonc}" = "yes"; then can_enable_aclk="yes" else can_enable_aclk="no" @@ -1452,6 +1473,7 @@ AC_SUBST([OPTIONAL_PROMETHEUS_REMOTE_WRITE_CFLAGS]) AC_SUBST([OPTIONAL_PROMETHEUS_REMOTE_WRITE_LIBS]) AC_SUBST([OPTIONAL_MONGOC_CFLAGS]) AC_SUBST([OPTIONAL_MONGOC_LIBS]) +AC_SUBST([OPTIONAL_LWS_LIBS]) # ----------------------------------------------------------------------------- # Check if cmocka is available - needed for unit testing diff --git a/daemon/buildinfo.c b/daemon/buildinfo.c index 743c290f69..de02a72e1a 100644 --- a/daemon/buildinfo.c +++ b/daemon/buildinfo.c @@ -68,7 +68,14 @@ #ifdef ACLK_NO_LWS #define FEAT_LWS "NO" #else -#define FEAT_LWS "YES" +#ifdef ENABLE_ACLK +#include <libwebsockets.h> +#endif +#ifdef BUNDLED_LWS +#define FEAT_LWS "YES static" +#else +#define FEAT_LWS "YES shared-lib" +#endif #endif #ifdef NETDATA_WITH_ZLIB @@ -193,7 +200,11 @@ void print_build_info(void) { printf(" libcap: %s\n", FEAT_LIBCAP); printf(" libcrypto: %s\n", FEAT_CRYPTO); printf(" libm: %s\n", FEAT_LIBM); +#if defined(ENABLE_ACLK) + printf(" LWS: %s v%d.%d.%d\n", FEAT_LWS, LWS_LIBRARY_VERSION_MAJOR, LWS_LIBRARY_VERSION_MINOR, LWS_LIBRARY_VERSION_PATCH); +#else printf(" LWS: %s\n", FEAT_LWS); +#endif printf(" mosquitto: %s\n", FEAT_MOSQUITTO); printf(" tcalloc: %s\n", FEAT_TCMALLOC); printf(" zlib: %s\n", FEAT_ZLIB); diff --git a/netdata-installer.sh b/netdata-installer.sh index d84b2b44d3..d529e38c04 100755 --- a/netdata-installer.sh +++ b/netdata-installer.sh @@ -234,6 +234,7 @@ USAGE: ${PROGRAM} [options] --enable-lto Enable Link-Time-Optimization. Default: enabled --disable-lto --disable-x86-sse Disable SSE instructions. By default SSE optimizations are enabled. + --use-system-lws Use a system copy of libwebsockets instead of bundling our own (default is to use the bundled copy). --zlib-is-really-here or --libs-are-really-here If you get errors about missing zlib or libuuid but you know it is available, you might have a broken pkg-config. Use this option to proceed without checking pkg-config. @@ -275,6 +276,7 @@ while [ -n "${1}" ]; do case "${1}" in "--zlib-is-really-here") LIBS_ARE_HERE=1 ;; "--libs-are-really-here") LIBS_ARE_HERE=1 ;; + "--use-system-lws") USE_SYSTEM_LWS=1 ;; "--dont-scrub-cflags-even-though-it-may-break-things") DONT_SCRUB_CFLAGS_EVEN_THOUGH_IT_MAY_BREAK_THINGS=1 ;; "--dont-start-it") DONOTSTART=1 ;; "--dont-wait") DONOTWAIT=1 ;; @@ -641,7 +643,7 @@ copy_libwebsockets() { } bundle_libwebsockets() { - if [ -n "${NETDATA_DISABLE_CLOUD}" ]; then + if [ -n "${NETDATA_DISABLE_CLOUD}" ] || [ -n "${USE_SYSTEM_LWS}" ]; then return 0 fi @@ -668,6 +670,7 @@ bundle_libwebsockets() { copy_libwebsockets "${tmp}/libwebsockets-${LIBWEBSOCKETS_PACKAGE_VERSION}" && rm -rf "${tmp}"; then run_ok "libwebsockets built and prepared." + NETDATA_CONFIGURE_OPTIONS="${NETDATA_CONFIGURE_OPTIONS} --with-bundled-lws=externaldeps/libwebsockets" else run_failed "Failed to build libwebsockets." if [ -n "${NETDATA_REQUIRE_CLOUD}" ]; then |