summaryrefslogtreecommitdiff
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
parent44c3d7e8cdef51b7e630d38015da9b571a07e526 (diff)
downloadluxio-e26661245f2c9ff1bfcc8d3862ab2c1c56543717.tar.bz2
add syslog
-rw-r--r--luxio.c72
-rw-r--r--luxio_constants.h.in31
2 files changed, 102 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 }
};
diff --git a/luxio_constants.h.in b/luxio_constants.h.in
index b7edfef..07a4f03 100644
--- a/luxio_constants.h.in
+++ b/luxio_constants.h.in
@@ -274,6 +274,37 @@ static const struct {
? E(_POSIX_TIMER_MAX),
? E(_POSIX_TZNAME_MAX),
+ E(LOG_PID),
+ E(LOG_CONS),
+ E(LOG_NDELAY),
+ E(LOG_ODELAY),
+ E(LOG_NOWAIT),
+ E(LOG_KERN),
+ E(LOG_USER),
+ E(LOG_MAIL),
+ E(LOG_NEWS),
+ E(LOG_UUCP),
+ E(LOG_DAEMON),
+ E(LOG_AUTH),
+ E(LOG_CRON),
+ E(LOG_LPR),
+ E(LOG_LOCAL0),
+ E(LOG_LOCAL1),
+ E(LOG_LOCAL2),
+ E(LOG_LOCAL3),
+ E(LOG_LOCAL4),
+ E(LOG_LOCAL5),
+ E(LOG_LOCAL6),
+ E(LOG_LOCAL7),
+ E(LOG_EMERG),
+ E(LOG_ALERT),
+ E(LOG_CRIT),
+ E(LOG_ERR),
+ E(LOG_WARNING),
+ E(LOG_NOTICE),
+ E(LOG_INFO),
+ E(LOG_DEBUG),
+
E(EXIT_SUCCESS),
E(EXIT_FAILURE),