|
1 | 1 | //! Configure the process resource limits.
|
2 | 2 | use std::mem;
|
3 | 3 |
|
4 |
| -use libc::{self, c_int, rlimit, RLIM_INFINITY}; |
| 4 | +use libc::{self, c_uint, rlimit, RLIM_INFINITY}; |
5 | 5 | pub use libc::rlim_t;
|
6 | 6 |
|
7 | 7 | use {Errno, Result};
|
8 | 8 |
|
9 | 9 | libc_enum!{
|
10 | 10 | /// A resource that limits apply to
|
11 |
| - #[repr(i32)] |
| 11 | + #[repr(u32)] |
12 | 12 | pub enum Resource {
|
13 | 13 | // POSIX
|
14 | 14 | /// This is the maximum size of the process's virtual memory (address space). The limit is specified in bytes, and is rounded down to the system page size.
|
@@ -97,8 +97,8 @@ libc_enum!{
|
97 | 97 | ///
|
98 | 98 | /// [`Resource`]: enum.Resource.html
|
99 | 99 | pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)> {
|
100 |
| - let mut rlim: rlimit = unsafe { mem::uninitialized() }; |
101 |
| - let res = unsafe { libc::getrlimit(resource as c_int, &mut rlim as *mut _) }; |
| 100 | + let mut rlim: rlimit = unsafe { mem::MaybeUninit::uninit().assume_init() }; |
| 101 | + let res = unsafe { libc::getrlimit(resource as c_uint, &mut rlim as *mut _) }; |
102 | 102 | // TODO: use Option::filter after it has been stabilized
|
103 | 103 | Errno::result(res).map(|_| {
|
104 | 104 | (if rlim.rlim_cur != RLIM_INFINITY { Some(rlim.rlim_cur) } else { None },
|
@@ -133,10 +133,10 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
|
133 | 133 | ///
|
134 | 134 | /// [`Resource`]: enum.Resource.html
|
135 | 135 | pub fn setrlimit(resource: Resource, soft_limit: Option<rlim_t>, hard_limit: Option<rlim_t>) -> Result<()> {
|
136 |
| - let mut rlim: rlimit = unsafe { mem::uninitialized() }; |
| 136 | + let mut rlim: rlimit = unsafe { mem::MaybeUninit::uninit().assume_init() }; |
137 | 137 | rlim.rlim_cur = soft_limit.unwrap_or(RLIM_INFINITY);
|
138 | 138 | rlim.rlim_max = hard_limit.unwrap_or(RLIM_INFINITY);
|
139 | 139 |
|
140 |
| - let res = unsafe { libc::setrlimit(resource as c_int, &rlim as *const _) }; |
| 140 | + let res = unsafe { libc::setrlimit(resource as c_uint, &rlim as *const _) }; |
141 | 141 | Errno::result(res).map(|_| ())
|
142 | 142 | }
|
0 commit comments