Page MenuHomeFreeBSD

bhyveload: do not hang on EOF from console input
AcceptedPublic

Authored by novel on Thu, Aug 27, 6:06 PM.
Tags
None
Referenced Files
F172519747: D59226.id187114.diff
Sat, Sep 19, 12:22 AM
Unknown Object (File)
Thu, Sep 17, 4:34 AM
Unknown Object (File)
Wed, Sep 16, 8:14 PM
Unknown Object (File)
Sun, Sep 13, 1:02 AM
Unknown Object (File)
Sun, Sep 13, 1:01 AM
Unknown Object (File)
Sun, Sep 13, 1:01 AM
Unknown Object (File)
Sat, Sep 12, 12:49 PM
Unknown Object (File)
Fri, Sep 11, 4:47 AM

Details

Reviewers
ziaee
markj
Group Reviewers
bhyve
manpages
Summary

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
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation

Test Plan

Invalid image, default (interactive mode):

# bhyveload -m 2024 -d ./fake.img test                                                                                                                                                                                                                                                                                 
Consoles: userboot                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                       
FreeBSD/amd64 User boot lua, Revision 3.0                                                                                                                                                                                                                                                                              
(Thu Aug 27 10:40:55 UTC 2026 root@freebsd14)                                                                                                                                                                                                                                                                          
ERROR: cannot open /boot/lua/loader.lua: no such file or directory.                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                       
Type '?' for a list of commands, 'help' for more detailed help.                                                                                                                                                                                                                                                        
OK quit                                                                                                                                                                                                                                                                                                                
#

Invalid image, non-interactive mode:

# bhyveload -m 2024 -n -d ./fake.img test                                                                                                                                                                                                                                                                              
Consoles: userboot                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                       
FreeBSD/amd64 User boot lua, Revision 3.0                                                                                                                                                                                                                                                                              
(Thu Aug 27 10:40:55 UTC 2026 root@freebsd14)                                                                                                                                                                                                                                                                          
ERROR: cannot open /boot/lua/loader.lua: no such file or directory.                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                       
Type '?' for a list of commands, 'help' for more detailed help.                                                                                                                                                                                                                                                        
OK bhyveload: user input requested in non-interactive mode                                                                                                                                                                                                                                                             
                                                          #                                                                                                                                                                                                                                                            
#                                                                                                                                                                                                                                                                                                                      
# echo $?                                                                                                                                                                                                                                                                                                              
1                                                                                                                                                                                                                                                                                                                      
#

Valid image, non-interactive mode:

# bhyveload -m 2024 -n -d ./FreeBSD-14.3-RELEASE-amd64-ufs.raw  test
Consoles: userboot  

FreeBSD/amd64 User boot lua, Revision 3.0
(Thu Aug 27 10:40:55 UTC 2026 root@freebsd14)
Loading /boot/defaults/loader.conf
Loading /boot/defaults/loader.conf
Loading /boot/device.hints
Loading /boot/loader.conf
Loading /boot/loader.conf.local
/
\
|  ______               ____   _____ _____  
  |  ____|             |  _ \ / ____|  __ \ 
  | |___ _ __ ___  ___ | |_) | (___ | |  | |
  |  ___| '__/ _ \/ _ \|  _ < \___ \| |  | |
  | |   | | |  __/  __/| |_) |____) | |__| |
  | |   | | |    |    ||     |      |      |
  |_|   |_|  \___|\___||____/|_____/|_____/      ```                        `
                                                s` `.....---.......--.```   -/
 +---------- Welcome to FreeBSD -----------+    +o   .--`         /y:`      +.
 |                                         |     yo`:.            :o      `+-
 |  1. Boot Multi user [Enter]             |      y/               -/`   -o/
 |  2. Boot Single user                    |     .-                  ::/sy+:.
 |  3. Escape to loader prompt             |     /                     `--  /
 |  4. Reboot                              |    `:                          :`
 |  5. Cons: Serial                        |    `:                          :`
 |                                         |     /                          /
 |  Options:                               |     .-                        -.
 |  6. Kernel: default/kernel (1 of 1)     |      --                      -.
 |  7. Boot Options                        |       `:`                  `:`
 |                                         |         .--             `--.
 |                                         |            .---.....----.
 |                                         |
 +-----------------------------------------+
   Autoboot in 0 seconds. [Space] to pause  
Loading kernel...
/boot/kernel/kernel text=0x180078 text=0xd97948 text=0x43a46b data=0x180+0xe80 data=0x187590+0x478a70 0x8+0x18e940+0x8+0x1b2b03
Loading configured modules...
/etc/hostid size=0x25
/boot/entropy size=0x1000
# echo $?
0
#

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77060
Build 73943: arc lint + arc unit

Event Timeline

novel requested review of this revision.Thu, Aug 27, 6:06 PM

Does running bhyveload ... </dev/null not provide the desired behaviour?

ziaee added inline comments.
usr.sbin/bhyveload/bhyveload.8
131–132 ↗(On Diff #185231)

Please move this after line 122 for alphabetical sorting.

Does running bhyveload ... </dev/null not provide the desired behaviour?

# bhyveload -m 2024 -d ./fake.img test </dev/null drops me into the loader prompt, but I cannot type anything in.
In the PR I have also tested -c /dev/null which does not help too.

Fix option order in the manpage.

manpage LGTM, no comment on implementation or if we should do this.

This revision is now accepted and ready to land.Fri, Aug 28, 7:14 PM

Does running bhyveload ... </dev/null not provide the desired behaviour?

# bhyveload -m 2024 -d ./fake.img test </dev/null drops me into the loader prompt, but I cannot type anything in.

This is because cb_getc() does not handle EOF. You can just check to see if read() returned 0 and exit automatically if so. There is no need for a new option IMO.

usr.sbin/bhyveload/bhyveload.c
141

Re-implement to make cb_getc() exit on EOF in input read().

This revision now requires review to proceed.Fri, Sep 18, 3:40 PM
usr.sbin/bhyveload/bhyveload.c
141

This should still be addressed.

novel retitled this revision from bhyveload: add non-interactive mode to bhyveload: do not hang on EOF from console input.Fri, Sep 18, 4:49 PM
novel edited the summary of this revision. (Show Details)
novel edited the summary of this revision. (Show Details)

cb_exit(NULL, 1) -> cb_exit(NULL, USERBOOT_EXIT_QUIT)

This revision is now accepted and ready to land.Fri, Sep 18, 6:35 PM