git: 49276e4b3638 - stable/15 - bhyveload: do not hang on EOF from console input

From: Roman Bogorodskiy <novel_at_FreeBSD.org>
Date: Sat, 03 Oct 2026 10:55:26 UTC
The branch stable/15 has been updated by novel:

URL: https://cgit.FreeBSD.org/src/commit/?id=49276e4b3638d5b319d51bb00777446c9691c331

commit 49276e4b3638d5b319d51bb00777446c9691c331
Author:     Roman Bogorodskiy <novel@FreeBSD.org>
AuthorDate: 2026-08-27 17:40:43 +0000
Commit:     Roman Bogorodskiy <novel@FreeBSD.org>
CommitDate: 2026-10-03 08:24:17 +0000

    bhyveload: do not hang on EOF from console input
    
    Currently, when bhyveload(8) fails to boot the guest,
    it drops into the loader prompt waiting for user input.
    
    This behaviour is inconvenient when using bhyveload(8) from
    scripts.
    
    Make it exit when it receives EOF from console input.
    
    PR:             286289
    Reviewed by:    markj
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D59226
    
    (cherry picked from commit 8c20260bc55d7b4be0cbcf0a940505ae15ab41a9)
---
 usr.sbin/bhyveload/bhyveload.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/usr.sbin/bhyveload/bhyveload.c b/usr.sbin/bhyveload/bhyveload.c
index be99bb342de6..3ee5f7ac7129 100644
--- a/usr.sbin/bhyveload/bhyveload.c
+++ b/usr.sbin/bhyveload/bhyveload.c
@@ -134,8 +134,12 @@ static int
 cb_getc(void *arg __unused)
 {
 	char c;
+	ssize_t nread;
 
-	if (read(consin_fd, &c, 1) == 1)
+	nread = read(consin_fd, &c, 1);
+	if (nread == 0)
+		cb_exit(NULL, USERBOOT_EXIT_QUIT);
+	if (nread == 1)
 		return (c);
 	return (-1);
 }