1 /* $NetBSD: syslog.c,v 1.1 2013/11/12 14:32:03 mbalmer Exp $ */
4 * Copyright (c) 2013 Marc Balmer <marc@msys.ch>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 /* Lua binding for syslog */
30 #include <sys/types.h>
39 int luaopen_syslog(lua_State
*);
42 syslog_openlog(lua_State
*L
)
48 ident
= luaL_checkstring(L
, 1);
49 option
= luaL_checkinteger(L
, 2);
50 facility
= luaL_checkinteger(L
, 3);
51 openlog(ident
, option
, facility
);
56 syslog_syslog(lua_State
*L
)
58 syslog(luaL_checkint(L
, 1), "%s", luaL_checkstring(L
, 2));
63 syslog_closelog(lua_State
*L
)
70 syslog_setlogmask(lua_State
*L
)
72 lua_pushinteger(L
, setlogmask(luaL_checkint(L
, 1)));
77 syslog_set_info(lua_State
*L
)
79 lua_pushliteral(L
, "_COPYRIGHT");
80 lua_pushliteral(L
, "Copyright (C) 2013 by "
81 "Marc Balmer <marc@msys.ch>");
83 lua_pushliteral(L
, "_DESCRIPTION");
84 lua_pushliteral(L
, "syslog binding for Lua");
86 lua_pushliteral(L
, "_VERSION");
87 lua_pushliteral(L
, "syslog 1.0.0");
96 #define CONSTANT(NAME) { #NAME, NAME }
98 static struct constant syslog_constant
[] = {
101 CONSTANT(LOG_NDELAY
),
102 CONSTANT(LOG_NOWAIT
),
103 CONSTANT(LOG_ODELAY
),
104 CONSTANT(LOG_PERROR
),
107 /* syslog facilities */
109 CONSTANT(LOG_AUTHPRIV
),
111 CONSTANT(LOG_DAEMON
),
114 CONSTANT(LOG_LOCAL0
),
115 CONSTANT(LOG_LOCAL1
),
116 CONSTANT(LOG_LOCAL2
),
117 CONSTANT(LOG_LOCAL3
),
118 CONSTANT(LOG_LOCAL4
),
119 CONSTANT(LOG_LOCAL5
),
120 CONSTANT(LOG_LOCAL6
),
121 CONSTANT(LOG_LOCAL7
),
125 CONSTANT(LOG_SYSLOG
),
134 CONSTANT(LOG_WARNING
),
135 CONSTANT(LOG_NOTICE
),
143 luaopen_syslog(lua_State
*L
)
146 struct luaL_Reg luasyslog
[] = {
147 { "openlog", syslog_openlog
},
148 { "syslog", syslog_syslog
},
149 { "closelog", syslog_closelog
},
150 { "setlogmask", syslog_setlogmask
},
154 #if LUA_VERSION_NUM >= 502
155 luaL_newlib(L
, luasyslog
);
157 luaL_register(L
, "syslog", luasyslog
);
160 for (n
= 0; syslog_constant
[n
].name
!= NULL
; n
++) {
161 lua_pushinteger(L
, syslog_constant
[n
].value
);
162 lua_setfield(L
, -2, syslog_constant
[n
].name
);