]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/log: set the log level with a pure Rust function
authorJason Ish <jason.ish@oisf.net>
Tue, 25 Aug 2020 18:50:31 +0000 (12:50 -0600)
committerVictor Julien <victor@inliniac.net>
Thu, 3 Sep 2020 11:04:14 +0000 (13:04 +0200)
Make sure the log level is setup with a pure Rust function, so
when it is set, its set within the address space of the caller.

This is important for Rust plugins where the Rust modules are not
in the address space of the Suricata main process.

rust/src/log.rs

index a7dcc73683aae514ff2f27cbc7fad45260226827..aeec3cbe8d05a31ec5ae86d6cd0e834c4f7d9411 100644 (file)
@@ -22,6 +22,7 @@ use std::path::Path;
 use crate::core::*;
 
 #[derive(Debug)]
+#[repr(C)]
 pub enum Level {
     NotSet = -1,
     None = 0,
@@ -141,15 +142,15 @@ macro_rules!SCLogDebug {
 
 #[no_mangle]
 pub extern "C" fn rs_log_set_level(level: i32) {
+    log_set_level(level);
+}
+
+pub fn log_set_level(level: i32) {
     unsafe {
         LEVEL = level;
     }
 }
 
-pub fn log_set_level(level: Level) {
-    rs_log_set_level(level as i32);
-}
-
 /// SCLogMessage wrapper. If the Suricata C context is not registered
 /// a more basic log format will be used (for example, when running
 /// Rust unit tests).