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 | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)

diff --git a/tools/jailhouse.c b/tools/jailhouse.c
index 84e5fe3d..46f82553 100644
--- a/tools/jailhouse.c
+++ b/tools/jailhouse.c
@@ -60,10 +60,11 @@ 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"
+              "   console [-f | --follow]\n"
               "   cell create CELLCONFIG\n"
               "   cell list\n"
               "   cell load { ID | [--name] NAME } "
@@ -79,6 +80,24 @@ 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 && fcntl(fd, F_SETFL, O_NONBLOCK) == -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 +523,26 @@ 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 = true;
+
+       if (argc == 3) {
+               if (match_opt(argv[2], "-f", "--follow"))
+                       non_block = false;
+               else
+                       help(argv[0], 1);
+       }
+
+       fd = open_dev();
+       ret = dump_console(fd, non_block);
+       close(fd);
+
+       return ret;
+}
+
 int main(int argc, char *argv[])
 {
        int fd;
@@ -522,6 +561,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);
-- 
2.11.0

-- 
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.

Reply via email to