diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2013-12-10 07:36:51 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2013-12-10 07:36:51 -0800 |
commit | 434ea4f4ce65a553205f4030a6b98268ff938f0f (patch) | |
tree | 5f60474635945f1c70af6c37c78b84f9a18d0180 /syslog.c | |
parent | 5114624a14456ae20dc8c57f9ac8ed0a5a0661f4 (diff) | |
download | txr-434ea4f4ce65a553205f4030a6b98268ff938f0f.tar.gz txr-434ea4f4ce65a553205f4030a6b98268ff938f0f.tar.bz2 txr-434ea4f4ce65a553205f4030a6b98268ff938f0f.zip |
syslog support; bitwise logior and logand functions become variadic.
* Makefile: Use -iquote to restrict our #include search paths from being
processed for #include <...>. Add syslog.o to OBJS-y if have_syslog is y.
* configure (have_syslog): New variable, set by detecting syslog API.
* eval.c (eval_init): logand and logior registrations changed to
go to variadic versions. New syslog variables and functions registered.
* lib.c (logandv, logiorv): New functions.
* lib.h (logandv, logiorv): Declared.
* txr.c (main): Call syslog_init.
* syslog.c: New file.
* syslog.h: New file.
Diffstat (limited to 'syslog.c')
-rw-r--r-- | syslog.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/syslog.c b/syslog.c new file mode 100644 index 00000000..6ab5826c --- /dev/null +++ b/syslog.c @@ -0,0 +1,101 @@ +/* Copyright 2012 + * Kaz Kylheku <kaz@kylheku.com> + * Vancouver, Canada + * All rights reserved. + * + * BSD License: + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. The name of the author may not be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <assert.h> +#include <setjmp.h> +#include <wchar.h> +#include <dirent.h> +#include <syslog.h> +#include "config.h" +#include "lib.h" +#include "stream.h" +#include "hash.h" +#include "gc.h" +#include "unwind.h" +#include "utf8.h" +#include "syslog.h" + +val log_pid_v, log_cons_v, log_ndelay_v; +val log_odelay_v, log_nowait_v, log_perror_v; + +val log_user_v, log_daemon_v, log_auth_v; + +val log_emerg_v, log_alert_v, log_crit_v, log_err_v; +val log_warning_v, log_notice_v, log_info_v, log_debug_v; + +void syslog_init(void) +{ + log_pid_v = num(LOG_PID); + log_cons_v = num(LOG_CONS); + log_ndelay_v = num(LOG_NDELAY); + + log_odelay_v = num(LOG_ODELAY); + log_nowait_v = num(LOG_NOWAIT); + log_perror_v = num(LOG_PERROR); + + log_user_v = num(LOG_USER); + log_daemon_v = num(LOG_DAEMON); + log_auth_v = num(LOG_AUTH); + + log_emerg_v = num(LOG_EMERG); + log_alert_v = num(LOG_ALERT); + log_crit_v = num(LOG_CRIT); + log_err_v = num(LOG_ERR); + log_warning_v = num(LOG_WARNING); + log_notice_v = num(LOG_NOTICE); + log_info_v = num(LOG_INFO); + log_debug_v = num(LOG_DEBUG); +} + +val openlog_wrap(val wident, val optmask, val facility) +{ + static char *ident; + char *old_ident = ident; + + ident = utf8_dup_to(c_str(wident)); + openlog(ident, + if3(optmask, c_num(optmask), 0), + if3(facility, c_num(facility), LOG_USER)); + free(old_ident); + + return nil; +} + +val setlogmask_wrap(val mask) +{ + return num(setlogmask(c_num(mask))); +} + +val syslog_wrap(val prio, val fmt, val args) +{ + val text = formatv(nil, fmt, args); + char *u8text = utf8_dup_to(c_str(text)); + syslog(c_num(prio), "%s", u8text); + return nil; +} |