supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
From: Jan Braun <janbraun@gmx.de>
To: Brett Neumeier <random@freesa.org>
Cc: Dewayne Geraghty <dewayne@heuristicsystems.com.au>,
	supervision@list.skarnet.org
Subject: Re: Possible to shut down an s6 service via command rather than signal?
Date: Mon, 29 Jul 2024 19:29:45 +0200	[thread overview]
Message-ID: <ZqfRifjzvhkm5JCc@abakus> (raw)
In-Reply-To: <20240725112655.586841fef892611b74fa22bb@freesa.org>

[-- Attachment #1: Type: text/plain, Size: 1680 bytes --]

Brett Neumeier schrob:
> 2. patch QEMU to add a signal handler so that it will gracefully
> shutdown when it receives a specific signal (and then tell s6 to use
> that signal to take the service down); or

A patch to do that has been available since 2017 at least, but the qemu
developers apparently can't agree to any signal to use. See
https://patchwork.kernel.org/project/qemu-devel/patch/23d89ab3bd16ebf7a864ab75c300de7b@whitewinterwolf.com/
and https://gitlab.com/qemu-project/qemu/-/issues/148 .

Here's a current version with SIGPWR.

HTH,
    Jan

diff --git a/os-posix.c b/os-posix.c
index 43f9a43f3..55fb3999a 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -64,6 +64,9 @@ void os_setup_signal_handling(void)
     sigaction(SIGINT,  &act, NULL);
     sigaction(SIGHUP,  &act, NULL);
     sigaction(SIGTERM, &act, NULL);
+#ifdef SIGPWR
+    sigaction(SIGPWR, &act, NULL);
+#endif
 }
 
 void os_set_proc_name(const char *s)
diff --git a/system/runstate.c b/system/runstate.c
index c833316f6..a75c10aa6 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -680,8 +680,18 @@ void qemu_system_killed(int signal, pid_t pid)
     /* Cannot call qemu_system_shutdown_request directly because
      * we are in a signal handler.
      */
-    shutdown_requested = SHUTDOWN_CAUSE_HOST_SIGNAL;
-    qemu_notify_event();
+#ifdef SIGPWR
+    if (signal==SIGPWR)
+    {
+       powerdown_requested = 1;
+       qemu_notify_event();
+    }
+    else
+#endif
+    {
+       shutdown_requested = SHUTDOWN_CAUSE_HOST_SIGNAL;
+       qemu_notify_event();
+    }
 }
 
 void qemu_system_shutdown_request_with_code(ShutdownCause reason,

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-07-29 17:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-24 17:30 Brett Neumeier via supervision
2024-07-24 18:15 ` Carlos Eduardo
2024-07-24 21:09   ` Laurent Bercot
2024-07-25  1:15 ` Dewayne Geraghty
2024-07-25 16:26   ` Brett Neumeier via supervision
2024-07-25 16:56     ` Mario Rugiero
2024-07-29 17:29     ` Jan Braun [this message]
2024-07-30 19:33       ` Brett Neumeier via supervision

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZqfRifjzvhkm5JCc@abakus \
    --to=janbraun@gmx.de \
    --cc=dewayne@heuristicsystems.com.au \
    --cc=random@freesa.org \
    --cc=supervision@list.skarnet.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).