summaryrefslogtreecommitdiff
path: root/luxio.c
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2013-09-25 12:31:31 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2013-09-25 12:31:31 +0100
commite26661245f2c9ff1bfcc8d3862ab2c1c56543717 (patch)
tree3d1cdb09eeb9bdcb9ed523a5cc811a4c6004edf7 /luxio.c
parent44c3d7e8cdef51b7e630d38015da9b571a07e526 (diff)
downloadluxio-e26661245f2c9ff1bfcc8d3862ab2c1c56543717.tar.gz
add syslog
Diffstat (limited to 'luxio.c')
-rw-r--r--luxio.c72
1 files changed, 71 insertions, 1 deletions
diff --git a/luxio.c b/luxio.c
index d3c2de5..5be8e23 100644
--- a/luxio.c
+++ b/luxio.c
@@ -40,6 +40,7 @@
#include <time.h>
#include <limits.h>
#include <signal.h>
+#include <syslog.h>
#ifdef HAVE_SENDFILE
# include <sys/sendfile.h>
@@ -3007,6 +3008,71 @@ luxio_strerror(lua_State *L)
return 1;
}
+static char *luxio_openlog_ident = NULL;
+
+static int
+luxio_openlog(lua_State *L)
+{
+ size_t len;
+ const char *ident = luaL_checklstring(L, 1, &len);
+ int option = luaL_checkint(L, 2);
+ int facility = luaL_checkint(L, 3);
+
+ /* openlog doesn't make its own copy of ident
+ * and lua could garbage collect ident
+ * so take a copy of ident
+ */
+ free(luxio_openlog_ident);
+ luxio_openlog_ident = malloc(len);
+ strncpy(luxio_openlog_ident, ident, len);
+
+ openlog(ident, option, facility);
+
+ return 0;
+}
+
+static int
+luxio_syslog(lua_State *L)
+{
+ int priority = luaL_checkint(L, 1);
+ const char *msg = luaL_checkstring(L, 2);
+
+ syslog(priority, "%s", msg);
+
+ return 0;
+}
+
+static int
+luxio_closelog(lua_State *L)
+{
+ free(luxio_openlog_ident);
+ closelog();
+
+ return 0;
+}
+
+static int
+luxio_setlogmask(lua_State *L)
+{
+ int mask = luaL_checkint(L, 1);
+
+ int oldmask = setlogmask(mask);
+ lua_pushinteger(L, oldmask);
+
+ return 1;
+}
+
+static int
+luxio_LOG_MASK(lua_State *L)
+{
+ int priority = luaL_checkint(L, 1);
+
+ int mask = LOG_MASK(priority);
+ lua_pushinteger(L, mask);
+
+ return 1;
+}
+
static const struct luaL_Reg
luxio_functions[] = {
{ "open", luxio_open },
@@ -3168,7 +3234,11 @@ luxio_functions[] = {
{ "mq_setattr", luxio_mq_setattr },
{ "mq_getattr", luxio_mq_getattr },
#endif
-
+ { "openlog", luxio_openlog },
+ { "syslog", luxio_syslog },
+ { "closelog", luxio_closelog },
+ { "setlogmask", luxio_setlogmask },
+ { "LOG_MASK", luxio_LOG_MASK },
{ NULL, NULL }
};