xenwatchdogd bugfixes and enhancements
v2 cover xenwatchdogd bugfixes and enhancements
From: Leigh Brown <[email protected]>
The primary intention of this patch series is to replace the pathologically bad behaviour of rebooting the domain if you run "xenwatchdogd -h". To that end, I have implemented comprehensive argument validation. This validation ensures you can't pass arguments that instantly reboot the domain or cause it to spin loop running sleep(0) repeatedly.
I added a couple of enhancements whilst working on the changes as they were easy enough. In particular, being able to run in the foreground, disarming the watchdog on exit, help and a manpage.
Changes since v1:
- Add Signed-off-by on every patch.
- Make global variables static.
Full list of changes:
- Use getopt_long() to add -h/--help with associated usage help.
- Add -F/--foreground parameter to run without daemonizing.
- Add -x/--save-exit parameter to disarm the watchdog when exiting.
- Validate timeout is numeric and is at least two seconds.
- Validate sleep is numeric and is at least one and less than timeout.
- Check for too many arguments.
- Use symbol constants instead of magic numbers where possible.
- Make all functions except main() and global variables static.
- Add a manual page for xenwatchdogd().
Leigh Brown (6):
tools/misc: xenwatchdogd: use EXIT_* constants
tools/misc: rework xenwatchdogd signal handling
tools/misc: xenwatchdogd: add static qualifier
tools/misc: xenwatchdogd: add parse_secs()
tools/misc: xenwatchdogd enhancements
docs/man: Add xenwatchdog manual page
docs/man/xenwatchdogd.8.pod | 54 +++++++++++ tools/misc/xenwatchdogd.c | 182 ++++++++++++++++++++++++++++-------- 2 files changed, 196 insertions(+), 40 deletions(-) create mode 100644 docs/man/xenwatchdogd.8.pod
Signature · 1 line
2.39.2
PATCH v2 1/6 tools/misc: xenwatchdogd: use EXIT_* constants
From: Leigh Brown <[email protected]>
Use EXIT_SUCCESS/EXIT_FAILURE constants instead of magic numbers.
--- tools/misc/xenwatchdogd.c | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
tools/misc/xenwatchdogd.c +20 -20
@@ -17,37 +17,37 @@ void daemonize(void) {switch (fork ()) {case -1 : -err (1 ,"fork" ); +err (EXIT_FAILURE ,"fork" );case 0 :break ;default : -exit (0 ); +exit (EXIT_SUCCESS ); }umask (0 );if (setsid () <0 ) -err (1 ,"setsid" ); +err (EXIT_FAILURE ,"setsid" );if (chdir ("/" ) <0 ) -err (1 ,"chdir /" ); +err (EXIT_FAILURE ,"chdir /" );if (freopen ("/dev/null" ,"r" , stdin) ==NULL ) -err (1 ,"reopen stdin" ); +err (EXIT_FAILURE ,"reopen stdin" );if (freopen ("/dev/null" ,"w" , stdout) ==NULL ) -err (1 ,"reopen stdout" ); +err (EXIT_FAILURE ,"reopen stdout" );if (freopen ("/dev/null" ,"w" , stderr) ==NULL ) -err (1 ,"reopen stderr" ); +err (EXIT_FAILURE ,"reopen stderr" ); }void catch_exit (int sig) {if (id)xc_watchdog (h, id,300 ); -exit (0 ); +exit (EXIT_SUCCESS ); }void catch_usr1 (int sig) {if (id)xc_watchdog (h, id,0 ); -exit (0 ); +exit (EXIT_SUCCESS ); }int main (int argc,char **argv)
@@ -56,44 +56,44 @@ int main(int argc, char **argv)int ret;if (argc <2 ) -errx (1 ,"usage: %s <timeout> <sleep>" , argv[0 ]); +errx (EXIT_FAILURE ,"usage: %s <timeout> <sleep>" , argv[0 ]);daemonize (); h =xc_interface_open (NULL ,NULL ,0 );if (h ==NULL ) -err (1 ,"xc_interface_open" ); +err (EXIT_FAILURE ,"xc_interface_open" ); t =strtoul (argv[1 ],NULL ,0 );if (t ==ULONG_MAX ) -err (1 ,"strtoul" ); +err (EXIT_FAILURE ,"strtoul" ); s = t /2 ;if (argc ==3 ) { s =strtoul (argv[2 ],NULL ,0 );if (s ==ULONG_MAX ) -err (1 ,"strtoul" ); +err (EXIT_FAILURE ,"strtoul" ); }if (signal (SIGHUP , &catch_exit) ==SIG_ERR ) -err (1 ,"signal" ); +err (EXIT_FAILURE ,"signal" );if (signal (SIGINT , &catch_exit) ==SIG_ERR ) -err (1 ,"signal" ); +err (EXIT_FAILURE ,"signal" );if (signal (SIGQUIT , &catch_exit) ==SIG_ERR ) -err (1 ,"signal" ); +err (EXIT_FAILURE ,"signal" );if (signal (SIGTERM , &catch_exit) ==SIG_ERR ) -err (1 ,"signal" ); +err (EXIT_FAILURE ,"signal" );if (signal (SIGUSR1 , &catch_usr1) ==SIG_ERR ) -err (1 ,"signal" ); +err (EXIT_FAILURE ,"signal" ); id =xc_watchdog (h,0 , t);if (id <=0 ) -err (1 ,"xc_watchdog setup" ); +err (EXIT_FAILURE ,"xc_watchdog setup" );for (;;) {sleep (s); ret =xc_watchdog (h, id, t);if (ret !=0 ) -err (1 ,"xc_watchdog" ); +err (EXIT_FAILURE ,"xc_watchdog" ); } }
Signature · 1 line
2.39.2
Re: [PATCH v2 1/6] tools/misc: xenwatchdogd: use EXIT_* constants
Quoted 5 lines · On Fri, Mar 29, 2024 at 11:10:51AM +0000, [email protected] wrote:
From: Leigh Brown <[email protected]>
Use EXIT_SUCCESS/EXIT_FAILURE constants instead of magic numbers.
Signed-off-by Leigh Brown <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v2 2/6 tools/misc: rework xenwatchdogd signal handling
In reply to [email protected]From: Leigh Brown <[email protected]>
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(-)
tools/misc/xenwatchdogd.c +12 -8
@@ -9,9 +9,11 @@#include <unistd.h> #include <signal.h> #include <stdio.h> +#include <stdbool.h> xc_interface *h; -int id =0 ; +static bool safeexit = false; +static 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 ; }
Signature · 1 line
2.39.2
Re: [PATCH v2 2/6] tools/misc: rework xenwatchdogd signal handling
Quoted 6 lines · On Fri, Mar 29, 2024 at 11:10:52AM +0000, [email protected] wrote:
From: Leigh Brown <[email protected]>
Rework xenwatchdogd signal handling to do the minimum in the signal handler. This is a very minor enhancement.
Signed-off-by Leigh Brown <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
Re: [PATCH v2 2/6] tools/misc: rework xenwatchdogd signal handling
In reply to [email protected]Quoted 5 lines · On 29/03/2024 11:10 am, [email protected] wrote:
tools/misc/xenwatchdogd.c +0
-0
tools/misc/xenwatchdogd.c line 16
Quoted 9 lines
tools/misc/xenwatchdogd.c +3
-1@@ -9,9 +9,11 @@#include <unistd.h> #include <signal.h> #include <stdio.h> +#include <stdbool.h> xc_interface *h; -int id =0 ; +static bool safeexit = false; +static bool done = false;
It's a common bug, but these need to be volatile. Right now, ...
tools/misc/xenwatchdogd.c int main(int argc, char **argv) · line 94
Quoted 7 lines
tools/misc/xenwatchdogd.c +1
-1@@ -90,10 +90,14 @@ int main(int argc, char **argv)if (id <=0 )err (EXIT_FAILURE ,"xc_watchdog setup" ); -for (;;) { +while (!done) {sleep (s);
... the only reason this isn't an infinite loop is because the compiler can't prove that sleep() doesn't modify the variable. This goes wrong in subtle and fun ways when using LTO.
I'll fix on commit.
For the record, I've taken 1-3 which are ready. You'll need to rework 4 and later per Anthony's feedback.
~Andrew
Re: [PATCH v2 2/6] tools/misc: rework xenwatchdogd signal handling
Hi Andrew,
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · On 29/03/2024 11:10 am, [email protected] wrote:
tools/misc/xenwatchdogd.c +1
-0@@ -9,9 +9,11 @@#include <unistd.h> #include <signal.h> #include <stdio.h> +#include <stdbool.h>
Quoted 6 lines
tools/misc/xenwatchdogd.c line 16
Quoted 4 lines
tools/misc/xenwatchdogd.c +2
-1xc_interface *h; -int id =0 ; +static bool safeexit = false; +static bool done = false;It's a common bug, but these need to be volatile. Right now, ...
I'm an idiot (I'm sure I've mentioned this a couple of times :-) )
Quoted 12 lines
tools/misc/xenwatchdogd.c int main(int argc, char **argv) · line 94
Quoted 7 lines
tools/misc/xenwatchdogd.c +1
-1@@ -90,10 +90,14 @@ int main(int argc, char **argv)if (id <=0 )err (EXIT_FAILURE ,"xc_watchdog setup" ); -for (;;) { +while (!done) {sleep (s);... the only reason this isn't an infinite loop is because the compiler can't prove that
sleep()doesn't modify the variable. This goes wrong in subtle and fun ways when using LTO.
Quoted 6 lines
I'll fix on commit.
For the record, I've taken 1-3 which are ready. You'll need to rework 4 and later per Anthony's feedback.
~Andrew
Thanks, I will get those done this evening, hopefully.
Regards,
Leigh.
PATCH v2 3/6 tools/misc: xenwatchdogd: add static qualifier
In reply to [email protected]From: Leigh Brown <[email protected]>
Make all functions except main() static in xenwatchdogd.c. Also make the remaining global variable static.
--- tools/misc/xenwatchdogd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
tools/misc/xenwatchdogd.c +4 -4
@@ -11,11 +11,11 @@#include <stdio.h> #include <stdbool.h> -xc_interface *h; +static xc_interface *h;static bool safeexit = false;static bool done = false; -void daemonize (void ) +static void daemonize (void ) {switch (fork ()) {case -1 :
@@ -38,12 +38,12 @@ void daemonize(void)err (EXIT_FAILURE ,"reopen stderr" ); } -void catch_exit (int sig) +static void catch_exit (int sig) { done = true; } -void catch_usr1 (int sig) +static void catch_usr1 (int sig) { safeexit = true; done = true;
Signature · 1 line
2.39.2
Re: [PATCH v2 3/6] tools/misc: xenwatchdogd: add static qualifier
Quoted 6 lines · On Fri, Mar 29, 2024 at 11:10:53AM +0000, [email protected] wrote:
From: Leigh Brown <[email protected]>
Make all functions except
main()static inxenwatchdogd.c. Also make the remaining global variable static.Signed-off-by Leigh Brown <[email protected]>
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v2 4/6 tools/misc: xenwatchdogd: add parse_secs()
In reply to [email protected]From: Leigh Brown <[email protected]>
Create a new parse_secs() function to parse the timeout and sleep parameters. This ensures that non-numeric parameters are not accidentally treated as numbers.
--- tools/misc/xenwatchdogd.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
tools/misc/xenwatchdogd.c +15 -8
@@ -49,6 +49,18 @@ static void catch_usr1(int sig) done = true; } +static int parse_secs (const char *arg,const char *what) +{ +char *endptr; +unsigned long val; + + val =strtoul (arg, &endptr,0 ); +if (val >INT_MAX || *endptr !=0 ) +errx (EXIT_FAILURE ,"invalid %s: '%s'" , what, arg); + +return val; +} +int main (int argc,char **argv) {int id;
@@ -64,16 +76,11 @@ int main(int argc, char **argv)if (h ==NULL )err (EXIT_FAILURE ,"xc_interface_open" ); - t =strtoul (argv[1 ],NULL ,0 ); -if (t ==ULONG_MAX ) -err (EXIT_FAILURE ,"strtoul" ); + t =parse_secs (argv[optind],"timeout" ); s = t /2 ; -if (argc ==3 ) { - s =strtoul (argv[2 ],NULL ,0 ); -if (s ==ULONG_MAX ) -err (EXIT_FAILURE ,"strtoul" ); - } +if (argc ==3 ) + s =parse_secs (argv[optind],"sleep" );if (signal (SIGHUP , &catch_exit) ==SIG_ERR )err (EXIT_FAILURE ,"signal" );
Signature · 1 line
2.39.2
Re: [PATCH v2 4/6] tools/misc: xenwatchdogd: add parse_secs()
Quoted 5 lines · On Fri, Mar 29, 2024 at 11:10:54AM +0000, [email protected] wrote:
tools/misc/xenwatchdogd.c +0
-0
tools/misc/xenwatchdogd.c static void catch_usr1(int sig) · line 58
Quoted 10 lines
tools/misc/xenwatchdogd.c +7
-0@@ -49,6 +49,18 @@ static void catch_usr1(int sig) done = true; } +static int parse_secs (const char *arg,const char *what) +{ +char *endptr; +unsigned long val; + + val =strtoul (arg, &endptr,0 ); +if (val >INT_MAX || *endptr !=0 )
nit: '\0' would be more accurate ^ here.
Otherwise, just *endptr without "!= 0" would work too. But comparing a char to a digit feels wrong.
Quoted 15 lines
tools/misc/xenwatchdogd.c +5
-3+errx (EXIT_FAILURE ,"invalid %s: '%s'" , what, arg); + +return val; +} +int main (int argc,char **argv) {int id;@@ -64,16 +76,11 @@ int main(int argc, char **argv)if (h ==NULL )err (EXIT_FAILURE ,"xc_interface_open" ); - t =strtoul (argv[1 ],NULL ,0 ); -if (t ==ULONG_MAX ) -err (EXIT_FAILURE ,"strtoul" );
tools/misc/xenwatchdogd.c int main(int argc, char **argv) · line 83
Quoted 10 lines
tools/misc/xenwatchdogd.c +3
-5+ t =parse_secs (argv[optind],"timeout" ); s = t /2 ; -if (argc ==3 ) { - s =strtoul (argv[2 ],NULL ,0 ); -if (s ==ULONG_MAX ) -err (EXIT_FAILURE ,"strtoul" ); - } +if (argc ==3 ) + s =parse_secs (argv[optind],"sleep" );
This is parsing the wrong value here, should it be +1 to parse the sleep argument instead of the timeout argument a second time.
Also, are you sure you want to start using "optind" here? It's a variable used by getopt(), but we don't use it yet. It almost feel like "optind" happen to be set to 1 by luck.
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v2 5/6 tools/misc: xenwatchdogd enhancements
In reply to [email protected]From: Leigh Brown <[email protected]>
Add enhanced parameter parsing and validation, making use of getopt_long(). Adds usage() function, ability to run in the foreground, and the ability to disarm the watchdog timer when exiting. Now checks the number of parameters are correct, that timeout is at least two seconds (to allow a minimum sleep time of one second), and that the sleep time is at least one and less than the watchdog timeout. After these changes, the daemon will no longer instantly reboot the domain if you enter a zero timeout (or non-numeric parameter), and prevent the daemon consuming 100% of a CPU. Add a copyright message. This is based on the previous commits which were from Citrix email addresses.
--- tools/misc/xenwatchdogd.c | 111 ++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 10 deletions(-)
tools/misc/xenwatchdogd.c +101 -10
@@ -1,3 +1,20 @@ +/* +* xenwatchdogd.c +* +* Watchdog based on Xen hypercall watchdog interface +* +* Copyright 2010-2024 Citrix Ltd and other contributors +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ #include <err.h> #include <limits.h>
@@ -10,6 +27,11 @@#include <signal.h> #include <stdio.h> #include <stdbool.h> +#include <getopt.h> + +#define WDOG_MIN_TIMEOUT 2 +#define WDOG_MIN_SLEEP 1 +#define WDOG_EXIT_TIMEOUT 300static xc_interface *h;static bool safeexit = false;
@@ -49,6 +71,26 @@ static void catch_usr1(int sig) done = true; } +static void __attribute__((noreturn))usage (int exit_code) +{ +FILE *out = exit_code ? stderr : stdout; + +fprintf (out, +"Usage: xenwatchdog [OPTION]... <timeout> [<sleep>]\n" +" -h, --help\t\tDisplay this help text and exit.\n" +" -F, --foreground\tRun in foreground.\n" +" -x, --safe-exit\tDisable watchdog on orderly exit.\n" +"\t\t\tNote: default is to set a %d second timeout on exit.\n\n" +" timeout\t\tInteger seconds to arm the watchdog each time.\n" +"\t\t\tNote: minimum timeout is %d seconds.\n\n" +" sleep\t\t\tInteger seconds to sleep between arming the watchdog.\n" +"\t\t\tNote: sleep must be at least %d and less than timeout.\n" +"\t\t\tIf not specified then set to half the timeout.\n" , +WDOG_EXIT_TIMEOUT ,WDOG_MIN_TIMEOUT ,WDOG_MIN_SLEEP + ); +exit (exit_code); +} +static int parse_secs (const char *arg,const char *what) {char *endptr;
@@ -66,21 +108,70 @@ int main(int argc, char **argv)int id;int t, s;int ret; +bool daemon = true; + +for ( ;; ) + { +int option_index =0 , c; +static const struct option long_options[] = + { + {"help" , no_argument,NULL ,'h' }, + {"foreground" , no_argument,NULL ,'F' }, + {"safe-exit" , no_argument,NULL ,'x' }, + {NULL ,0 ,NULL ,0 }, + }; + + c =getopt_long (argc, argv,"hFxD" , long_options, &option_index); +if (c ==-1 ) +break ; + +switch (c) + { +case 'h' : +usage (EXIT_SUCCESS ); + +case 'F' : + daemon = false; +break ; + +case 'x' : + safeexit = true; +break ; + +default : +usage (EXIT_FAILURE ); + } + } -if (argc <2 ) -errx (EXIT_FAILURE ,"usage: %s <timeout> <sleep>" , argv[0 ]); +if (argc - optind <1 ) +errx (EXIT_FAILURE ,"timeout must be specified" ); -daemonize (); - - h =xc_interface_open (NULL ,NULL ,0 ); -if (h ==NULL ) -err (EXIT_FAILURE ,"xc_interface_open" ); +if (argc - optind >2 ) +errx (EXIT_FAILURE ,"too many arguments" ); t =parse_secs (argv[optind],"timeout" ); +if (t <WDOG_MIN_TIMEOUT ) +errx (EXIT_FAILURE ,"Error: timeout must be at least %d seconds" , +WDOG_MIN_TIMEOUT ); - s = t /2 ; -if (argc ==3 ) + ++optind; +if (optind < argc) { s =parse_secs (argv[optind],"sleep" ); +if (s <WDOG_MIN_SLEEP ) +errx (EXIT_FAILURE ,"Error: sleep must be no less than %d" , +WDOG_MIN_SLEEP ); +if (s >= t) +errx (EXIT_FAILURE ,"Error: sleep must be less than timeout" ); + } +else + s = t /2 ; + +if (daemon) +daemonize (); + + h =xc_interface_open (NULL ,NULL ,0 ); +if (h ==NULL ) +err (EXIT_FAILURE ,"xc_interface_open" );if (signal (SIGHUP , &catch_exit) ==SIG_ERR )err (EXIT_FAILURE ,"signal" );
@@ -105,6 +196,6 @@ int main(int argc, char **argv) }// Zero seconds timeout will disarm the watchdog timer -xc_watchdog (h, id, safeexit ?0 :300 ); +xc_watchdog (h, id, safeexit ?0 :WDOG_EXIT_TIMEOUT );return 0 ; }
Signature · 1 line
2.39.2
Re: [PATCH v2 5/6] tools/misc: xenwatchdogd enhancements
Quoted 12 lines · On Fri, Mar 29, 2024 at 11:10:55AM +0000, [email protected] wrote:
From: Leigh Brown <[email protected]>
Add enhanced parameter parsing and validation, making use of
getopt_long(). Addsusage()function, ability to run in the foreground, and the ability to disarm the watchdog timer when exiting. Now checks the number of parameters are correct, that timeout is at least two seconds (to allow a minimum sleep time of one second), and that the sleep time is at least one and less than the watchdog timeout. After these changes, the daemon will no longer instantly reboot the domain if you enter a zero timeout (or non-numeric parameter), and prevent the daemon consuming 100% of a CPU. Add a copyright message. This is based on the previous commits which were from Citrix email addresses.
This to me is really hard to read, it just looks like a blob of text, where it supposed to be a list with several modification listed. The part about the copyright should be in its own paragraph for example.
Quoted 10 lines
Signed-off-by Leigh Brown <[email protected]>--- tools/misc/xenwatchdogd.c | 111 ++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 10 deletions(-)tools/misc/xenwatchdogd.c +0
-0
tools/misc/xenwatchdogd.c line 6
Quoted 6 lines
tools/misc/xenwatchdogd.c +6
-0@@ -1,3 +1,20 @@ +/* +* xenwatchdogd.c +* +* Watchdog based on Xen hypercall watchdog interface +* +* Copyright 2010-2024 Citrix Ltd and other contributors
This is probably more like:
Copyright (C) 2010 Citrix Ltd.
Copyright (C) 2024 *** your copyright here ***
Because it's looks like the only contribution from us was in 2010, and I suppose it's fine to have more than one copyright line.
tools/misc/xenwatchdogd.c line 16
Quoted 9 lines
tools/misc/xenwatchdogd.c +9
-0+* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details.
This might be the wrong license, the default license we use is GPL 2.0 only, not LGPL. See :/COPYING .
These days, we prefer SPDX tags instead of the full licence text.
So overall, the header of the file should look something like:
/* SPDX-License-Identifier: GPL-2.0-only */ /*
* xenwatchdogd.c
*
* Watchdog based on Xen hypercall watchdog interface *
* Copyright (C) 2010 Citrix Ltd.
* Copyright (C) 2024 *** your copyright here *** */
I don't know if adding the file name in that header is very useful, but I don't mind either way.
Also, could you do this in a separate patch?
tools/misc/xenwatchdogd.c line 20
Quoted 4 lines
tools/misc/xenwatchdogd.c +1
-0+*/ #include <err.h> #include <limits.h>
Nice change overall, it's just the license part that need fixing.
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v2 6/6 docs/man: Add xenwatchdog manual page
In reply to [email protected]From: Leigh Brown <[email protected]>
Add a manual page for xenwatchdogd.
--- docs/man/xenwatchdogd.8.pod | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 docs/man/xenwatchdogd.8.pod
docs/man/xenwatchdogd.8.pod new file +54 -0
@@ -0,0 +1,54 @@ +=head1 NAME + +xenwatchdogd - Xen hypercall based watchdog daemon + +=head1 SYNOPSIS + +B<xenwatchdogd> [ I<OPTIONS> ] <I<TIMEOUT>> [ <I<SLEEP>> ] + +=head1 DESCRIPTION + +B<xenwatchdogd> arms the Xen watchdog timer to I<TIMEOUT> every I<SLEEP> +seconds. If the xenwatchdogd process dies or is delayed for more than +I<TIMEOUT> seconds, then Xen will reboot the domain. If the domain being +rebooted is domain 0, the whole system will reboot. + +=head1 OPTIONS + +=over 4 + +=item B<-h>, B<--help> + +Display a help message. + +=item B<-F>, B<--foreground> + +Run in the foreground. The default behaviour is to daemonize. + +=item B<-x>, B<--safe-exit> + +Disable watchdog on orderly exit. The default behaviour is to arm the +watchdog to 300 seconds to allow time for the domain to shutdown. See +also the B<SIGNALS> section. + +=item B<timeout> + +The number of seconds to arm the Xen watchdog timer. This must be set to +a minimum of two. + +=item B<sleep> + +The number of seconds to sleep in between calls to arm the Xen watchdog +timer. This must be at least one second, and less than the I<timeout> +value. If not specified, it defaults to half the I<timeout> value. + +=back + +=head1 SIGNALS + +B<SIGUSR1> Will cause the program to disarm the watchdog timer and exit, +regardless of whether the safe exit option was passed. + +=head1 AUTHOR + +Citrix Ltd and other contributors.
Signature · 1 line
2.39.2
Re: [PATCH v2 6/6] docs/man: Add xenwatchdog manual page
Quoted 9 lines · On Fri, Mar 29, 2024 at 11:10:56AM +0000, [email protected] wrote:
docs/man/xenwatchdogd.8.pod new file +3
-0@@ -0,0 +1,54 @@ +=head1 NAME + +xenwatchdogd - Xen hypercall based watchdog daemon
docs/man/xenwatchdogd.8.pod line 13
Quoted 10 lines
docs/man/xenwatchdogd.8.pod new file +10
-0+ +=head1 SYNOPSIS + +B<xenwatchdogd> [ I<OPTIONS> ] <I<TIMEOUT>> [ <I<SLEEP>> ] + +=head1 DESCRIPTION + +B<xenwatchdogd> arms the Xen watchdog timer to I<TIMEOUT> every I<SLEEP> +seconds. If the xenwatchdogd process dies or is delayed for more than +I<TIMEOUT> seconds, then Xen will reboot the domain.
Xen will not reboot the domain, it will just kill the domain with watchdog as explanation. I think the toolstack is in charge of rebooting the domain. There's a setting for xl created VM named on_watchdog="ACTION", which by default is "destroy". So it's more likely that the domain will be killed rather than rebooted.
So something like:
Depending on the configuration for the guest, the domain might be destroyed, rebooted, or other. See B<on_watchdog> in xl.cfg(5)
docs/man/xenwatchdogd.8.pod line 15
Quoted 2 lines
docs/man/xenwatchdogd.8.pod new file +2
-0+ If the domain being +rebooted is domain 0, the whole system will reboot.
Maybe something like "if B<xenwatchdogd> is running in dom0, the whole system will reboot". I'm not sure if the host reboot in this case by default, probably.
docs/man/xenwatchdogd.8.pod line 50
Quoted 4 lines
docs/man/xenwatchdogd.8.pod new file +4
-0+=head1 SIGNALS + +B<SIGUSR1> Will cause the program to disarm the watchdog timer and exit, +regardless of whether the safe exit option was passed.
"whether B<--safe-exit> option" ..
I think it's better to call-out the option explicitly.
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 17 lines · On Fri, Mar 29, 2024 at 11:10:50AM +0000, [email protected] wrote:
From: Leigh Brown <[email protected]>
The primary intention of this patch series is to replace the pathologically bad behaviour of rebooting the domain if you run "xenwatchdogd -h". To that end, I have implemented comprehensive argument validation. This validation ensures you can't pass arguments that instantly reboot the domain or cause it to spin loop running sleep(0) repeatedly.
I added a couple of enhancements whilst working on the changes as they were easy enough. In particular, being able to run in the foreground, disarming the watchdog on exit, help and a manpage.
Changes since v1:
- Add Signed-off-by on every patch.
- Make global variables static.
Quoted 10 lines
Full list of changes:
- Usegetopt_long()to add -h/--help with associated usage help.
- Add -F/--foreground parameter to run without daemonizing.
- Add -x/--save-exit parameter to disarm the watchdog when exiting.
- Validate timeout is numeric and is at least two seconds.
- Validate sleep is numeric and is at least one and less than timeout.
- Check for too many arguments.
- Use symbol constants instead of magic numbers where possible.
- Make all functions exceptmain()and global variables static.
- Add a manual page forxenwatchdogd().
It might be worth mentioning something about these in the CHANGELOG. Probably not need to go into detail, maybe just "improved xenwatchdogd options, see new man page."
Cheers,
Signature · 1 line
Anthony PERARD