From: Lennart Poettering Date: Fri, 19 Jan 2024 18:32:36 +0000 (+0100) Subject: vmspawn: print a helpful message when we start the VM X-Git-Tag: v256-rc1~1083^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dbb2718f927dfb9202043f6f57a6b37cafaa9fa9;p=thirdparty%2Fsystemd.git vmspawn: print a helpful message when we start the VM Let people know how they can exit the VM, it's not obvious after all. --- diff --git a/src/vmspawn/vmspawn.c b/src/vmspawn/vmspawn.c index 08d5a647ed6..b2c040b037a 100644 --- a/src/vmspawn/vmspawn.c +++ b/src/vmspawn/vmspawn.c @@ -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();