Skip to content

Commit 02af011

Browse files
committed
Fixed fatal error: sys/random.h: No such file or directory
When building git dependency on redhat 7 with git v2.50 we get a compilation error due to the include of a missing file. ``` 15:05:27 + make CURL_LDFLAGS=-lcurl 15:05:28 GIT_VERSION=2.50.0 15:05:28 * new build flags 15:05:28 CC daemon.o 15:05:28 In file included from git-compat-util.h:26:0, 15:05:28 from daemon.c:3: 15:05:28 compat/posix.h:159:24: fatal error: sys/random.h: No such file or directory 15:05:28 #include <sys/random.h> 15:05:28 ^ 15:05:28 compilation terminated. ``` Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> (cherry picked from commit 16fc9aa)
1 parent f07a646 commit 02af011

File tree

2 files changed

+63
-4
lines changed

2 files changed

+63
-4
lines changed

deps-packaging/git/cfbuild-git.spec

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ mkdir -p %{_builddir}
2222

2323
%build
2424

25+
case "$OS" in
26+
rhel|centos)
27+
if [ $(echo $OS_VERSION | cut -d. -f1) = 7 ]
28+
then
29+
# Fixes the following compilation error on rhel 7:
30+
# 15:05:28 compat/posix.h:159:24: fatal error: sys/random.h: No such file or directory
31+
# 15:05:28 #include <sys/random.h>
32+
# 15:05:28 ^
33+
# 15:05:28 compilation terminated.
34+
patch -p1 < %{_topdir}/SOURCES/fix_git_on_rhel7.patch
35+
fi
36+
;;
37+
esac
38+
2539
make CURL_LDFLAGS="-lcurl"
2640

2741
%install
@@ -36,6 +50,7 @@ rm -rf ${RPM_BUILD_ROOT}%{prefix}/lib/python*
3650
rm -rf ${RPM_BUILD_ROOT}%{prefix}/lib64
3751
rm -rf ${RPM_BUILD_ROOT}%{prefix}/perl5
3852
rm -rf ${RPM_BUILD_ROOT}%{prefix}/share/perl5
53+
rm -rf ${RPM_BUILD_ROOT}%{prefix}/share/bash-completion
3954
rm -rf ${RPM_BUILD_ROOT}%{prefix}/bin/scalar
4055

4156
%clean
@@ -67,7 +82,3 @@ CFEngine Build Automation -- git
6782
%{prefix}/lib/git-core
6883

6984
%changelog
70-
71-
72-
73-
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
diff -ruN git-2.50.0/compat/posix.h git-2.50.0-modified/compat/posix.h
2+
--- git-2.50.0/compat/posix.h 2025-06-24 15:50:16.431161905 +0200
3+
+++ git-2.50.0-modified/compat/posix.h 2025-06-24 15:56:12.823192406 +0200
4+
@@ -155,9 +155,9 @@
5+
#ifdef HAVE_ARC4RANDOM_LIBBSD
6+
#include <bsd/stdlib.h>
7+
#endif
8+
-#ifdef HAVE_GETRANDOM
9+
-#include <sys/random.h>
10+
-#endif
11+
+// #ifdef HAVE_GETRANDOM
12+
+// #include <sys/random.h>
13+
+// #endif
14+
#ifdef NO_INTPTR_T
15+
/*
16+
* On I16LP32, ILP32 and LP64 "long" is the safe bet, however
17+
diff -ruN git-2.50.0/wrapper.c git-2.50.0-modified/wrapper.c
18+
--- git-2.50.0/wrapper.c 2025-06-16 07:42:57.000000000 +0200
19+
+++ git-2.50.0-modified/wrapper.c 2025-06-24 15:56:09.560108133 +0200
20+
@@ -775,17 +775,17 @@
21+
/* This function never returns an error. */
22+
arc4random_buf(buf, len);
23+
return 0;
24+
-#elif defined(HAVE_GETRANDOM)
25+
- ssize_t res;
26+
- char *p = buf;
27+
- while (len) {
28+
- res = getrandom(p, len, 0);
29+
- if (res < 0)
30+
- return -1;
31+
- len -= res;
32+
- p += res;
33+
- }
34+
- return 0;
35+
+// #elif defined(HAVE_GETRANDOM)
36+
+// ssize_t res;
37+
+// char *p = buf;
38+
+// while (len) {
39+
+// res = getrandom(p, len, 0);
40+
+// if (res < 0)
41+
+// return -1;
42+
+// len -= res;
43+
+// p += res;
44+
+// }
45+
+// return 0;
46+
#elif defined(HAVE_GETENTROPY)
47+
int res;
48+
char *p = buf;

0 commit comments

Comments
 (0)