From 1380768f4e0276aa7950ad322c49a9f70924d9f6 Mon Sep 17 00:00:00 2001 From: u5surf Date: Sat, 17 Oct 2020 03:40:40 +0900 Subject: [PATCH] Fix Rlimit breaking change. (#283) * Replace rlimit::rlim with rlimit::RawRlim Signed-off-by: u5surf --- Cargo.lock | 5 ++--- Cargo.toml | 2 +- src/input.rs | 4 ++-- src/main.rs | 18 +++++++++--------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3700e4b9d..98c4188ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1076,11 +1076,10 @@ dependencies = [ [[package]] name = "rlimit" -version = "0.4.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49b02d62c38353a6fce45c25ca19783e25dd5f495ca681c674a4ee15aa4c1536" +checksum = "2ae7aac7f5ad5159594e4e9a59c28949217f9aee8e80c2991d8672453e9e4316" dependencies = [ - "cfg-if", "libc", ] diff --git a/Cargo.toml b/Cargo.toml index 5bfc6d764..f7f3374a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ colored = "2.0.0" structopt = "0.3.20" async-std = "1.6.4" futures = "0.3" -rlimit = "0.4.0" +rlimit = "0.5.2" shell-words = "1.0.0" log = "0.4.0" env_logger = "0.7.1" diff --git a/src/input.rs b/src/input.rs index c1f3a9b2a..23cc2ae4c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -103,7 +103,7 @@ pub struct Opts { /// Automatically ups the ULIMIT with the value you provided. #[structopt(short, long)] - pub ulimit: Option, + pub ulimit: Option, /// The order of scanning to be performed. The "serial" option will /// scan ports in ascending order while the "random" option will scan @@ -205,7 +205,7 @@ pub struct Config { timeout: Option, tries: Option, no_nmap: Option, - ulimit: Option, + ulimit: Option, scan_order: Option, command: Option>, } diff --git a/src/main.rs b/src/main.rs index f97638eaa..fca733145 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use benchmark::{Benchmark, NamedTimer}; use cidr_utils::cidr::IpCidr; use colorful::{Color, Colorful}; use futures::executor::block_on; -use rlimit::{getrlimit, setrlimit, Resource}; +use rlimit::{getrlimit, setrlimit, RawRlim, Resource, Rlim}; use std::collections::HashMap; use std::fs::File; use std::io::{prelude::*, BufReader}; @@ -31,9 +31,9 @@ extern crate colorful; extern crate dirs; // Average value for Ubuntu -const DEFAULT_FILE_DESCRIPTORS_LIMIT: rlimit::rlim = 8000; +const DEFAULT_FILE_DESCRIPTORS_LIMIT: RawRlim = 8000; // Safest batch size based on experimentation -const AVERAGE_BATCH_SIZE: rlimit::rlim = 3000; +const AVERAGE_BATCH_SIZE: RawRlim = 3000; #[macro_use] extern crate log; @@ -67,7 +67,7 @@ fn main() { std::process::exit(1); } - let ulimit: rlimit::rlim = adjust_ulimit_size(&opts); + let ulimit: RawRlim = adjust_ulimit_size(&opts); let batch_size: u16 = infer_batch_size(&opts, ulimit); let scanner = Scanner::new( @@ -319,9 +319,9 @@ fn build_nmap_arguments<'a>( arguments } -fn adjust_ulimit_size(opts: &Opts) -> rlimit::rlim { +fn adjust_ulimit_size(opts: &Opts) -> RawRlim { if opts.ulimit.is_some() { - let limit: rlimit::rlim = opts.ulimit.unwrap(); + let limit: Rlim = Rlim::from_raw(opts.ulimit.unwrap()); match setrlimit(Resource::NOFILE, limit, limit) { Ok(_) => { @@ -343,11 +343,11 @@ fn adjust_ulimit_size(opts: &Opts) -> rlimit::rlim { let (rlim, _) = getrlimit(Resource::NOFILE).unwrap(); - rlim + rlim.as_raw() } -fn infer_batch_size(opts: &Opts, ulimit: rlimit::rlim) -> u16 { - let mut batch_size: rlimit::rlim = opts.batch_size.into(); +fn infer_batch_size(opts: &Opts, ulimit: RawRlim) -> u16 { + let mut batch_size: RawRlim = opts.batch_size.into(); // Adjust the batch size when the ulimit value is lower than the desired batch size if ulimit < batch_size {