| author | |
| committer | |
| log | 6418284680920a19fd34ec1a10d79113a5bec75d |
| tree | 9c12e2ada9ee871191b9a818c819ad34bb8a28d2 |
| parent | 36f1788762ef5584bd0ebf5cef85a99318230ac4 |
7 files changed, 167 insertions(+), 6 deletions(-)
lib/std/os.zig-2| ... | @@ -5663,7 +5663,6 @@ pub fn prctl(option: i32, args: anytype) PrctlError!u31 { | ... | @@ -5663,7 +5663,6 @@ pub fn prctl(option: i32, args: anytype) PrctlError!u31 { |
| 5663 | pub const GetrlimitError = UnexpectedError; | 5663 | pub const GetrlimitError = UnexpectedError; |
| 5664 | 5664 | ||
| 5665 | pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { | 5665 | pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { |
| 5666 | // TODO implement for systems other than linux and enable test | ||
| 5667 | var limits: rlimit = undefined; | 5666 | var limits: rlimit = undefined; |
| 5668 | const rc = system.getrlimit(resource, &limits); | 5667 | const rc = system.getrlimit(resource, &limits); |
| 5669 | switch (errno(rc)) { | 5668 | switch (errno(rc)) { |
| ... | @@ -5677,7 +5676,6 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { | ... | @@ -5677,7 +5676,6 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit { |
| 5677 | pub const SetrlimitError = error{PermissionDenied} || UnexpectedError; | 5676 | pub const SetrlimitError = error{PermissionDenied} || UnexpectedError; |
| 5678 | 5677 | ||
| 5679 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { | 5678 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { |
| 5680 | // TODO implement for systems other than linux and enable test | ||
| 5681 | const rc = system.setrlimit(resource, &limits); | 5679 | const rc = system.setrlimit(resource, &limits); |
| 5682 | switch (errno(rc)) { | 5680 | switch (errno(rc)) { |
| 5683 | 0 => return, | 5681 | 0 => return, |
lib/std/os/bits/darwin.zig+30| ... | @@ -1496,3 +1496,33 @@ pub const rusage = extern struct { | ... | @@ -1496,3 +1496,33 @@ pub const rusage = extern struct { |
| 1496 | nvcsw: isize, | 1496 | nvcsw: isize, |
| 1497 | nivcsw: isize, | 1497 | nivcsw: isize, |
| 1498 | }; | 1498 | }; |
| 1499 | |||
| 1500 | pub const rlimit_resource = extern enum(c_int) { | ||
| 1501 | CPU = 0, | ||
| 1502 | FSIZE = 1, | ||
| 1503 | DATA = 2, | ||
| 1504 | STACK = 3, | ||
| 1505 | CORE = 4, | ||
| 1506 | AS = 5, | ||
| 1507 | RSS = 5, | ||
| 1508 | MEMLOCK = 6, | ||
| 1509 | NPROC = 7, | ||
| 1510 | NOFILE = 8, | ||
| 1511 | |||
| 1512 | _, | ||
| 1513 | }; | ||
| 1514 | |||
| 1515 | pub const rlim_t = u64; | ||
| 1516 | |||
| 1517 | /// No limit | ||
| 1518 | pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1; | ||
| 1519 | |||
| 1520 | pub const RLIM_SAVED_MAX = RLIM_INFINITY; | ||
| 1521 | pub const RLIM_SAVED_CUR = RLIM_INFINITY; | ||
| 1522 | |||
| 1523 | pub const rlimit = extern struct { | ||
| 1524 | /// Soft limit | ||
| 1525 | cur: rlim_t, | ||
| 1526 | /// Hard limit | ||
| 1527 | max: rlim_t, | ||
| 1528 | }; |
lib/std/os/bits/dragonfly.zig+33| ... | @@ -721,3 +721,36 @@ pub const Flock = extern struct { | ... | @@ -721,3 +721,36 @@ pub const Flock = extern struct { |
| 721 | l_type: c_short, | 721 | l_type: c_short, |
| 722 | l_whence: c_short, | 722 | l_whence: c_short, |
| 723 | }; | 723 | }; |
| 724 | |||
| 725 | pub const rlimit_resource = extern enum(c_int) { | ||
| 726 | CPU = 0, | ||
| 727 | FSIZE = 1, | ||
| 728 | DATA = 2, | ||
| 729 | STACK = 3, | ||
| 730 | CORE = 4, | ||
| 731 | RSS = 5, | ||
| 732 | MEMLOCK = 6, | ||
| 733 | NPROC = 7, | ||
| 734 | NOFILE = 8, | ||
| 735 | SBSIZE = 9, | ||
| 736 | AS = 10, | ||
| 737 | VMEM = 10, | ||
| 738 | POSIXLOCKS = 11, | ||
| 739 | |||
| 740 | _, | ||
| 741 | }; | ||
| 742 | |||
| 743 | pub const rlim_t = i64; | ||
| 744 | |||
| 745 | /// No limit | ||
| 746 | pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1; | ||
| 747 | |||
| 748 | pub const RLIM_SAVED_MAX = RLIM_INFINITY; | ||
| 749 | pub const RLIM_SAVED_CUR = RLIM_INFINITY; | ||
| 750 | |||
| 751 | pub const rlimit = extern struct { | ||
| 752 | /// Soft limit | ||
| 753 | cur: rlim_t, | ||
| 754 | /// Hard limit | ||
| 755 | max: rlim_t, | ||
| 756 | }; |
lib/std/os/bits/freebsd.zig+36| ... | @@ -1358,3 +1358,39 @@ pub const IPPROTO_RESERVED_253 = 253; | ... | @@ -1358,3 +1358,39 @@ pub const IPPROTO_RESERVED_253 = 253; |
| 1358 | 1358 | ||
| 1359 | /// Reserved | 1359 | /// Reserved |
| 1360 | pub const IPPROTO_RESERVED_254 = 254; | 1360 | pub const IPPROTO_RESERVED_254 = 254; |
| 1361 | |||
| 1362 | pub const rlimit_resource = extern enum(c_int) { | ||
| 1363 | CPU = 0, | ||
| 1364 | FSIZE = 1, | ||
| 1365 | DATA = 2, | ||
| 1366 | STACK = 3, | ||
| 1367 | CORE = 4, | ||
| 1368 | RSS = 5, | ||
| 1369 | MEMLOCK = 6, | ||
| 1370 | NPROC = 7, | ||
| 1371 | NOFILE = 8, | ||
| 1372 | SBSIZE = 9, | ||
| 1373 | VMEM = 10, | ||
| 1374 | AS = 10, | ||
| 1375 | NPTS = 11, | ||
| 1376 | SWAP = 12, | ||
| 1377 | KQUEUES = 13, | ||
| 1378 | UMTXP = 14, | ||
| 1379 | |||
| 1380 | _, | ||
| 1381 | }; | ||
| 1382 | |||
| 1383 | pub const rlim_t = i64; | ||
| 1384 | |||
| 1385 | /// No limit | ||
| 1386 | pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1; | ||
| 1387 | |||
| 1388 | pub const RLIM_SAVED_MAX = RLIM_INFINITY; | ||
| 1389 | pub const RLIM_SAVED_CUR = RLIM_INFINITY; | ||
| 1390 | |||
| 1391 | pub const rlimit = extern struct { | ||
| 1392 | /// Soft limit | ||
| 1393 | cur: rlim_t, | ||
| 1394 | /// Hard limit | ||
| 1395 | max: rlim_t, | ||
| 1396 | }; |
lib/std/os/bits/netbsd.zig+33| ... | @@ -1169,3 +1169,36 @@ pub const IPPROTO_PFSYNC = 240; | ... | @@ -1169,3 +1169,36 @@ pub const IPPROTO_PFSYNC = 240; |
| 1169 | 1169 | ||
| 1170 | /// raw IP packet | 1170 | /// raw IP packet |
| 1171 | pub const IPPROTO_RAW = 255; | 1171 | pub const IPPROTO_RAW = 255; |
| 1172 | |||
| 1173 | pub const rlimit_resource = extern enum(c_int) { | ||
| 1174 | CPU = 0, | ||
| 1175 | FSIZE = 1, | ||
| 1176 | DATA = 2, | ||
| 1177 | STACK = 3, | ||
| 1178 | CORE = 4, | ||
| 1179 | RSS = 5, | ||
| 1180 | MEMLOCK = 6, | ||
| 1181 | NPROC = 7, | ||
| 1182 | NOFILE = 8, | ||
| 1183 | SBSIZE = 9, | ||
| 1184 | AS = 10, | ||
| 1185 | VMEM = 10, | ||
| 1186 | NTHR = 11, | ||
| 1187 | |||
| 1188 | _, | ||
| 1189 | }; | ||
| 1190 | |||
| 1191 | pub const rlim_t = u64; | ||
| 1192 | |||
| 1193 | /// No limit | ||
| 1194 | pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1; | ||
| 1195 | |||
| 1196 | pub const RLIM_SAVED_MAX = RLIM_INFINITY; | ||
| 1197 | pub const RLIM_SAVED_CUR = RLIM_INFINITY; | ||
| 1198 | |||
| 1199 | pub const rlimit = extern struct { | ||
| 1200 | /// Soft limit | ||
| 1201 | cur: rlim_t, | ||
| 1202 | /// Hard limit | ||
| 1203 | max: rlim_t, | ||
| 1204 | }; |
lib/std/os/bits/openbsd.zig+29| ... | @@ -1050,3 +1050,32 @@ pub const IPPROTO_PFSYNC = 240; | ... | @@ -1050,3 +1050,32 @@ pub const IPPROTO_PFSYNC = 240; |
| 1050 | 1050 | ||
| 1051 | /// raw IP packet | 1051 | /// raw IP packet |
| 1052 | pub const IPPROTO_RAW = 255; | 1052 | pub const IPPROTO_RAW = 255; |
| 1053 | |||
| 1054 | pub const rlimit_resource = extern enum(c_int) { | ||
| 1055 | CPU, | ||
| 1056 | FSIZE, | ||
| 1057 | DATA, | ||
| 1058 | STACK, | ||
| 1059 | CORE, | ||
| 1060 | RSS, | ||
| 1061 | MEMLOCK, | ||
| 1062 | NPROC, | ||
| 1063 | NOFILE, | ||
| 1064 | |||
| 1065 | _, | ||
| 1066 | }; | ||
| 1067 | |||
| 1068 | pub const rlim_t = u64; | ||
| 1069 | |||
| 1070 | /// No limit | ||
| 1071 | pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1; | ||
| 1072 | |||
| 1073 | pub const RLIM_SAVED_MAX = RLIM_INFINITY; | ||
| 1074 | pub const RLIM_SAVED_CUR = RLIM_INFINITY; | ||
| 1075 | |||
| 1076 | pub const rlimit = extern struct { | ||
| 1077 | /// Soft limit | ||
| 1078 | cur: rlim_t, | ||
| 1079 | /// Hard limit | ||
| 1080 | max: rlim_t, | ||
| 1081 | }; |
lib/std/os/test.zig+6-4| ... | @@ -593,11 +593,13 @@ test "fsync" { | ... | @@ -593,11 +593,13 @@ test "fsync" { |
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | test "getrlimit and setrlimit" { | 595 | test "getrlimit and setrlimit" { |
| 596 | // TODO enable for other systems when implemented | 596 | if (!@hasDecl(os, "rlimit")) { |
| 597 | if (builtin.os.tag != .linux) { | ||
| 598 | return error.SkipZigTest; | 597 | return error.SkipZigTest; |
| 599 | } | 598 | } |
| 600 | 599 | ||
| 601 | const cpuLimit = try os.getrlimit(.CPU); | 600 | inline for (std.meta.fields(os.rlimit_resource)) |field| { |
| 602 | try os.setrlimit(.CPU, cpuLimit); | 601 | const resource = @intToEnum(os.rlimit_resource, field.value); |
| 602 | const limit = try os.getrlimit(resource); | ||
| 603 | try os.setrlimit(resource, limit); | ||
| 604 | } | ||
| 603 | } | 605 | } |