Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --debug-sandbox #3197

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,7 @@ class Args:
debug: bool
debug_shell: bool
debug_workspace: bool
debug_sandbox: bool
pager: bool
genkey_valid_days: str
genkey_common_name: str
Expand Down Expand Up @@ -3775,6 +3776,12 @@ def create_argument_parser(chdir: bool = True) -> argparse.ArgumentParser:
action="store_true",
default=False,
)
parser.add_argument(
"--debug-sandbox",
help="Run mkosi-sandbox with strace",
action="store_true",
default=False,
)
parser.add_argument(
"--no-pager",
action="store_false",
Expand Down Expand Up @@ -4555,6 +4562,8 @@ def load_args(args: argparse.Namespace) -> Args:
ARG_DEBUG.set(args.debug)
if args.debug_shell:
ARG_DEBUG_SHELL.set(args.debug_shell)
if args.debug_sandbox:
ARG_DEBUG_SANDBOX.set(args.debug_sandbox)

return Args.from_namespace(args)

Expand Down
1 change: 1 addition & 0 deletions mkosi/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# This global should be initialized after parsing arguments
ARG_DEBUG = contextvars.ContextVar("debug", default=False)
ARG_DEBUG_SHELL = contextvars.ContextVar("debug-shell", default=False)
ARG_DEBUG_SANDBOX = contextvars.ContextVar("debug-sandbox", default=False)
LEVEL = 0


Expand Down
7 changes: 5 additions & 2 deletions mkosi/resources/man/mkosi.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,19 @@ Those settings cannot be configured in the configuration files.
for in this directory, hence using this option is an effective way to
build a project located in a specific directory.

`--debug=`
`--debug`
: Enable additional debugging output.

`--debug-shell`
: When executing a command in the image fails, mkosi will start an interactive
shell in the image allowing further debugging.

`--debug-workspace=`
`--debug-workspace`
: When an error occurs, the workspace directory will not be deleted.

`--debug-sandbox`
: Run `mkosi-sandbox` with `strace`.

`--version`
: Show package version.

Expand Down
3 changes: 2 additions & 1 deletion mkosi/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing import Any, Callable, NoReturn, Optional, Protocol

import mkosi.sandbox
from mkosi.log import ARG_DEBUG, ARG_DEBUG_SHELL, die
from mkosi.log import ARG_DEBUG, ARG_DEBUG_SHELL, ARG_DEBUG_SANDBOX, die
Copy link
Contributor

Choose a reason for hiding this comment

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

Ruff complains

Suggested change
from mkosi.log import ARG_DEBUG, ARG_DEBUG_SHELL, ARG_DEBUG_SANDBOX, die
from mkosi.log import ARG_DEBUG, ARG_DEBUG_SANDBOX, ARG_DEBUG_SHELL, die

from mkosi.sandbox import acquire_privileges, joinpath, umask
from mkosi.types import _FILE, CompletedProcess, PathString, Popen
from mkosi.util import current_home_dir, flatten, one_zero
Expand Down Expand Up @@ -485,6 +485,7 @@ def sandbox_cmd(

cmdline: list[PathString] = [
*setup,
*(["strace", "--detach-on=execve"] if ARG_DEBUG_SANDBOX.get() else []),
sys.executable, "-SI", mkosi.sandbox.__file__,
"--proc", "/proc",
# We mounted a subdirectory of TMPDIR to /var/tmp so we unset TMPDIR so that /tmp or /var/tmp are
Expand Down
Loading