Changeset

4878:c26f515751af

mod_measure_process: Handle unlimited FD limits While unlikely, better type-safe than sorry
author Kim Alvefur <zash@zash.se>
date Tue, 18 Jan 2022 19:09:01 +0100
parents 4877:adc6241e5d16
children 4879:883d45d2082a
files mod_measure_process/mod_measure_process.lua
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_measure_process/mod_measure_process.lua	Tue Jan 18 18:55:20 2022 +0100
+++ b/mod_measure_process/mod_measure_process.lua	Tue Jan 18 19:09:01 2022 +0100
@@ -57,6 +57,13 @@
 		module:log("warn", "not reporting maximum number of file descriptors because mod_posix is not available")
 	end
 
+	local function limit2num(limit)
+		if limit == "unlimited" then
+			return math.huge
+		end
+		return limit
+	end
+
 	module:hook("stats-update", function ()
 		local count = 0
 		for _ in lfs.dir("/proc/self/fd") do
@@ -67,7 +74,7 @@
 		if has_posix then
 			local ok, soft, hard = posix.getrlimit("NOFILE")
 			if ok then
-				max_fds:set(soft or hard);
+				max_fds:set(limit2num(soft or hard));
 			end
 		end
 	end);