Move is_niceness logic out of clap utils to reduce dependencies (#32331)
Move is_niceness logic out of clap utils to reduce dependencies.. ..for solana-keygen
This commit is contained in:
parent
cbb5381a98
commit
7ff5e463e9
|
@ -5361,7 +5361,6 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap 2.33.3",
|
"clap 2.33.3",
|
||||||
"rpassword",
|
"rpassword",
|
||||||
"solana-perf",
|
|
||||||
"solana-remote-wallet",
|
"solana-remote-wallet",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
|
@ -5378,7 +5377,6 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap 3.2.23",
|
"clap 3.2.23",
|
||||||
"rpassword",
|
"rpassword",
|
||||||
"solana-perf",
|
|
||||||
"solana-remote-wallet",
|
"solana-remote-wallet",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"solana-zk-token-sdk",
|
"solana-zk-token-sdk",
|
||||||
|
|
|
@ -13,7 +13,6 @@ edition = { workspace = true }
|
||||||
chrono = { workspace = true, features = ["default"] }
|
chrono = { workspace = true, features = ["default"] }
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
rpassword = { workspace = true }
|
rpassword = { workspace = true }
|
||||||
solana-perf = { workspace = true }
|
|
||||||
solana-remote-wallet = { workspace = true }
|
solana-remote-wallet = { workspace = true }
|
||||||
solana-sdk = { workspace = true }
|
solana-sdk = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
|
|
|
@ -393,25 +393,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_niceness_adjustment_valid<T>(value: T) -> Result<(), String>
|
|
||||||
where
|
|
||||||
T: AsRef<str> + Display,
|
|
||||||
{
|
|
||||||
let adjustment = value
|
|
||||||
.as_ref()
|
|
||||||
.parse::<i8>()
|
|
||||||
.map_err(|err| format!("error parsing niceness adjustment value '{value}': {err}"))?;
|
|
||||||
if solana_perf::thread::is_renice_allowed(adjustment) {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(String::from(
|
|
||||||
"niceness adjustment supported only on Linux; negative adjustment \
|
|
||||||
(priority increase) requires root or CAP_SYS_NICE (see `man 7 capabilities` \
|
|
||||||
for details)",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn validate_maximum_full_snapshot_archives_to_retain<T>(value: T) -> Result<(), String>
|
pub fn validate_maximum_full_snapshot_archives_to_retain<T>(value: T) -> Result<(), String>
|
||||||
where
|
where
|
||||||
T: AsRef<str> + Display,
|
T: AsRef<str> + Display,
|
||||||
|
@ -456,11 +437,4 @@ mod tests {
|
||||||
assert!(is_derivation("a/b").is_err());
|
assert!(is_derivation("a/b").is_err());
|
||||||
assert!(is_derivation("0/4294967296").is_err());
|
assert!(is_derivation("0/4294967296").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_niceness_adjustment_valid() {
|
|
||||||
assert_eq!(is_niceness_adjustment_valid("0"), Ok(()));
|
|
||||||
assert!(is_niceness_adjustment_valid("128").is_err());
|
|
||||||
assert!(is_niceness_adjustment_valid("-129").is_err());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ edition = { workspace = true }
|
||||||
chrono = { workspace = true, features = ["default"] }
|
chrono = { workspace = true, features = ["default"] }
|
||||||
clap = { version = "3.2.23", features = ["cargo"] }
|
clap = { version = "3.2.23", features = ["cargo"] }
|
||||||
rpassword = { workspace = true }
|
rpassword = { workspace = true }
|
||||||
solana-perf = { workspace = true }
|
|
||||||
solana-remote-wallet = { workspace = true }
|
solana-remote-wallet = { workspace = true }
|
||||||
solana-sdk = { workspace = true }
|
solana-sdk = { workspace = true }
|
||||||
solana-zk-token-sdk = { workspace = true }
|
solana-zk-token-sdk = { workspace = true }
|
||||||
|
|
|
@ -387,25 +387,6 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_niceness_adjustment_valid<T>(value: T) -> Result<(), String>
|
|
||||||
where
|
|
||||||
T: AsRef<str> + Display,
|
|
||||||
{
|
|
||||||
let adjustment = value
|
|
||||||
.as_ref()
|
|
||||||
.parse::<i8>()
|
|
||||||
.map_err(|err| format!("error parsing niceness adjustment value '{value}': {err}"))?;
|
|
||||||
if solana_perf::thread::is_renice_allowed(adjustment) {
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(String::from(
|
|
||||||
"niceness adjustment supported only on Linux; negative adjustment \
|
|
||||||
(priority increase) requires root or CAP_SYS_NICE (see `man 7 capabilities` \
|
|
||||||
for details)",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -422,11 +403,4 @@ mod tests {
|
||||||
assert!(is_derivation("a/b").is_err());
|
assert!(is_derivation("a/b").is_err());
|
||||||
assert!(is_derivation("0/4294967296").is_err());
|
assert!(is_derivation("0/4294967296").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_is_niceness_adjustment_valid() {
|
|
||||||
assert_eq!(is_niceness_adjustment_valid("0"), Ok(()));
|
|
||||||
assert!(is_niceness_adjustment_valid("128").is_err());
|
|
||||||
assert!(is_niceness_adjustment_valid("-129").is_err());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::fmt::Display;
|
||||||
|
|
||||||
/// Wrapper for `nice(3)`.
|
/// Wrapper for `nice(3)`.
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
fn nice(adjustment: i8) -> Result<i8, nix::errno::Errno> {
|
fn nice(adjustment: i8) -> Result<i8, nix::errno::Errno> {
|
||||||
|
@ -67,6 +69,25 @@ pub fn is_renice_allowed(adjustment: i8) -> bool {
|
||||||
adjustment == 0
|
adjustment == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_niceness_adjustment_valid<T>(value: T) -> Result<(), String>
|
||||||
|
where
|
||||||
|
T: AsRef<str> + Display,
|
||||||
|
{
|
||||||
|
let adjustment = value
|
||||||
|
.as_ref()
|
||||||
|
.parse::<i8>()
|
||||||
|
.map_err(|err| format!("error parsing niceness adjustment value '{value}': {err}"))?;
|
||||||
|
if is_renice_allowed(adjustment) {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(String::from(
|
||||||
|
"niceness adjustment supported only on Linux; negative adjustment \
|
||||||
|
(priority increase) requires root or CAP_SYS_NICE (see `man 7 capabilities` \
|
||||||
|
for details)",
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
|
@ -101,4 +122,11 @@ mod tests {
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_niceness_adjustment_valid() {
|
||||||
|
assert_eq!(is_niceness_adjustment_valid("0"), Ok(()));
|
||||||
|
assert!(is_niceness_adjustment_valid("128").is_err());
|
||||||
|
assert!(is_niceness_adjustment_valid("-129").is_err());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4613,7 +4613,6 @@ dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"clap 2.33.3",
|
"clap 2.33.3",
|
||||||
"rpassword",
|
"rpassword",
|
||||||
"solana-perf",
|
|
||||||
"solana-remote-wallet",
|
"solana-remote-wallet",
|
||||||
"solana-sdk",
|
"solana-sdk",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
|
|
@ -6,9 +6,8 @@ use {
|
||||||
solana_clap_utils::{
|
solana_clap_utils::{
|
||||||
hidden_unless_forced,
|
hidden_unless_forced,
|
||||||
input_validators::{
|
input_validators::{
|
||||||
is_keypair, is_keypair_or_ask_keyword, is_niceness_adjustment_valid, is_parsable,
|
is_keypair, is_keypair_or_ask_keyword, is_parsable, is_pow2, is_pubkey,
|
||||||
is_pow2, is_pubkey, is_pubkey_or_keypair, is_slot, is_url_or_moniker,
|
is_pubkey_or_keypair, is_slot, is_url_or_moniker, is_valid_percentage, is_within_range,
|
||||||
is_valid_percentage, is_within_range,
|
|
||||||
validate_maximum_full_snapshot_archives_to_retain,
|
validate_maximum_full_snapshot_archives_to_retain,
|
||||||
validate_maximum_incremental_snapshot_archives_to_retain,
|
validate_maximum_incremental_snapshot_archives_to_retain,
|
||||||
},
|
},
|
||||||
|
@ -485,7 +484,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
|
||||||
.long("snapshot-packager-niceness-adjustment")
|
.long("snapshot-packager-niceness-adjustment")
|
||||||
.value_name("ADJUSTMENT")
|
.value_name("ADJUSTMENT")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.validator(is_niceness_adjustment_valid)
|
.validator(solana_perf::thread::is_niceness_adjustment_valid)
|
||||||
.default_value(&default_args.snapshot_packager_niceness_adjustment)
|
.default_value(&default_args.snapshot_packager_niceness_adjustment)
|
||||||
.help("Add this value to niceness of snapshot packager thread. Negative value \
|
.help("Add this value to niceness of snapshot packager thread. Negative value \
|
||||||
increases priority, positive value decreases priority.")
|
increases priority, positive value decreases priority.")
|
||||||
|
@ -840,7 +839,7 @@ pub fn app<'a>(version: &'a str, default_args: &'a DefaultArgs) -> App<'a, 'a> {
|
||||||
.long("rpc-niceness-adjustment")
|
.long("rpc-niceness-adjustment")
|
||||||
.value_name("ADJUSTMENT")
|
.value_name("ADJUSTMENT")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.validator(is_niceness_adjustment_valid)
|
.validator(solana_perf::thread::is_niceness_adjustment_valid)
|
||||||
.default_value(&default_args.rpc_niceness_adjustment)
|
.default_value(&default_args.rpc_niceness_adjustment)
|
||||||
.help("Add this value to niceness of RPC threads. Negative value \
|
.help("Add this value to niceness of RPC threads. Negative value \
|
||||||
increases priority, positive value decreases priority.")
|
increases priority, positive value decreases priority.")
|
||||||
|
|
Loading…
Reference in New Issue