Commit 43a43a75 43a43a758881ae1294b73696175bc066e9257aa2 by Sergey Poznyakoff

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.
1 parent ee08a14e
...@@ -21,39 +21,22 @@ ...@@ -21,39 +21,22 @@
21 21
22 #include <syslog.h> 22 #include <syslog.h>
23 23
24 static char *log_tag;
25
24 SCM_DEFINE (scm_mu_openlog, "mu-openlog", 3, 0, 0, 26 SCM_DEFINE (scm_mu_openlog, "mu-openlog", 3, 0, 0,
25 (SCM IDENT, SCM OPTION, SCM FACILITY), 27 (SCM IDENT, SCM OPTION, SCM FACILITY),
26 "Opens a connection to the system logger for Guile program.\n" 28 "Opens a connection to the system logger for Guile program.\n"
27 "IDENT, OPTION and FACILITY have the same meaning as in openlog(3)") 29 "IDENT, OPTION and FACILITY have the same meaning as in openlog(3)")
28 #define FUNC_NAME s_scm_mu_openlog 30 #define FUNC_NAME s_scm_mu_openlog
29 { 31 {
30 char *ident, *ident_mem = NULL;
31 int option, facility;
32
33 if (IDENT == SCM_BOOL_F)
34 ident = "libmu_scm";
35 else
36 {
37 SCM_ASSERT (scm_is_string (IDENT), IDENT, SCM_ARG1, FUNC_NAME); 32 SCM_ASSERT (scm_is_string (IDENT), IDENT, SCM_ARG1, FUNC_NAME);
38 ident = ident_mem = scm_to_locale_string (IDENT); 33 if (log_tag)
39 } 34 free (log_tag);
35 log_tag = scm_to_locale_string(IDENT);
40 36
41 if (scm_is_integer (OPTION)) 37 SCM_ASSERT (scm_is_integer (OPTION), OPTION, SCM_ARG2, FUNC_NAME);
42 option = scm_to_int32 (OPTION); 38 SCM_ASSERT (scm_is_integer (FACILITY), FACILITY, SCM_ARG3, FUNC_NAME);
43 else if (SCM_BIGP (OPTION)) 39 openlog (log_tag, scm_to_int (OPTION), scm_to_int (FACILITY));
44 option = (int) scm_i_big2dbl (OPTION);
45 else
46 SCM_ASSERT (0, OPTION, SCM_ARG2, FUNC_NAME);
47
48 if (scm_is_integer (FACILITY))
49 facility = scm_to_int32 (FACILITY);
50 else if (SCM_BIGP (FACILITY))
51 facility = (int) scm_i_big2dbl (FACILITY);
52 else
53 SCM_ASSERT (0, FACILITY, SCM_ARG3, FUNC_NAME);
54
55 openlog (ident, option, facility);
56 free (ident_mem);
57 return SCM_UNSPECIFIED; 40 return SCM_UNSPECIFIED;
58 } 41 }
59 #undef FUNC_NAME 42 #undef FUNC_NAME
...@@ -66,18 +49,13 @@ SCM_DEFINE (scm_mu_logger, "mu-logger", 2, 0, 0, ...@@ -66,18 +49,13 @@ SCM_DEFINE (scm_mu_logger, "mu-logger", 2, 0, 0,
66 int prio; 49 int prio;
67 char *str; 50 char *str;
68 51
69 if (PRIO == SCM_BOOL_F) 52 SCM_ASSERT (scm_is_integer (PRIO), PRIO, SCM_ARG1, FUNC_NAME);
70 prio = LOG_INFO; 53 prio = scm_to_int (PRIO);
71 else if (scm_is_integer (PRIO))
72 prio = scm_to_int32 (PRIO);
73 else if (SCM_BIGP (PRIO))
74 prio = (int) scm_i_big2dbl (PRIO);
75 else
76 SCM_ASSERT (0, PRIO, SCM_ARG1, FUNC_NAME);
77 54
78 SCM_ASSERT (scm_is_string (TEXT), TEXT, SCM_ARG2, FUNC_NAME); 55 SCM_ASSERT (scm_is_string (TEXT), TEXT, SCM_ARG2, FUNC_NAME);
79 str = scm_to_locale_string (TEXT); 56 str = scm_to_locale_string (TEXT);
80 syslog (prio, "%s", str); 57 syslog (prio, "%s", str);
58 free (str);
81 return SCM_UNSPECIFIED; 59 return SCM_UNSPECIFIED;
82 } 60 }
83 #undef FUNC_NAME 61 #undef FUNC_NAME
...@@ -88,6 +66,11 @@ SCM_DEFINE (scm_mu_closelog, "mu-closelog", 0, 0, 0, ...@@ -88,6 +66,11 @@ SCM_DEFINE (scm_mu_closelog, "mu-closelog", 0, 0, 0,
88 #define FUNC_NAME s_scm_mu_closelog 66 #define FUNC_NAME s_scm_mu_closelog
89 { 67 {
90 closelog (); 68 closelog ();
69 if (log_tag)
70 {
71 free (log_tag);
72 log_tag = NULL;
73 }
91 return SCM_UNSPECIFIED; 74 return SCM_UNSPECIFIED;
92 } 75 }
93 #undef FUNC_NAME 76 #undef FUNC_NAME
......