Conversation
|
It looks like @seunlanlege signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
ordian
left a comment
There was a problem hiding this comment.
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 |
ordian
left a comment
There was a problem hiding this comment.
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.
This breaks the C-bindings in parity-clib you need to update them accordingly
There was a problem hiding this comment.
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.
We're not exposing RotatingLogger in C API, we expose only Logger params struct.
There was a problem hiding this comment.
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
| /// | ||
| /// 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.
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
| let cfg: &ParityParams = &*cfg; | ||
|
|
||
| let mode = { | ||
| if logger.mode_len == 0 { |
There was a problem hiding this comment.
Make sure an empty string is not constructed!
There was a problem hiding this comment.
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.
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
| }; | ||
|
|
||
| let file = { | ||
| if logger.file_len == 0 { |
There was a problem hiding this comment.
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 |
| let cfg: &ParityParams = &*cfg; | ||
|
|
||
| let mode = { | ||
| if logger.mode_len == 0 { |
There was a problem hiding this comment.
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 <seunlanlege@gmail.com>
* 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 <seunlanlege@gmail.com>
* 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
daemonizepipes thedaemon's STDOUT/STDERR to the parent process, afterparity-ethereumsuccessfully starts the daemon process detaches from the parent and the parent exits.TODO: