relibc/header/sys_syslog/
mod.rs1#[cfg(target_os = "redox")]
8#[path = "redox.rs"]
9pub mod sys;
10
11#[cfg(target_os = "linux")]
12#[path = "linux.rs"]
13pub mod sys;
14
15pub mod logger;
16
17use core::ffi::VaList;
18
19use crate::{
20 c_str::CStr,
21 platform::types::{c_char, c_int},
22};
23use logger::{LOGGER, Priority};
24
25pub const LOG_PID: c_int = 0x01;
27pub const LOG_CONS: c_int = 0x02;
29pub const LOG_ODELAY: c_int = 0x04;
32pub const LOG_NDELAY: c_int = 0x08;
34pub const LOG_NOWAIT: c_int = 0x10;
35pub const LOG_PERROR: c_int = 0x20;
37
38pub const LOG_KERN: c_int = 0 << 3;
39pub const LOG_USER: c_int = 1 << 3;
40pub const LOG_MAIL: c_int = 2 << 3;
41pub const LOG_DAEMON: c_int = 3 << 3;
42pub const LOG_AUTH: c_int = 4 << 3;
43pub const LOG_SYSLOG: c_int = 5 << 3;
44pub const LOG_LPR: c_int = 6 << 3;
45pub const LOG_NEWS: c_int = 7 << 3;
46pub const LOG_UUCP: c_int = 8 << 3;
47pub const LOG_CRON: c_int = 9 << 3;
48pub const LOG_AUTHPRIV: c_int = 10 << 3;
49pub const LOG_FTP: c_int = 11 << 3;
50
51pub const LOG_LOCAL0: c_int = 16 << 3;
52pub const LOG_LOCAL1: c_int = 17 << 3;
53pub const LOG_LOCAL2: c_int = 18 << 3;
54pub const LOG_LOCAL3: c_int = 19 << 3;
55pub const LOG_LOCAL4: c_int = 20 << 3;
56pub const LOG_LOCAL5: c_int = 21 << 3;
57pub const LOG_LOCAL6: c_int = 22 << 3;
58pub const LOG_LOCAL7: c_int = 23 << 3;
59pub const LOG_NFACILITIES: c_int = 24;
60
61pub const LOG_EMERG: c_int = 0;
63pub const LOG_ALERT: c_int = 1;
64pub const LOG_CRIT: c_int = 2;
65pub const LOG_ERR: c_int = 3;
66pub const LOG_WARNING: c_int = 4;
67pub const LOG_NOTICE: c_int = 5;
68pub const LOG_INFO: c_int = 6;
69pub const LOG_DEBUG: c_int = 7;
70
71#[unsafe(no_mangle)]
73pub const extern "C" fn LOG_UPTO(p: c_int) -> c_int {
74 (1 << (p + 1)) - 1
75}
76
77#[unsafe(no_mangle)]
79pub const extern "C" fn LOG_MASK(p: c_int) -> c_int {
80 1 << p
81}
82
83#[unsafe(no_mangle)]
85pub extern "C" fn setlogmask(mask: c_int) -> c_int {
86 let mut params = LOGGER.lock();
87 let old = params.mask.bits();
88 if mask != 0
89 && let Some(mask) = params.mask.with_mask(mask)
90 {
91 params.mask = mask;
92 }
93 old
94}
95
96#[unsafe(no_mangle)]
98pub unsafe extern "C" fn openlog(ident: *const c_char, opt: c_int, facility: c_int) {
99 let ident = unsafe { CStr::from_nullable_ptr(ident) };
100 let conf = logger::Config::from_bits_truncate(opt);
101
102 let mut params = LOGGER.lock();
103 params.set_identity_cstr(ident);
104 params.opt = conf;
105 params.mask = params.mask.with_facility(facility).unwrap_or(
106 params
107 .mask
108 .with_facility(Priority::User.bits())
109 .expect("`User` is a valid syslog facility"),
110 );
111
112 if conf.contains(logger::Config::NoDelay)
114 && let Ok(()) = params.open_logger()
115 {}; }
117
118#[unsafe(no_mangle)]
122pub unsafe extern "C" fn vsyslog(priority: c_int, message: *const c_char, ap: VaList) {
123 let Some(message) = (unsafe { CStr::from_nullable_ptr(message) }) else {
124 return;
125 };
126 let Some(priority) = Priority::from_bits(priority) else {
127 return;
128 };
129
130 let mut logger = LOGGER.lock();
131 if logger.mask.should_log(priority) {
132 logger.write_log(priority, message, ap);
133 }
134}
135
136#[unsafe(no_mangle)]
138pub unsafe extern "C" fn syslog(priority: c_int, message: *const c_char, __valist: ...) {
139 unsafe { vsyslog(priority, message, __valist) };
140}
141
142#[unsafe(no_mangle)]
144pub extern "C" fn closelog() {
145 LOGGER.lock().close();
146}