Subject: bug#63982: Shepherd can crash when a user service fails to start

From: Ludovic Courtès <[email-masked]>
Date: Wed, 21 Jun 2023 16:20:58 +0200

Hi,

Maxim Cournoyer <[email-masked]> skribis:

> The other surprising thing is that because it thinks that Emacs hasn't
> finished starting, it doesn't even attempt to try starting the other
> services; they remain stopped although they should work.

This is because you’re starting them sequentially with:

  (for-each start …)

If you instead use ‘start-in-the-background’, it’ll start them in
parallel.

(BTW, you might want to use the new interface eventually:
<https://gnu.org/s/shepherd/manual/html_node/Legacy-GOOPS-Interface.html>.)

> Using /gnu/store/ahzl8vxxcd5bqlljwgn8wkp4884sr72l-shepherd-0.10.99-tarball/bin/shepherd
>
> $ herd status
> Started:
>  + root
> Starting:
>  ^ emacs
> Stopped:
>  - gpg-agent
>  - ibus-daemon
>  - jackd
>  - workrave
>
> ~/.local/state/shepherd/shepherd.log:
>
> 2023-06-18 21:06:12 Starting service root...
> 2023-06-18 21:06:12 Service root started.
> 2023-06-18 21:06:12 Service root running with value #t.
> 2023-06-18 21:06:12 Service root démarré.
> 2023-06-18 21:06:12 Starting service emacs...
> 2023-06-18 21:06:12 [bash] 
> 2023-06-18 21:06:12 [bash] Warning: due to a long standing Gtk+ bug
> 2023-06-18 21:06:12 [bash] https://gitlab.gnome.org/GNOME/gtk/issues/221
> 2023-06-18 21:06:12 [bash] Emacs might crash when run in daemon mode and the X11 connection is unexpectedly lost.
> 2023-06-18 21:06:12 [bash] Using an Emacs configured with --with-x-toolkit=lucid does not have this problem.
> 2023-06-18 21:06:13 [bash] Loading time (native compiled elisp)...
> 2023-06-18 21:06:13 [bash] Loading time (native compiled elisp)...done
> 2023-06-18 21:06:13 [bash] Loading /home/maxim/.emacs.d/recentf...
> 2023-06-18 21:06:13 [bash] Loading /home/maxim/.emacs.d/recentf...done
> 2023-06-18 21:06:13 [bash] Cleaning up the recentf list...
> 2023-06-18 21:06:13 [bash] Cleaning up the recentf list...done (0 removed)
> 2023-06-18 21:06:13 [bash] .emacs: Warning: Use keywords rather than deprecated positional arguments to `define-minor-mode'
> 2023-06-18 21:06:15 [bash] Preparing diary...
> 2023-06-18 21:06:15 [bash] No diary entries for Sunday, June 18, 2023: Father's Day
> 2023-06-18 21:06:15 [bash] Preparing diary...done
> 2023-06-18 21:06:15 [bash] Appointment reminders enabled
> 2023-06-18 21:06:16 [bash] Loading /home/maxim/.emacs.d/emms/cache...
> 2023-06-18 21:06:16 [bash] Loading /home/maxim/.emacs.d/emms/cache...done
> 2023-06-18 21:06:18 [bash] [yas] Prepared just-in-time loading of snippets successfully.
> 2023-06-18 21:06:20 [bash] [yas] Prepared just-in-time loading of snippets successfully.
> 2023-06-18 21:06:22 [bash] Starting new Ispell process aspell with english dictionary... \ 
> 2023-06-18 21:06:22 [bash] Starting new Ispell process aspell with english dictionary...done
> 2023-06-18 21:06:22 [bash] Starting Emacs daemon.

And what’s the process tree like, if you run “pstree -p N” where N is
the PID of shepherd?

It looks as though ‘bash -c "emacs --daemon"’ didn’t terminate, which is
what’s needed to transition from “starting” to “running”.

Could you ‘strace -f -s 100 -o /tmp/log.strace shepherd’, keeping only
the ‘emacs’ service?

Thanks,
Ludo’.