On 2017-01-19 21:11, Ralf Ramsauer wrote:
> Similar to other tools, like 'tail -f', allow 'jailhosue console' to
> follow the console output when jailhouse gets enabled.
>
> 'jailhouse console' will print all available console log of the
> hypervisor.
>
> 'jailhouse console -f' will print all available console log of the
> hypervisor and append new data as it arrives.
>
> Use this patch to remove a redundant '|' in the usage string of the
> tool.
>
> Signed-off-by: Ralf Ramsauer <[email protected]>
> ---
> tools/jailhouse.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 45 insertions(+), 2 deletions(-)
>
> diff --git a/tools/jailhouse.c b/tools/jailhouse.c
> index 84e5fe3d64..ede6ad4412 100644
> --- a/tools/jailhouse.c
> +++ b/tools/jailhouse.c
> @@ -60,7 +60,7 @@ static void __attribute__((noreturn)) help(char *prog, int
> exit_status)
> {
> const struct extension *ext;
>
> - printf("Usage: %s { COMMAND | --help || --version }\n"
> + printf("Usage: %s { COMMAND | --help | --version }\n"
> "\nAvailable commands:\n"
> " enable SYSCONFIG\n"
> " disable\n"
> @@ -71,7 +71,8 @@ static void __attribute__((noreturn)) help(char *prog, int
> exit_status)
> " [-a | --address ADDRESS] ...\n"
> " cell start { ID | [--name] NAME }\n"
> " cell shutdown { ID | [--name] NAME }\n"
> - " cell destroy { ID | [--name] NAME }\n",
> + " cell destroy { ID | [--name] NAME }\n"
> + " console [-f | --follow]\n",
Let's move that line before the first "cell" command - the extension
scripts will add further "cell" entries, and that breaks ordering.
> basename(prog));
> for (ext = extensions; ext->cmd; ext++)
> printf(" %s %s %s\n", ext->cmd, ext->subcmd, ext->help);
> @@ -79,6 +80,30 @@ static void __attribute__((noreturn)) help(char *prog, int
> exit_status)
> exit(exit_status);
> }
>
> +static int dump_console(int fd, bool non_block)
> +{
> + int ret;
> + char buffer[128];
> +
> + if (non_block) {
> + ret = fcntl(fd, F_GETFL, 0);
> + if (ret == -1)
> + return -errno;
> + ret = fcntl(fd, F_SETFL, ret | O_NONBLOCK);
We can set O_NONBLOCK without reading the current flags - we know that
there are none set.
> + if (ret == -1)
> + return -errno;
> + }
> +
> + do {
> + ret = read(fd, buffer, sizeof(buffer));
> + if (ret < 0)
> + break;
> + ret = write(STDOUT_FILENO, buffer, ret);
> + } while (ret > 0);
> +
> + return ret;
> +}
> +
> static void call_extension_script(const char *cmd, int argc, char *argv[])
> {
> const struct extension *ext;
> @@ -504,6 +529,22 @@ static int cell_management(int argc, char *argv[])
> return err;
> }
>
> +static int console(int argc, char *argv[])
> +{
> + int fd;
> + ssize_t ret;
> + bool non_block = false;
> +
> + if (!(argc == 3 && match_opt(argv[2], "-f", "--follow")))
> + non_block = true;
You should handle invalid options as well and dump help() in that case.
> +
> + fd = open_dev();
> + ret = dump_console(fd, non_block);
> + close(fd);
> +
> + return ret;
> +}
> +
> int main(int argc, char *argv[])
> {
> int fd;
> @@ -522,6 +563,8 @@ int main(int argc, char *argv[])
> close(fd);
> } else if (strcmp(argv[1], "cell") == 0) {
> err = cell_management(argc, argv);
> + } else if (strcmp(argv[1], "console") == 0) {
> + err = console(argc, argv);
> } else if (strcmp(argv[1], "config") == 0 ||
> strcmp(argv[1], "hardware") == 0) {
> call_extension_script(argv[1], argc, argv);
>
Jan
--
You received this message because you are subscribed to the Google Groups
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.