rpc: Throw error in setlogfilter if filter reloading fails
This commit is contained in:
parent
58c410974d
commit
ba831f814a
|
@ -268,7 +268,9 @@ UniValue setlogfilter(const UniValue& params, bool fHelp)
|
|||
}
|
||||
|
||||
if (pTracingHandle) {
|
||||
tracing_reload(pTracingHandle, newFilter.c_str());
|
||||
if (!tracing_reload(pTracingHandle, newFilter.c_str())) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Filter reload failed; check logs");
|
||||
}
|
||||
}
|
||||
|
||||
return NullUniValue;
|
||||
|
|
|
@ -33,7 +33,9 @@ TracingHandle* tracing_init(
|
|||
void tracing_free(TracingHandle* handle);
|
||||
|
||||
/// Reloads the tracing filter.
|
||||
void tracing_reload(TracingHandle* handle, const char* new_filter);
|
||||
///
|
||||
/// Returns `true` if the reload succeeded.
|
||||
bool tracing_reload(TracingHandle* handle, const char* new_filter);
|
||||
|
||||
struct TracingCallsite;
|
||||
typedef struct TracingCallsite TracingCallsite;
|
||||
|
|
|
@ -138,14 +138,26 @@ pub extern "C" fn tracing_free(handle: *mut TracingHandle) {
|
|||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn tracing_reload(handle: *mut TracingHandle, new_filter: *const c_char) {
|
||||
pub extern "C" fn tracing_reload(handle: *mut TracingHandle, new_filter: *const c_char) -> bool {
|
||||
let handle = unsafe { &mut *handle };
|
||||
let new_filter = unsafe { CStr::from_ptr(new_filter) }
|
||||
.to_str()
|
||||
.expect("new filter should be a valid string");
|
||||
|
||||
let new_filter = EnvFilter::new(new_filter);
|
||||
handle.reload_handle.reload(new_filter).unwrap();
|
||||
match unsafe { CStr::from_ptr(new_filter) }
|
||||
.to_str()
|
||||
.map(EnvFilter::new)
|
||||
{
|
||||
Err(e) => {
|
||||
tracing::error!("New filter is not valid UTF-8: {}", e);
|
||||
false
|
||||
}
|
||||
Ok(new_filter) => {
|
||||
if let Err(e) = handle.reload_handle.reload(new_filter) {
|
||||
tracing::error!("Filter reload failed: {}", e);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FfiCallsite {
|
||||
|
|
Loading…
Reference in New Issue