From 1ae7e76e4b06b203f5b5f2cf45297fd4616788c2 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Sun, 17 Feb 2019 12:02:31 +0100 Subject: [PATCH 1/6] feat(add lints): `missing_docs` + `rust_2018` --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a766c2e..862d60d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +#![warn(missing_docs, rust_2018_idioms)] + use crate::error::{Error, ErrorKind}; use std::path::PathBuf; From 0f731f54419fbdfcda37b86e6ff48087ab0147d7 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Sun, 17 Feb 2019 13:11:20 +0100 Subject: [PATCH 2/6] fix(lint): `rust_2018_idioms` --- src/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index c8b7fa0..330f38b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -80,7 +80,7 @@ pub enum ErrorKind { } impl Fail for Error { - fn cause(&self) -> Option<&Fail> { + fn cause(&self) -> Option<&dyn Fail> { self.inner.cause() } @@ -90,7 +90,7 @@ impl Fail for Error { } impl Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { Display::fmt(&self.inner, f) } } From 38d000aeb1d614bf164d2218f586dadfc2e29a73 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Sun, 17 Feb 2019 13:12:01 +0100 Subject: [PATCH 3/6] lint(docs): add documentation --- src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 862d60d..b500a11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2015-2018 Parity Technologies (UK) Ltd. +// Copyright 2015-2019 Parity Technologies (UK) Ltd. // This file is part of Parity. // Parity is free software: you can redistribute it and/or modify @@ -14,11 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +//! Library for running a process as daemon. +//! Currently Linux is only supported. + #![warn(missing_docs, rust_2018_idioms)] use crate::error::{Error, ErrorKind}; use std::path::PathBuf; +/// Error types pub mod error; mod platform; @@ -31,6 +35,7 @@ type Result = std::result::Result; /// this can be useful, as the daemon will pipe it's stdout/stderr to the parent process /// to communicate if start up was successful pub trait AsHandle { + /// File descriptor type Fd; /// Creates a `Handle` from a raw file descriptor @@ -53,6 +58,9 @@ pub trait AsHandle { } #[macro_export] +/// Macro for calling `c-style functions` and wrapping the return status in a `Result` +/// If the function return `-1` it will return `Err<$err:expr>` otherwise `Ok(int)` +// FIXME: this is not platform independent: `https://github.com/paritytech/parity-daemonize/issues/14` macro_rules! map_err { ($e:expr, $err:expr) => { match $e { From 45590b96175aea81a7ccebb775baa0ab3f5b1d66 Mon Sep 17 00:00:00 2001 From: Andronik Ordian Date: Mon, 18 Feb 2019 09:32:43 +0100 Subject: [PATCH 4/6] doc(nits) Co-Authored-By: niklasad1 --- src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b500a11..94458f3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -//! Library for running a process as daemon. -//! Currently Linux is only supported. +//! Library for running a process as a daemon. +//! Currently, only Linux is supported. #![warn(missing_docs, rust_2018_idioms)] @@ -35,7 +35,7 @@ type Result = std::result::Result; /// this can be useful, as the daemon will pipe it's stdout/stderr to the parent process /// to communicate if start up was successful pub trait AsHandle { - /// File descriptor + /// File descriptor type type Fd; /// Creates a `Handle` from a raw file descriptor @@ -58,6 +58,7 @@ pub trait AsHandle { } #[macro_export] +#[doc(hidden)] /// Macro for calling `c-style functions` and wrapping the return status in a `Result` /// If the function return `-1` it will return `Err<$err:expr>` otherwise `Ok(int)` // FIXME: this is not platform independent: `https://github.com/paritytech/parity-daemonize/issues/14` From f8eabb23f7cb9b3a2ca96252c78c703a605f687a Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 18 Feb 2019 09:51:24 +0100 Subject: [PATCH 5/6] docs(readme): update `rust example` --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b52682c..b50375d 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,17 @@ ## Example ```rust + extern crate parity_daemonize; -use parity_daemonize::daemonize; +use parity_daemonize::{AsHandle, daemonize}; use std::{thread, time, process, io}; use io::Write; fn main() { match daemonize("pid_file.txt") { // we are now in the daemon, use this handle to detach from the parent process - Ok(handle) => { + Ok(mut handle) => { let mut count = 0; loop { // the daemon's output is piped to the parent process' stdout @@ -35,7 +36,7 @@ fn main() { // if this is the daemon, this is piped to the parent's stderr eprintln!("{}", e); // don't forget to flush - io::stderr().flush(); + let _ = io::stderr().flush(); process::exit(1); } } From a101014c8141c3cd30edab0707a74c3900d7eea0 Mon Sep 17 00:00:00 2001 From: Niklas Adolfsson Date: Mon, 18 Feb 2019 09:56:10 +0100 Subject: [PATCH 6/6] fix(tests): compiler warnings --- tests/tests.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index c1227e3..8bcd1c1 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,11 +1,4 @@ -use std::{ - process, - env, - thread, - time, - fs, - io::Read -}; +use std::{fs, io::Read, process}; #[test] fn test_simple() { @@ -18,7 +11,7 @@ fn test_simple() { let mut file = fs::File::open("pid_file").unwrap(); let mut pid = String::new(); - file.read_to_string(&mut pid); + file.read_to_string(&mut pid).unwrap(); let _ = process::Command::new("kill") .arg("-9")