1From 91edcc55c681dac41d2213b498ec6450aee22d9f Mon Sep 17 00:00:00 2001 2From: Ian Kent <raven@themaw.net> 3Date: Mon, 26 Jul 2021 13:18:38 +0800 4Subject: autofs-5.1.7 - use default stack size for threads 5 6autofs uses PTHREAD_STACK_MIN to set the stack size for threads it 7creates. 8 9In two cases it is used to reduce the stack size for long running 10service threads while it's used to allocate a larger stack for worker 11threads that can have larger memory requirements. 12 13In recent glibc releases PTHREAD_STACK_MIN is no longer a constant 14which can lead to unexpectedly different stack sizes on different 15architectures and the autofs assumption it's a constant causes a 16compile failure. 17 18The need to alter the stack size was due to observed stack overflow 19which was thought to be due the thread stack being too small for autofs 20and glibc alloca(3) usage. 21 22Quite a bit of that alloca(3) usage has been eliminated from autofs now, 23particularly those that might be allocating largish amounts of storage, 24and there has been a lot of change in glibc too so using the thread 25default stack should be ok. 26 27Signed-off-by: Ian Kent <raven@themaw.net> 28 29[Retrieved (and updated to drop CHANGELOG update) from: 30https://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git/commit/?id=91edcc55c681dac41d2213b498ec6450aee22d9f] 31Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 32--- 33 CHANGELOG | 1 + 34 daemon/automount.c | 29 ----------------------------- 35 daemon/state.c | 6 +----- 36 lib/alarm.c | 6 +----- 37 4 files changed, 3 insertions(+), 39 deletions(-) 38 39diff --git a/daemon/automount.c b/daemon/automount.c 40index 23235a7..d743235 100644 41--- a/daemon/automount.c 42+++ b/daemon/automount.c 43@@ -84,7 +84,6 @@ static size_t kpkt_len; 44 /* Attributes for creating detached and joinable threads */ 45 pthread_attr_t th_attr; 46 pthread_attr_t th_attr_detached; 47-size_t detached_thread_stack_size = PTHREAD_STACK_MIN * 144; 48 49 struct master_readmap_cond mrc = { 50 PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0, NULL, 0, 0, 0, 0}; 51@@ -2620,34 +2619,6 @@ int main(int argc, char *argv[]) 52 exit(1); 53 } 54 55-#ifdef _POSIX_THREAD_ATTR_STACKSIZE 56- if (pthread_attr_setstacksize( 57- &th_attr_detached, detached_thread_stack_size)) { 58- logerr("%s: failed to set stack size thread attribute!", 59- program); 60- if (start_pipefd[1] != -1) { 61- res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); 62- close(start_pipefd[1]); 63- } 64- release_flag_file(); 65- macro_free_global_table(); 66- exit(1); 67- } 68-#endif 69- 70- if (pthread_attr_getstacksize( 71- &th_attr_detached, &detached_thread_stack_size)) { 72- logerr("%s: failed to get detached thread stack size!", 73- program); 74- if (start_pipefd[1] != -1) { 75- res = write(start_pipefd[1], pst_stat, sizeof(*pst_stat)); 76- close(start_pipefd[1]); 77- } 78- release_flag_file(); 79- macro_free_global_table(); 80- exit(1); 81- } 82- 83 info(logging, "Starting automounter version %s, master map %s", 84 version, master_list->name); 85 info(logging, "using kernel protocol version %d.%02d", 86diff --git a/daemon/state.c b/daemon/state.c 87index 5156bb2..5df0561 100644 88--- a/daemon/state.c 89+++ b/daemon/state.c 90@@ -1177,12 +1177,8 @@ int st_start_handler(void) 91 status = pthread_attr_init(pattrs); 92 if (status) 93 pattrs = NULL; 94- else { 95+ else 96 pthread_attr_setdetachstate(pattrs, PTHREAD_CREATE_DETACHED); 97-#ifdef _POSIX_THREAD_ATTR_STACKSIZE 98- pthread_attr_setstacksize(pattrs, PTHREAD_STACK_MIN*4); 99-#endif 100- } 101 102 status = pthread_create(&thid, pattrs, st_queue_handler, NULL); 103 104diff --git a/lib/alarm.c b/lib/alarm.c 105index f27e13c..1631a9b 100755 106--- a/lib/alarm.c 107+++ b/lib/alarm.c 108@@ -270,12 +270,8 @@ int alarm_start_handler(void) 109 status = pthread_attr_init(pattrs); 110 if (status) 111 pattrs = NULL; 112- else { 113+ else 114 pthread_attr_setdetachstate(pattrs, PTHREAD_CREATE_DETACHED); 115-#ifdef _POSIX_THREAD_ATTR_STACKSIZE 116- pthread_attr_setstacksize(pattrs, PTHREAD_STACK_MIN*4); 117-#endif 118- } 119 120 status = pthread_condattr_init(&condattrs); 121 if (status) 122-- 123cgit 1.2.3-1.el7 124 125