Fold dump_console into its only remaining user and add some more error
messages.

Signed-off-by: Jan Kiszka <[email protected]>
---
 tools/jailhouse.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/tools/jailhouse.c b/tools/jailhouse.c
index bc96b099..74029bac 100644
--- a/tools/jailhouse.c
+++ b/tools/jailhouse.c
@@ -80,24 +80,6 @@ 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;
@@ -531,9 +513,10 @@ static int cell_management(int argc, char *argv[])
 
 static int console(int argc, char *argv[])
 {
-       int fd;
-       ssize_t ret;
        bool non_block = true;
+       char buffer[128];
+       ssize_t ret;
+       int fd;
 
        if (argc == 3) {
                if (match_opt(argv[2], "-f", "--follow"))
@@ -543,7 +526,25 @@ static int console(int argc, char *argv[])
        }
 
        fd = open_dev();
-       ret = dump_console(fd, non_block);
+
+       if (non_block) {
+               ret = fcntl(fd, F_SETFL, O_NONBLOCK);
+               if (ret < 0) {
+                       perror("fcntl(set O_NONBLOCK)");
+                       goto out;
+               }
+       }
+
+       do {
+               ret = read(fd, buffer, sizeof(buffer));
+               if (ret < 0) {
+                       perror("read(console)");
+                       break;
+               }
+               ret = write(STDOUT_FILENO, buffer, ret);
+       } while (ret > 0);
+
+out:
        close(fd);
 
        return ret;

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