소스 검색

rust: Allow trailing nul in CPG names

A lot of programs (mentioning no Pacemakers) add a trailing
nul to CPG names for some reason, despite the cpg_name struct
having a member for name length.

To allow Rust to have compatibilty with this I've added some code
to the Rust binding that allows strings with \0 be used as CPG names.

eg

cpg::join(&handle, "crmd\0");

will join the crmd group with Pacemaker.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
Jan Friesse 1 개월 전
부모
커밋
c414ed93ad
1개의 변경된 파일6개의 추가작업 그리고 6개의 파일을 삭제
  1. 6 6
      bindings/rust/src/cpg.rs

+ 6 - 6
bindings/rust/src/cpg.rs

@@ -14,7 +14,7 @@
 use crate::sys::cpg as ffi;
 
 use std::collections::HashMap;
-use std::ffi::{CStr, CString};
+use std::ffi::{c_char, CStr};
 use std::fmt;
 use std::os::raw::{c_int, c_void};
 use std::ptr::copy_nonoverlapping;
@@ -202,10 +202,6 @@ fn string_to_cpg_name(group: &str) -> Result<ffi::cpg_name> {
         return Err(CsError::CsErrInvalidParam);
     }
 
-    let c_name = match CString::new(group) {
-        Ok(n) => n,
-        Err(_) => return Err(CsError::CsErrLibrary),
-    };
     let mut c_group = ffi::cpg_name {
         length: group.len() as u32,
         value: [0; CPG_NAMELEN_MAX],
@@ -213,7 +209,11 @@ fn string_to_cpg_name(group: &str) -> Result<ffi::cpg_name> {
 
     unsafe {
         // NOTE param order is 'wrong-way round' from C
-        copy_nonoverlapping(c_name.as_ptr(), c_group.value.as_mut_ptr(), group.len());
+        copy_nonoverlapping(
+            group.as_ptr() as *const c_char,
+            c_group.value.as_mut_ptr(),
+            group.len(),
+        );
     }
 
     Ok(c_group)