93 lines
4.5 KiB
Scheme
93 lines
4.5 KiB
Scheme
;;; SPDX-License-Identifier: LGPL-3.0-only
|
||
;;; SPDX-FileCopyrightText: 2026 afiw
|
||
|
||
;;; syslog – a CHICKEN interface to syslog(3)
|
||
;;; Copyright (C) 2026 afiw <afiw@linuxposting.xyz>
|
||
;;;
|
||
;;; This program is free software: you can redistribute it and/or modify
|
||
;;; it under the terms of the GNU Lesser General Public License as published
|
||
;;; by the Free Software Foundation, exclusively version 3 of the License.
|
||
;;;
|
||
;;; This program 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 Lesser General Public License
|
||
;;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||
|
||
(foreign-declare "#include <syslog.h>")
|
||
|
||
;;; Define fallbacks for non-POSIX flags if not present
|
||
(foreign-declare "#ifndef LOG_AUTH\n#define LOG_AUTH LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_AUTHPRIV\n#define LOG_AUTHPRIV LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_CRON\n#define LOG_CRON LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_DAEMON\n#define LOG_DAEMON LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_FTP\n#define LOG_FTP LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_KERN\n#define LOG_KERN LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_LPR\n#define LOG_LPR LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_MAIL\n#define LOG_MAIL LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_NEWS\n#define LOG_NEWS LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_SYSLOG\n#define LOG_SYSLOG LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_UUCP\n#define LOG_UUCP LOG_USER\n#endif")
|
||
(foreign-declare "#ifndef LOG_PERROR\n#define LOG_PERROR 0\n#endif")
|
||
|
||
(define log/cons (foreign-value "LOG_CONS" int))
|
||
(define log/ndelay (foreign-value "LOG_NDELAY" int))
|
||
(define log/nowait (foreign-value "LOG_NOWAIT" int))
|
||
(define log/odelay (foreign-value "LOG_ODELAY" int))
|
||
(define log/perror (foreign-value "LOG_PERROR" int))
|
||
(define log/pid (foreign-value "LOG_PID" int))
|
||
|
||
(define facility/auth (foreign-value "LOG_AUTH" int))
|
||
(define facility/authpriv (foreign-value "LOG_AUTHPRIV" int))
|
||
(define facility/cron (foreign-value "LOG_CRON" int))
|
||
(define facility/daemon (foreign-value "LOG_DAEMON" int))
|
||
(define facility/ftp (foreign-value "LOG_FTP" int))
|
||
(define facility/kern (foreign-value "LOG_KERN" int))
|
||
(define facility/local0 (foreign-value "LOG_LOCAL0" int))
|
||
(define facility/local1 (foreign-value "LOG_LOCAL1" int))
|
||
(define facility/local2 (foreign-value "LOG_LOCAL2" int))
|
||
(define facility/local3 (foreign-value "LOG_LOCAL3" int))
|
||
(define facility/local4 (foreign-value "LOG_LOCAL4" int))
|
||
(define facility/local5 (foreign-value "LOG_LOCAL5" int))
|
||
(define facility/local6 (foreign-value "LOG_LOCAL6" int))
|
||
(define facility/local7 (foreign-value "LOG_LOCAL7" int))
|
||
(define facility/lpr (foreign-value "LOG_LPR" int))
|
||
(define facility/mail (foreign-value "LOG_MAIL" int))
|
||
(define facility/news (foreign-value "LOG_NEWS" int))
|
||
(define facility/syslog (foreign-value "LOG_SYSLOG" int))
|
||
(define facility/user (foreign-value "LOG_USER" int))
|
||
(define facility/uucp (foreign-value "LOG_UUCP" int))
|
||
|
||
(define priority/emerg (foreign-value "LOG_EMERG" int))
|
||
(define priority/alert (foreign-value "LOG_ALERT" int))
|
||
(define priority/crit (foreign-value "LOG_CRIT" int))
|
||
(define priority/err (foreign-value "LOG_ERR" int))
|
||
(define priority/warning (foreign-value "LOG_WARNING" int))
|
||
(define priority/notice (foreign-value "LOG_NOTICE" int))
|
||
(define priority/info (foreign-value "LOG_INFO" int))
|
||
(define priority/debug (foreign-value "LOG_DEBUG" int))
|
||
|
||
(define mask/emerg (foreign-value "LOG_MASK(LOG_EMERG)" int))
|
||
(define mask/alert (foreign-value "LOG_MASK(LOG_ALERT)" int))
|
||
(define mask/crit (foreign-value "LOG_MASK(LOG_CRIT)" int))
|
||
(define mask/err (foreign-value "LOG_MASK(LOG_ERR)" int))
|
||
(define mask/warning (foreign-value "LOG_MASK(LOG_WARNING)" int))
|
||
(define mask/notice (foreign-value "LOG_MASK(LOG_NOTICE)" int))
|
||
(define mask/info (foreign-value "LOG_MASK(LOG_INFO)" int))
|
||
(define mask/debug (foreign-value "LOG_MASK(LOG_DEBUG)" int))
|
||
|
||
(define (open-syslog ident options facility)
|
||
((foreign-lambda void "openlog" c-string int int) ident options facility))
|
||
|
||
(define (syslog priority str)
|
||
((foreign-lambda* void ((int priority) (nonnull-c-string str))
|
||
"syslog(priority, \"%s\", str);")
|
||
priority str))
|
||
|
||
(define close-syslog
|
||
(foreign-lambda void "closelog"))
|
||
|
||
(define (set-syslog-mask! mask)
|
||
((foreign-lambda int "setlogmask" int) mask))
|