37d145c71807801efd9cb02926515c82e84c1c71
braney
  Wed Feb 7 10:12:23 2024 -0800
set up a mechanism to limit memory through an hg.conf variable

diff --git src/lib/osunix.c src/lib/osunix.c
index fdf25b4..3ded594 100644
--- src/lib/osunix.c
+++ src/lib/osunix.c
@@ -815,15 +815,28 @@
  * seconds. */
 {
 struct runTimes rts;
 
 struct timeval tv;
 gettimeofday(&tv, NULL);
 rts.clockSecs = timevalToSeconds(tv);
 
 struct rusage usage;
 getrusage(RUSAGE_SELF, &usage);
 rts.userSecs = timevalToSeconds(usage.ru_utime);
 rts.sysSecs = timevalToSeconds(usage.ru_stime);
 
 return rts;
 }
+
+void setMemLimit(unsigned long maxMem)
+/* Set the maximum amount of memory that the application can use. */
+{
+struct rlimit rlimit;
+
+rlimit.rlim_cur = maxMem;
+rlimit.rlim_max = rlimit.rlim_cur ;
+int val = setrlimit(RLIMIT_AS, &rlimit);
+
+if (val != 0)
+    errnoAbort("Couldn't set maxMem to %ld\n", maxMem);
+}