From ca08bb1d295f2be3b8eaf337b05ee7e2d55b5eb9 Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Tue, 12 Apr 2022 09:46:40 -0700 Subject: [PATCH] fix print_stdout/err lints (#353) The `print_stdout`, `print_stderr`, and `dbg_macro` lints can't be set at the crate level. Rather than setting them in every file, we set them as compiler options. See https://github.com/rust-lang/rust-clippy/issues/6610 --- cmd/zfs_object_agent/.cargo/config.toml | 11 +++++++++++ cmd/zfs_object_agent/client/src/client.rs | 4 ++++ cmd/zfs_object_agent/client/src/main.rs | 4 ++++ cmd/zfs_object_agent/object_perf/src/main.rs | 4 ++++ cmd/zfs_object_agent/object_perf/src/s3perf.rs | 4 ++++ cmd/zfs_object_agent/server/src/main.rs | 3 ++- cmd/zfs_object_agent/util/src/die.rs | 3 ++- cmd/zfs_object_agent/util/src/logging.rs | 3 ++- .../zettaobject/src/object_access/blob.rs | 2 ++ .../zettaobject/src/test_connectivity.rs | 6 ++++-- 10 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 cmd/zfs_object_agent/.cargo/config.toml diff --git a/cmd/zfs_object_agent/.cargo/config.toml b/cmd/zfs_object_agent/.cargo/config.toml new file mode 100644 index 000000000000..b441aa8fa90d --- /dev/null +++ b/cmd/zfs_object_agent/.cargo/config.toml @@ -0,0 +1,11 @@ +# These lints can't be set at the crate level. Rather than setting them +# in every file, we set them as compiler options. +# +# See https://github.com/rust-lang/rust-clippy/issues/6610 +[target.'cfg(feature = "cargo-clippy")'] +rustflags = [ + "-Dclippy::print_stdout", + "-Dclippy::print_stderr", + "-Dclippy::dbg_macro", +] + diff --git a/cmd/zfs_object_agent/client/src/client.rs b/cmd/zfs_object_agent/client/src/client.rs index a1b4b9de979d..f021b959c233 100644 --- a/cmd/zfs_object_agent/client/src/client.rs +++ b/cmd/zfs_object_agent/client/src/client.rs @@ -1,3 +1,7 @@ +// This file is not used in production. +#![allow(clippy::print_stderr)] +#![allow(clippy::print_stdout)] + use nvpair::NvEncoding; use nvpair::NvList; use nvpair::NvListRef; diff --git a/cmd/zfs_object_agent/client/src/main.rs b/cmd/zfs_object_agent/client/src/main.rs index 56d5f590685e..336e05fe0bae 100644 --- a/cmd/zfs_object_agent/client/src/main.rs +++ b/cmd/zfs_object_agent/client/src/main.rs @@ -1,3 +1,7 @@ +// This file is not used in production. +#![allow(clippy::print_stderr)] +#![allow(clippy::print_stdout)] + use std::collections::BTreeSet; use std::error::Error; use std::fs; diff --git a/cmd/zfs_object_agent/object_perf/src/main.rs b/cmd/zfs_object_agent/object_perf/src/main.rs index c141ec6bec89..00c1409b66e8 100644 --- a/cmd/zfs_object_agent/object_perf/src/main.rs +++ b/cmd/zfs_object_agent/object_perf/src/main.rs @@ -1,3 +1,7 @@ +// This file is not used in production. +#![allow(clippy::print_stderr)] +#![allow(clippy::print_stdout)] + use std::time::Duration; use clap::Parser; diff --git a/cmd/zfs_object_agent/object_perf/src/s3perf.rs b/cmd/zfs_object_agent/object_perf/src/s3perf.rs index 51610973f7e3..5a5b50286026 100644 --- a/cmd/zfs_object_agent/object_perf/src/s3perf.rs +++ b/cmd/zfs_object_agent/object_perf/src/s3perf.rs @@ -1,3 +1,7 @@ +// This file is not used in production. +#![allow(clippy::print_stderr)] +#![allow(clippy::print_stdout)] + use std::cmp::max; use std::error::Error; use std::string::String; diff --git a/cmd/zfs_object_agent/server/src/main.rs b/cmd/zfs_object_agent/server/src/main.rs index c8e8549238ce..a549e83cdcfe 100644 --- a/cmd/zfs_object_agent/server/src/main.rs +++ b/cmd/zfs_object_agent/server/src/main.rs @@ -5,6 +5,7 @@ use clap::Subcommand; use git_version::git_version; use log::*; use util::tunable; +use util::writeln_stderr; use util::TrackingAllocator; use util::ALLOCATOR_PRINT_MIN_ALLOCS; use util::ALLOCATOR_PRINT_MIN_BYTES; @@ -183,7 +184,7 @@ fn main() { runtime, ) { Ok(()) => panic!("unreachable statement"), - Err(err) => eprintln!("error: couldn't start server: {}", err), + Err(err) => writeln_stderr!("error: couldn't start server: {}", err), } } } diff --git a/cmd/zfs_object_agent/util/src/die.rs b/cmd/zfs_object_agent/util/src/die.rs index cf6bd35abf2d..873a0f838fae 100644 --- a/cmd/zfs_object_agent/util/src/die.rs +++ b/cmd/zfs_object_agent/util/src/die.rs @@ -26,6 +26,7 @@ use lazy_static::lazy_static; use log::*; use crate::tunable; +use crate::writeln_stderr; tunable! { static ref DIE_MTBF: Option = None; @@ -103,7 +104,7 @@ where let msg = f(); let backtrace = Backtrace::new(); warn!("exiting to test failure handling: {} {:?}", msg, backtrace); - println!("exiting to test failure handling: {} {:?}", msg, backtrace); + writeln_stderr!("exiting to test failure handling: {} {:?}", msg, backtrace); std::process::exit(0); } } diff --git a/cmd/zfs_object_agent/util/src/logging.rs b/cmd/zfs_object_agent/util/src/logging.rs index 048687af996a..fa200d52d943 100644 --- a/cmd/zfs_object_agent/util/src/logging.rs +++ b/cmd/zfs_object_agent/util/src/logging.rs @@ -35,6 +35,7 @@ use crate::lazy_static_ptr; use crate::measure; use crate::tunable; use crate::with_alloctag_hf; +use crate::writeln_stderr; use crate::TrackingAllocator; use crate::ALLOCATOR_PRINT_MIN_ALLOCS; use crate::ALLOCATOR_PRINT_MIN_BYTES; @@ -355,7 +356,7 @@ pub fn register_siguser1_to_dump_tracing() -> Result<(), std::io::Error> { _ => { // This should never be executed as we are registered for // SIGUSER1 only. - eprintln!("Got an unexpected signal: {:?}", signum); + writeln_stderr!("Got an unexpected signal: {:?}", signum); emulate_default_handler(signum).unwrap(); } } diff --git a/cmd/zfs_object_agent/zettaobject/src/object_access/blob.rs b/cmd/zfs_object_agent/zettaobject/src/object_access/blob.rs index 60c5eb352e8e..e365b9f5647f 100644 --- a/cmd/zfs_object_agent/zettaobject/src/object_access/blob.rs +++ b/cmd/zfs_object_agent/zettaobject/src/object_access/blob.rs @@ -185,6 +185,8 @@ impl BlobObjectAccess { config_file: &str, credentials_profile: Option, ) -> Result, Box> { + #![allow(clippy::print_stderr)] // XXX remove before production + let http_client = azure_core::new_http_client(); match fs::metadata(config_file) { Ok(file) => { diff --git a/cmd/zfs_object_agent/zettaobject/src/test_connectivity.rs b/cmd/zfs_object_agent/zettaobject/src/test_connectivity.rs index 2b13f19ba32d..b0c094b7bb64 100644 --- a/cmd/zfs_object_agent/zettaobject/src/test_connectivity.rs +++ b/cmd/zfs_object_agent/zettaobject/src/test_connectivity.rs @@ -2,6 +2,8 @@ use std::time::Duration; use rand::Rng; use serde::Deserialize; +use util::writeln_stderr; +use util::writeln_stdout; use crate::access_stats::ObjectAccessOpType; use crate::object_access::s3::S3ObjectAccess; @@ -94,11 +96,11 @@ pub fn test_connectivity( std::process::exit(match do_test_connectivity(&object_access).await { Err(err) => { - eprintln!("{}", err); + writeln_stderr!("{}", err); 1 } Ok(_) => { - println!("Connectivity test succeeded."); + writeln_stdout!("Connectivity test succeeded."); 0 } });