[master] e79c02546 Use RLIMIT_MEMLOCK only where available

Nils Goroll nils.goroll at uplex.de
Mon Sep 23 16:33:05 UTC 2024


commit e79c025469116b0a4b9a4b82dc93f447098677d9
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Sep 23 18:31:56 2024 +0200

    Use RLIMIT_MEMLOCK only where available
    
    Solaris does not have it and I overlooked the CONFORMING TO section in the Linux
    manpage.
    
    Ref #4193

diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index 51315f9c3..79d1d740a 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -275,6 +275,7 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg)
 
 /*--------------------------------------------------------------------*/
 
+#ifdef RLIMIT_MEMLOCK
 static void
 printlim(const char *name, rlim_t lim)
 {
@@ -286,11 +287,22 @@ printlim(const char *name, rlim_t lim)
 		fprintf(stderr, "%ju bytes\n", (uintmax_t)lim);
 }
 
+static void
+printmemlock(void) {
+	struct rlimit rlim;
+
+	AZ(getrlimit(RLIMIT_MEMLOCK, &rlim));
+	printlim("max locked memory (soft)", rlim.rlim_cur);
+	printlim("max locked memory (hard)", rlim.rlim_max);
+}
+#else
+static void printmemlock(void) {}
+#endif
+
 static struct vsmw_cluster *
 vsmw_newcluster(struct vsmw *vsmw, size_t len, const char *pfx)
 {
 	struct vsmw_cluster *vc;
-	struct rlimit rlim;
 	static int warn = 0;
 	int fd;
 	size_t ps;
@@ -324,9 +336,7 @@ vsmw_newcluster(struct vsmw *vsmw, size_t len, const char *pfx)
 	if (mlock(vc->ptr, len) && warn++ == 0)  {
 		fprintf(stderr, "Warning: mlock() of VSM failed: %s (%d)\n",
 		    VAS_errtxt(errno), errno);
-		AZ(getrlimit(RLIMIT_MEMLOCK, &rlim));
-		printlim("max locked memory (soft)", rlim.rlim_cur);
-		printlim("max locked memory (hard)", rlim.rlim_max);
+		printmemlock();
 	}
 
 	return (vc);
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index 4edc1f0a3..d48a3fd06 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -875,6 +875,7 @@ main(int argc, char * const *argv)
 		    workdir, VAS_errtxt(errno));
 
 	VJ_master(JAIL_MASTER_SYSTEM);
+#ifdef RLIMIT_MEMLOCK
 	/* try to raise to max (ignore error), then set _cur to whatever we got */
 	rlim.rlim_cur = 0;
 	rlim.rlim_max = RLIM_INFINITY;
@@ -882,6 +883,7 @@ main(int argc, char * const *argv)
 	AZ(getrlimit(RLIMIT_MEMLOCK, &rlim));
 	rlim.rlim_cur = rlim.rlim_max;
 	AZ(setrlimit(RLIMIT_MEMLOCK, &rlim));
+#endif
 
 	AZ(system("rm -rf vmod_cache vext_cache worker_tmpdir"));
 	VJ_master(JAIL_MASTER_LOW);


More information about the varnish-commit mailing list