gnu: python-babel: Update to 2.7.0.
[guix.git] / gnu / packages / patches / glibc-reinstate-prlimit64-fallback.patch
blobccc153c12a0ed3d5a4a9ff79a6e999645d347d4a
1 This patch reinstates fallback code when the 'prlimit64' system call is
2 missing by reverting the relevant part of this upstream commit:
4 commit 695d7d138eda449678a1650a8b8b58181033353f
5 Author: Joseph Myers <joseph@codesourcery.com>
6 Date: Tue May 9 14:05:09 2017 +0000
8 Assume prlimit64 is available.
10 The fallback code is useful on systems that lack 'prlimit64', such as the
11 2.6.32-on-steroid kernel found on RHEL 6:
13 <https://lists.gnu.org/archive/html/guix-devel/2018-03/msg00349.html>
15 diff --git a/sysdeps/unix/sysv/linux/getrlimit64.c b/sysdeps/unix/sysv/linux/getrlimit64.c
16 index 37c173286f..56af3c0646 100644
17 --- b/sysdeps/unix/sysv/linux/getrlimit64.c
18 +++ a/sysdeps/unix/sysv/linux/getrlimit64.c
19 @@ -35,7 +35,40 @@
20 int
21 __getrlimit64 (enum __rlimit_resource resource, struct rlimit64 *rlimits)
23 - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
24 +#ifdef __NR_prlimit64
25 + int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, NULL, rlimits);
26 + if (res == 0 || errno != ENOSYS)
27 + return res;
28 +#endif
30 +/* The fallback code only makes sense if the platform supports either
31 + __NR_ugetrlimit and/or __NR_getrlimit. */
32 +#if defined (__NR_ugetrlimit) || defined (__NR_getrlimit)
33 +# ifndef __NR_ugetrlimit
34 +# define __NR_ugetrlimit __NR_getrlimit
35 +# endif
36 +# if __RLIM_T_MATCHES_RLIM64_T
37 +# define rlimits32 (*rlimits)
38 +# else
39 + struct rlimit rlimits32;
40 +# endif
42 + if (INLINE_SYSCALL_CALL (ugetrlimit, resource, &rlimits32) < 0)
43 + return -1;
45 +# if !__RLIM_T_MATCHES_RLIM64_T
46 + if (rlimits32.rlim_cur == RLIM_INFINITY)
47 + rlimits->rlim_cur = RLIM64_INFINITY;
48 + else
49 + rlimits->rlim_cur = rlimits32.rlim_cur;
50 + if (rlimits32.rlim_max == RLIM_INFINITY)
51 + rlimits->rlim_max = RLIM64_INFINITY;
52 + else
53 + rlimits->rlim_max = rlimits32.rlim_max;
54 +# endif /* !__RLIM_T_MATCHES_RLIM64_T */
55 +#endif /* defined (__NR_ugetrlimit) || defined (__NR_getrlimit) */
57 + return 0;
59 libc_hidden_def (__getrlimit64)
61 diff --git a/sysdeps/unix/sysv/linux/setrlimit.c b/sysdeps/unix/sysv/linux/setrlimit.c
62 index 01812ac355..8773c78236 100644
63 --- b/sysdeps/unix/sysv/linux/setrlimit.c
64 +++ a/sysdeps/unix/sysv/linux/setrlimit.c
65 @@ -34,6 +34,7 @@
66 int
67 __setrlimit (enum __rlimit_resource resource, const struct rlimit *rlim)
69 +# ifdef __NR_prlimit64
70 struct rlimit64 rlim64;
72 if (rlim->rlim_cur == RLIM_INFINITY)
73 @@ -45,7 +46,11 @@
74 else
75 rlim64.rlim_max = rlim->rlim_max;
77 - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL);
78 + int res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, &rlim64, NULL);
79 + if (res == 0 || errno != ENOSYS)
80 + return res;
81 +# endif
82 + return INLINE_SYSCALL_CALL (setrlimit, resource, rlim);
85 # if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
86 diff --git a/sysdeps/unix/sysv/linux/setrlimit64.c b/sysdeps/unix/sysv/linux/setrlimit64.c
87 index 2dd129d99e..db1960fc18 100644
88 --- b/sysdeps/unix/sysv/linux/setrlimit64.c
89 +++ a/sysdeps/unix/sysv/linux/setrlimit64.c
90 @@ -36,7 +36,36 @@
91 int
92 __setrlimit64 (enum __rlimit_resource resource, const struct rlimit64 *rlimits)
94 - return INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
95 + int res;
97 +#ifdef __NR_prlimit64
98 + res = INLINE_SYSCALL_CALL (prlimit64, 0, resource, rlimits, NULL);
99 + if (res == 0 || errno != ENOSYS)
100 + return res;
101 +#endif
103 +/* The fallback code only makes sense if the platform supports
104 + __NR_setrlimit. */
105 +#ifdef __NR_setrlimit
106 +# if !__RLIM_T_MATCHES_RLIM64_T
107 + struct rlimit rlimits32;
109 + if (rlimits->rlim_cur >= RLIM_INFINITY)
110 + rlimits32.rlim_cur = RLIM_INFINITY;
111 + else
112 + rlimits32.rlim_cur = rlimits->rlim_cur;
113 + if (rlimits->rlim_max >= RLIM_INFINITY)
114 + rlimits32.rlim_max = RLIM_INFINITY;
115 + else
116 + rlimits32.rlim_max = rlimits->rlim_max;
117 +# else
118 +# define rlimits32 (*rlimits)
119 +# endif
121 + res = INLINE_SYSCALL_CALL (setrlimit, resource, &rlimits32);
122 +#endif
124 + return res;
126 weak_alias (__setrlimit64, setrlimit64)