diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-12-05 12:46:48 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-12-05 12:46:56 +0100 |
commit | 4b0071f70c09019e9ba33f55347637c822e20cfe (patch) | |
tree | fe786b29057149fef348b167ce81c2328b968d3f | |
parent | 9d4e6b0677de90bf90656f8615a51e8ac2d7d955 (diff) | |
download | deployment-4b0071f70c09019e9ba33f55347637c822e20cfe.tar.gz deployment-4b0071f70c09019e9ba33f55347637c822e20cfe.tar.bz2 deployment-4b0071f70c09019e9ba33f55347637c822e20cfe.zip |
missing module
-rw-r--r-- | guix/shepherd-with-sock.scm | 119 |
1 files changed, 61 insertions, 58 deletions
diff --git a/guix/shepherd-with-sock.scm b/guix/shepherd-with-sock.scm index cb6ff5d..3eed0c2 100644 --- a/guix/shepherd-with-sock.scm +++ b/guix/shepherd-with-sock.scm @@ -1,4 +1,5 @@ (define-module (shepherd-with-sock) + #:use-module (ice-9 match) #:use-module ((shepherd service) #:select (handle-SIGCHLD read-pid-file)) #:use-module ((shepherd support) @@ -21,14 +22,14 @@ (match stdin-socket (('unix sockpath) (get-sock PF_UNIX AF_UNIX sockpath) - (('tcp addr port) - (get-sock PF_INET AF_INET (inet-pton AF_INET addr) port)) - (('tcp6 addr port) - (get-sock PF_INET6 AF_INET6 (inet-pton AF_INET6 addr) port)) - (#f - ;; Make sure file descriptor zero is used, so we don't end up reusing - ;; it for something unrelated, which can confuse some packages. - (open-fdes "/dev/null" O_RDONLY))))) + (('tcp addr port) + (get-sock PF_INET AF_INET (inet-pton AF_INET addr) port)) + (('tcp6 addr port) + (get-sock PF_INET6 AF_INET6 (inet-pton AF_INET6 addr) port)) + (#f + ;; Make sure file descriptor zero is used, so we don't end up reusing + ;; it for something unrelated, which can confuse some packages. + (open-fdes "/dev/null" O_RDONLY))))) (define* (exec-command command @@ -83,45 +84,45 @@ false." (print-exception (current-error-port) #f key args) (primitive-exit 1)))) - ;; setgid must be done *before* setuid, otherwise the user will - ;; likely no longer have permissions to setgid. - (when group - (catch #t - (lambda () - ;; Clear supplementary groups. - (setgroups #()) - (setgid (group:gid (getgr group)))) - (lambda (key . args) - (format (current-error-port) - "failed to change to group ~s:~%" group) - (print-exception (current-error-port) #f key args) - (primitive-exit 1)))) - - (when user - (catch #t - (lambda () - (setuid (passwd:uid (getpw user)))) - (lambda (key . args) - (format (current-error-port) - "failed to change to user ~s:~%" user) - (print-exception (current-error-port) #f key args) - (primitive-exit 1)))) - - ;; As the last action, close file descriptors. Doing it last makes - ;; "error in the finalization thread: Bad file descriptor" issues - ;; unlikely on 2.2. - (let loop ((i 3)) - (when (< i max-fd) - ;; First try to close any ports associated with file descriptor I. - ;; Otherwise the finalization thread might get around to closing - ;; those ports eventually, which will raise an EBADF exception (on - ;; 2.2), leading to messages like "error in the finalization - ;; thread: Bad file descriptor". - (for-each (lambda (port) - (catch-system-error (close-port port))) - (fdes->ports i)) - (catch-system-error (close-fdes i)) - (loop (+ i 1))))) + ;; setgid must be done *before* setuid, otherwise the user will + ;; likely no longer have permissions to setgid. + (when group + (catch #t + (lambda () + ;; Clear supplementary groups. + (setgroups #()) + (setgid (group:gid (getgr group)))) + (lambda (key . args) + (format (current-error-port) + "failed to change to group ~s:~%" group) + (print-exception (current-error-port) #f key args) + (primitive-exit 1)))) + + (when user + (catch #t + (lambda () + (setuid (passwd:uid (getpw user)))) + (lambda (key . args) + (format (current-error-port) + "failed to change to user ~s:~%" user) + (print-exception (current-error-port) #f key args) + (primitive-exit 1)))) + + ;; As the last action, close file descriptors. Doing it last makes + ;; "error in the finalization thread: Bad file descriptor" issues + ;; unlikely on 2.2. + (let loop ((i 3)) + (when (< i max-fd) + ;; First try to close any ports associated with file descriptor I. + ;; Otherwise the finalization thread might get around to closing + ;; those ports eventually, which will raise an EBADF exception (on + ;; 2.2), leading to messages like "error in the finalization + ;; thread: Bad file descriptor". + (for-each (lambda (port) + (catch-system-error (close-port port))) + (fdes->ports i)) + (catch-system-error (close-fdes i)) + (loop (+ i 1))))) (catch 'system-error (lambda () @@ -161,6 +162,17 @@ its PID." #:stdin-socket stdin-socket) pid))) + +(define (clean-up file) + (when file + (catch 'system-error + (lambda () + (delete-file file)) + (lambda args + (unless (= ENOENT (system-error-errno args)) + (apply throw args)))))) + + (define make-forkexec-constructor (let ((warn-deprecated-form ;; Until 0.1, this procedure took a rest list. @@ -197,17 +209,8 @@ start." (list command)) command))) (lambda args - (define (clean-up file) - (when file - (catch 'system-error - (lambda () - (delete-file file)) - (lambda args - (unless (= ENOENT (system-error-errno args)) - (apply throw args)))))) - - (clean-up pid-file) - (clean-up log-file) + (clean-up-file pid-file) + (clean-up-file log-file) (let ((pid (fork+exec-command command #:user user |