1
1
//! Configure the process resource limits.
2
+ use cfg_if:: cfg_if;
2
3
use std:: mem;
3
4
4
5
#[ cfg( any( target_os = "linux" ) ) ]
@@ -21,98 +22,127 @@ use crate::Result;
21
22
22
23
pub use libc:: rlim_t;
23
24
24
- #[ cfg( any( target_os = "linux" ) ) ]
25
- libc_enum ! {
26
- #[ repr( u32 ) ]
27
- pub enum Resource {
28
- /// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
29
- RLIMIT_AS ,
30
- RLIMIT_CORE ,
31
- RLIMIT_CPU ,
32
- RLIMIT_DATA ,
33
- RLIMIT_FSIZE ,
34
- RLIMIT_LOCKS ,
35
- RLIMIT_MEMLOCK ,
36
- RLIMIT_MSGQUEUE ,
37
- RLIMIT_NICE ,
38
- RLIMIT_NOFILE ,
39
- RLIMIT_NPROC ,
40
- RLIMIT_RSS ,
41
- RLIMIT_RTPRIO ,
42
- RLIMIT_RTTIME ,
43
- RLIMIT_SIGPENDING ,
44
- RLIMIT_STACK ,
45
- }
46
- }
47
-
48
- #[ cfg( any(
49
- target_os = "freebsd" ,
50
- target_os = "openbsd" ,
51
- target_os = "netbsd" ,
52
- target_os = "macos" ,
53
- target_os = "ios" ,
54
- target_os = "android" ,
55
- target_os = "dragonfly" ,
56
- target_os = "bitrig" ,
57
- ) ) ]
58
- libc_enum ! {
59
- #[ repr( i32 ) ]
60
- pub enum Resource {
61
- /// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
62
- /// BSD specific Resource https://www.freebsd.org/cgi/man.cgi?query=setrlimit
63
- RLIMIT_AS ,
64
- RLIMIT_CORE ,
65
- RLIMIT_CPU ,
66
- RLIMIT_DATA ,
67
- RLIMIT_FSIZE ,
68
- RLIMIT_NOFILE ,
69
- RLIMIT_STACK ,
70
-
71
- // platform specific
72
- #[ cfg( target_os = "freebsd" ) ]
73
- RLIMIT_KQUEUES ,
74
-
75
- #[ cfg( any( target_os = "android" ) ) ]
76
- RLIMIT_LOCKS ,
77
-
78
- #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "openbsd" ) ) ]
79
- RLIMIT_MEMLOCK ,
80
-
81
- #[ cfg( any( target_os = "android" ) ) ]
82
- RLIMIT_MSGQUEUE ,
83
-
84
- #[ cfg( any( target_os = "android" ) ) ]
85
- RLIMIT_NICE ,
86
-
87
- #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "openbsd" ) ) ]
88
- RLIMIT_NPROC ,
89
-
90
- #[ cfg( target_os = "freebsd" ) ]
91
- RLIMIT_NPTS ,
92
-
93
- #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "openbsd" ) ) ]
94
- RLIMIT_RSS ,
95
-
96
- #[ cfg( any( target_os = "android" ) ) ]
97
- RLIMIT_RTPRIO ,
98
-
99
- #[ cfg( any( target_os = "android" ) ) ]
100
- RLIMIT_SIGPENDING ,
101
-
102
- #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
103
- RLIMIT_SBSIZE ,
104
-
105
- #[ cfg( target_os = "freebsd" ) ]
106
- RLIMIT_SWAP ,
107
-
108
- #[ cfg( target_os = "freebsd" ) ]
109
- RLIMIT_VMEM ,
25
+ cfg_if ! {
26
+ if #[ cfg( target_os = "linux" ) ] {
27
+ if #[ cfg( target_env = "gnu" ) ] {
28
+ libc_enum!{
29
+ #[ repr( u32 ) ]
30
+ pub enum Resource {
31
+ /// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
32
+ RLIMIT_AS ,
33
+ RLIMIT_CORE ,
34
+ RLIMIT_CPU ,
35
+ RLIMIT_DATA ,
36
+ RLIMIT_FSIZE ,
37
+ RLIMIT_LOCKS ,
38
+ RLIMIT_MEMLOCK ,
39
+ RLIMIT_MSGQUEUE ,
40
+ RLIMIT_NICE ,
41
+ RLIMIT_NOFILE ,
42
+ RLIMIT_NPROC ,
43
+ RLIMIT_RSS ,
44
+ RLIMIT_RTPRIO ,
45
+ RLIMIT_RTTIME ,
46
+ RLIMIT_SIGPENDING ,
47
+ RLIMIT_STACK ,
48
+ }
49
+ }
50
+ } else{
51
+ libc_enum!{
52
+ #[ repr( i32 ) ]
53
+ pub enum Resource {
54
+ /// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
55
+ RLIMIT_AS ,
56
+ RLIMIT_CORE ,
57
+ RLIMIT_CPU ,
58
+ RLIMIT_DATA ,
59
+ RLIMIT_FSIZE ,
60
+ RLIMIT_LOCKS ,
61
+ RLIMIT_MEMLOCK ,
62
+ RLIMIT_MSGQUEUE ,
63
+ RLIMIT_NICE ,
64
+ RLIMIT_NOFILE ,
65
+ RLIMIT_NPROC ,
66
+ RLIMIT_RSS ,
67
+ RLIMIT_RTPRIO ,
68
+ RLIMIT_RTTIME ,
69
+ RLIMIT_SIGPENDING ,
70
+ RLIMIT_STACK ,
71
+ }
72
+ }
73
+ }
74
+ } else if #[ cfg( any(
75
+ target_os = "freebsd" ,
76
+ target_os = "openbsd" ,
77
+ target_os = "netbsd" ,
78
+ target_os = "macos" ,
79
+ target_os = "ios" ,
80
+ target_os = "android" ,
81
+ target_os = "dragonfly" ,
82
+ target_os = "bitrig" ,
83
+ ) ) ] {
84
+ libc_enum! {
85
+ #[ repr( i32 ) ]
86
+ pub enum Resource {
87
+ /// See detail of each Resource https://man7.org/linux/man-pages/man2/getrlimit.2.html
88
+ /// BSD specific Resource https://www.freebsd.org/cgi/man.cgi?query=setrlimit
89
+ RLIMIT_AS ,
90
+ RLIMIT_CORE ,
91
+ RLIMIT_CPU ,
92
+ RLIMIT_DATA ,
93
+ RLIMIT_FSIZE ,
94
+ RLIMIT_NOFILE ,
95
+ RLIMIT_STACK ,
96
+
97
+ // platform specific
98
+ #[ cfg( target_os = "freebsd" ) ]
99
+ RLIMIT_KQUEUES ,
100
+
101
+ #[ cfg( any( target_os = "android" ) ) ]
102
+ RLIMIT_LOCKS ,
103
+
104
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "openbsd" ) ) ]
105
+ RLIMIT_MEMLOCK ,
106
+
107
+ #[ cfg( any( target_os = "android" ) ) ]
108
+ RLIMIT_MSGQUEUE ,
109
+
110
+ #[ cfg( any( target_os = "android" ) ) ]
111
+ RLIMIT_NICE ,
112
+
113
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "openbsd" ) ) ]
114
+ RLIMIT_NPROC ,
115
+
116
+ #[ cfg( target_os = "freebsd" ) ]
117
+ RLIMIT_NPTS ,
118
+
119
+ #[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "openbsd" ) ) ]
120
+ RLIMIT_RSS ,
121
+
122
+ #[ cfg( any( target_os = "android" ) ) ]
123
+ RLIMIT_RTPRIO ,
124
+
125
+ #[ cfg( any( target_os = "android" ) ) ]
126
+ RLIMIT_SIGPENDING ,
127
+
128
+ #[ cfg( any( target_os = "freebsd" , target_os = "dragonfly" ) ) ]
129
+ RLIMIT_SBSIZE ,
130
+
131
+ #[ cfg( target_os = "freebsd" ) ]
132
+ RLIMIT_SWAP ,
133
+
134
+ #[ cfg( target_os = "freebsd" ) ]
135
+ RLIMIT_VMEM ,
136
+ }
137
+ }
138
+ } else{
139
+ // unkown os
110
140
}
111
141
}
112
142
113
143
/// Get the current processes resource limits
114
144
///
115
- /// A value of None indicates that there's no limit.
145
+ /// A value of ` None` indicates that there's no limit.
116
146
///
117
147
/// # Parameters
118
148
///
0 commit comments