Skip to content

Commit da761c5

Browse files
authored
Merge pull request #172 from Apokleos/rlimit-posix
Rlimit: Make rlimits POSIX-specific
2 parents d338cf8 + f858e8a commit da761c5

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/runtime/process.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub struct Process {
7474
#[serde(default, skip_serializing_if = "Option::is_none")]
7575
#[getset(get = "pub", set = "pub")]
7676
/// Rlimits specifies rlimit options to apply to the process.
77-
rlimits: Option<Vec<LinuxRlimit>>,
77+
rlimits: Option<Vec<PosixRlimit>>,
7878

7979
#[serde(default, skip_serializing_if = "Option::is_none")]
8080
#[getset(get_copy = "pub", set = "pub")]
@@ -141,8 +141,8 @@ impl Default for Process {
141141
capabilities: Some(Default::default()),
142142
// Sets the default maximum of 1024 files the process can open
143143
// This is the same as the linux kernel default
144-
rlimits: vec![LinuxRlimit {
145-
typ: LinuxRlimitType::RlimitNofile,
144+
rlimits: vec![PosixRlimit {
145+
typ: PosixRlimitType::RlimitNofile,
146146
hard: 1024,
147147
soft: 1024,
148148
}]
@@ -180,63 +180,79 @@ pub struct Box {
180180
#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)]
181181
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
182182
/// Available rlimit types (see <https://man7.org/linux/man-pages/man2/getrlimit.2.html>)
183-
pub enum LinuxRlimitType {
183+
pub enum PosixRlimitType {
184184
/// Limit in seconds of the amount of CPU time that the process can consume.
185+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
185186
RlimitCpu,
186187

187188
/// Maximum size in bytes of the files that the process creates.
189+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
188190
RlimitFsize,
189191

190192
/// Maximum size of the process's data segment (init data, uninit data and
191193
/// heap) in bytes.
194+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
192195
RlimitData,
193196

194197
/// Maximum size of the proces stack in bytes.
198+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
195199
RlimitStack,
196200

197201
/// Maximum size of a core dump file in bytes.
202+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
198203
RlimitCore,
199204

200205
/// Limit on the process's resident set (the number of virtual pages
201206
/// resident in RAM).
207+
#[cfg(target_os = "linux")]
202208
RlimitRss,
203209

204210
/// Limit on number of threads for the real uid calling processes.
211+
#[cfg(target_os = "linux")]
205212
RlimitNproc,
206213

207214
/// One greator than the maximum number of file descritors that one process
208215
/// may open.
216+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
209217
RlimitNofile,
210218

211219
/// Maximum number of bytes of memory that may be locked into RAM.
220+
#[cfg(target_os = "linux")]
212221
RlimitMemlock,
213222

214223
/// Maximum size of the process's virtual memory(address space) in bytes.
224+
#[cfg(any(target_os = "linux", target_os = "solaris"))]
215225
RlimitAs,
216226

217227
/// Limit on the number of locks and leases for the process.
228+
#[cfg(target_os = "linux")]
218229
RlimitLocks,
219230

220231
/// Limit on number of signals that may be queued for the process.
232+
#[cfg(target_os = "linux")]
221233
RlimitSigpending,
222234

223235
/// Limit on the number of bytes that can be allocated for POSIX message
224236
/// queue.
237+
#[cfg(target_os = "linux")]
225238
RlimitMsgqueue,
226239

227240
/// Specifies a ceiling to which the process's nice value can be raised.
241+
#[cfg(target_os = "linux")]
228242
RlimitNice,
229243

230244
/// Specifies a ceiling on the real-time priority.
245+
#[cfg(target_os = "linux")]
231246
RlimitRtprio,
232247

233248
/// This is a limit (in microseconds) on the amount of CPU time that a
234249
/// process scheduled under a real-time scheduling policy may consume
235250
/// without making a blocking system call.
251+
#[cfg(target_os = "linux")]
236252
RlimitRttime,
237253
}
238254

239-
impl Default for LinuxRlimitType {
255+
impl Default for PosixRlimitType {
240256
fn default() -> Self {
241257
Self::RlimitCpu
242258
}
@@ -253,10 +269,10 @@ impl Default for LinuxRlimitType {
253269
)]
254270
#[getset(get_copy = "pub", set = "pub")]
255271
/// RLimit types and restrictions.
256-
pub struct LinuxRlimit {
272+
pub struct PosixRlimit {
257273
#[serde(rename = "type")]
258274
/// Type of Rlimit to set
259-
typ: LinuxRlimitType,
275+
typ: PosixRlimitType,
260276

261277
#[serde(default)]
262278
/// Hard limit for specified type

0 commit comments

Comments
 (0)