Skip to content

Skip the kernel install when system start cannot read an answer - #2504

Open
jaeyeonme wants to merge 1 commit into
apple:mainfrom
jaeyeonme:skip-kernel-prompt-without-tty
Open

jaeyeonme wants to merge 1 commit into
apple:mainfrom
jaeyeonme:skip-kernel-prompt-without-tty

Conversation

@jaeyeonme

Copy link
Copy Markdown

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Fixes #2489.

When no default kernel is configured and neither --enable-kernel-install nor --disable-kernel-install is given, container system start prompts for an answer. Without a terminal, for example under launchd, readLine returns nil and the command exits 1 with failed to read user input, although the services have already started.

system start still prompts and reads the answer as before, so a piped answer such as yes | container system start keeps working. Only when no answer can be read and standard input is not a terminal does it now log a warning that names container system kernel set --recommended and --enable-kernel-install, skip the install, and exit 0, as it already does when the answer is n. With either flag there is still no prompt, and an interactive run where input ends still fails as before.

The decision moves into kernelInstallDecision, which has unit tests for each case. The option's help text and docs/command-reference.md describe the new default.

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

Added SystemStartTests. missingAnswerSkipsWithoutTerminal fails if the no-answer case is reverted to an error. make test and make check pass.

Ran a debug build with a fresh --app-root and no default kernel on macOS 27.2:

  • system start < /dev/null: exit 0, and system status reports running. It logs: "Services started, but no default kernel is configured and none was installed because no answer could be read from standard input. Containers cannot start until a default kernel is set. Run container system kernel set --recommended, or start with --enable-kernel-install."
  • echo n | system start: exit 0 with the existing "Please use the container system kernel set --recommended command" message and no new warning.
  • system start --disable-kernel-install < /dev/null: exit 0, no prompt and no warning.

I did not run the paths that install a kernel (answering yes, --enable-kernel-install). This PR has unit tests only; I can add an integration test for the /dev/null case if you'd like it here.

When no default kernel is configured and neither `--enable-kernel-install`
nor `--disable-kernel-install` is given, `container system start` prompts
for an answer. Without a terminal, for example under launchd, `readLine`
returns nil and the command failed with "failed to read user input" even
though the services had already started.

Keep prompting and reading the answer as before, so a piped answer such
as `yes | container system start` still works. When no answer can be read
and standard input is not a terminal, log a warning that names the ways
to set a default kernel, skip the install, and exit successfully. Move
the decision into a function with unit tests, and update the option's
help text and the command reference.

Fixes apple#2489.

@resker resker left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested at 21b4855 on macOS 27.3 (debug build, fresh app roots, no default kernel):

  • stdin from /dev/null, no flag: exits 0, services are running, and the warning names both fixes. container run then fails with the expected "default kernel not configured".
  • printf 'n\n' | container system start: declines and exits 0, same as before.
  • SystemStartTests pass, and swift-fmt-check is clean.

LGTM.

@jaeyeonme

Copy link
Copy Markdown
Author

Thanks for testing it, and for checking that container run afterwards fails with the expected error.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container system start under launchd (brew services) loops on the default-kernel prompt with no TTY

2 participants