1#![cfg_attr(feature = "unstable-doc-cfg", feature(doc_cfg))]
2#![warn(rust_2018_idioms)]
3
4#[cfg(all(feature = "journal", doctest))]
5doc_comment::doctest!("../README.md", readme);
6
7extern crate libsystemd_sys as ffi;
8
9#[cfg(feature = "journal")]
16#[allow(deprecated)]
17pub use journal::JournalFiles;
18#[cfg(feature = "journal")]
19pub use journal::{Journal, JournalLog, JournalRecord, JournalSeek, JournalWaitResult};
20use libc::{c_char, c_void, free, strlen};
21pub use std::io::{Error, Result};
22
23#[cfg(any(feature = "journal", feature = "bus"))]
24fn usec_from_duration(duration: std::time::Duration) -> u64 {
25 let sub_usecs = duration.subsec_micros() as u64;
26 duration.as_secs() * 1_000_000 + sub_usecs
27}
28
29pub fn ffi_result(ret: ffi::c_int) -> Result<ffi::c_int> {
31 if ret < 0 {
32 Err(Error::from_raw_os_error(-ret))
33 } else {
34 Ok(ret)
35 }
36}
37
38unsafe fn free_cstring(ptr: *mut c_char) -> Option<String> {
41 if ptr.is_null() {
42 return None;
43 }
44 let len = strlen(ptr);
45 let char_slice = std::slice::from_raw_parts(ptr as *mut u8, len);
46 let s = String::from_utf8_lossy(char_slice).into_owned();
47 free(ptr as *mut c_void);
48 Some(s)
49}
50
51#[cfg(feature = "journal")]
56pub mod journal;
57
58#[macro_export]
61macro_rules! log_with{
62 ($func:expr, $lvl:expr, $($arg:tt),+) => ({
63 $func(&::log::Record::builder()
64 .args(format_args!($($arg),+))
65 .level($lvl)
66 .file(Some(file!()))
67 .line(Some(line!()))
68 .module_path(Some(module_path!()))
69 .build())
70 });
71 (@raw $func:expr, $lvl:expr, $($arg:tt),+) => ({
72 $func($lvl, file!(), line!(), module_path!(), &format_args!($($arg),+))
73 });
74 (@target $tgt:expr, $func:expr, $lvl:expr, $($arg:tt),+) => ({
75 $func(&::log::Record::builder()
76 .args(format_args!($($arg),+))
77 .level($lvl)
78 .target($tgt)
79 .file(Some(file!()))
80 .line(Some(line!()))
81 .module_path(Some(module_path!()))
82 .build())
83 })
84}
85
86#[cfg(feature = "journal")]
87#[macro_export]
88macro_rules! sd_journal_log{
89 ($lvl:expr, $($arg:tt)+) => ($crate::log_with!(@raw ::systemd::journal::log, $lvl, $($arg)+))
90}
91
92pub mod daemon;
93
94pub mod id128;
95
96pub mod login;
98
99#[cfg(feature = "bus")]
102pub mod bus;
103
104pub mod unit;