0001-autofs-5-1-7-use-default-stack-size-for-threads.patch 4.0 KB

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