Skip to content

Commit

Permalink
Auto merge of rust-lang#278 - lemonrock:syslog, r=alexcrichton
Browse files Browse the repository at this point in the history
Adding syslog functions, constants and structs

This commit adds the functions:-
- syslog
- openlog
- closelog
- setlogmask

It adds LOG_* constants.

It adds the `CODE` struct used by the `#define` definitions `prioritynames` and `facilitynames`.

It does not add:-
- the function `vsyslog`; this is an extension to POSIX and uses va_list macros;
- the `#define`s `prioritynames` and `facilitynames`, as usage is not common
- rust functions mirroring the macros:-
  - LOG_PRI
  - LOG_MAKEPRI
  - LOG_MASK
  - LOG_UPTO
  - LOG_FAC
* `CODE` is included in case a third-party unsafe C function returns or takes it.
  • Loading branch information
bors committed May 5, 2016
2 parents ac75250 + 828766f commit 4fc03fe
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ fn main() {
cfg.header("sched.h");
cfg.header("termios.h");
cfg.header("poll.h");
cfg.header("syslog.h");
}

if android {
Expand Down
7 changes: 7 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,13 @@ pub const RTLD_GLOBAL: ::c_int = 0x8;

pub const _WSTOPPED: ::c_int = 0o177;

pub const LOG_NETINFO: ::c_int = 12 << 3;
pub const LOG_REMOTEAUTH: ::c_int = 13 << 3;
pub const LOG_INSTALL: ::c_int = 14 << 3;
pub const LOG_RAS: ::c_int = 15 << 3;
pub const LOG_LAUNCHD: ::c_int = 24 << 3;
pub const LOG_NFACILITIES: ::c_int = 25;

f! {
pub fn WSTOPSIG(status: ::c_int) -> ::c_int {
status >> 8
Expand Down
5 changes: 5 additions & 0 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,11 @@ pub const RTLD_NODELETE: ::c_int = 0x1000;
pub const RTLD_NOLOAD: ::c_int = 0x2000;
pub const RTLD_GLOBAL: ::c_int = 0x100;

pub const LOG_NTP: ::c_int = 12 << 3;
pub const LOG_SECURITY: ::c_int = 13 << 3;
pub const LOG_CONSOLE: ::c_int = 14 << 3;
pub const LOG_NFACILITIES: ::c_int = 24;

#[link(name = "util")]
extern {
pub fn getnameinfo(sa: *const ::sockaddr,
Expand Down
5 changes: 5 additions & 0 deletions src/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ pub const WNOHANG: ::c_int = 1;
pub const RTLD_NOW: ::c_int = 0x2;
pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void;

pub const LOG_CRON: ::c_int = 9 << 3;
pub const LOG_AUTHPRIV: ::c_int = 10 << 3;
pub const LOG_FTP: ::c_int = 11 << 3;
pub const LOG_PERROR: ::c_int = 0x20;

f! {
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ pub const Q_SETQUOTA: ::c_int = 0x400;

pub const RTLD_GLOBAL: ::c_int = 0x100;

pub const LOG_NFACILITIES: ::c_int = 24;

#[link(name = "util")]
extern {
pub fn mincore(addr: *mut ::c_void, len: ::size_t,
Expand Down
41 changes: 41 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ pub const IF_NAMESIZE: ::size_t = 16;

pub const RTLD_LAZY: ::c_int = 0x1;

pub const LOG_EMERG: ::c_int = 0;
pub const LOG_ALERT: ::c_int = 1;
pub const LOG_CRIT: ::c_int = 2;
pub const LOG_ERR: ::c_int = 3;
pub const LOG_WARNING: ::c_int = 4;
pub const LOG_NOTICE: ::c_int = 5;
pub const LOG_INFO: ::c_int = 6;
pub const LOG_DEBUG: ::c_int = 7;

pub const LOG_KERN: ::c_int = 0;
pub const LOG_USER: ::c_int = 1 << 3;
pub const LOG_MAIL: ::c_int = 2 << 3;
pub const LOG_DAEMON: ::c_int = 3 << 3;
pub const LOG_AUTH: ::c_int = 4 << 3;
pub const LOG_SYSLOG: ::c_int = 5 << 3;
pub const LOG_LPR: ::c_int = 6 << 3;
pub const LOG_NEWS: ::c_int = 7 << 3;
pub const LOG_UUCP: ::c_int = 8 << 3;
pub const LOG_LOCAL0: ::c_int = 16 << 3;
pub const LOG_LOCAL1: ::c_int = 17 << 3;
pub const LOG_LOCAL2: ::c_int = 18 << 3;
pub const LOG_LOCAL3: ::c_int = 19 << 3;
pub const LOG_LOCAL4: ::c_int = 20 << 3;
pub const LOG_LOCAL5: ::c_int = 21 << 3;
pub const LOG_LOCAL6: ::c_int = 22 << 3;
pub const LOG_LOCAL7: ::c_int = 23 << 3;

pub const LOG_PID: ::c_int = 0x01;
pub const LOG_CONS: ::c_int = 0x02;
pub const LOG_ODELAY: ::c_int = 0x04;
pub const LOG_NDELAY: ::c_int = 0x08;
pub const LOG_NOWAIT: ::c_int = 0x10;

pub const LOG_PRIMASK: ::c_int = 7;
pub const LOG_FACMASK: ::c_int = 0x3f8;

cfg_if! {
if #[cfg(dox)] {
// on dox builds don't pull in anything
Expand Down Expand Up @@ -732,6 +768,11 @@ extern {
pub fn mkdtemp(template: *mut ::c_char) -> *mut ::c_char;
pub fn futimes(fd: ::c_int, times: *const ::timeval) -> ::c_int;
pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char;

pub fn openlog(ident: *const ::c_char, logopt: ::c_int, facility: ::c_int);
pub fn closelog();
pub fn setlogmask(maskpri: ::c_int) -> ::c_int;
pub fn syslog(priority: ::c_int, message: *const ::c_char, ...);
}

cfg_if! {
Expand Down
2 changes: 2 additions & 0 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ pub const NCCS: usize = 32;

pub const AF_NETLINK: ::c_int = 16;

pub const LOG_NFACILITIES: ::c_int = 24;

f! {
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.bits.iter_mut() {
Expand Down
5 changes: 5 additions & 0 deletions src/unix/notbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ pub const POSIX_FADV_NOREUSE: ::c_int = 5;
pub const AT_FDCWD: ::c_int = -100;
pub const AT_SYMLINK_NOFOLLOW: ::c_int = 0x100;

pub const LOG_CRON: ::c_int = 9 << 3;
pub const LOG_AUTHPRIV: ::c_int = 10 << 3;
pub const LOG_FTP: ::c_int = 11 << 3;
pub const LOG_PERROR: ::c_int = 0x20;

f! {
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/solaris/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ pub const _RWL_MAGIC: u16 = 0x5257; // RW

pub const NCCS: usize = 19;

pub const LOG_CRON: ::c_int = 15 << 3;

pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
__pthread_mutex_flag1: 0,
__pthread_mutex_flag2: 0,
Expand Down

0 comments on commit 4fc03fe

Please sign in to comment.