I think my request (about logging facility) is not clear. So, I attached two patches to this post. First adds a FFI for `sendfile' system call on Linux, and second adds support for `openlog', `syslog', `closelog' and `setlogmask' syscalls (also it include a simple `with-log' macro in the IOLIB.OS package).
2010/12/1, marsijanin <[email protected]>: > Hi Stelian! > > On gitorious IOLib repo there are two merge requests: one add logging > facility, and the other (which is mine) termios api support. The first > one is four month old. I assumed, that it is because of nobody use > gitorious web interface, so that merge requests are still unknown to you. > > Could you, please, tell us about you plans on that merge requests. > > wbr, > > Nikolay V. Razbegaev > > _______________________________________________ > IOLib-devel mailing list > [email protected] > http://common-lisp.net/cgi-bin/mailman/listinfo/iolib-devel >
From e29f87851fe4fc6e6073e64fe76dc8d85d748fca Mon Sep 17 00:00:00 2001 From: treep <[email protected]> Date: Fri, 17 Dec 2010 00:48:51 +0300 Subject: [PATCH] Add SENDFILE on Linux --- src/syscalls/ffi-functions-unix.lisp | 8 ++++++++ src/syscalls/pkgdcl.lisp | 1 + 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/src/syscalls/ffi-functions-unix.lisp b/src/syscalls/ffi-functions-unix.lisp index 3901a3d..3992c6d 100644 --- a/src/syscalls/ffi-functions-unix.lisp +++ b/src/syscalls/ffi-functions-unix.lisp @@ -232,6 +232,14 @@ to the argument OFFSET according to the directive WHENCE." "Change permissions of open file referenced by FD to mode MODE." (fd :int) (mode mode-t)) + +#+linux +(defsyscall (sendfile "sendfile") size-t + "Copies data between one file descriptor and another (zero-copy I/O)." + (out-fd :int) + (in-fd :int) + (offset :pointer) + (count size-t)) ;;;------------------------------------------------------------------------- diff --git a/src/syscalls/pkgdcl.lisp b/src/syscalls/pkgdcl.lisp index cd30b2f..a38d5c5 100644 --- a/src/syscalls/pkgdcl.lisp +++ b/src/syscalls/pkgdcl.lisp @@ -463,6 +463,7 @@ #:sync #:fsync #:mkstemp + #+linux #:sendfile ;; Directories #:mkdir -- 1.7.3.2
From 4315a786517cc33dd3dd6be72fbd65229f3c9d8d Mon Sep 17 00:00:00 2001 From: treep <[email protected]> Date: Fri, 17 Dec 2010 01:16:29 +0300 Subject: [PATCH] Implement logging facility with {OPENLOG, SYSLOG, CLOSELOG} syscalls --- src/os/os-unix.lisp | 18 ++++++++++++ src/os/pkgdcl.lisp | 6 ++++ src/syscalls/ffi-functions-unix.lisp | 47 +++++++++++++++++++++++++++++++ src/syscalls/ffi-types-unix.lisp | 50 +++++++++++++++++++++++++++++++++- src/syscalls/pkgdcl.lisp | 35 +++++++++++++++++++++++ 5 files changed, 155 insertions(+), 1 deletions(-) diff --git a/src/os/os-unix.lisp b/src/os/os-unix.lisp index 0af1fdf..2eca086 100644 --- a/src/os/os-unix.lisp +++ b/src/os/os-unix.lisp @@ -571,3 +571,21 @@ numerical user ID, as an assoc-list." (cons :home home) (cons :shell shell)) nil))) + + +;;;; Logging facility + +(setf (symbol-function 'open-log) (symbol-function 'isys:openlog) + (symbol-function 'write-log) (symbol-function 'isys:syslog) + (symbol-function 'close-log) (symbol-function 'isys:closelog)) + +(defmacro with-log ((name &key (option isys:log-odelay) + (facility isys:log-daemon) + (priority isys:log-info)) + &body body) + "Open a log called NAME, logging with WRITE-LOG function, then close log." + `(progn + (open-log ,name :option ,option :facility ,facility) + (unwind-protect + (progn ,@body) + (close-log)))) diff --git a/src/os/pkgdcl.lisp b/src/os/pkgdcl.lisp index 65b36b5..7ff3f4b 100644 --- a/src/os/pkgdcl.lisp +++ b/src/os/pkgdcl.lisp @@ -65,6 +65,12 @@ ;; Time #:get-monotonic-time + ;; Logging facility + #:open-log + #:write-log + #:close-log + #:with-log + ;; Specials #:*temporary-directory* )) diff --git a/src/syscalls/ffi-functions-unix.lisp b/src/syscalls/ffi-functions-unix.lisp index 3992c6d..e47ff01 100644 --- a/src/syscalls/ffi-functions-unix.lisp +++ b/src/syscalls/ffi-functions-unix.lisp @@ -1038,3 +1038,50 @@ variable *environ* to NULL." (defentrypoint getgrnam (name) "Gets a group-entry, by group name (reentrant)." (funcall-getgr #'%getgrnam-r name)) + + +;;;------------------------------------------------------------------------- +;;; Syslog +;;;------------------------------------------------------------------------- + +(defvar *syslog-identity* nil) + +(defsyscall (%openlog "openlog") :void + "Opens a connection to the system logger for a program." + (ident :string) + (option :int) + (facility :int)) + +(defentrypoint openlog (name &key (option log-odelay) (facility log-daemon)) + "Opens a connection to the system logger for a program." + (when *syslog-identity* + (foreign-string-free *syslog-identity*) + (setf *syslog-identity* nil)) + (setf *syslog-identity* (foreign-string-alloc name)) + (%openlog *syslog-identity* option facility)) + +(defsyscall (%syslog "syslog") :void + "Generates a log message, which will be distributed by syslogd." + (priority :int) + (format :string) + (message :string)) + +(defentrypoint syslog (priority format &rest args) + "Generates a log message, which will be distributed by syslogd. +Using a FORMAT string and ARGS for lisp-side message formating." + (with-foreign-string (c-string (format nil "~?" format args)) + (%syslog priority "%s" c-string))) + +(defsyscall (%closelog "closelog") :void + "Closes the descriptor being used to write to the system logger (optional).") + +(defentrypoint closelog () + "Closes the descriptor being used to write to the system logger (optional)." + (%closelog) + (when *syslog-identity* + (foreign-string-free *syslog-identity*) + (setf *syslog-identity* nil))) + +(defsyscall (setlogmask "setlogmask") :int + "Set the log mask level." + (mask :int)) diff --git a/src/syscalls/ffi-types-unix.lisp b/src/syscalls/ffi-types-unix.lisp index 3c823cb..108e1c6 100644 --- a/src/syscalls/ffi-types-unix.lisp +++ b/src/syscalls/ffi-types-unix.lisp @@ -19,7 +19,7 @@ (include "stdlib.h" "errno.h" "sys/types.h" "sys/stat.h" "sys/mman.h" "fcntl.h" "signal.h" "unistd.h" "limits.h" "time.h" "sys/select.h" "sys/poll.h" "sys/ioctl.h" "sys/resource.h" "pwd.h" "grp.h" - "dirent.h" "sys/utsname.h" "sys/wait.h") + "dirent.h" "sys/utsname.h" "sys/wait.h" "sys/syslog.h") #+linux (include "sys/epoll.h" "sys/syscall.h") @@ -534,3 +534,51 @@ (passwd "gr_passwd" :type sstring) (gid "gr_gid" :type gid-t) (mem "gr_mem" :type :pointer)) + + +;;;------------------------------------------------------------------------- +;;; sys/syslog.h +;;;------------------------------------------------------------------------- + +;;; priorities (these are ordered) +(constant (log-emerg "LOG_EMERG") :documentation "system is unusable") +(constant (log-alert "LOG_ALERT") :documentation "action must be taken immediately") +(constant (log-crit "LOG_CRIT") :documentation "critical conditions") +(constant (log-err "LOG_ERR") :documentation "error conditions") +(constant (log-warning "LOG_WARNING") :documentation "warning conditions") +(constant (log-notice "LOG_NOTICE") :documentation "normal but significant condition") +(constant (log-info "LOG_INFO") :documentation "informational") +(constant (log-debug "LOG_DEBUG") :documentation "debug-level messages") + +;;; facility codes +(constant (log-kern "LOG_KERN") :documentation "kernel messages") +(constant (log-user "LOG_USER") :documentation "random user-level messages") +(constant (log-mail "LOG_MAIL") :documentation "mail system") +(constant (log-daemon "LOG_DAEMON") :documentation "system daemons") +(constant (log-auth "LOG_AUTH") :documentation "security/authorization messages") +(constant (log-syslog "LOG_SYSLOG") :documentation "messages generated internally by syslogd") +(constant (log-lpr "LOG_LPR") :documentation "line printer subsystem") +(constant (log-news "LOG_NEWS") :documentation "network news subsystem") +(constant (log-uucp "LOG_UUCP") :documentation "UUCP subsystem") +(constant (log-cron "LOG_CRON") :documentation "clock daemon") +(constant (log-authpriv "LOG_AUTHPRIV") :documentation "security/authorization messages (private") +(constant (log-ftp "LOG_FTP") :documentation "ftp daemon") +#+bsd(constant (log-security "LOG_SECURITY") :optional t) + +;;; other codes through 15 reserved for system use +(constant (log-local0 "LOG_LOCAL0")) +(constant (log-local1 "LOG_LOCAL1")) +(constant (log-local2 "LOG_LOCAL2")) +(constant (log-local3 "LOG_LOCAL3")) +(constant (log-local4 "LOG_LOCAL4")) +(constant (log-local5 "LOG_LOCAL5")) +(constant (log-local6 "LOG_LOCAL6")) +(constant (log-local7 "LOG_LOCAL7")) + +;;; Option flags for openlog. +(constant (log-pid "LOG_PID") :documentation "log the pid with each message") +(constant (log-cons "LOG_CONS") :documentation "log on the console if errors in sending") +(constant (log-odelay "LOG_ODELAY") :documentation "delay open until first syslog() (default)") +(constant (log-ndelay "LOG_NDELAY") :documentation "don't delay open") +(constant (log-nowait "LOG_NOWAIT") :documentation "don't wait for console forks: DEPRECATED") +(constant (log-perror "LOG_PERROR") :documentation "log to stderr as well") diff --git a/src/syscalls/pkgdcl.lisp b/src/syscalls/pkgdcl.lisp index a38d5c5..2d8ccf6 100644 --- a/src/syscalls/pkgdcl.lisp +++ b/src/syscalls/pkgdcl.lisp @@ -394,6 +394,35 @@ #+linux #:rlimit-sigpending #+bsd #:rlimit-sbsize + ;; Syslog + #:log-emerg + #:log-alert + #:log-crit + #:log-err + #:log-warning + #:log-notice + #:log-info + #:log-debug + #:log-kern + #:log-user + #:log-mail + #:log-daemon + #:log-auth + #:log-syslog + #:log-lpr + #:log-news + #:log-uucp + #:log-cron + #:log-authpriv + #:log-ftp + #+bsd #:log-security + #:log-pid + #:log-cons + #:log-odelay + #:log-ndelay + #:log-nowait + #:log-perror + ;; Syscall error codes #:errno-values #:e2big #:eacces #:eaddrinuse #:eaddrnotavail @@ -589,6 +618,12 @@ #:cmsg.space #:cmsg.len #:cmsg.data + + ;; Syslog + #:openlog + #:syslog + #:closelog + #:setlogmask ;;;---------------------------------------------------------------------- -- 1.7.3.2
_______________________________________________ IOLib-devel mailing list [email protected] http://common-lisp.net/cgi-bin/mailman/listinfo/iolib-devel
