summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2010-03-06 16:03:32 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2010-03-06 16:03:32 (GMT)
commit68015bc90675e797d2d0269a6581da0cc497f7e7 (patch) (side-by-side diff)
tree737fb41d58e4ffba59f9b8bf2eb88fd73d3b23a1
parent58a64d8294c264422ec2c13f51d9776cb9cbf469 (diff)
downloadgamma-68015bc90675e797d2d0269a6581da0cc497f7e7.tar.gz
gamma-68015bc90675e797d2d0269a6581da0cc497f7e7.tar.bz2
Add syslog interfaces.
* src/syslog.c: New file. * src/syslog.sci: New file. * README, configure.ac, src/Makefile.am: Update.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--README5
-rw-r--r--configure.ac12
-rw-r--r--src/Makefile.am37
-rw-r--r--src/syslog.c138
-rw-r--r--src/syslog.sci50
5 files changed, 232 insertions, 10 deletions
diff --git a/README b/README
index 4e99fea..ad485d0 100644
--- a/README
+++ b/README
@@ -3,6 +3,7 @@ GAMMA = Guile Archive of Multiple Modules with 'A' just for the 'A' of it.
It is a set of possibly useful modules. Currently it includes
* interfaces for two SQL DBMS: MySQL and PostgreSQL
+* interfaces to syslog
Both are extensively used by Ellinika (http://ellinika.farlep.net)
and Runasimi (http://www.runasimi.org).
@@ -18,6 +19,10 @@ Configure to work without MySQL
Configure to work without Postgres
+* --without-syslog
+
+Do not compile syslog bindings.
+
* --with-guiledir=DIR
Specify the directory where to install guile modules.
diff --git a/configure.ac b/configure.ac
index 444cc1a..1d59c37 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,6 +109,18 @@ if test $mu_cv_lib_guile = yes; then
AC_LIBOBJ([pgsql])
fi
fi
+
+ want_syslog=yes
+ AC_ARG_WITH([syslog],
+ AC_HELP_STRING([--without-syslog],
+ [do not include syslog interfaces]),
+ [want_syslog=$withval])
+ if test $want_syslog = yes; then
+ BUILD_LIBS="$BUILD_LIBS \$(LIB_SYSLOG)"
+ BUILD_DATA="$BUILD_DATA \$(SCM_SYSLOG)"
+ BUILD_X="$BUILD_X \$(X_SYSLOG)"
+ INSTALL_HOOKS="$INSTALL_HOOKS install-syslog-hook"
+ fi
fi
if test x"$BUILD_LIBS" = x; then
diff --git a/src/Makefile.am b/src/Makefile.am
index 92894eb..1a07e18 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,8 +17,9 @@
INCLUDES =-I$(top_builddir) -I$(srcdir) -I. @GUILE_INCLUDES@ @INCLUDEPATH@
LIB_SQL=libgamma-sql.la
+LIB_SYSLOG=libgamma-syslog.la
-EXTRA_LTLIBRARIES=libgamma-sql.la
+EXTRA_LTLIBRARIES=libgamma-sql.la libgamma-syslog.la
lib_LTLIBRARIES=@BUILD_LIBS@
libgamma_sql_la_LIBADD = @LTLIBOBJS@ @GUILE_LIBS@
@@ -28,8 +29,11 @@ libgamma_sql_la_SOURCES=\
libgamma_sql_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0
+libgamma_syslog_la_SOURCES=syslog.c
+libgamma_syslog_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0
+
noinst_HEADERS=guile-sql.h app.h
-EXTRA_DIST=sql.sci mysql.c pgsql.c
+EXTRA_DIST=sql.sci syslog.sci mysql.c pgsql.c
.sci.scm:
$(AM_V_GEN)m4 -DVERSION=$(VERSION) -DLIBDIR=$(libdir) \
@@ -40,6 +44,27 @@ sql.scm: Makefile $(libgamma_sql_la_SOURCES:.c=.inc)
SCM_SQL=sql.scm
X_SQL=gsql_conn.x
+install-sql-hook:
+ @here=`pwd`
+ cd $(DESTDIR)$(libdir);\
+ if test -f libgamma-sql.so; then \
+ $(LN_S) -f libgamma-sql.so libgamma-sql-v-$(VERSION).so; \
+ fi; \
+ cd $$here
+
+syslog.scm: Makefile $(libgamma_syslog_la_SOURCES:.c=.inc)
+SCM_SYSLOG=syslog.scm
+X_SYSLOG=syslog.x
+
+install-syslog-hook:
+ @here=`pwd`
+ cd $(DESTDIR)$(libdir);\
+ if test -f libgamma-syslog.so; then \
+ $(LN_S) -f libgamma-syslog.so libgamma-syslog-v-$(VERSION).so; \
+ fi; \
+ cd $$here
+
+
guiledir=$(GUILE_SITE)/$(PACKAGE)
guile_DATA=guile-procedures.txt @BUILD_DATA@
DOT_X_FILES=@BUILD_X@
@@ -76,13 +101,5 @@ guile-procedures.txt: $(DOT_DOC_FILES)
## Add -MG to make the .x magic work with auto-dep code.
MKDEP = $(CC) -M -MG $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
-install-sql-hook:
- @here=`pwd`
- cd $(DESTDIR)$(libdir);\
- if test -f libgamma-sql.so; then \
- $(LN_S) -f libgamma-sql.so libgamma-sql-v-$(VERSION).so; \
- fi; \
- cd $$here
-
install-data-hook: @INSTALL_HOOKS@
diff --git a/src/syslog.c b/src/syslog.c
new file mode 100644
index 0000000..d604be0
--- a/dev/null
+++ b/src/syslog.c
@@ -0,0 +1,138 @@
+/* This file is part of Gamma.
+ Copyright (C) 2002, 2010 Sergey Poznyakoff
+
+ Gamma is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Gamma is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Gamma. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <libguile.h>
+#include <syslog.h>
+
+static char *log_tag;
+
+SCM_DEFINE(scm_openlog, "openlog", 3, 0, 0,
+ (SCM IDENT, SCM OPTION, SCM FACILITY),
+"Opens a connection to the system logger for Guile program.\n"
+"IDENT, OPTION and FACILITY have the same meaning as in openlog(3)")
+#define FUNC_NAME s_scm_openlog
+{
+ SCM_ASSERT(scm_is_string(IDENT), IDENT, SCM_ARG1, FUNC_NAME);
+ if (log_tag)
+ free(log_tag);
+ log_tag = scm_to_locale_string(IDENT);
+ SCM_ASSERT(scm_is_integer(OPTION), OPTION, SCM_ARG2, FUNC_NAME);
+ SCM_ASSERT(scm_is_integer(FACILITY), FACILITY, SCM_ARG3, FUNC_NAME);
+ openlog(log_tag, scm_to_int(OPTION), scm_to_int(FACILITY));
+ return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+SCM_DEFINE(scm_openlog_p, "openlog?", 0, 0, 0,
+ (),
+ "Returns #t if @code{openlog} was called.")
+#define FUNC_NAME s_scm_openlog_p
+{
+ return log_tag ? SCM_BOOL_T : SCM_BOOL_F;
+}
+#undef FUNC_NAME
+
+SCM_DEFINE(scm_syslog_tag, "syslog-tag", 0, 0, 0,
+ (),
+ "Returns the tag given to the recent @code{openlog}.")
+#define FUNC_NAME s_scm_syslog_tag
+{
+ if (!log_tag)
+ scm_misc_error("syslog-tag",
+ "openlog have not been called",
+ SCM_EOL);
+ return scm_makfrom0str(log_tag);
+}
+#undef FUNC_NAME
+
+SCM_DEFINE(scm_syslog, "syslog", 2, 0, 0,
+ (SCM PRIO, SCM TEXT),
+ "Distributes TEXT via syslogd priority PRIO.")
+#define FUNC_NAME s_scm_syslog
+{
+ int prio;
+ char *str;
+
+ SCM_ASSERT(scm_is_integer(PRIO), PRIO, SCM_ARG1, FUNC_NAME);
+ prio = scm_to_int(PRIO);
+
+ SCM_ASSERT(scm_is_string(TEXT), TEXT, SCM_ARG2, FUNC_NAME);
+ str = scm_to_locale_string(TEXT);
+ syslog(prio, "%s", str);
+ free(str);
+ return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+SCM_DEFINE(scm_closelog, "closelog", 0, 0, 0,
+ (),
+ "Closes the channel to the system logger opened by @code{openlog}.")
+#define FUNC_NAME s_scm_closelog
+{
+ closelog();
+ if (log_tag) {
+ free(log_tag);
+ log_tag = NULL;
+ }
+ return SCM_UNSPECIFIED;
+}
+#undef FUNC_NAME
+
+
+static struct {
+ char *name;
+ int facility;
+} syslog_kw[] = {
+ { "LOG_USER", LOG_USER },
+ { "LOG_DAEMON", LOG_DAEMON },
+ { "LOG_AUTH", LOG_AUTH },
+ { "LOG_LOCAL0", LOG_LOCAL0 },
+ { "LOG_LOCAL1", LOG_LOCAL1 },
+ { "LOG_LOCAL2", LOG_LOCAL2 },
+ { "LOG_LOCAL3", LOG_LOCAL3 },
+ { "LOG_LOCAL4", LOG_LOCAL4 },
+ { "LOG_LOCAL5", LOG_LOCAL5 },
+ { "LOG_LOCAL6", LOG_LOCAL6 },
+ { "LOG_LOCAL7", LOG_LOCAL7 },
+ /* severity */
+ { "LOG_EMERG", LOG_EMERG },
+ { "LOG_ALERT", LOG_ALERT },
+ { "LOG_CRIT", LOG_CRIT },
+ { "LOG_ERR", LOG_ERR },
+ { "LOG_WARNING", LOG_WARNING },
+ { "LOG_NOTICE", LOG_NOTICE },
+ { "LOG_INFO", LOG_INFO },
+ { "LOG_DEBUG", LOG_DEBUG },
+ /* options */
+ { "LOG_CONS", LOG_CONS },
+ { "LOG_NDELAY", LOG_NDELAY },
+ { "LOG_PID", LOG_PID }
+};
+
+void
+syslog_init()
+{
+ int i;
+
+ for (i = 0; i < sizeof (syslog_kw)/sizeof(syslog_kw[0]); i++)
+ scm_c_define (syslog_kw[i].name,
+ scm_from_int(syslog_kw[i].facility));
+#include <syslog.x>
+}
diff --git a/src/syslog.sci b/src/syslog.sci
new file mode 100644
index 0000000..46e00fa
--- a/dev/null
+++ b/src/syslog.sci
@@ -0,0 +1,50 @@
+;;;; This file is part of Gamma. -*- scheme -*-
+;;;; Copyright (C) 2010 Sergey Poznyakoff
+;;;;
+;;;; Gamma is free software; you can redistribute it and/or modify
+;;;; it under the terms of the GNU General Public License as published by
+;;;; the Free Software Foundation; either version 3, or (at your option)
+;;;; any later version.
+;;;;
+;;;; Gamma is distributed in the hope that it will be useful,
+;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;;; GNU General Public License for more details.
+;;;;
+;;;; You should have received a copy of the GNU General Public License
+;;;; along with Gamma. If not, see <http://www.gnu.org/licenses/>.
+
+changequote([,])dnl
+
+(define-module (gamma syslog))
+
+(let ((lib-path "LIBDIR/"))
+ (load-extension (string-append
+ lib-path "libgamma-syslog-v-VERSION") "syslog_init"))
+
+include(BUILDDIR/syslog.inc)
+
+(export LOG_USER)
+(export LOG_DAEMON)
+(export LOG_AUTH)
+(export LOG_LOCAL0)
+(export LOG_LOCAL1)
+(export LOG_LOCAL2)
+(export LOG_LOCAL3)
+(export LOG_LOCAL4)
+(export LOG_LOCAL5)
+(export LOG_LOCAL6)
+(export LOG_LOCAL7)
+(export LOG_EMERG)
+(export LOG_ALERT)
+(export LOG_CRIT)
+(export LOG_ERR)
+(export LOG_WARNING)
+(export LOG_NOTICE)
+(export LOG_INFO)
+(export LOG_DEBUG)
+(export LOG_CONS)
+(export LOG_NDELAY)
+(export LOG_PID)
+
+;;;; End of syslog.scm

Return to:

Send suggestions and report system problems to the System administrator.