* [PATCH v2] xenconsole: add option to avoid escape sequences in log
@ 2018-07-31 3:15 Marek Marczykowski-Górecki
2018-07-31 9:10 ` Wei Liu
0 siblings, 1 reply; 3+ messages in thread
From: Marek Marczykowski-Górecki @ 2018-07-31 3:15 UTC (permalink / raw)
To: xen-devel
Cc: Wei Liu, Ian Jackson, Marek Marczykowski-Górecki, xen-devel
Add --replace-escape 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@invisiblethingslab.com>
---
Changes in v2:
- optimize do_replace_escape() per Wei's suggestion
- expand help string
- avoid variable sized array on stack per Christopher's suggestion
(although this made the code a little more ugly :/ - I try hard to
not impact performance when this option is disabled)
---
tools/console/daemon/io.c | 27 ++++++++++++++++++++++++++-
tools/console/daemon/main.c | 8 +++++++-
2 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c
index e22009aa39..1457b954fa 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,10 +228,34 @@ static inline int console_iter_int_arg3(struct domain *d,
return ret;
}
+static void do_replace_escape(const char *src, char *dest, int len)
+{
+ int i;
+
+ for (i = 0; i < len; i++) {
+ if (src[i] == '\033')
+ dest[i] = '.';
+ else
+ dest[i] = src[i];
+ }
+}
+
static int write_all(int fd, const char* buf, size_t len)
{
+ char buf_replaced[1024];
+ size_t this_round;
+
while (len) {
- ssize_t ret = write(fd, buf, len);
+ ssize_t ret;
+ if (replace_escape) {
+ if (len > sizeof(buf_replaced))
+ this_round = sizeof(buf_replaced);
+ else
+ this_round = len;
+ do_replace_escape(buf, buf_replaced, this_round);
+ ret = write(fd, buf_replaced, this_round);
+ } else
+ ret = write(fd, buf, len);
if (ret == -1 && errno == EINTR)
continue;
if (ret <= 0)
diff --git a/tools/console/daemon/main.c b/tools/console/daemon/main.c
index 806d2fd611..5d9d55b430 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,8 @@ 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] [--replace-escape]\n", name);
+ printf(" --replace-escape - replace ESC character with dot when writing console log\n");
}
static void version(char *name)
@@ -104,6 +106,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 +171,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@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] xenconsole: add option to avoid escape sequences in log
2018-07-31 3:15 [PATCH v2] xenconsole: add option to avoid escape sequences in log Marek Marczykowski-Górecki
@ 2018-07-31 9:10 ` Wei Liu
2018-07-31 16:11 ` Marek Marczykowski-Górecki
0 siblings, 1 reply; 3+ messages in thread
From: Wei Liu @ 2018-07-31 9:10 UTC (permalink / raw)
To: Marek Marczykowski-Górecki
Cc: Wei Liu, Ian Jackson, xen-devel, xen-devel
On Tue, Jul 31, 2018 at 05:15:32AM +0200, Marek Marczykowski-Górecki wrote:
> Add --replace-escape 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@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
... though I would like to make a minor modification when committing.
See below.
> static int write_all(int fd, const char* buf, size_t len)
> {
> + char buf_replaced[1024];
> + size_t this_round;
These two can be moved into ...
> +
> while (len) {
> - ssize_t ret = write(fd, buf, len);
> + ssize_t ret;
> + if (replace_escape) {
... here.
Let me know if you disagree.
> + if (len > sizeof(buf_replaced))
> + this_round = sizeof(buf_replaced);
> + else
> + this_round = len;
> + do_replace_escape(buf, buf_replaced, this_round);
> + ret = write(fd, buf_replaced, this_round);
> + } else
> + ret = write(fd, buf, len);
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] xenconsole: add option to avoid escape sequences in log
2018-07-31 9:10 ` Wei Liu
@ 2018-07-31 16:11 ` Marek Marczykowski-Górecki
0 siblings, 0 replies; 3+ messages in thread
From: Marek Marczykowski-Górecki @ 2018-07-31 16:11 UTC (permalink / raw)
To: Wei Liu; +Cc: xen-devel, Ian Jackson
[-- Attachment #1.1: Type: text/plain, Size: 1483 bytes --]
On Tue, Jul 31, 2018 at 10:10:10AM +0100, Wei Liu wrote:
> On Tue, Jul 31, 2018 at 05:15:32AM +0200, Marek Marczykowski-Górecki wrote:
> > Add --replace-escape 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@invisiblethingslab.com>
>
> Acked-by: Wei Liu <wei.liu2@citrix.com>
>
> ... though I would like to make a minor modification when committing.
> See below.
>
> > static int write_all(int fd, const char* buf, size_t len)
> > {
> > + char buf_replaced[1024];
> > + size_t this_round;
>
> These two can be moved into ...
>
> > +
> > while (len) {
> > - ssize_t ret = write(fd, buf, len);
> > + ssize_t ret;
> > + if (replace_escape) {
>
> ... here.
>
> Let me know if you disagree.
Sure, that's fine with me.
> > + if (len > sizeof(buf_replaced))
> > + this_round = sizeof(buf_replaced);
> > + else
> > + this_round = len;
> > + do_replace_escape(buf, buf_replaced, this_round);
> > + ret = write(fd, buf_replaced, this_round);
> > + } else
> > + ret = write(fd, buf, len);
--
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 157 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-07-31 16:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-31 3:15 [PATCH v2] xenconsole: add option to avoid escape sequences in log Marek Marczykowski-Górecki
2018-07-31 9:10 ` Wei Liu
2018-07-31 16:11 ` Marek Marczykowski-Górecki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).