|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH] xenconsole: add option to avoid escape sequences in log
Add --replace-escape, -e option to xenconsoled, which replaces ESC with
'.' in console output written to log file. This makes it slightly safer
to do tail -f on a console output of untrusted guest.
The pty output is unaffected by this option.
Signed-off-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>
---
Is there any more documentation to be updated? I didn't found
xenconsoled man page or such.
---
tools/console/daemon/io.c | 18 ++++++++++++++++++
tools/console/daemon/main.c | 9 +++++++--
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e22009aa39..c8280e0b7c 100644
--- a/tools/console/daemon/io.c
+++ b/tools/console/daemon/io.c
@@ -68,6 +68,7 @@ extern int log_time_hv;
extern int log_time_guest;
extern char *log_dir;
extern int discard_overflowed_data;
+extern int replace_escape;
static int log_time_hv_needts = 1;
static int log_time_guest_needts = 1;
@@ -227,8 +228,25 @@ static inline int console_iter_int_arg3(struct domain *d,
return ret;
}
+static void do_replace_escape(const char *buf, char *dest, int len) {
+ int i;
+
+ memcpy(dest, buf, len);
+ for (i = 0; i < len; i++) {
+ if (dest[i] == '\033')
+ dest[i] = '.';
+ }
+}
+
static int write_all(int fd, const char* buf, size_t len)
{
+ char buf_replaced[len];
+
+ if (replace_escape) {
+ do_replace_escape(buf, buf_replaced, len);
+ buf = buf_replaced;
+ }
+
while (len) {
ssize_t ret = write(fd, buf, len);
if (ret == -1 && errno == EINTR)
diff --git a/tools/console/daemon/main.c b/tools/console/daemon/main.c
index 806d2fd611..b716e38c27 100644
--- a/tools/console/daemon/main.c
+++ b/tools/console/daemon/main.c
@@ -40,6 +40,7 @@ int log_time_hv = 0;
int log_time_guest = 0;
char *log_dir = NULL;
int discard_overflowed_data = 1;
+int replace_escape = 0;
static void handle_hup(int sig)
{
@@ -48,7 +49,7 @@ static void handle_hup(int sig)
static void usage(char *name)
{
- printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all]
[--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o,
--overflow-data=discard|keep]\n", name);
+ printf("Usage: %s [-h] [-V] [-v] [-i] [--log=none|guest|hv|all]
[--log-dir=DIR] [--pid-file=PATH] [-t, --timestamp=none|guest|hv|all] [-o,
--overflow-data=discard|keep] [-e, --replace-escape]\n", name);
}
static void version(char *name)
@@ -93,7 +94,7 @@ static void increase_fd_limit(void)
int main(int argc, char **argv)
{
- const char *sopts = "hVvit:o:";
+ const char *sopts = "hVvit:o:e";
struct option lopts[] = {
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'V' },
@@ -104,6 +105,7 @@ int main(int argc, char **argv)
{ "pid-file", 1, 0, 'p' },
{ "timestamp", 1, 0, 't' },
{ "overflow-data", 1, 0, 'o'},
+ { "replace-escape", 0, 0, 'e'},
{ 0 },
};
bool is_interactive = false;
@@ -168,6 +170,9 @@ int main(int argc, char **argv)
discard_overflowed_data = 1;
}
break;
+ case 'e':
+ replace_escape = 1;
+ break;
case '?':
fprintf(stderr,
"Try `%s --help' for more information\n",
--
2.17.1
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |