Skip to content

Commit ad6a2f3

Browse files
committed
Wrap openlog
Signed-off-by: tison <[email protected]>
1 parent ae86c6a commit ad6a2f3

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/syslog.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#[cfg(target_os = "macos")]
2+
pub fn openlog(ident: &str, logopt: LogFlags, facility: Facility) {
3+
let ident = CString::new(ident).expect("TODO: handle error");
4+
unsafe {
5+
libc::openlog(ident.as_ptr(), logopt.bits(), facility as libc::c_int)
6+
}
7+
}
8+
9+
pub use self::consts::*;
10+
use std::ffi::CString;
11+
12+
#[cfg(target_os = "macos")]
13+
mod consts {
14+
libc_bitflags! {
15+
pub struct LogFlags: libc::c_int {
16+
/// Log the process id with each message: useful for identifying instantiations of
17+
/// daemons.
18+
LOG_PID;
19+
/// If syslog() cannot pass the message to syslogd(8) it will attempt to write the
20+
/// message to the console ("/dev/console").
21+
LOG_CONS;
22+
/// Open the connection to syslogd(8) immediately. Normally the open is delayed until
23+
/// the first message is logged. Useful for programs that need to manage the order in
24+
/// which file descriptors are allocated.
25+
LOG_NDELAY;
26+
/// Write the message to standard error output as well to the system log.
27+
LOG_PERROR;
28+
}
29+
}
30+
31+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
32+
#[repr(i32)]
33+
#[non_exhaustive]
34+
pub enum Facility {
35+
LOG_KERN = libc::LOG_KERN,
36+
LOG_USER = libc::LOG_USER,
37+
LOG_MAIL = libc::LOG_MAIL,
38+
LOG_DAEMON = libc::LOG_DAEMON,
39+
LOG_AUTH = libc::LOG_AUTH,
40+
LOG_SYSLOG = libc::LOG_SYSLOG,
41+
LOG_LPR = libc::LOG_LPR,
42+
LOG_NEWS = libc::LOG_NEWS,
43+
LOG_UUCP = libc::LOG_UUCP,
44+
LOG_LOCAL0 = libc::LOG_LOCAL0,
45+
LOG_LOCAL1 = libc::LOG_LOCAL1,
46+
LOG_LOCAL2 = libc::LOG_LOCAL2,
47+
LOG_LOCAL3 = libc::LOG_LOCAL3,
48+
LOG_LOCAL4 = libc::LOG_LOCAL4,
49+
LOG_LOCAL5 = libc::LOG_LOCAL5,
50+
LOG_LOCAL6 = libc::LOG_LOCAL6,
51+
LOG_LOCAL7 = libc::LOG_LOCAL7,
52+
}
53+
}

0 commit comments

Comments
 (0)