rpc: Throw error in setlogfilter if filter reloading fails

This commit is contained in:
Jack Grigg 2020-08-06 01:01:41 +01:00
parent 58c410974d
commit ba831f814a
3 changed files with 24 additions and 8 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 {