Hi all, I've just submitted a patch to upstream Xen which will be of interest to rumprun users who want to run "rumprun -i" non-interactively, ie. without stdin and piping stdout to eg. logger. This also allows you to trivially run a rumprun unokernel as a systemd service.
I'm including the patch here, it's very non-intrusive and if you want to try it out on an Xen setup it is sufficient to rebuild only the "xenconsole" binary from source and replace it on your system. I also have a version for Xen 4.4.1 (in Debian jessie) should someone want that. Martin >From 1594369612ca712da5f14c63bc500aef3c960e2b Mon Sep 17 00:00:00 2001 From: Martin Lucina <[email protected]> Date: Wed, 22 Jul 2015 18:48:09 +0200 Subject: [PATCH] xenconsole: Allow non-interactive use If xenconsole is run with stdin closed or redirected to /dev/null, console_loop() will return immediately due to failure to read from STDIN_FILENO. This patch tests if stdin and stdout are both connected to a TTY and, if not, xenconsole will not attempt to read from stdin or modify stdout terminal attributes. Existing behaviour when xenconsole is run from a terminal does not change. This allows for non-interactive use, eg. running "xl create -c" under systemd or piping the output of "xl console" to another command. Signed-off-by: Martin Lucina <[email protected]> Cc: Ian Jackson <[email protected]> Cc: Stefano Stabellini <[email protected]> Cc: Ian Campbell <[email protected]> Cc: Wei Liu <[email protected]> --- tools/console/client/main.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/tools/console/client/main.c b/tools/console/client/main.c index f4c783b..8a42101 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -168,7 +168,8 @@ static void restore_term(int fd, struct termios *old) tcsetattr(fd, TCSANOW, old); } -static int console_loop(int fd, struct xs_handle *xs, char *pty_path) +static int console_loop(int fd, struct xs_handle *xs, char *pty_path, + bool interactive) { int ret, xs_fd = xs_fileno(xs), max_fd; @@ -176,8 +177,13 @@ static int console_loop(int fd, struct xs_handle *xs, char *pty_path) fd_set fds; FD_ZERO(&fds); - FD_SET(STDIN_FILENO, &fds); - max_fd = STDIN_FILENO; + if (interactive) { + FD_SET(STDIN_FILENO, &fds); + max_fd = STDIN_FILENO; + } + else { + max_fd = -1; + } FD_SET(xs_fd, &fds); if (xs_fd > max_fd) max_fd = xs_fd; if (fd != -1) FD_SET(fd, &fds); @@ -284,6 +290,10 @@ int main(int argc, char **argv) struct xs_handle *xs; char *end; console_type type = CONSOLE_INVAL; + bool interactive = 0; + + if (isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) + interactive = 1; while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) { switch(ch) { @@ -390,9 +400,11 @@ int main(int argc, char **argv) } init_term(spty, &attr); - init_term(STDIN_FILENO, &stdin_old_attr); - atexit(restore_term_stdin); /* if this fails, oh dear */ - console_loop(spty, xs, path); + if (interactive) { + init_term(STDIN_FILENO, &stdin_old_attr); + atexit(restore_term_stdin); /* if this fails, oh dear */ + } + console_loop(spty, xs, path, interactive); free(path); free(dom_path); -- 2.1.4
