1898184e3Ssthen /* 2898184e3Ssthen * Syslog.xs 3898184e3Ssthen * 4898184e3Ssthen * XS wrapper for the syslog(3) facility. 5898184e3Ssthen * 6898184e3Ssthen */ 7898184e3Ssthen 8b39c5158Smillert #if defined(_WIN32) 9b39c5158Smillert # include <windows.h> 10b39c5158Smillert #endif 11b39c5158Smillert 12b39c5158Smillert #include "EXTERN.h" 13b39c5158Smillert #include "perl.h" 14b39c5158Smillert #include "XSUB.h" 15b39c5158Smillert #ifdef USE_PPPORT_H 16b39c5158Smillert # include "ppport.h" 17b39c5158Smillert #endif 18b39c5158Smillert 19b39c5158Smillert #ifndef HAVE_SYSLOG 20b39c5158Smillert #define HAVE_SYSLOG 1 21b39c5158Smillert #endif 22b39c5158Smillert 23b39c5158Smillert #if defined(_WIN32) && !defined(__CYGWIN__) 24b39c5158Smillert # undef HAVE_SYSLOG 25b39c5158Smillert # include "fallback/syslog.h" 26b39c5158Smillert #else 27b39c5158Smillert # if defined(I_SYSLOG) || PATCHLEVEL < 6 28b39c5158Smillert # include <syslog.h> 29*5759b3d2Safresh1 # else 30*5759b3d2Safresh1 # undef HAVE_SYSLOG 31*5759b3d2Safresh1 # include "fallback/syslog.h" 32b39c5158Smillert # endif 33b39c5158Smillert #endif 34b39c5158Smillert 35b39c5158Smillert static SV *ident_svptr; 36b39c5158Smillert 37898184e3Ssthen 38898184e3Ssthen #ifndef LOG_FAC 39898184e3Ssthen #define LOG_FACMASK 0x03f8 40898184e3Ssthen #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) 41898184e3Ssthen #endif 42898184e3Ssthen 4391f110e0Safresh1 #ifndef LOG_PRIMASK 4491f110e0Safresh1 #define LOG_PRIMASK 0x07 4591f110e0Safresh1 #endif 4691f110e0Safresh1 47898184e3Ssthen #ifndef LOG_PRI 48898184e3Ssthen #define LOG_PRI(p) ((p) & LOG_PRIMASK) 49898184e3Ssthen #endif 50898184e3Ssthen 51898184e3Ssthen #ifndef LOG_MAKEPRI 52898184e3Ssthen #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) 53898184e3Ssthen #endif 54898184e3Ssthen 55898184e3Ssthen #ifndef LOG_MASK 56898184e3Ssthen #define LOG_MASK(pri) (1 << (pri)) 57898184e3Ssthen #endif 58898184e3Ssthen 59898184e3Ssthen #ifndef LOG_UPTO 60898184e3Ssthen #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) 61898184e3Ssthen #endif 62898184e3Ssthen 6391f110e0Safresh1 #include "const-c.inc" 6491f110e0Safresh1 65898184e3Ssthen 66b39c5158Smillert MODULE = Sys::Syslog PACKAGE = Sys::Syslog 67b39c5158Smillert 68b39c5158Smillert INCLUDE: const-xs.inc 69b39c5158Smillert 70b39c5158Smillert int 71b39c5158Smillert LOG_FAC(p) 72b39c5158Smillert INPUT: 73b39c5158Smillert int p 74b39c5158Smillert 75b39c5158Smillert int 76b39c5158Smillert LOG_PRI(p) 77b39c5158Smillert INPUT: 78b39c5158Smillert int p 79b39c5158Smillert 80b39c5158Smillert int 81b39c5158Smillert LOG_MAKEPRI(fac,pri) 82b39c5158Smillert INPUT: 83b39c5158Smillert int fac 84b39c5158Smillert int pri 85b39c5158Smillert 86b39c5158Smillert int 87b39c5158Smillert LOG_MASK(pri) 88b39c5158Smillert INPUT: 89b39c5158Smillert int pri 90b39c5158Smillert 91b39c5158Smillert int 92b39c5158Smillert LOG_UPTO(pri) 93b39c5158Smillert INPUT: 94b39c5158Smillert int pri 95b39c5158Smillert 96b39c5158Smillert #ifdef HAVE_SYSLOG 97b39c5158Smillert 98b39c5158Smillert void 99b39c5158Smillert openlog_xs(ident, option, facility) 100b39c5158Smillert INPUT: 101b39c5158Smillert SV* ident 102b39c5158Smillert int option 103b39c5158Smillert int facility 104b39c5158Smillert PREINIT: 105b39c5158Smillert STRLEN len; 106b39c5158Smillert char* ident_pv; 107b39c5158Smillert CODE: 108b39c5158Smillert ident_svptr = newSVsv(ident); 109b39c5158Smillert ident_pv = SvPV(ident_svptr, len); 110b39c5158Smillert openlog(ident_pv, option, facility); 111b39c5158Smillert 112b39c5158Smillert void 113b39c5158Smillert syslog_xs(priority, message) 114b39c5158Smillert INPUT: 115b39c5158Smillert int priority 116b39c5158Smillert const char * message 117b39c5158Smillert CODE: 118b39c5158Smillert syslog(priority, "%s", message); 119b39c5158Smillert 120b39c5158Smillert int 121b39c5158Smillert setlogmask_xs(mask) 122b39c5158Smillert INPUT: 123b39c5158Smillert int mask 124b39c5158Smillert CODE: 125b39c5158Smillert RETVAL = setlogmask(mask); 126b39c5158Smillert OUTPUT: 127b39c5158Smillert RETVAL 128b39c5158Smillert 129b39c5158Smillert void 130b39c5158Smillert closelog_xs() 131898184e3Ssthen PREINIT: 132898184e3Ssthen U32 refcnt; 133b39c5158Smillert CODE: 134898184e3Ssthen if (!ident_svptr) 135898184e3Ssthen return; 136b39c5158Smillert closelog(); 137898184e3Ssthen refcnt = SvREFCNT(ident_svptr); 138898184e3Ssthen if (refcnt) { 139b39c5158Smillert SvREFCNT_dec(ident_svptr); 140898184e3Ssthen if (refcnt == 1) 141898184e3Ssthen ident_svptr = NULL; 142898184e3Ssthen } 143b39c5158Smillert 144b39c5158Smillert #else /* HAVE_SYSLOG */ 145b39c5158Smillert 146b39c5158Smillert void 147b39c5158Smillert openlog_xs(ident, option, facility) 148b39c5158Smillert INPUT: 149b39c5158Smillert SV* ident 150b39c5158Smillert int option 151b39c5158Smillert int facility 152b39c5158Smillert CODE: 153b39c5158Smillert 154b39c5158Smillert void 155b39c5158Smillert syslog_xs(priority, message) 156b39c5158Smillert INPUT: 157b39c5158Smillert int priority 158b39c5158Smillert const char * message 159b39c5158Smillert CODE: 160b39c5158Smillert 161b39c5158Smillert int 162b39c5158Smillert setlogmask_xs(mask) 163b39c5158Smillert INPUT: 164b39c5158Smillert int mask 165b39c5158Smillert CODE: 166b39c5158Smillert 167b39c5158Smillert void 168b39c5158Smillert closelog_xs() 169b39c5158Smillert CODE: 170b39c5158Smillert 171b39c5158Smillert #endif /* HAVE_SYSLOG */ 172