diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-12-03 23:32:33 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2015-12-03 23:32:33 +0000 |
commit | 8807054e2779e04ad0d47023071e6de67b318fdc (patch) | |
tree | 7146c1df1206c29cc3862dadfeb491231359a2ac /usr.sbin/vmd/vmd.c | |
parent | 393c2127ea1d235eff95309344dbbb306b61410c (diff) |
Re-add the "load" and "reload" commands to vmctl: Instead of parsing
the configuration in vmctl directly, it now sends a (re)load request
to vmd. The reload also resets the existing configuration status -
this doesn't do much difference yet but a future change will compare
if a specified VM is already running. "load" will allow to add
configuration, while "reload" resets the state before loading.
Diffstat (limited to 'usr.sbin/vmd/vmd.c')
-rw-r--r-- | usr.sbin/vmd/vmd.c | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/usr.sbin/vmd/vmd.c b/usr.sbin/vmd/vmd.c index cbf65513c1d..674848628a2 100644 --- a/usr.sbin/vmd/vmd.c +++ b/usr.sbin/vmd/vmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmd.c,v 1.15 2015/12/03 16:18:13 reyk Exp $ */ +/* $OpenBSD: vmd.c,v 1.16 2015/12/03 23:32:32 reyk Exp $ */ /* * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> @@ -31,6 +31,7 @@ #include <signal.h> #include <syslog.h> #include <unistd.h> +#include <ctype.h> #include "proc.h" #include "vmd.h" @@ -56,8 +57,9 @@ int vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg) { struct privsep *ps = p->p_ps; - int res = 0, cmd = 0; + int res = 0, cmd = 0, v = 0; struct vm_create_params vcp; + char *str = NULL; switch (imsg->hdr.type) { case IMSG_VMDOP_START_VM_REQUEST: @@ -73,6 +75,15 @@ vmd_dispatch_control(int fd, struct privsep_proc *p, struct imsg *imsg) case IMSG_VMDOP_GET_INFO_VM_REQUEST: proc_forward_imsg(ps, imsg, PROC_VMM, -1); break; + case IMSG_VMDOP_RELOAD: + v = 1; + case IMSG_VMDOP_LOAD: + if (IMSG_DATA_SIZE(imsg) > 0) + str = get_string((uint8_t *)imsg->data, + IMSG_DATA_SIZE(imsg)); + vmd_reload(v, str); + free(str); + break; default: return (-1); } @@ -152,7 +163,13 @@ vmd_sighdlr(int sig, short event, void *arg) switch (sig) { case SIGHUP: - log_info("%s: ignoring SIGHUP", __func__); + log_info("%s: reload requested with SIGHUP", __func__); + + /* + * This is safe because libevent uses async signal handlers + * that run in the event loop and not in signal context. + */ + vmd_reload(1, NULL); break; case SIGPIPE: log_info("%s: ignoring SIGPIPE", __func__); @@ -358,6 +375,24 @@ vmd_configure(void) } void +vmd_reload(int reset, const char *filename) +{ + /* Switch back to the default config file */ + if (filename == NULL || *filename == '\0') + filename = env->vmd_conffile; + + log_debug("%s: level %d config file %s", __func__, reset, filename); + + if (reset) + config_setreset(env, CONFIG_ALL); + + if (parse_config(filename) == -1) { + log_debug("%s: failed to load config file %s", + __func__, filename); + } +} + +void vmd_shutdown(void) { proc_kill(&env->vmd_ps); @@ -405,3 +440,15 @@ vm_remove(struct vmd_vm *vm) free(vm); } + +char * +get_string(uint8_t *ptr, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) + if (!isprint(ptr[i])) + break; + + return strndup(ptr, i); +} |