[PATCH 0/2] Simplify 'user-processes' tear-down

  • Done
  • quality assurance status badge
Details
One participant
  • Ludovic Courtès
Owner
unassigned
Submitted by
Ludovic Courtès
Severity
normal

Debbugs page

Ludovic Courtès wrote on 25 Jan 15:26 +0100
(address . guix-patches@gnu.org)(name . Ludovic Courtès)(address . ludo@gnu.org)
cover.1737815077.git.ludo@gnu.org
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
Ludovic Courtès wrote on 25 Jan 15:53 +0100
[PATCH 1/2] services: user-processes: Simplify an d streamline ‘stop’ action.
(address . 75829@debbugs.gnu.org)(name . Ludovic Courtès)(address . ludo@gnu.org)
385c0d16704cc24b517572cbb9119881b948840e.1737815077.git.ludo@gnu.org
* 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(-)

Toggle diff (67 lines)
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
Ludovic Courtès wrote on 25 Jan 15:53 +0100
[PATCH 2/2] services: user-processes: Remove support for /etc/shepherd/do-not-kill.
(address . 75829@debbugs.gnu.org)(name . Ludovic Courtès)(address . ludo@gnu.org)
f44317abdbaa2b1641480960dac94d113c449ced.1737815077.git.ludo@gnu.org
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(-)

Toggle diff (71 lines)
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
Ludovic Courtès wrote on 9 Feb 18:23 +0100
Re: [bug#75829] [PATCH 0/2] Simplify 'user-processes' tear-down
(address . 75829-done@debbugs.gnu.org)
87y0yfoww5.fsf@gnu.org
Pushed:

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

Ludo’.
Closed
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 75829@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 75829
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch