- if (memory_limit)
- {
- rl.rlim_cur = rl.rlim_max = memory_limit * 1024;
- if (setrlimit(RLIMIT_AS, &rl) < 0)
- die("setrlimit(RLIMIT_AS): %m");
- }
+static void
+setup_rlim(const char *res_name, int res, rlim_t limit)
+{
+ struct rlimit rl = { .rlim_cur = limit, .rlim_max = limit };
+ if (setrlimit(res, &rl) < 0)
+ die("setrlimit(%s, %jd)", res_name, (intmax_t) limit);
+}
+
+static void
+setup_rlimits(void)
+{
+#define RLIM(res, val) setup_rlim("RLIMIT_" #res, RLIMIT_##res, val)