cmake: only use `getloadavg` where it exists
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 58e5825..d16cfe5 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -71,6 +71,7 @@ check_function_exists(qsort_s GIT_QSORT_S)
# random / entropy data
check_function_exists(getentropy GIT_RAND_GETENTROPY)
+check_function_exists(getloadavg GIT_RAND_GETLOADAVG)
# determine architecture of the machine
diff --git a/src/features.h.in b/src/features.h.in
index e14e833..fbf0cab 100644
--- a/src/features.h.in
+++ b/src/features.h.in
@@ -57,5 +57,6 @@
#cmakedefine GIT_SHA256_MBEDTLS 1
#cmakedefine GIT_RAND_GETENTROPY 1
+#cmakedefine GIT_RAND_GETLOADAVG 1
#endif
diff --git a/src/util/rand.c b/src/util/rand.c
index 4324949..d28e4aa 100644
--- a/src/util/rand.c
+++ b/src/util/rand.c
@@ -106,8 +106,6 @@ GIT_INLINE(int) getseed(uint64_t *seed)
return -1;
}
- getloadavg(loadavg, 3);
-
*seed = 0;
*seed |= ((uint64_t)tv.tv_usec << 40);
*seed |= ((uint64_t)tv.tv_sec);
@@ -119,9 +117,15 @@ GIT_INLINE(int) getseed(uint64_t *seed)
*seed ^= ((uint64_t)getuid() << 8);
*seed ^= ((uint64_t)getgid());
+# if defined(GIT_RAND_GETLOADAVG)
+ getloadavg(loadavg, 3);
+
convert.f = loadavg[0]; *seed ^= (convert.d >> 36);
convert.f = loadavg[1]; *seed ^= (convert.d);
convert.f = loadavg[2]; *seed ^= (convert.d >> 16);
+# else
+ GIT_UNUSED(loadavg[0]);
+# endif
convert.f = git__timer(); *seed ^= (convert.d);