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

128
ftpd.scm
View File

@ -72,10 +72,7 @@
(define log
(lambda (level format-message . args)
(syslog level
(apply format #f format-message args)
(format "ftpd[~D]" (thread-uid (current-thread)))
#f
(syslog-facility daemon))))
(apply format #f format-message args))))
(define (protocol-family->string protocol-family)
(cond ((= protocol-family protocol-family/unspecified)
@ -104,68 +101,81 @@
(define (ftpd anonymous-home . maybe-port)
(let ((port (optional maybe-port 21)))
(log (syslog-level notice)
"starting on port ~D with ~S as anonymous home"
port (expand-file-name anonymous-home (cwd)))
(bind-listen-accept-loop
protocol-family/internet
(lambda (socket address)
(with-syslog-destination
"ftpd"
(syslog-options log-pid)
(syslog-facility daemon)
syslog-mask-all
(lambda ()
(log (syslog-level info)
"new connection with ~S"
(socket-address->string address)
(log (syslog-level notice)
"starting on port ~D with ~S as anonymous home"
port (expand-file-name anonymous-home (cwd)))
(bind-listen-accept-loop
protocol-family/internet
(lambda (socket address)
(log (syslog-level debug)
"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
"new connection with ~S"
(socket-address->string address))
port)))
(log (syslog-level debug)
"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)
(log (syslog-level info)
"new connection on current input- and output-port with ~S as anonymous home"
(expand-file-name anonymous-home (cwd)))
(with-syslog-destination
"ftpd"
(syslog-option log-pid)
(syslog-facility daemon)
#f
(lambda ()
(log (syslog-level info)
"new connection on current input- and output-port with ~S as anonymous home"
(expand-file-name anonymous-home (cwd)))
(log (syslog-level debug)
"new connection on current input-port ~A and current output-port ~A with ~S as anonymous home"
(current-input-port)
(current-output-port)
(expand-file-name anonymous-home (cwd)))
(log (syslog-level debug)
"new connection on current input-port ~A and current output-port ~A with ~S as 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)))
(handle-connection (current-input-port)
(current-output-port)
(file-name-as-directory anonymous-home)))))
(define (set-ftp-socket-options! socket)
;; If the client closes the connection, we won't lose when we try to
@ -876,7 +886,7 @@
; Version
(define *ftpd-version* "$Revision: 1.17 $")
(define *ftpd-version* "$Revision: 1.18 $")
(define (copy-port->port-binary input-port output-port)
(let ((buffer (make-string *window-size*)))