From ba9af3e151db8f0f86aeaea681a937e995b5b265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 25 Jan 2025 12:38:00 +0100 Subject: [PATCH] =?UTF-8?q?services:=20user-processes:=20Simplify=20and=20?= =?UTF-8?q?streamline=20=E2=80=98stop=E2=80=99=20action.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * gnu/services/shepherd.scm (user-processes-shepherd-service): In ‘stop’ action, remove ‘sleep*’, which is unnecessary when using Fibers, and remove the ‘reap-children’ loop and its ‘waitpid’ call, which is redundant with ‘waitpid’ calls made by shepherd itself and could cause confusion. Change-Id: I0df1733f0cbe781a0ad5fef4830d903483e0da27 --- gnu/services/shepherd.scm | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm index 328bfbedfff..d2226282807 100644 --- a/gnu/services/shepherd.scm +++ b/gnu/services/shepherd.scm @@ -594,18 +594,6 @@ system mounts, etc. This is similar to the 'sysvinit' target in systemd." (@ (ice-9 rdelim) read-string)))) '())) - (define (now) - (car (gettimeofday))) - - (define (sleep* n) - ;; Really sleep N seconds. - ;; Work around . - (define start (now)) - (let loop ((elapsed 0)) - (when (> n elapsed) - (sleep (- n elapsed)) - (loop (- (now) start))))) - (define lset= (@ (srfi srfi-1) lset=)) (display "sending all processes the TERM signal\n") @@ -614,7 +602,7 @@ system mounts, etc. This is similar to the 'sysvinit' target in systemd." (begin ;; Easy: terminate all of them. (kill -1 SIGTERM) - (sleep* #$grace-delay) + (sleep #$grace-delay) (kill -1 SIGKILL)) (begin ;; Kill them all except OMITTED-PIDS. XXX: We would @@ -622,30 +610,17 @@ system mounts, etc. This is similar to the 'sysvinit' target in systemd." ;; processes, like 'killall5' does, but that seems ;; unreliable. (kill-except omitted-pids SIGTERM) - (sleep* #$grace-delay) + (sleep #$grace-delay) (kill-except omitted-pids SIGKILL) (delete-file #$%do-not-kill-file))) (let wait () - ;; Reap children, if any, so that we don't end up with - ;; zombies and enter an infinite loop. - (let reap-children () - (define result - (false-if-exception - (waitpid WAIT_ANY (if (null? omitted-pids) - 0 - WNOHANG)))) - - (when (and (pair? result) - (not (zero? (car result)))) - (reap-children))) - (let ((pids (processes))) (unless (lset= = pids (cons 1 omitted-pids)) (format #t "waiting for process termination\ (processes left: ~s)~%" pids) - (sleep* 2) + (sleep 1) (wait)))) (display "all processes have been terminated\n")