summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2021-12-05 15:48:18 -0500
committerTavian Barnes <tavianator@tavianator.com>2021-12-05 15:48:18 -0500
commit26c0bb082ca1c03aa4eb788385d4fecf7cc46a6b (patch)
treec7b7ae78492138cd4d67a240b0d4a5d615711d6f
parentc550942047e3f95d38d44a1d1cd00df20287eb4a (diff)
downloadbfs-26c0bb082ca1c03aa4eb788385d4fecf7cc46a6b.tar.xz
eval: Check that RLIM_SAVED_{CUR,MAX} are defined before using them
Apparently they're missing on Debian kfreebsd: https://buildd.debian.org/status/fetch.php?pkg=bfs&arch=kfreebsd-amd64&ver=2.3-1&stamp=1638379495&raw=0
-rw-r--r--eval.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/eval.c b/eval.c
index b35a236..ec2701b 100644
--- a/eval.c
+++ b/eval.c
@@ -1416,11 +1416,32 @@ done:
return state.action;
}
+/** Check if an rlimit value is infinite. */
+static bool rlim_isinf(rlim_t r) {
+ // Consider RLIM_{INFINITY,SAVED_{CUR,MAX}} all equally infinite
+ if (r == RLIM_INFINITY) {
+ return true;
+ }
+
+#ifdef RLIM_SAVED_CUR
+ if (r == RLIM_SAVED_CUR) {
+ return true;
+ }
+#endif
+
+#ifdef RLIM_SAVED_MAX
+ if (r == RLIM_SAVED_MAX) {
+ return true;
+ }
+#endif
+
+ return false;
+}
+
/** Compare two rlimit values, accounting for RLIM_INFINITY etc. */
static int rlim_cmp(rlim_t a, rlim_t b) {
- // Consider RLIM_{INFINITY,SAVED_{CUR,MAX}} all equally infinite
- bool a_inf = a == RLIM_INFINITY || a == RLIM_SAVED_CUR || a == RLIM_SAVED_MAX;
- bool b_inf = b == RLIM_INFINITY || b == RLIM_SAVED_CUR || b == RLIM_SAVED_MAX;
+ bool a_inf = rlim_isinf(a);
+ bool b_inf = rlim_isinf(b);
if (a_inf || b_inf) {
return a_inf - b_inf;
}