init: accept -1 or 'unlimited' for an infinite rlimit
Due to a bug with ParseUint(), init would defacto accept -1 for an
infinite rlimit, but only on 64bit devices. That bug is now fixed,
such that -1 would be rejected by ParseUint() for all devices.
This change explicitly checks for -1 for all devices or 'unlimited' to
match ulimit's reporting and accepts either as an infinite rlimit.
Bug: 112668205
Test: new (and old) unit tests
Change-Id: Ie28ff622cdf375a65ceb5f32ffb14fb3d5d9f2ba
diff --git a/init/rlimit_parser.cpp b/init/rlimit_parser.cpp
index fe1d6a7..1e0754a 100644
--- a/init/rlimit_parser.cpp
+++ b/init/rlimit_parser.cpp
@@ -65,12 +65,18 @@
}
rlimit limit;
- if (!ParseUint(args[2], &limit.rlim_cur)) {
+ if (args[2] == "-1" || args[2] == "unlimited") {
+ limit.rlim_cur = RLIM_INFINITY;
+ } else if (!ParseUint(args[2], &limit.rlim_cur)) {
return Error() << "Could not parse soft limit '" << args[2] << "'";
}
- if (!ParseUint(args[3], &limit.rlim_max)) {
+
+ if (args[3] == "-1" || args[3] == "unlimited") {
+ limit.rlim_max = RLIM_INFINITY;
+ } else if (!ParseUint(args[3], &limit.rlim_max)) {
return Error() << "Could not parse hard limit '" << args[3] << "'";
}
+
return {resource, limit};
}