Subject: bug#6079: 24.0.50; set-process-sentinel doesn't work inside sentinels

From: Lars Ingebrigtsen <[email-masked]>
Date: Wed, 21 Aug 2019 16:58:21 -0700

Helmut Eller <[email-masked]> writes:

> set-process-sentinel can't be used inside sentinels because
> exec_sentinel_unwind always restores the old value.  This code 
>
> (let* ((proc (start-process "foo" nil "/bin/bash" "-c" "sleep 100"))
>        (a-called nil)
>        (sentinel-a (lambda (proc msg)
>                      (message "a: %s" msg)
>                      (setq a-called t)))
>        (b-called nil)
>        (sentinel-b (lambda (proc msg)
>                      (message "b: %s" msg)
>                      (set-process-sentinel proc sentinel-a)
>                      (setq b-called t))))
>   (set-process-sentinel proc sentinel-b)
>   (signal-process proc 'SIGSTOP)
>   (message "waiting for b")
>   (while (not b-called)
>     (accept-process-output proc))
>   (signal-process proc 'SIGKILL)
>   (message "waiting for a")
>   (while (not a-called)
>     (accept-process-output proc)))
>
> prints:
>
>   waiting for b
>   b: stopped (signal)
>   waiting for a
>   b: killed
>
> which means that sentinel-b was called twice.  Since sentinel-b sets the
> the process sentinel to sentinel-a I would expect that sentinel-b can
> only be called once.

(I'm going through old bug reports that have unfortunately gotten no
attention yet.)

I tried reproducing this bug in Emacs 27, but I get:

waiting for b
b: stopped (signal)

waiting for a
a: killed

The exec_sentinel_unwind function no longer exists in Emacs, so the code
in this area has changed in the nine years since you reported this bug.

Do you still see this bug in more modern Emacs versions?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no