All of lore.kernel.org
 help / color / mirror / Atom feed
From: leigh@solinno.co.uk
To: xen-devel@lists.xenproject.org
Cc: andrew.cooper3@citrix.com, anthony.perard@citrix.com,
	slack@rabbit.lu, Leigh Brown <leigh@solinno.co.uk>
Subject: [PATCH 2/6] tools/misc: rework xenwatchdogd signal handling
Date: Wed, 27 Mar 2024 18:13:49 +0000	[thread overview]
Message-ID: <20240327181353.10951-3-leigh@solinno.co.uk> (raw)
In-Reply-To: <20240327181353.10951-1-leigh@solinno.co.uk>

From: Leigh Brown <leigh@solinno.co.uk>

Rework xenwatchdogd signal handling to do the minimum in the signal
handler. This is a very minor enhancement.
---
 tools/misc/xenwatchdogd.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/tools/misc/xenwatchdogd.c b/tools/misc/xenwatchdogd.c
index 2f7c822d61..d4da0ad0b6 100644
--- a/tools/misc/xenwatchdogd.c
+++ b/tools/misc/xenwatchdogd.c
@@ -9,9 +9,11 @@
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
+#include <stdbool.h>
 
 xc_interface *h;
-int id = 0;
+bool safeexit = false;
+bool done = false;
 
 void daemonize(void)
 {
@@ -38,20 +40,18 @@ void daemonize(void)
 
 void catch_exit(int sig)
 {
-    if (id)
-        xc_watchdog(h, id, 300);
-    exit(EXIT_SUCCESS);
+    done = true;
 }
 
 void catch_usr1(int sig)
 {
-    if (id)
-        xc_watchdog(h, id, 0);
-    exit(EXIT_SUCCESS);
+    safeexit = true;
+    done = true;
 }
 
 int main(int argc, char **argv)
 {
+    int id;
     int t, s;
     int ret;
 
@@ -90,10 +90,14 @@ int main(int argc, char **argv)
     if (id <= 0)
         err(EXIT_FAILURE, "xc_watchdog setup");
 
-    for (;;) {
+    while (!done) {
         sleep(s);
         ret = xc_watchdog(h, id, t);
         if (ret != 0)
             err(EXIT_FAILURE, "xc_watchdog");
     }
+
+    // Zero seconds timeout will disarm the watchdog timer
+    xc_watchdog(h, id, safeexit ? 0 : 300);
+    return 0;
 }
-- 
2.39.2



  parent reply	other threads:[~2024-03-27 18:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26  5:15 [PATCH] tools/misc: fix xenwatchdogd invocation zithro / Cyril Rébert
2024-03-26  8:19 ` Jan Beulich
2024-03-27 18:13   ` [PATCH 0/6] xenwatchdogd enhancements leigh
2024-03-27 18:13     ` [PATCH 1/6] tools/misc: xenwatchdogd: use EXIT_* constants leigh
2024-03-27 18:13     ` leigh [this message]
2024-03-28  9:31       ` [PATCH 2/6] tools/misc: rework xenwatchdogd signal handling Jan Beulich
2024-03-28  9:43         ` Jan Beulich
2024-03-27 18:13     ` [PATCH 3/6] tools/misc: xenwatchdogd: make functions static leigh
2024-03-28  9:37       ` Jan Beulich
2024-03-27 18:13     ` [PATCH 4/6] tools/misc: xenwatchdogd: add parse_secs() leigh
2024-03-27 18:13     ` [PATCH 5/6] tools/misc: xenwatchdogd enhancements leigh
2024-03-27 18:13     ` [PATCH 6/6] docs/man: Add xenwatchdog manual page leigh

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=20240327181353.10951-3-leigh@solinno.co.uk \
    --to=leigh@solinno.co.uk \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@citrix.com \
    --cc=slack@rabbit.lu \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.