]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vmspawn: print a helpful message when we start the VM
authorLennart Poettering <lennart@poettering.net>
Fri, 19 Jan 2024 18:32:36 +0000 (19:32 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 22 Jan 2024 15:24:00 +0000 (16:24 +0100)
Let people know how they can exit the VM, it's not obvious after all.

src/vmspawn/vmspawn.c

index 08d5a647ed69a0fd99ab07c3942a05816281720e..b2c040b037a06575d36649a89e3239ede3391377 100644 (file)
@@ -36,6 +36,7 @@
 #include "vmspawn-settings.h"
 #include "vmspawn-util.h"
 
+static bool arg_quiet = false;
 static PagerFlags arg_pager_flags = 0;
 static char *arg_image = NULL;
 static char *arg_machine = NULL;
@@ -72,6 +73,7 @@ static int help(void) {
                "%5$sSpawn a command or OS in a virtual machine.%6$s\n\n"
                "  -h --help                 Show this help\n"
                "     --version              Print version string\n"
+               "  -q --quiet                Do not show status information\n"
                "     --no-pager             Do not pipe output into a pager\n"
                "\n%3$sImage:%4$s\n"
                "  -i --image=PATH           Root file system disk image (or device node) for\n"
@@ -124,6 +126,7 @@ static int parse_argv(int argc, char *argv[]) {
         static const struct option options[] = {
                 { "help",            no_argument,       NULL, 'h'                 },
                 { "version",         no_argument,       NULL, ARG_VERSION         },
+                { "quiet",           no_argument,       NULL, 'q'                 },
                 { "no-pager",        no_argument,       NULL, ARG_NO_PAGER        },
                 { "image",           required_argument, NULL, 'i'                 },
                 { "machine",         required_argument, NULL, 'M'                 },
@@ -146,7 +149,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argv);
 
         optind = 0;
-        while ((c = getopt_long(argc, argv, "+hi:M", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "+hi:Mq", options, NULL)) >= 0)
                 switch (c) {
                 case 'h':
                         return help();
@@ -154,6 +157,10 @@ static int parse_argv(int argc, char *argv[]) {
                 case ARG_VERSION:
                         return version();
 
+                case 'q':
+                        arg_quiet = true;
+                        break;
+
                 case 'i':
                         r = parse_path_argument(optarg, /* suppress_root= */ false, &arg_image);
                         if (r < 0)
@@ -804,6 +811,11 @@ static int run(int argc, char *argv[]) {
         if (r < 0)
                 return r;
 
+        if (!arg_quiet)
+                log_info("Spawning VM %s on %s.\n"
+                         "Press Ctrl-a x to kill VM.",
+                         arg_machine, arg_image);
+
         assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGCHLD, -1) >= 0);
 
         return run_virtual_machine();