diff options
author | pd <pd@cvs.openbsd.org> | 2017-07-15 05:05:37 +0000 |
---|---|---|
committer | pd <pd@cvs.openbsd.org> | 2017-07-15 05:05:37 +0000 |
commit | 4839139e8da8e83ecc70559813145910ee3434bc (patch) | |
tree | 343abf1d2da53d507cdcc053c761c2df43800f8a /usr.sbin/vmctl/vmctl.c | |
parent | e70b5a78d5d1ed659db35edc2145e8e5b59558f8 (diff) |
Add vmctl send and vmctl receive
ok reyk@ and mlarkin@
Diffstat (limited to 'usr.sbin/vmctl/vmctl.c')
-rw-r--r-- | usr.sbin/vmctl/vmctl.c | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/usr.sbin/vmctl/vmctl.c b/usr.sbin/vmctl/vmctl.c index 1ae0e1d42e6..3335f30b7d4 100644 --- a/usr.sbin/vmctl/vmctl.c +++ b/usr.sbin/vmctl/vmctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmctl.c,v 1.31 2017/07/09 00:51:40 pd Exp $ */ +/* $OpenBSD: vmctl.c,v 1.32 2017/07/15 05:05:36 pd Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> @@ -40,6 +40,7 @@ #include "vmd.h" #include "vmctl.h" +#include "atomicio.h" extern char *__progname; uint32_t info_id; @@ -197,6 +198,68 @@ vm_start_complete(struct imsg *imsg, int *ret, int autoconnect) } void +send_vm(uint32_t id, const char *name) +{ + struct vmop_id vid; + int fds[2], readn, writen; + char buf[PAGE_SIZE]; + + memset(&vid, 0, sizeof(vid)); + vid.vid_id = id; + if (name != NULL) + strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fds) == -1) { + warnx("%s: socketpair creation failed", __func__); + } else { + imsg_compose(ibuf, IMSG_VMDOP_SEND_VM_REQUEST, 0, 0, fds[0], + &vid, sizeof(vid)); + imsg_flush(ibuf); + while (1) { + readn = atomicio(read, fds[1], buf, sizeof(buf)); + if (!readn) + break; + writen = atomicio(vwrite, STDOUT_FILENO, buf, + readn); + if (writen != readn) + break; + } + if (vid.vid_id) + warnx("sent vm %d successfully", vid.vid_id); + else + warnx("sent vm %s successfully", vid.vid_name); + } +} + +void +vm_receive(uint32_t id, const char *name) +{ + struct vmop_id vid; + int fds[2], readn, writen; + char buf[PAGE_SIZE]; + + memset(&vid, 0, sizeof(vid)); + if (name != NULL) + strlcpy(vid.vid_name, name, sizeof(vid.vid_name)); + if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fds) == -1) { + warnx("%s: socketpair creation failed", __func__); + } else { + imsg_compose(ibuf, IMSG_VMDOP_RECEIVE_VM_REQUEST, 0, 0, fds[0], + &vid, sizeof(vid)); + imsg_flush(ibuf); + while (1) { + readn = atomicio(read, STDIN_FILENO, buf, sizeof(buf)); + if (!readn) { + close(fds[1]); + break; + } + writen = atomicio(vwrite, fds[1], buf, readn); + if (writen != readn) + break; + } + } +} + +void pause_vm(uint32_t pause_id, const char *name) { struct vmop_id vid; |