]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Allow running qemu as an unprivileged user
authorJacob Emmert-Aronson <jacob@roadnottaken2718.com>
Sat, 23 Jul 2022 04:34:58 +0000 (21:34 -0700)
committerJacob Emmert-Aronson <jacob@roadnottaken2718.com>
Thu, 28 Jul 2022 02:38:26 +0000 (19:38 -0700)
mkosi.md
mkosi/__init__.py
mkosi/machine.py

index b07effefeee81ee2a1d5fbdfbd0dec920e5d9f47..d79135745668243220245f0b05bfecc647a7c608 100644 (file)
--- a/mkosi.md
+++ b/mkosi.md
@@ -85,6 +85,9 @@ The following command line verbs are known:
   only supported on images that contain a boot loader, i.e. those
   built with `Bootable=yes` (see below). This command must be executed
   as `root` unless the image already exists and `-f` is not specified.
+  Some qemu arguments (such as those set by `Netdev=yes`) may also
+  prevent qemu from starting when this command is executed by a
+  non-root user.
 
 `ssh`
 
index 30269740a0978bef2450b86baedca5582828c4f9..56cceaa0121143c052ca0ccae260eb114cb190d1 100644 (file)
@@ -125,7 +125,7 @@ SomeIO = Union[BinaryIO, TextIO]
 PathString = Union[Path, str]
 
 MKOSI_COMMANDS_NEED_BUILD = (Verb.shell, Verb.boot, Verb.qemu, Verb.serve)
-MKOSI_COMMANDS_SUDO = (Verb.build, Verb.clean, Verb.shell, Verb.boot, Verb.qemu, Verb.serve)
+MKOSI_COMMANDS_SUDO = (Verb.build, Verb.clean, Verb.shell, Verb.boot, Verb.serve)
 MKOSI_COMMANDS_CMDLINE = (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.ssh)
 
 DRACUT_SYSTEMD_EXTRAS = [
@@ -6041,9 +6041,6 @@ def empty_directory(path: Path) -> None:
 
 
 def unlink_output(args: MkosiArgs) -> None:
-    if not args.force and args.verb != Verb.clean:
-        return
-
     if not args.skip_final_phase:
         with complete_step("Removing output files…"):
             unlink_try_hard(args.output)
@@ -8115,16 +8112,18 @@ def run_verb(raw: argparse.Namespace) -> None:
 
     if args.verb in MKOSI_COMMANDS_SUDO:
         check_root()
-        unlink_output(args)
 
-    if args.verb == Verb.build:
+    if args.verb == Verb.build and not args.force:
         check_output(args)
 
+    if needs_build(args) or args.verb == Verb.clean:
+        check_root()
+        unlink_output(args)
+
     if args.verb == Verb.summary:
         print_summary(args)
 
     if needs_build(args):
-        check_root()
         check_native(args)
         init_namespace(args)
         manifest = build_stuff(args)
index 3133f8b33a1f6658544eb347e515b772dc4c6c8b..14e25e18e7e77d9ff50b47dad8b1e4b8a0f72f28 100644 (file)
@@ -15,7 +15,7 @@ from typing import Any, Iterator, Optional, Sequence, TextIO, Union
 import pexpect  # type: ignore
 
 from . import (
-    MKOSI_COMMANDS_SUDO,
+    MKOSI_COMMANDS_NEED_BUILD,
     CompletedProcess,
     build_stuff,
     check_native,
@@ -106,7 +106,7 @@ class Machine:
         assert self._serial is not None or self.args.verb == Verb.shell
 
     def build(self) -> None:
-        if self.args.verb in MKOSI_COMMANDS_SUDO:
+        if self.args.verb in MKOSI_COMMANDS_NEED_BUILD + (Verb.build, Verb.clean):
             check_root()
             unlink_output(self.args)