diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-03-06 18:03:32 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-03-06 18:03:32 +0200 |
commit | 68015bc90675e797d2d0269a6581da0cc497f7e7 (patch) | |
tree | 737fb41d58e4ffba59f9b8bf2eb88fd73d3b23a1 | |
parent | 58a64d8294c264422ec2c13f51d9776cb9cbf469 (diff) | |
download | gamma-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.
-rw-r--r-- | README | 5 | ||||
-rw-r--r-- | configure.ac | 12 | ||||
-rw-r--r-- | src/Makefile.am | 37 | ||||
-rw-r--r-- | src/syslog.c | 138 | ||||
-rw-r--r-- | src/syslog.sci | 50 |
5 files changed, 232 insertions, 10 deletions
@@ -3,6 +3,7 @@ GAMMA = Guile Archive of Multiple Modules with 'A' just for the 'A' of it. | |||
3 | It is a set of possibly useful modules. Currently it includes | 3 | It is a set of possibly useful modules. Currently it includes |
4 | 4 | ||
5 | * interfaces for two SQL DBMS: MySQL and PostgreSQL | 5 | * interfaces for two SQL DBMS: MySQL and PostgreSQL |
6 | * interfaces to syslog | ||
6 | 7 | ||
7 | Both are extensively used by Ellinika (http://ellinika.farlep.net) | 8 | Both are extensively used by Ellinika (http://ellinika.farlep.net) |
8 | and Runasimi (http://www.runasimi.org). | 9 | and Runasimi (http://www.runasimi.org). |
@@ -18,6 +19,10 @@ Configure to work without MySQL | |||
18 | 19 | ||
19 | Configure to work without Postgres | 20 | Configure to work without Postgres |
20 | 21 | ||
22 | * --without-syslog | ||
23 | |||
24 | Do not compile syslog bindings. | ||
25 | |||
21 | * --with-guiledir=DIR | 26 | * --with-guiledir=DIR |
22 | 27 | ||
23 | Specify the directory where to install guile modules. | 28 | 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 | |||
109 | AC_LIBOBJ([pgsql]) | 109 | AC_LIBOBJ([pgsql]) |
110 | fi | 110 | fi |
111 | fi | 111 | fi |
112 | |||
113 | want_syslog=yes | ||
114 | AC_ARG_WITH([syslog], | ||
115 | AC_HELP_STRING([--without-syslog], | ||
116 | [do not include syslog interfaces]), | ||
117 | [want_syslog=$withval]) | ||
118 | if test $want_syslog = yes; then | ||
119 | BUILD_LIBS="$BUILD_LIBS \$(LIB_SYSLOG)" | ||
120 | BUILD_DATA="$BUILD_DATA \$(SCM_SYSLOG)" | ||
121 | BUILD_X="$BUILD_X \$(X_SYSLOG)" | ||
122 | INSTALL_HOOKS="$INSTALL_HOOKS install-syslog-hook" | ||
123 | fi | ||
112 | fi | 124 | fi |
113 | 125 | ||
114 | if test x"$BUILD_LIBS" = x; then | 126 | 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 @@ | |||
17 | INCLUDES =-I$(top_builddir) -I$(srcdir) -I. @GUILE_INCLUDES@ @INCLUDEPATH@ | 17 | INCLUDES =-I$(top_builddir) -I$(srcdir) -I. @GUILE_INCLUDES@ @INCLUDEPATH@ |
18 | 18 | ||
19 | LIB_SQL=libgamma-sql.la | 19 | LIB_SQL=libgamma-sql.la |
20 | LIB_SYSLOG=libgamma-syslog.la | ||
20 | 21 | ||
21 | EXTRA_LTLIBRARIES=libgamma-sql.la | 22 | EXTRA_LTLIBRARIES=libgamma-sql.la libgamma-syslog.la |
22 | 23 | ||
23 | lib_LTLIBRARIES=@BUILD_LIBS@ | 24 | lib_LTLIBRARIES=@BUILD_LIBS@ |
24 | libgamma_sql_la_LIBADD = @LTLIBOBJS@ @GUILE_LIBS@ | 25 | libgamma_sql_la_LIBADD = @LTLIBOBJS@ @GUILE_LIBS@ |
@@ -28,8 +29,11 @@ libgamma_sql_la_SOURCES=\ | |||
28 | 29 | ||
29 | libgamma_sql_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0 | 30 | libgamma_sql_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0 |
30 | 31 | ||
32 | libgamma_syslog_la_SOURCES=syslog.c | ||
33 | libgamma_syslog_la_LDFLAGS = -rpath $(libdir) -version-info 0:0:0 | ||
34 | |||
31 | noinst_HEADERS=guile-sql.h app.h | 35 | noinst_HEADERS=guile-sql.h app.h |
32 | EXTRA_DIST=sql.sci mysql.c pgsql.c | 36 | EXTRA_DIST=sql.sci syslog.sci mysql.c pgsql.c |
33 | 37 | ||
34 | .sci.scm: | 38 | .sci.scm: |
35 | $(AM_V_GEN)m4 -DVERSION=$(VERSION) -DLIBDIR=$(libdir) \ | 39 | $(AM_V_GEN)m4 -DVERSION=$(VERSION) -DLIBDIR=$(libdir) \ |
@@ -40,6 +44,27 @@ sql.scm: Makefile $(libgamma_sql_la_SOURCES:.c=.inc) | |||
40 | SCM_SQL=sql.scm | 44 | SCM_SQL=sql.scm |
41 | X_SQL=gsql_conn.x | 45 | X_SQL=gsql_conn.x |
42 | 46 | ||
47 | install-sql-hook: | ||
48 | @here=`pwd` | ||
49 | cd $(DESTDIR)$(libdir);\ | ||
50 | if test -f libgamma-sql.so; then \ | ||
51 | $(LN_S) -f libgamma-sql.so libgamma-sql-v-$(VERSION).so; \ | ||
52 | fi; \ | ||
53 | cd $$here | ||
54 | |||
55 | syslog.scm: Makefile $(libgamma_syslog_la_SOURCES:.c=.inc) | ||
56 | SCM_SYSLOG=syslog.scm | ||
57 | X_SYSLOG=syslog.x | ||
58 | |||
59 | install-syslog-hook: | ||
60 | @here=`pwd` | ||
61 | cd $(DESTDIR)$(libdir);\ | ||
62 | if test -f libgamma-syslog.so; then \ | ||
63 | $(LN_S) -f libgamma-syslog.so libgamma-syslog-v-$(VERSION).so; \ | ||
64 | fi; \ | ||
65 | cd $$here | ||
66 | |||
67 | |||
43 | guiledir=$(GUILE_SITE)/$(PACKAGE) | 68 | guiledir=$(GUILE_SITE)/$(PACKAGE) |
44 | guile_DATA=guile-procedures.txt @BUILD_DATA@ | 69 | guile_DATA=guile-procedures.txt @BUILD_DATA@ |
45 | DOT_X_FILES=@BUILD_X@ | 70 | DOT_X_FILES=@BUILD_X@ |
@@ -76,13 +101,5 @@ guile-procedures.txt: $(DOT_DOC_FILES) | |||
76 | ## Add -MG to make the .x magic work with auto-dep code. | 101 | ## Add -MG to make the .x magic work with auto-dep code. |
77 | MKDEP = $(CC) -M -MG $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) | 102 | MKDEP = $(CC) -M -MG $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) |
78 | 103 | ||
79 | install-sql-hook: | ||
80 | @here=`pwd` | ||
81 | cd $(DESTDIR)$(libdir);\ | ||
82 | if test -f libgamma-sql.so; then \ | ||
83 | $(LN_S) -f libgamma-sql.so libgamma-sql-v-$(VERSION).so; \ | ||
84 | fi; \ | ||
85 | cd $$here | ||
86 | |||
87 | install-data-hook: @INSTALL_HOOKS@ | 104 | install-data-hook: @INSTALL_HOOKS@ |
88 | 105 | ||
diff --git a/src/syslog.c b/src/syslog.c new file mode 100644 index 0000000..d604be0 --- /dev/null +++ b/src/syslog.c | |||
@@ -0,0 +1,138 @@ | |||
1 | /* This file is part of Gamma. | ||
2 | Copyright (C) 2002, 2010 Sergey Poznyakoff | ||
3 | |||
4 | Gamma is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 3, or (at your option) | ||
7 | any later version. | ||
8 | |||
9 | Gamma 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 General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with Gamma. If not, see <http://www.gnu.org/licenses/>. */ | ||
16 | |||
17 | #ifdef HAVE_CONFIG_H | ||
18 | # include <config.h> | ||
19 | #endif | ||
20 | |||
21 | #include <libguile.h> | ||
22 | #include <syslog.h> | ||
23 | |||
24 | static char *log_tag; | ||
25 | |||
26 | SCM_DEFINE(scm_openlog, "openlog", 3, 0, 0, | ||
27 | (SCM IDENT, SCM OPTION, SCM FACILITY), | ||
28 | "Opens a connection to the system logger for Guile program.\n" | ||
29 | "IDENT, OPTION and FACILITY have the same meaning as in openlog(3)") | ||
30 | #define FUNC_NAME s_scm_openlog | ||
31 | { | ||
32 | SCM_ASSERT(scm_is_string(IDENT), IDENT, SCM_ARG1, FUNC_NAME); | ||
33 | if (log_tag) | ||
34 | free(log_tag); | ||
35 | log_tag = scm_to_locale_string(IDENT); | ||
36 | SCM_ASSERT(scm_is_integer(OPTION), OPTION, SCM_ARG2, FUNC_NAME); | ||
37 | SCM_ASSERT(scm_is_integer(FACILITY), FACILITY, SCM_ARG3, FUNC_NAME); | ||
38 | openlog(log_tag, scm_to_int(OPTION), scm_to_int(FACILITY)); | ||
39 | return SCM_UNSPECIFIED; | ||
40 | } | ||
41 | #undef FUNC_NAME | ||
42 | |||
43 | SCM_DEFINE(scm_openlog_p, "openlog?", 0, 0, 0, | ||
44 | (), | ||
45 | "Returns #t if @code{openlog} was called.") | ||
46 | #define FUNC_NAME s_scm_openlog_p | ||
47 | { | ||
48 | return log_tag ? SCM_BOOL_T : SCM_BOOL_F; | ||
49 | } | ||
50 | #undef FUNC_NAME | ||
51 | |||
52 | SCM_DEFINE(scm_syslog_tag, "syslog-tag", 0, 0, 0, | ||
53 | (), | ||
54 | "Returns the tag given to the recent @code{openlog}.") | ||
55 | #define FUNC_NAME s_scm_syslog_tag | ||
56 | { | ||
57 | if (!log_tag) | ||
58 | scm_misc_error("syslog-tag", | ||
59 | "openlog have not been called", | ||
60 | SCM_EOL); | ||
61 | return scm_makfrom0str(log_tag); | ||
62 | } | ||
63 | #undef FUNC_NAME | ||
64 | |||
65 | SCM_DEFINE(scm_syslog, "syslog", 2, 0, 0, | ||
66 | (SCM PRIO, SCM TEXT), | ||
67 | "Distributes TEXT via syslogd priority PRIO.") | ||
68 | #define FUNC_NAME s_scm_syslog | ||
69 | { | ||
70 | int prio; | ||
71 | char *str; | ||
72 | |||
73 | SCM_ASSERT(scm_is_integer(PRIO), PRIO, SCM_ARG1, FUNC_NAME); | ||
74 | prio = scm_to_int(PRIO); | ||
75 | |||
76 | SCM_ASSERT(scm_is_string(TEXT), TEXT, SCM_ARG2, FUNC_NAME); | ||
77 | str = scm_to_locale_string(TEXT); | ||
78 | syslog(prio, "%s", str); | ||
79 | free(str); | ||
80 | return SCM_UNSPECIFIED; | ||
81 | } | ||
82 | #undef FUNC_NAME | ||
83 | |||
84 | SCM_DEFINE(scm_closelog, "closelog", 0, 0, 0, | ||
85 | (), | ||
86 | "Closes the channel to the system logger opened by @code{openlog}.") | ||
87 | #define FUNC_NAME s_scm_closelog | ||
88 | { | ||
89 | closelog(); | ||
90 | if (log_tag) { | ||
91 | free(log_tag); | ||
92 | log_tag = NULL; | ||
93 | } | ||
94 | return SCM_UNSPECIFIED; | ||
95 | } | ||
96 | #undef FUNC_NAME | ||
97 | |||
98 | |||
99 | static struct { | ||
100 | char *name; | ||
101 | int facility; | ||
102 | } syslog_kw[] = { | ||
103 | { "LOG_USER", LOG_USER }, | ||
104 | { "LOG_DAEMON", LOG_DAEMON }, | ||
105 | { "LOG_AUTH", LOG_AUTH }, | ||
106 | { "LOG_LOCAL0", LOG_LOCAL0 }, | ||
107 | { "LOG_LOCAL1", LOG_LOCAL1 }, | ||
108 | { "LOG_LOCAL2", LOG_LOCAL2 }, | ||
109 | { "LOG_LOCAL3", LOG_LOCAL3 }, | ||
110 | { "LOG_LOCAL4", LOG_LOCAL4 }, | ||
111 | { "LOG_LOCAL5", LOG_LOCAL5 }, | ||
112 | { "LOG_LOCAL6", LOG_LOCAL6 }, | ||
113 | { "LOG_LOCAL7", LOG_LOCAL7 }, | ||
114 | /* severity */ | ||