summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-04-01 13:25:41 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-04-01 13:25:41 +0300
commit43a43a758881ae1294b73696175bc066e9257aa2 (patch)
treee69e1372f44fd7b309102cc9d571471b1e5002a9
parentee08a14e8d73482297fa603938e0ba04475c092c (diff)
downloadmailutils-43a43a758881ae1294b73696175bc066e9257aa2.tar.gz
mailutils-43a43a758881ae1294b73696175bc066e9257aa2.tar.bz2
Fix SCM syslog interface.
* libmu_scm/mu_logger.c (log_tag): New static. (mu-openlog): Preserve log tag in log_tag, because openlog stores its first argument as-is. Simplify argument handling. (mu-logger): Simplify argument handling. (mu-closelog): Free log_tag.
-rw-r--r--libmu_scm/mu_logger.c51
1 files changed, 17 insertions, 34 deletions
diff --git a/libmu_scm/mu_logger.c b/libmu_scm/mu_logger.c
index 5b6d0f4e1..4dc7841f0 100644
--- a/libmu_scm/mu_logger.c
+++ b/libmu_scm/mu_logger.c
@@ -21,39 +21,22 @@
#include <syslog.h>
+static char *log_tag;
+
SCM_DEFINE (scm_mu_openlog, "mu-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_mu_openlog
{
- char *ident, *ident_mem = NULL;
- int option, facility;
-
- if (IDENT == SCM_BOOL_F)
- ident = "libmu_scm";
- else
- {
- SCM_ASSERT (scm_is_string (IDENT), IDENT, SCM_ARG1, FUNC_NAME);
- ident = ident_mem = scm_to_locale_string (IDENT);
- }
+ SCM_ASSERT (scm_is_string (IDENT), IDENT, SCM_ARG1, FUNC_NAME);
+ if (log_tag)
+ free (log_tag);
+ log_tag = scm_to_locale_string(IDENT);
- if (scm_is_integer (OPTION))
- option = scm_to_int32 (OPTION);
- else if (SCM_BIGP (OPTION))
- option = (int) scm_i_big2dbl (OPTION);
- else
- SCM_ASSERT (0, OPTION, SCM_ARG2, FUNC_NAME);
-
- if (scm_is_integer (FACILITY))
- facility = scm_to_int32 (FACILITY);
- else if (SCM_BIGP (FACILITY))
- facility = (int) scm_i_big2dbl (FACILITY);
- else
- SCM_ASSERT (0, FACILITY, SCM_ARG3, FUNC_NAME);
-
- openlog (ident, option, facility);
- free (ident_mem);
+ 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
@@ -66,18 +49,13 @@ SCM_DEFINE (scm_mu_logger, "mu-logger", 2, 0, 0,
int prio;
char *str;
- if (PRIO == SCM_BOOL_F)
- prio = LOG_INFO;
- else if (scm_is_integer (PRIO))
- prio = scm_to_int32 (PRIO);
- else if (SCM_BIGP (PRIO))
- prio = (int) scm_i_big2dbl (PRIO);
- else
- SCM_ASSERT (0, PRIO, SCM_ARG1, FUNC_NAME);
+ 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
@@ -88,6 +66,11 @@ SCM_DEFINE (scm_mu_closelog, "mu-closelog", 0, 0, 0,
#define FUNC_NAME s_scm_mu_closelog
{
closelog ();
+ if (log_tag)
+ {
+ free (log_tag);
+ log_tag = NULL;
+ }
return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

Return to:

Send suggestions and report system problems to the System administrator.