mirror of
https://git.proxmox.com/git/proxmox
synced 2025-07-15 06:16:18 +00:00
28 lines
741 B
Rust
28 lines
741 B
Rust
use std::ffi::{c_int, CString, OsStr};
|
|
use std::io;
|
|
use std::os::fd::{FromRawFd, OwnedFd};
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
use crate::sys;
|
|
|
|
pub fn stream_fd<I: AsRef<OsStr>>(
|
|
identifier: I,
|
|
priority: c_int,
|
|
level_prefix: bool,
|
|
) -> Result<OwnedFd, io::Error> {
|
|
let ident = CString::new(identifier.as_ref().as_bytes()).map_err(|_| {
|
|
io::Error::new(
|
|
io::ErrorKind::Other,
|
|
"invalid identifier for journal stream",
|
|
)
|
|
})?;
|
|
let fd = unsafe {
|
|
sys::sd_journal_stream_fd(ident.as_bytes().as_ptr(), priority, level_prefix as c_int)
|
|
};
|
|
if fd < 0 {
|
|
Err(std::io::Error::from_raw_os_error(-fd))
|
|
} else {
|
|
Ok(unsafe { OwnedFd::from_raw_fd(fd) })
|
|
}
|
|
}
|