From 9709f2c562cff3791fa0ab8146110194ab93c760 Mon Sep 17 00:00:00 2001 From: Virtually Nick Date: Sun, 2 Jan 2022 23:41:18 -0500 Subject: [PATCH] GUACAMOLE-663: Set pthread stack size for guacd --- configure.ac | 4 ++++ src/guacd/daemon.c | 9 +++++++++ src/guacd/proc-map.h | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/configure.ac b/configure.ac index 469f01e39..21a0ef4aa 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,7 @@ AC_CHECK_HEADERS([fcntl.h stdlib.h string.h sys/socket.h time.h sys/time.h syslo # Source characteristics AC_DEFINE([_XOPEN_SOURCE], [700], [Uses X/Open and POSIX APIs]) AC_DEFINE([__BSD_VISIBLE], [1], [Uses BSD-specific APIs (if available)]) +AC_DEFINE([_GNU_SOURCE], [1], [Use GNU sources (if available)]) # Check for whether math library is required AC_CHECK_LIB([m], [cos], @@ -71,6 +72,9 @@ AC_CHECK_LIB([pthread], [pthread_create], [PTHREAD_LIBS=-lpthread AC_DEFINE([HAVE_LIBPTHREAD],, [Whether libpthread was found])]) +# Check for pthread_setattr_default_np +AC_CHECK_DECLS([pthread_setattr_default_np], , , [[#include ]]) + # librt AC_CHECK_FUNC([timer_create], [AC_MSG_RESULT([timer_create was found without librt.])], [AC_CHECK_LIB([rt], [timer_create], diff --git a/src/guacd/daemon.c b/src/guacd/daemon.c index 8bf81482e..1701a366a 100644 --- a/src/guacd/daemon.c +++ b/src/guacd/daemon.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -320,6 +321,14 @@ int main(int argc, char* argv[]) { /* General */ int retval; +#ifdef HAVE_DECL_PTHREAD_SETATTR_DEFAULT_NP + /* Set default stack size */ + pthread_attr_t default_pthread_attr; + pthread_attr_init(&default_pthread_attr); + pthread_attr_setstacksize(&default_pthread_attr, GUACD_THREAD_STACK_SIZE); + pthread_setattr_default_np(&default_pthread_attr); +#endif // HAVE_DECL_PTHREAD_SETATTR_DEFAULT_NP + /* Load configuration */ guacd_config* config = guacd_conf_load(); if (config == NULL || guacd_conf_parse_args(config, argc, argv)) diff --git a/src/guacd/proc-map.h b/src/guacd/proc-map.h index adce8cf6d..5bae48978 100644 --- a/src/guacd/proc-map.h +++ b/src/guacd/proc-map.h @@ -32,6 +32,11 @@ */ #define GUACD_CLIENT_MAX_CONNECTIONS 65536 +/** + * The pthread stack size for the guacd daemon. + */ +#define GUACD_THREAD_STACK_SIZE 8388608 + /** * The number of hash buckets in each process map. */