Skip to content

Commit

Permalink
fix print_stdout/err lints (openzfs#353)
Browse files Browse the repository at this point in the history
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 rust-lang/rust-clippy#6610
  • Loading branch information
ahrens authored Apr 12, 2022
1 parent 512d338 commit ca08bb1
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 5 deletions.
11 changes: 11 additions & 0 deletions cmd/zfs_object_agent/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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",
]

4 changes: 4 additions & 0 deletions cmd/zfs_object_agent/client/src/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 4 additions & 0 deletions cmd/zfs_object_agent/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 4 additions & 0 deletions cmd/zfs_object_agent/object_perf/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 4 additions & 0 deletions cmd/zfs_object_agent/object_perf/src/s3perf.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion cmd/zfs_object_agent/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/zfs_object_agent/util/src/die.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use lazy_static::lazy_static;
use log::*;

use crate::tunable;
use crate::writeln_stderr;

tunable! {
static ref DIE_MTBF: Option<Duration> = None;
Expand Down Expand Up @@ -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);
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/zfs_object_agent/util/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/zfs_object_agent/zettaobject/src/object_access/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ impl BlobObjectAccess {
config_file: &str,
credentials_profile: Option<String>,
) -> Result<Arc<StorageClient>, Box<dyn Error>> {
#![allow(clippy::print_stderr)] // XXX remove before production

let http_client = azure_core::new_http_client();
match fs::metadata(config_file) {
Ok(file) => {
Expand Down
6 changes: 4 additions & 2 deletions cmd/zfs_object_agent/zettaobject/src/test_connectivity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
});
Expand Down

0 comments on commit ca08bb1

Please sign in to comment.