diff options
author | Arun Isaac | 2023-01-26 22:37:39 +0000 |
---|---|---|
committer | Arun Isaac | 2023-01-26 22:37:39 +0000 |
commit | bb6c6897de39d0b7316f05a173fce8383f07d399 (patch) | |
tree | 20add3d230835d873a0f0d113c2e67aa2afdcc5d | |
parent | 22d71881e5fae4a530249fb4f0d63203b3f3a462 (diff) | |
download | tissue-bb6c6897de39d0b7316f05a173fce8383f07d399.tar.gz tissue-bb6c6897de39d0b7316f05a173fce8383f07d399.tar.lz tissue-bb6c6897de39d0b7316f05a173fce8383f07d399.zip |
web: Clean up socket file when Unix sockets are used.
* tissue/web/server.scm (start-web-server): Clean up socket file when
Unix sockets are used.
-rw-r--r-- | tissue/web/server.scm | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/tissue/web/server.scm b/tissue/web/server.scm index e7b2019..e794ed0 100644 --- a/tissue/web/server.scm +++ b/tissue/web/server.scm @@ -208,24 +208,33 @@ list containing parameters for that host." ;; Unix socket ((= (sockaddr:fam socket-address) AF_UNIX) (sockaddr:path socket-address)))) - (run-server (lambda (request body) - ;; Explicitly dereference the module and handler - ;; variable each time so as to support live hacking. - ((module-ref (resolve-module '(tissue web server)) - 'handler) - request body hosts)) - 'http - (cond - ;; IPv4 or IPv6 address - ((or (= (sockaddr:fam socket-address) AF_INET) - (= (sockaddr:fam socket-address) AF_INET6)) - (list #:family (sockaddr:fam socket-address) - #:addr (sockaddr:addr socket-address) - #:port (sockaddr:port socket-address))) - ;; Unix socket - ((= (sockaddr:fam socket-address) AF_UNIX) - (let ((socket (make-unix-domain-server-socket - #:path (sockaddr:path socket-address)))) - ;; Grant read-write permissions to all users. - (chmod (sockaddr:path socket-address) #o666) - (list #:socket socket)))))) + (let ((unix-socket #f)) + (dynamic-wind + (lambda () + (when (= (sockaddr:fam socket-address) AF_UNIX) + (set! socket (make-unix-domain-server-socket + #:path (sockaddr:path socket-address))) + ;; Grant read-write permissions to all users. + (chmod (sockaddr:path socket-address) #o666))) + (cut run-server + (lambda (request body) + ;; Explicitly dereference the module and handler + ;; variable each time so as to support live hacking. + ((module-ref (resolve-module '(tissue web server)) + 'handler) + request body hosts)) + 'http + (cond + ;; IPv4 or IPv6 address + ((or (= (sockaddr:fam socket-address) AF_INET) + (= (sockaddr:fam socket-address) AF_INET6)) + (list #:family (sockaddr:fam socket-address) + #:addr (sockaddr:addr socket-address) + #:port (sockaddr:port socket-address))) + ;; Unix socket + ((= (sockaddr:fam socket-address) AF_UNIX) + (list #:socket socket)))) + (lambda () + ;; Clean up socket file if Unix socket. + (when (= (sockaddr:fam socket-address) AF_UNIX) + (delete-file (sockaddr:path socket-address))))))) |