simplify api and add smoke test
parent
4ec26be424
commit
1b4296831a
|
@ -5413,10 +5413,12 @@ pub fn prctl(option: i32, args: anytype) PrctlError!u31 {
|
|||
|
||||
pub const GetrlimitError = UnexpectedError;
|
||||
|
||||
pub fn getrlimit(resource: rlimit_resource, limits: *rlimit) GetrlimitError!void {
|
||||
const rc = system.getrlimit(resource, limits);
|
||||
pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
|
||||
// TODO implement for systems other than linux and enable test
|
||||
var limits: rlimit = undefined;
|
||||
const rc = system.getrlimit(resource, &limits);
|
||||
switch (errno(rc)) {
|
||||
0 => return,
|
||||
0 => return limits,
|
||||
EFAULT => unreachable, // bogus pointer
|
||||
EINVAL => unreachable,
|
||||
else => |err| return std.os.unexpectedErrno(err),
|
||||
|
@ -5427,8 +5429,9 @@ pub const SetrlimitError = error{
|
|||
PermissionDenied,
|
||||
} || UnexpectedError;
|
||||
|
||||
pub fn setrlimit(resource: rlimit_resource, limits: *const rlimit) SetrlimitError!void {
|
||||
const rc = system.setrlimit(resource, limits);
|
||||
pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
|
||||
// TODO implement for systems other than linux and enable test
|
||||
const rc = system.setrlimit(resource, &limits);
|
||||
switch (errno(rc)) {
|
||||
0 => return,
|
||||
EFAULT => unreachable, // bogus pointer
|
||||
|
|
|
@ -591,3 +591,13 @@ test "fsync" {
|
|||
try os.fsync(file.handle);
|
||||
try os.fdatasync(file.handle);
|
||||
}
|
||||
|
||||
test "getrlimit and setrlimit" {
|
||||
// TODO enable for other systems when implemented
|
||||
if(builtin.os.tag != .linux){
|
||||
return error.SkipZigTest;
|
||||
}
|
||||
|
||||
const cpuLimit = try os.getrlimit(.CPU);
|
||||
try os.setrlimit(.CPU, cpuLimit);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue