Generate enough of a skeleton to get code loaded but not properly configured
There are still some function calls which must be invoked in modInit in order to properly configure the object environment needed for rsyslog plugins
This commit is contained in:
parent
7f887e44cb
commit
91e0c3816c
|
@ -4,6 +4,10 @@ version = "0.1.0"
|
|||
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "impstatsd"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
statsd = "^0.9.0"
|
||||
|
||||
|
|
51
src/lib.rs
51
src/lib.rs
|
@ -3,18 +3,65 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
use std::os::raw::c_int;
|
||||
|
||||
/*
|
||||
* Pull our wacky rsyslog.h generated bindings
|
||||
*/
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
|
||||
fn modGetType(m: &mut eModType_t) -> rsRetVal {
|
||||
/**
|
||||
* Set the type of rsyslog module, in this case an input module
|
||||
*/
|
||||
#[no_mangle]
|
||||
pub extern fn modGetType(m: &mut eModType_t) -> rsRetVal {
|
||||
// Set ourselves up as an input module
|
||||
*m = 0;
|
||||
return 0; // ok
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rsyslog module name
|
||||
*/
|
||||
#[no_mangle]
|
||||
pub extern fn modGetCnfName(name: *mut *const c_char) -> rsRetVal {
|
||||
let n: CString = CString::new("impstatsd").expect("Failed to alloc CString");
|
||||
/*
|
||||
* This is awful, and I hate C
|
||||
*/
|
||||
unsafe {
|
||||
*name = n.as_ptr();
|
||||
}
|
||||
return 0; // ok
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn modInit(versionRequested: c_int,
|
||||
versionProvided: *mut c_int,
|
||||
queryEntryFunc: *mut Option<unsafe extern "C" fn() -> rsRetVal>,
|
||||
hostEntryFunc: *mut Option<unsafe extern "C" fn() -> rsRetVal>,
|
||||
modInfo: modInfo_t) -> rsRetVal {
|
||||
|
||||
println!(">> Bootstrapping Rust module");
|
||||
|
||||
let mut iret = rsRetVal__RS_RET_OK;
|
||||
|
||||
println!(">> Finished bootstrapping Rust module");
|
||||
return iret;
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn modExit() -> rsRetVal {
|
||||
println!(">> Exiting Rust module");
|
||||
rsRetVal__RS_RET_OK
|
||||
}
|
||||
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
Loading…
Reference in New Issue