summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkn <kn@cvs.openbsd.org>2020-01-16 14:55:20 +0000
committerkn <kn@cvs.openbsd.org>2020-01-16 14:55:20 +0000
commit22e9c471bf31b26c264e0a32e2aef047bf792e3d (patch)
tree52f79af35621474de4208e0cd58aac2dbaa18ca7
parentd7b9c1f2927579a05746b3c4158fc2f03d727fb9 (diff)
Implement "start -c" to automatically connect to the console
Just like amd64 vmctl(8). Manual feedback schwarze OK kettenis
-rw-r--r--usr.sbin/ldomctl/ldomctl.810
-rw-r--r--usr.sbin/ldomctl/ldomctl.c68
2 files changed, 56 insertions, 22 deletions
diff --git a/usr.sbin/ldomctl/ldomctl.8 b/usr.sbin/ldomctl/ldomctl.8
index 97df3815028..b5aee4b35c2 100644
--- a/usr.sbin/ldomctl/ldomctl.8
+++ b/usr.sbin/ldomctl/ldomctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ldomctl.8,v 1.24 2020/01/09 21:30:18 kn Exp $
+.\" $OpenBSD: ldomctl.8,v 1.25 2020/01/16 14:55:19 kn Exp $
.\"
.\" Copyright (c) 2012 Mark Kettenis <kettenis@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 9 2020 $
+.Dd $Mdocdate: January 16 2020 $
.Dt LDOMCTL 8 sparc64
.Os
.Sh NAME
@@ -94,8 +94,12 @@ the default behaviour is to enter
.It Cm select Ar configuration
Select the next logical domain configuration to use
(after resetting the machine).
-.It Cm start Ar domain
+.It Cm start Oo Fl c Oc Ar domain
Start a guest domain.
+.Bl -tag -width Fl
+.It Fl c
+Automatically connect to the guest console.
+.El
.It Cm status Op Ar domain
Display status information for
.Ar domain ,
diff --git a/usr.sbin/ldomctl/ldomctl.c b/usr.sbin/ldomctl/ldomctl.c
index c5941fd480a..3c81a3f8b83 100644
--- a/usr.sbin/ldomctl/ldomctl.c
+++ b/usr.sbin/ldomctl/ldomctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldomctl.c,v 1.34 2020/01/04 17:30:41 kn Exp $ */
+/* $OpenBSD: ldomctl.c,v 1.35 2020/01/16 14:55:19 kn Exp $ */
/*
* Copyright (c) 2012 Mark Kettenis
@@ -131,7 +131,10 @@ usage(void)
"\t%1$s dump|list|list-io\n"
"\t%1$s init-system [-n] file\n"
"\t%1$s create-vdisk -s size file\n"
- "\t%1$s console|panic|start|status|stop [domain]\n", getprogname());
+ "\t%1$s start [-c] [domain]\n"
+ "\t%1$s console|panic|status|stop [domain]\n",
+ getprogname());
+
exit(EXIT_FAILURE);
}
@@ -399,23 +402,61 @@ download(int argc, char **argv)
}
void
+console_exec(uint64_t gid)
+{
+ struct guest *guest;
+ char console_str[8];
+
+ if (gid == 0)
+ errx(1, "no console for primary domain");
+
+ TAILQ_FOREACH(guest, &guest_list, link) {
+ if (guest->gid != gid)
+ continue;
+ snprintf(console_str, sizeof(console_str),
+ "ttyV%llu", guest->gid - 1);
+
+ closefrom(STDERR_FILENO + 1);
+ execl(LDOMCTL_CU, LDOMCTL_CU, "-r", "-l", console_str,
+ (char *)NULL);
+ err(1, "failed to open console");
+ }
+}
+
+void
guest_start(int argc, char **argv)
{
struct hvctl_msg msg;
ssize_t nbytes;
+ uint64_t gid;
+ int ch, console = 0;
- if (argc != 2)
+ while ((ch = getopt(argc, argv, "c")) != -1) {
+ switch (ch) {
+ case 'c':
+ console = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 1)
usage();
hv_config();
+ gid = find_guest(argv[0]);
+
/*
* Start guest domain.
*/
bzero(&msg, sizeof(msg));
msg.hdr.op = HVCTL_OP_GUEST_START;
msg.hdr.seq = hvctl_seq++;
- msg.msg.guestop.guestid = find_guest(argv[1]);
+ msg.msg.guestop.guestid = gid;
nbytes = write(hvctl_fd, &msg, sizeof(msg));
if (nbytes != sizeof(msg))
err(1, "write");
@@ -424,6 +465,9 @@ guest_start(int argc, char **argv)
nbytes = read(hvctl_fd, &msg, sizeof(msg));
if (nbytes != sizeof(msg))
err(1, "read");
+
+ if (console)
+ console_exec(gid);
}
void
@@ -615,9 +659,7 @@ guest_status(int argc, char **argv)
void
guest_console(int argc, char **argv)
{
- struct guest *guest;
uint64_t gid;
- char console_str[8];
if (argc != 2)
usage();
@@ -625,20 +667,8 @@ guest_console(int argc, char **argv)
hv_config();
gid = find_guest(argv[1]);
- if (gid == 0)
- errx(1, "no console for primary domain");
- TAILQ_FOREACH(guest, &guest_list, link) {
- if (guest->gid != gid)
- continue;
- snprintf(console_str, sizeof(console_str),
- "ttyV%llu", guest->gid - 1);
-
- closefrom(STDERR_FILENO + 1);
- execl(LDOMCTL_CU, LDOMCTL_CU, "-r", "-l", console_str,
- (char *)NULL);
- err(1, "failed to open console");
- }
+ console_exec(gid);
}
void