guile-clipboard-speaker

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit db935f07e10b928cb415aa1d8a9f6a762b4b1fa5
parent 06c659251761c21868fafc18420a6efef977060f
Author: Yuval Langer <yuval.langer@gmail.com>
Date:   Fri, 23 Jun 2023 19:57:24 +0300

Change the naming of the lock file from "pid file" into "lock file".

Also:
- Do not write PID into the lock file.
- Set the sigaction at the loop start, not at each iteration.

Diffstat:
Mclipboard-speaker.scm | 36++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)

diff --git a/clipboard-speaker.scm b/clipboard-speaker.scm @@ -17,8 +17,6 @@ ((config parser sexp) #:prefix config:parser:sexp:) ) -;;;(define espeak-ng-pid #f) - (define (dp x) ;; Debug print. (display x) (newline)) @@ -53,7 +51,7 @@ (define result (match (filter (lambda (x) (equal? (cdadr x) - (config:option-ref options 'pid-file-path))) + (config:option-ref options 'lock-file-path))) ((compose vector->list cdar) @@ -85,9 +83,9 @@ (define DEFAULT-CLIPBOARD-SPEAKER-HOME-PATH ".config/clipboard-speaker/") -(define DEFAULT-PID-FILE-PATH +(define DEFAULT-LOCK-FILE-PATH (string-append DEFAULT-CLIPBOARD-SPEAKER-HOME-PATH - "pid")) + "lock")) (define DEFAULT-FIFO-FILE-PATH (string-append DEFAULT-CLIPBOARD-SPEAKER-HOME-PATH @@ -150,11 +148,11 @@ "/" DEFAULT-FIFO-FILE-PATH))) (config:api:setting - (name 'pid-file-path) - (synopsis "Path to PID file.") + (name 'lock-file-path) + (synopsis "Path to lock file.") (default (string-append (get-home-directory) "/" - DEFAULT-PID-FILE-PATH))))) + DEFAULT-LOCK-FILE-PATH))))) (directory (config:api:in-home DEFAULT-CLIPBOARD-SPEAKER-HOME-PATH)))) @@ -238,11 +236,6 @@ (define espeak-ng-pid (espeak-ng-speak text-to-speak words-per-minute)) - (sigaction SIGTERM - (lambda (x) - (kill 0 x) ;; Kill all processes in this group. - (exit EXIT_SUCCESS))) - (waitpid espeak-ng-pid) (espeak-loop fifo-read-port @@ -272,7 +265,7 @@ 'kill) (cond ((file-exists? (config:option-ref options - 'pid-file-path)) + 'lock-file-path)) (let ([pid (get-pid-of-file-locking-process options)]) (cond ((number? pid) @@ -283,7 +276,7 @@ (format #t "clipboard-speaker is not running.~%") (exit EXIT_FAILURE))))) (else - (format #t "No pid file: ~a~%" (config:option-ref options 'pid-file-path)) + (format #t "No pid file: ~a~%" (config:option-ref options 'lock-file-path)) (exit EXIT_FAILURE)))) ;; Make / open read and write fifo files. @@ -300,12 +293,15 @@ (put-string (cdr fifo-r+w) clipboard-output) - (define pid-file-port (open-file-locked (config:option-ref options - 'pid-file-path))) - (when pid-file-port + (define lock-file-port (open-file-locked (config:option-ref options + 'lock-file-path))) + + (when lock-file-port ;; We're the speaker server. - (put-string pid-file-port (number->string (getpid))) - (force-output pid-file-port) + (sigaction SIGTERM + (lambda (x) + (kill 0 x) ;; Kill all processes in this group. + (exit EXIT_SUCCESS))) (espeak-loop (car fifo-r+w) (config:option-ref options 'words-per-minute)))