-
Notifications
You must be signed in to change notification settings - Fork 1.7k
prevent silent errors in daemon mode #10007
Conversation
It looks like @seunlanlege signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It fails silently on my linux laptop (need to investigate further).
Open questions:
- Do we want to maintain our custom fork (or rather reimplementation) of
daemonize
? - If we do, should it be placed in
util/daemonize
? (E.g. why not in a separate repo)
If we want to maintain this it should go in a separate repo preferable forked under the |
not sure why the c++ example isn't compiling @5chdn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The c++ example is failing because the interface for start
has changed, clib needs to be updated here.
The code looks good in general, but I still think we should move it to a separate repository (and maybe publish to crates.io
), because it seems like a general improvement (modulo missing features) over daemonize
, which others would probably want to use (and it seems like daemonize
is unmaintained atm). Also we need tests like these and it would be nice to run them on linux and macOS.
pub fn start<Cr, Rr>(conf: Configuration, on_client_rq: Cr, on_updater_rq: Rr) -> Result<ExecutionAction, String> | ||
pub fn start<Cr, Rr>( | ||
conf: Configuration, | ||
logger: Arc<RotatingLogger>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the C-bindings in parity-clib
you need to update them accordingly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difficult part of #8574 (and the reason why it wasn't done immediately when parity-clib
was created) is that ideally the RotatingLogger
wouldn't be exposed in the API.
However I guess we can ignore the problem in the name of "meh, who cares", and open another issue for that specific thing instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not exposing RotatingLogger
in C API
, we expose only Logger
params struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mentioned "when parity-clib was created", because the Rust lib and the C library were created at the same time.
The logging system is unfortunately a global variable, and thus it shouldn't be the job of a library to set it.
The consequence is that if a program wants to use parity-as-a-library, they cannot setup their own logging compatible with the log
crate.
An ideal world, it is main.rs
that would setup the logging and that's it. The C library would have an independent function (not tied to parity, just like parity_set_panic_hook
is totally independent as well) that sets up the Rust logging and explicitly mentions in its documentation that this applies to the log
Rust crate as a whole.
@seunlanlege The changes you did |
@niklasad1 please do, thanks. |
moved the implementation to here |
FYI: The naming convention for rust crates from the api-guidelines:
Could you remove |
8a0125e
to
df07353
Compare
parity-clib/parity.h
Outdated
@@ -78,7 +90,7 @@ void parity_config_destroy(void* cfg); | |||
/// On success, the produced object will be written to the `void*` pointed by `out`. | |||
/// | |||
/// Returns 0 on success, and non-zero on error. | |||
int parity_start(const ParityParams* params, void** out); | |||
int parity_start(const ParityParams* params, Logger logger, void** out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we could also pass Logger
as a pointer to be uniform
but I decided to pass it by value to reduce the possibility for deref NULL
in the library. However, it will requre 4 words of memory instead of 1 word and it will probably not fit in the registers and need to pushed on the stack (assuming not inlined)
It is still possible to deref NULL
if a null pointer is passed as string with len != 0
parity-clib/src/lib.rs
Outdated
panic::catch_unwind(|| { | ||
*output = ptr::null_mut(); | ||
let cfg: &ParityParams = &*cfg; | ||
|
||
let mode = { | ||
if logger.mode_len == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure an empty string is not constructed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not using this check in parity_config_from_cli
, I think it's safe since mem::align_of::<u8> == 1
and also String::from_utf8(slice.to_owned())
does not allocate if the slice.is_empty()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it is redundant thus it should be removed
However, when it comes to log-file we need the check because an empty string as file name
will be a run-time error/panic
parity-clib/src/lib.rs
Outdated
}; | ||
|
||
let file = { | ||
if logger.file_len == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure an empty string is not constructed!
@5chdn I can't sign in to gitlab, could you please restart the android build? |
@seunlanlege I restarted it but it looks like you need to bump |
looks like alls good here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
parity-clib/src/lib.rs
Outdated
panic::catch_unwind(|| { | ||
*output = ptr::null_mut(); | ||
let cfg: &ParityParams = &*cfg; | ||
|
||
let mode = { | ||
if logger.mode_len == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not using this check in parity_config_from_cli
, I think it's safe since mem::align_of::<u8> == 1
and also String::from_utf8(slice.to_owned())
does not allocate if the slice.is_empty()
.
I'm fine with leaving it as it is, because doing it properly requires a lot of work. |
…g to create logfile
Co-Authored-By: seunlanlege <[email protected]>
* Add FIXME comment regarding @tomaka grumbles * Unify logger with the C-API in ParityParams (less type-safety with more from_raw() conversions) * Add better documentation in the `parity.h`
Co-Authored-By: seunlanlege <[email protected]>
* Update example to the API changes * Remove needless printouts which can be controlled via logger instead
This PR replaces daemonize from crates.io, with a custom daemonize
The custom
daemonize
pipes thedaemon
's STDOUT/STDERR to the parent process, afterparity-ethereum
successfully starts the daemon process detaches from the parent and the parent exits.TODO: