Skip to content

Commit 5c547d6

Browse files
committed
fixup all
Signed-off-by: tison <[email protected]>
1 parent ee8ffed commit 5c547d6

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ feature! {
200200
pub mod spawn;
201201
}
202202

203-
#[cfg(any(target_os = "macos"))]
203+
#[cfg(target_os = "macos")]
204204
feature! {
205205
#![feature = "syslog"]
206206
pub mod syslog;

src/syslog.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ pub fn openlog<P: NixPath + ?Sized>(
2323
///
2424
/// The message is then written to the system console, log files, logged-in users, or forwarded
2525
/// to other machines as appropriate.
26-
pub fn syslog<S: AsRef<OsStr> + ?Sized>(priority: Priority, message: &S) {
26+
pub fn syslog<S: AsRef<OsStr> + ?Sized>(
27+
priority: Priority,
28+
message: &S,
29+
) -> Result<()> {
2730
let formatter = OsStr::new("%s");
2831
let message = OsStr::new(message);
29-
unsafe { libc::syslog(priority.0, formatter.as_ptr(), message.as_ptr()) }
32+
formatter.with_nix_path(|formatter| {
33+
message.with_nix_path(|message| unsafe {
34+
libc::syslog(priority.0, formatter.as_ptr(), message.as_ptr())
35+
})
36+
})??;
37+
Ok(())
3038
}
3139

3240
/// The priority for a log message.
@@ -48,6 +56,7 @@ impl Priority {
4856
}
4957

5058
libc_bitflags! {
59+
/// Options for system logging.
5160
pub struct LogFlags: libc::c_int {
5261
/// Log the process id with each message: useful for identifying instantiations of
5362
/// daemons.

test/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod test_sendfile;
4242
))]
4343
mod test_spawn;
4444

45-
#[cfg(any(target_os = "macos"))]
45+
#[cfg(target_os = "macos")]
4646
mod test_syslog;
4747

4848
mod test_time;

test/test_syslog.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use nix::syslog::Priority;
1+
use nix::syslog::{openlog, syslog, Facility, LogFlags, Priority, Severity};
22

3-
#[cfg(target_os = "macos")]
43
#[test]
54
fn test_syslog_hello_world() {
6-
use nix::syslog::{openlog, syslog, Facility, LogFlags, Severity};
7-
85
let name = "test_syslog_hello_world";
6+
let priority = Priority::from_severity(Severity::LOG_EMERG);
97
openlog(name, LogFlags::LOG_PID, Facility::LOG_USER).unwrap();
10-
syslog(Priority::from_severity(Severity::LOG_EMERG), "Hello, nix!");
8+
syslog(priority, "Hello, nix!").unwrap();
119
}

0 commit comments

Comments
 (0)