]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3741] 4.2.8p15 can't build with glibc 2.34
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 16 Jan 2022 10:35:06 +0000 (11:35 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 16 Jan 2022 10:35:06 +0000 (11:35 +0100)
 PTHREAD stack sizes can be runtime variant, so make all size adjustments
 runtime checks (as opposed to the compile time checks they were before)

bk: 61e3f4da51hNselhp9D9bXx8xpSapg

ChangeLog
libntp/work_thread.c

index eeceaa9f10cb57b56caf561eaab50a81ec861f63..bed65246ac094c9410df6c09e63f0d064d489ea8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+---
+* [Bug 3741] 4.2.8p15 can't build with glibc 2.34 <perlinger@ntp.org>
+
 ---
 (4.2.8p15) 2020/06/23 Released by Harlan Stenn <stenn@ntp.org>
 
index 03a5647bea36b8df2060b8a48c3006fd8bb254ee..a8e3e2766be46daf205a0e11d16eb66fe23e9cdb 100644 (file)
 #ifndef THREAD_MINSTACKSIZE
 # define THREAD_MINSTACKSIZE   (64U * 1024)
 #endif
-#ifndef __sun
-#if defined(PTHREAD_STACK_MIN) && THREAD_MINSTACKSIZE < PTHREAD_STACK_MIN
-# undef THREAD_MINSTACKSIZE
-# define THREAD_MINSTACKSIZE PTHREAD_STACK_MIN
-#endif
-#endif
 
 #ifndef THREAD_MAXSTACKSIZE
 # define THREAD_MAXSTACKSIZE   (256U * 1024)
 #endif
-#if THREAD_MAXSTACKSIZE < THREAD_MINSTACKSIZE
-# undef  THREAD_MAXSTACKSIZE
-# define THREAD_MAXSTACKSIZE THREAD_MINSTACKSIZE
-#endif
 
 /* need a good integer to store a pointer... */
 #ifndef UINTPTR_T
@@ -594,12 +584,25 @@ start_blocking_thread_internal(
                        "start_blocking_thread: pthread_attr_getstacksize() -> %s",
                        strerror(rc));
        } else {
-               if (ostacksize < THREAD_MINSTACKSIZE)
-                       nstacksize = THREAD_MINSTACKSIZE;
-               else if (ostacksize > THREAD_MAXSTACKSIZE)
+               nstacksize = ostacksize;
+               /* order is important here: first clamp on upper limit,
+                * and the PTHREAD min stack size is ultimate override!
+                */ 
+               if (nstacksize > THREAD_MAXSTACKSIZE)
                        nstacksize = THREAD_MAXSTACKSIZE;
-               else
-                       nstacksize = ostacksize;
+#            ifdef PTHREAD_STACK_MAX
+               if (nstacksize > PTHREAD_STACK_MAX)
+                       nstacksize = PTHREAD_STACK_MAX;
+#            endif
+
+               /* now clamp on lower stack limit. */
+               if (nstacksize < THREAD_MINSTACKSIZE)
+                       nstacksize = THREAD_MINSTACKSIZE;
+#            ifdef PTHREAD_STACK_MIN
+               if (nstacksize < PTHREAD_STACK_MIN)
+                       nstacksize = PTHREAD_STACK_MIN;
+#            endif
+
                if (nstacksize != ostacksize)
                        rc = pthread_attr_setstacksize(&thr_attr, nstacksize);
                if (0 != rc)