fix: Make --quiet flag work again

This commit is contained in:
Carlos Fernandez Sanz
2026-01-02 21:35:42 +01:00
committed by GitHub
4 changed files with 35 additions and 3 deletions

View File

@@ -435,6 +435,9 @@ int main(int argc, char *argv[])
int compile_ret = ccxr_parse_parameters(argc, argv);
// Update the Rust logger target after parsing so --quiet is respected
ccxr_update_logger_target();
if (compile_ret == EXIT_NO_INPUT_FILES)
{
print_usage();

View File

@@ -160,6 +160,7 @@ struct lib_ccx_ctx *init_libraries(struct ccx_s_options *opt);
void dinit_libraries(struct lib_ccx_ctx **ctx);
extern void ccxr_init_basic_logger();
extern void ccxr_update_logger_target();
// ccextractor.c
void print_end_msg(void);

View File

@@ -269,6 +269,11 @@ impl<'a> CCExtractorLogger {
self.target
}
/// Sets the target for logging messages.
pub fn set_target(&mut self, target: OutputTarget) {
self.target = target;
}
/// Check if the messages are intercepted by GUI.
pub fn is_gui_mode(&self) -> bool {
self.gui_mode

View File

@@ -33,10 +33,11 @@ pub unsafe extern "C" fn ccxr_init_basic_logger() {
.unwrap_or(DebugMessageFlag::VERBOSE);
let mask = DebugMessageMask::new(debug_mask, debug_mask_on_debug);
let gui_mode_reports = ccx_options.gui_mode_reports != 0;
// CCX_MESSAGES_QUIET=0, CCX_MESSAGES_STDOUT=1, CCX_MESSAGES_STDERR=2
let messages_target = match ccx_options.messages_target {
0 => OutputTarget::Stdout,
1 => OutputTarget::Stderr,
2 => OutputTarget::Quiet,
0 => OutputTarget::Quiet,
1 => OutputTarget::Stdout,
2 => OutputTarget::Stderr,
_ => OutputTarget::Stderr, // Default to stderr for invalid values
};
let _ = set_logger(CCExtractorLogger::new(
@@ -46,6 +47,28 @@ pub unsafe extern "C" fn ccxr_init_basic_logger() {
));
}
/// Updates the logger target after command-line arguments have been parsed.
/// This is needed because the logger is initialized before argument parsing,
/// and options like --quiet need to be applied afterwards.
///
/// # Safety
///
/// `ccx_options` in C must be properly initialized and the logger must have
/// been initialized via `ccxr_init_basic_logger` before calling this function.
#[no_mangle]
pub unsafe extern "C" fn ccxr_update_logger_target() {
// CCX_MESSAGES_QUIET=0, CCX_MESSAGES_STDOUT=1, CCX_MESSAGES_STDERR=2
let messages_target = match ccx_options.messages_target {
0 => OutputTarget::Quiet,
1 => OutputTarget::Stdout,
2 => OutputTarget::Stderr,
_ => OutputTarget::Stderr,
};
if let Some(mut logger) = logger_mut() {
logger.set_target(messages_target);
}
}
/// Rust equivalent for `verify_crc32` function in C. Uses C-native types as input and output.
///
/// # Safety