GNU bug report logs - #75829
[PATCH 0/2] Simplify 'user-processes' tear-down

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Sat, 25 Jan 2025 14:27:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 75829 in the body.
You can then email your comments to 75829 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#75829; Package guix-patches. (Sat, 25 Jan 2025 14:27:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ludovic Courtès <ludo <at> gnu.org>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Sat, 25 Jan 2025 14:27:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: guix-patches <at> gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 0/2] Simplify 'user-processes' tear-down
Date: Sat, 25 Jan 2025 15:26:11 +0100
Hello,

This is an overdue simplification of the ‘stop’ method of
‘user-processes’.

Thoughts?

Ludo’.

Ludovic Courtès (2):
  services: user-processes: Simplify and streamline ‘stop’ action.
  services: user-processes: Remove support for
    /etc/shepherd/do-not-kill.

 gnu/services/shepherd.scm | 73 +++------------------------------------
 1 file changed, 5 insertions(+), 68 deletions(-)


base-commit: 646202bf73f90de4f9b7cc66248b8f8e6e381014
-- 
2.47.1





Information forwarded to guix-patches <at> gnu.org:
bug#75829; Package guix-patches. (Sat, 25 Jan 2025 14:54:02 GMT) Full text and rfc822 format available.

Message #8 received at 75829 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 75829 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 1/2] services: user-processes: Simplify and streamline ‘stop’ action.
Date: Sat, 25 Jan 2025 15:53:36 +0100
* 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 0de3c9c55c..d4406e9ba9 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -592,18 +592,6 @@ (define (user-processes-shepherd-service requirements)
                                          (@ (ice-9 rdelim) read-string))))
                          '()))
 
-                   (define (now)
-                     (car (gettimeofday)))
-
-                   (define (sleep* n)
-                     ;; Really sleep N seconds.
-                     ;; Work around <http://bugs.gnu.org/19581>.
-                     (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")
@@ -612,7 +600,7 @@ (define (user-processes-shepherd-service requirements)
                        (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
@@ -620,30 +608,17 @@ (define (user-processes-shepherd-service requirements)
                          ;; 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")
-- 
2.47.1





Information forwarded to guix-patches <at> gnu.org:
bug#75829; Package guix-patches. (Sat, 25 Jan 2025 14:54:02 GMT) Full text and rfc822 format available.

Message #11 received at 75829 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 75829 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 2/2] services: user-processes: Remove support for
 /etc/shepherd/do-not-kill.
Date: Sat, 25 Jan 2025 15:53:37 +0100
The /etc/shepherd/do-not-kill feature has been unused since commit
c8289690365887ca1dd122645e479a89cf7cd969, which switched from
unionfs (FUSE) to overlayfs.

* gnu/services/shepherd.scm (%do-not-kill-file): Remove.
(user-processes-shepherd-service): In ‘stop’ action, remove
‘kill-except’, ‘omitted-pids’, and ‘lset=’.  Remove conditionals on
‘omitted-pids’ being non-empty.

Change-Id: Id7c6031fc12fd8ff0a3fde955fb01e373751e2d0
---
 gnu/services/shepherd.scm | 46 ++++-----------------------------------
 1 file changed, 4 insertions(+), 42 deletions(-)

diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index d4406e9ba9..e64b16b3f3 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -551,11 +551,6 @@ (define (shepherd-service-upgrade live target)
 ;;; User processes.
 ;;;
 
-(define %do-not-kill-file
-  ;; Name of the file listing PIDs of processes that must survive when halting
-  ;; the system.  Typical example is user-space file systems.
-  "/etc/shepherd/do-not-kill")
-
 (define (user-processes-shepherd-service requirements)
   "Return the 'user-processes' Shepherd service with dependencies on
 REQUIREMENTS (a list of service names).
@@ -573,48 +568,15 @@ (define (user-processes-shepherd-service requirements)
          (requirement requirements)
          (start #~(const #t))
          (stop #~(lambda _
-                   (define (kill-except omit signal)
-                     ;; Kill all the processes with SIGNAL except those listed
-                     ;; in OMIT and the current process.
-                     (let ((omit (cons (getpid) omit)))
-                       (for-each (lambda (pid)
-                                   (unless (memv pid omit)
-                                     (false-if-exception
-                                      (kill pid signal))))
-                                 (processes))))
-
-                   (define omitted-pids
-                     ;; List of PIDs that must not be killed.
-                     (if (file-exists? #$%do-not-kill-file)
-                         (map string->number
-                              (call-with-input-file #$%do-not-kill-file
-                                (compose string-tokenize
-                                         (@ (ice-9 rdelim) read-string))))
-                         '()))
-
-                   (define lset= (@ (srfi srfi-1) lset=))
-
                    (display "sending all processes the TERM signal\n")
 
-                   (if (null? omitted-pids)
-                       (begin
-                         ;; Easy: terminate all of them.
-                         (kill -1 SIGTERM)
-                         (sleep #$grace-delay)
-                         (kill -1 SIGKILL))
-                       (begin
-                         ;; Kill them all except OMITTED-PIDS.  XXX: We would
-                         ;; like to (kill -1 SIGSTOP) to get a fixed list of
-                         ;; processes, like 'killall5' does, but that seems
-                         ;; unreliable.
-                         (kill-except omitted-pids SIGTERM)
-                         (sleep #$grace-delay)
-                         (kill-except omitted-pids SIGKILL)
-                         (delete-file #$%do-not-kill-file)))
+                   (kill -1 SIGTERM)
+                   (sleep #$grace-delay)
+                   (kill -1 SIGKILL)
 
                    (let wait ()
                      (let ((pids (processes)))
-                       (unless (lset= = pids (cons 1 omitted-pids))
+                       (unless (equal? '(1) pids)
                          (format #t "waiting for process termination\
  (processes left: ~s)~%"
                                  pids)
-- 
2.47.1





Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sun, 09 Feb 2025 17:24:02 GMT) Full text and rfc822 format available.

Notification sent to Ludovic Courtès <ludo <at> gnu.org>:
bug acknowledged by developer. (Sun, 09 Feb 2025 17:24:02 GMT) Full text and rfc822 format available.

Message #16 received at 75829-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 75829-done <at> debbugs.gnu.org
Subject: Re: [bug#75829] [PATCH 0/2] Simplify 'user-processes' tear-down
Date: Sun, 09 Feb 2025 18:23:06 +0100
Pushed:

  5f6fdadb4af * services: user-processes: Remove support for /etc/shepherd/do-not-kill.
  ba9af3e151d * services: user-processes: Simplify and streamline ‘stop’ action.

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 10 Mar 2025 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 3 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.