using WITH-SYSLOG-DESTINATION

This commit is contained in:
interp 2001-06-26 13:15:56 +00:00
parent 1e164e08b2
commit 5b666fb2e4
1 changed files with 75 additions and 65 deletions

140
ftpd.scm
View File

@ -72,11 +72,8 @@
(define log (define log
(lambda (level format-message . args) (lambda (level format-message . args)
(syslog level (syslog level
(apply format #f format-message args) (apply format #f format-message args))))
(format "ftpd[~D]" (thread-uid (current-thread)))
#f
(syslog-facility daemon))))
(define (protocol-family->string protocol-family) (define (protocol-family->string protocol-family)
(cond ((= protocol-family protocol-family/unspecified) (cond ((= protocol-family protocol-family/unspecified)
"unspecified") "unspecified")
@ -104,68 +101,81 @@
(define (ftpd anonymous-home . maybe-port) (define (ftpd anonymous-home . maybe-port)
(let ((port (optional maybe-port 21))) (let ((port (optional maybe-port 21)))
(log (syslog-level notice) (with-syslog-destination
"starting on port ~D with ~S as anonymous home" "ftpd"
port (expand-file-name anonymous-home (cwd))) (syslog-options log-pid)
(bind-listen-accept-loop (syslog-facility daemon)
protocol-family/internet syslog-mask-all
(lambda (socket address) (lambda ()
(log (syslog-level info) (log (syslog-level notice)
"new connection with ~S" "starting on port ~D with ~S as anonymous home"
(socket-address->string address) port (expand-file-name anonymous-home (cwd)))
(bind-listen-accept-loop
(log (syslog-level debug) protocol-family/internet
"got connection with socket ~S and address ~S" (lambda (socket address)
(socket->string socket)
(socket-address->string address))
(set-ftp-socket-options! socket)
(spawn
(lambda ()
(handle-connection (socket:inport socket)
(socket:outport socket)
(file-name-as-directory anonymous-home))
(call-with-current-continuation
(lambda (exit)
(with-errno-handler*
(lambda (errno packet)
(cond
;; I dunno why SHUTDOWN-SOCKET can die this way, but it
;; can and does
((= errno errno/notconn)
(log (syslog-level warning)
"socket not connected any more - exiting thread")
(log (syslog-level debug) "socket ~S not connected any more"
(socket->string socket))
(exit 'fick-dich-ins-knie))))
(lambda ()
(log (syslog-level debug)
"shutting down socket ~S"
(socket->string socket))
(shutdown-socket socket shutdown/sends+receives)))))
(log (syslog-level info) (log (syslog-level info)
"closing socket") "new connection with ~S"
(close-socket socket)) (socket-address->string address))
(socket-address->string address)))) ; use remote address as thread-name
(log (syslog-level debug)
port))) "got connection with socket ~S and address ~S"
(socket->string socket)
(socket-address->string address))
(set-ftp-socket-options! socket)
(spawn
(lambda ()
(handle-connection (socket:inport socket)
(socket:outport socket)
(file-name-as-directory anonymous-home))
(call-with-current-continuation
(lambda (exit)
(with-errno-handler*
(lambda (errno packet)
(cond
;; I dunno why SHUTDOWN-SOCKET can die this way, but it
;; can and does
((= errno errno/notconn)
(log (syslog-level warning)
"socket not connected any more - exiting thread")
(log (syslog-level debug)
"socket ~S not connected any more"
(socket->string socket))
(exit 'fick-dich-ins-knie))))
(lambda ()
(log (syslog-level debug)
"shutting down socket ~S"
(socket->string socket))
(shutdown-socket socket shutdown/sends+receives)))))
(log (syslog-level info)
"closing socket")
(close-socket socket))
(socket-address->string address))) ; use remote address as thread-name
port)))))
(define (ftpd-inetd anonymous-home) (define (ftpd-inetd anonymous-home)
(log (syslog-level info) (with-syslog-destination
"new connection on current input- and output-port with ~S as anonymous home" "ftpd"
(expand-file-name anonymous-home (cwd))) (syslog-option log-pid)
(syslog-facility daemon)
(log (syslog-level debug) #f
"new connection on current input-port ~A and current output-port ~A with ~S as anonymous home" (lambda ()
(current-input-port) (log (syslog-level info)
(current-output-port) "new connection on current input- and output-port with ~S as anonymous home"
(expand-file-name anonymous-home (cwd))) (expand-file-name anonymous-home (cwd)))
(handle-connection (current-input-port) (log (syslog-level debug)
(current-output-port) "new connection on current input-port ~A and current output-port ~A with ~S as anonymous home"
(file-name-as-directory anonymous-home))) (current-input-port)
(current-output-port)
(expand-file-name anonymous-home (cwd)))
(handle-connection (current-input-port)
(current-output-port)
(file-name-as-directory anonymous-home)))))
(define (set-ftp-socket-options! socket) (define (set-ftp-socket-options! socket)
;; If the client closes the connection, we won't lose when we try to ;; If the client closes the connection, we won't lose when we try to
@ -876,7 +886,7 @@
; Version ; Version
(define *ftpd-version* "$Revision: 1.17 $") (define *ftpd-version* "$Revision: 1.18 $")
(define (copy-port->port-binary input-port output-port) (define (copy-port->port-binary input-port output-port)
(let ((buffer (make-string *window-size*))) (let ((buffer (make-string *window-size*)))