1 /*
2  * Copyright (C) 2006-2009 Citrix Systems Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published
6  * by the Free Software Foundation; version 2.1 only. with the special
7  * exception on linking described in file LICENSE.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Lesser General Public License for more details.
13  */
14 
15 #include <syslog.h>
16 #include <string.h>
17 #include <caml/mlvalues.h>
18 #include <caml/memory.h>
19 #include <caml/alloc.h>
20 #include <caml/custom.h>
21 #include <caml/signals.h>
22 
23 static int __syslog_level_table[] = {
24 	LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING,
25 	LOG_NOTICE, LOG_INFO, LOG_DEBUG
26 };
27 
28 static int __syslog_facility_table[] = {
29 	LOG_AUTH, LOG_AUTHPRIV, LOG_CRON, LOG_DAEMON, LOG_FTP, LOG_KERN,
30 	LOG_LOCAL0, LOG_LOCAL1, LOG_LOCAL2, LOG_LOCAL3,
31 	LOG_LOCAL4, LOG_LOCAL5, LOG_LOCAL6, LOG_LOCAL7,
32 	LOG_LPR | LOG_MAIL | LOG_NEWS | LOG_SYSLOG | LOG_USER | LOG_UUCP
33 };
34 
stub_syslog(value facility,value level,value msg)35 value stub_syslog(value facility, value level, value msg)
36 {
37 	CAMLparam3(facility, level, msg);
38 	const char *c_msg = strdup(String_val(msg));
39 	int c_facility = __syslog_facility_table[Int_val(facility)]
40 	               | __syslog_level_table[Int_val(level)];
41 
42 	caml_enter_blocking_section();
43 	syslog(c_facility, "%s", c_msg);
44 	caml_leave_blocking_section();
45 
46 	free((void*)c_msg);
47 	CAMLreturn(Val_unit);
48 }
49