diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2010-06-04 11:35:23 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2010-06-04 11:35:23 +0100 |
commit | 78c8506e77b393c00001fce9e8b21eda22ed3007 (patch) | |
tree | 389ca22b5b3f4cb280364e264beca2974ce4b924 /tools/misc/xenwatchdogd.c | |
parent | 77622d85cf3fd61e96b71750d75af58b60eddfc4 (diff) | |
download | xen-78c8506e77b393c00001fce9e8b21eda22ed3007.tar.gz xen-78c8506e77b393c00001fce9e8b21eda22ed3007.tar.bz2 xen-78c8506e77b393c00001fce9e8b21eda22ed3007.zip |
Watchdog timers for domains
Each domain is allowed to set, reset and disable its timers; when any
timer runs out the domain is killed.
Patch from Christian Limpach <Christian.Limpach@citrix.com>
Signed-off-by: Tim Deegan <Tim.Deegan@citrix.com>
Diffstat (limited to 'tools/misc/xenwatchdogd.c')
-rw-r--r-- | tools/misc/xenwatchdogd.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/tools/misc/xenwatchdogd.c b/tools/misc/xenwatchdogd.c new file mode 100644 index 0000000000..aa96834e5f --- /dev/null +++ b/tools/misc/xenwatchdogd.c @@ -0,0 +1,96 @@ + +#include <err.h> +#include <limits.h> +#include "xenctrl.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <signal.h> +#include <stdio.h> + +xc_interface *h; +int id = 0; + +void daemonize(void) +{ + switch (fork()) { + case -1: + err(1, "fork"); + case 0: + break; + default: + exit(0); + } + umask(0); + if (setsid() < 0) + err(1, "setsid"); + if (chdir("/") < 0) + err(1, "chdir /"); + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "w", stdout); + freopen("/dev/null", "w", stderr); +} + +void catch_exit(int sig) +{ + if (id) + xc_watchdog(h, id, 300); + exit(0); +} + +void catch_usr1(int sig) +{ + if (id) + xc_watchdog(h, id, 0); + exit(0); +} + +int main(int argc, char **argv) +{ + int t, s; + int ret; + + if (argc < 2) + errx(1, "usage: %s <timeout> <sleep>", argv[0]); + + daemonize(); + + h = xc_interface_open(NULL, NULL, 0); + if (h == NULL) + err(1, "xc_interface_open"); + + t = strtoul(argv[1], NULL, 0); + if (t == ULONG_MAX) + err(1, "strtoul"); + + s = t / 2; + if (argc == 3) { + s = strtoul(argv[2], NULL, 0); + if (s == ULONG_MAX) + err(1, "strtoul"); + } + + if (signal(SIGHUP, &catch_exit) == SIG_ERR) + err(1, "signal"); + if (signal(SIGINT, &catch_exit) == SIG_ERR) + err(1, "signal"); + if (signal(SIGQUIT, &catch_exit) == SIG_ERR) + err(1, "signal"); + if (signal(SIGTERM, &catch_exit) == SIG_ERR) + err(1, "signal"); + if (signal(SIGUSR1, &catch_usr1) == SIG_ERR) + err(1, "signal"); + + id = xc_watchdog(h, 0, t); + if (id <= 0) + err(1, "xc_watchdog setup"); + + for (;;) { + sleep(s); + ret = xc_watchdog(h, id, t); + if (ret != 0) + err(1, "xc_watchdog"); + } +} |