LibCore: Add system call wrappers around getrlimit and setrlimit

This commit is contained in:
Timothy Flynn 2024-07-22 10:11:18 -04:00 committed by Andreas Kling
parent 7b10eb7225
commit 0d6115e8ae
Notes: github-actions[bot] 2024-07-23 07:40:42 +00:00
2 changed files with 25 additions and 0 deletions

View file

@ -1848,4 +1848,25 @@ ErrorOr<Bytes> allocate(size_t count, size_t size)
return Bytes { data, size * count }; return Bytes { data, size * count };
} }
ErrorOr<rlimit> get_resource_limits(int resource)
{
rlimit limits;
if (::getrlimit(resource, &limits) != 0)
return Error::from_errno(errno);
return limits;
}
ErrorOr<void> set_resource_limits(int resource, rlim_t limit)
{
auto limits = TRY(get_resource_limits(resource));
limits.rlim_cur = limit;
if (::setrlimit(resource, &limits) != 0)
return Error::from_errno(errno);
return {};
}
} }

View file

@ -22,6 +22,7 @@
#include <signal.h> #include <signal.h>
#include <spawn.h> #include <spawn.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
@ -289,4 +290,7 @@ ErrorOr<ByteString> current_executable_path();
ErrorOr<Bytes> allocate(size_t count, size_t size); ErrorOr<Bytes> allocate(size_t count, size_t size);
ErrorOr<rlimit> get_resource_limits(int resource);
ErrorOr<void> set_resource_limits(int resource, rlim_t limit);
} }