From 7e0dbc3270b0c4ddb9206c295d3c35b66646df7a Mon Sep 17 00:00:00 2001
From: Raphael Cohn <raphael.cohn@stormmq.com>
Date: Wed, 4 May 2016 11:47:02 +0100
Subject: [PATCH] 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 #defines 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.
---
 src/unix/mod.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index c29d8f40..7c2a3c11 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -109,6 +109,11 @@ s! {
         pub ws_xpixel: ::c_ushort,
         pub ws_ypixel: ::c_ushort,
     }
+
+    pub struct CODE {
+        pub c_name: *mut ::c_char,
+        pub c_val: *mut ::c_int,
+    }
 }
 
 pub const SIG_DFL: sighandler_t = 0 as sighandler_t;
@@ -145,6 +150,47 @@ 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_CRON: ::c_int = 9 << 3;
+pub const LOG_AUTHPRIV: ::c_int = 10 << 3;
+pub const LOG_FTP: ::c_int = 11 << 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_PERROR: ::c_int = 0x20;
+
+pub const LOG_PRIMASK: ::c_int = 7;
+pub const LOG_NFACILITIES: ::c_int = 24;
+pub const LOG_FACMASK: ::c_int = 0x3f8;
+
 cfg_if! {
     if #[cfg(dox)] {
         // on dox builds don't pull in anything
@@ -732,6 +778,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! {
-- 
GitLab