[sudo-workers] Output symbolic name of limit in warnings

Kimmo Suominen kimmo at suominen.com
Wed Dec 18 09:08:33 MST 2019


Hi all,

I thought it would be more user-friendly to output the symbolic name of the
limit when setrlimit(2) or getrlimit(2) fails. Patch attached.

Kind regards,
+ Kimmo
-------------- next part --------------
# HG changeset patch
# User Kimmo Suominen <kimmo at suominen.com>
# Date 1576684877 -7200
#      Wed Dec 18 18:01:17 2019 +0200
# Branch 1.8
# Node ID 3a0fed5daaf259f957f29cacc92bb34bdcd2e088
# Parent  614f2b6a358ecef45a29b09b509b9ed5b408a791
Output the name of the limit when warning about setrlimit or getrlimit

diff -r 614f2b6a358e -r 3a0fed5daaf2 plugins/sudoers/sudoers.c
--- a/plugins/sudoers/sudoers.c	Wed Dec 11 13:06:05 2019 -0700
+++ b/plugins/sudoers/sudoers.c	Wed Dec 18 18:01:17 2019 +0200
@@ -129,12 +129,12 @@
     debug_decl(unlimit_nproc, SUDOERS_DEBUG_UTIL)
 
     if (getrlimit(RLIMIT_NPROC, &nproclimit) != 0)
-	    sudo_warn("getrlimit");
+	    sudo_warn("getrlimit(RLIMIT_NPROC)");
     rl.rlim_cur = rl.rlim_max = RLIM_INFINITY;
     if (setrlimit(RLIMIT_NPROC, &rl) != 0) {
 	rl.rlim_cur = rl.rlim_max = nproclimit.rlim_max;
 	if (setrlimit(RLIMIT_NPROC, &rl) != 0)
-	    sudo_warn("setrlimit");
+	    sudo_warn("setrlimit(RLIMIT_NPROC)");
     }
     debug_return;
 #endif /* __linux__ */
@@ -150,7 +150,7 @@
     debug_decl(restore_nproc, SUDOERS_DEBUG_UTIL)
 
     if (setrlimit(RLIMIT_NPROC, &nproclimit) != 0)
-	sudo_warn("setrlimit");
+	sudo_warn("setrlimit(RLIMIT_NPROC)");
 
     debug_return;
 #endif /* __linux__ */
diff -r 614f2b6a358e -r 3a0fed5daaf2 src/limits.c
--- a/src/limits.c	Wed Dec 11 13:06:05 2019 -0700
+++ b/src/limits.c	Wed Dec 18 18:01:17 2019 +0200
@@ -56,6 +56,7 @@
 static struct rlimit stack_fallback = { 8192 * 1024, 65532 * 1024 };
 
 static struct saved_limit {
+    char *name;
     int resource;
     bool saved;
     struct rlimit *fallback;
@@ -63,19 +64,19 @@
     struct rlimit oldlimit;
 } saved_limits[] = {
 #ifdef RLIMIT_AS
-    { RLIMIT_AS, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_AS", RLIMIT_AS, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
 #endif
-    { RLIMIT_CPU, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
-    { RLIMIT_DATA, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
-    { RLIMIT_FSIZE, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
-    { RLIMIT_NOFILE, false, &nofile_fallback, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_CPU", RLIMIT_CPU, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_DATA", RLIMIT_DATA, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_FSIZE", RLIMIT_FSIZE, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_NOFILE", RLIMIT_NOFILE, false, &nofile_fallback, { RLIM_INFINITY, RLIM_INFINITY } },
 #ifdef RLIMIT_NPROC
-    { RLIMIT_NPROC, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_NPROC", RLIMIT_NPROC, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
 #endif
 #ifdef RLIMIT_RSS
-    { RLIMIT_RSS, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
+    { "RLIMIT_RSS", RLIMIT_RSS, false, NULL, { RLIM_INFINITY, RLIM_INFINITY } },
 #endif
-    { RLIMIT_STACK, false, &stack_fallback, { 8192 * 1024, RLIM_INFINITY } }
+    { "RLIMIT_STACK", RLIMIT_STACK, false, &stack_fallback, { 8192 * 1024, RLIM_INFINITY } }
 };
 
 static struct rlimit corelimit;
@@ -209,7 +210,7 @@
 		rc = setrlimit(lim->resource, &lim->newlimit);
 	    }
 	    if (rc == -1)
-		sudo_warn("setrlimit(%d)", lim->resource);
+		sudo_warn("setrlimit(%s)", lim->name);
 	}
     }
 
@@ -230,7 +231,7 @@
 	struct saved_limit *lim = &saved_limits[idx];
 	if (lim->saved) {
 	    if (setrlimit(lim->resource, &lim->oldlimit) == -1)
-		sudo_warn("setrlimit(%d)", lim->resource);
+		sudo_warn("setrlimit(%s)", lim->name);
 	}
     }
     restore_coredump();


More information about the sudo-workers mailing list