[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] tools/oxenstored: Render backtraces more nicely in Syslog


  • To: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • From: Christian Lindig <christian.lindig@xxxxxxxxxx>
  • Date: Fri, 2 Dec 2022 09:14:22 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lbvyAF1A4AWxEnk7jMvx//LRJm6IgEx0w3Poeek+NVw=; b=ekeZOCPz4Y0jmltPMES5Cx44wirzPFe82rTyAcNvV5VcodBmurBO96qrAZxwU1RqTeHkEU0xzHlKENiihyCrebDJv9JzOjuJNzKIVaHIAMth7ey3YP1zkgZSxxf9GFW9qt4MM0pQWdRIGo/N/2Pf1Yx9zC8IpKgFCwbEfOmHJ0wo9SBzXzMriIQIRlNz5D7JmO+FiwpKc+EqzNwZwT0VEyH06C7JOekA1VYh/Mogoh/G2rDtPxkxpKJIIyd7JKL9lJYaAzkUjVVWM1U9e6dEM0KkLQ7bqpewppcQmBRtwm2XHYg2yzsOwFvo3jA/XI00nu9WBlWexBOLfnkDD1gc4Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CRnyKbXd7Jb9J0D9VWk2ob1X++RQzEjezH+CMMUFFEdNyKp8mAd0uADBPCqdVLUEgTLPMXe2mKI0VlR9L1GqyzNpW3EANeJqzFqR289QxLJED/yCSc9dZPBzhkuiQke3Vn89hrawDi4wXVcALS26alr5+eYTeSOCihRuSnV7rjC+zZwnm4cV/Y4xRr3XWIdoAj12pCtQ4NBKkM/OtBbQkRXnJnVvogy6tyMVc2xeepl4QHVDH3KLhyu4gbA0bBcDndkwLmXchS+33WhF0qmpDyBv0uTM0I/dzdeg5ThWgxs9Q9MxpwQNdYgcultp0tKL8+9hs5dTgvyZTGB63Q+sNw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Edwin Torok <edvin.torok@xxxxxxxxxx>, Rob Hoes <Rob.Hoes@xxxxxxxxxx>
  • Delivery-date: Fri, 02 Dec 2022 09:14:31 +0000
  • Ironport-data: A9a23:tJSn7Kk8nXZaVdveSMGymDjo5gyfJ0RdPkR7XQ2eYbSJt1+Wr1Gzt xJMXGvQb//fZ2r0ctggPI7gpxlXu5CDnNExGlNupSExEiMWpZLJC+rCIxarNUt+DCFhoGFPt JxCN4aafKjYaleG+39B55C49SEUOZmgH+a6U6icf3grHmeIcQ954Tp7gek1n4V0ttawBgKJq LvartbWfVSowFaYCEpNg064gE4p7aqaVA8w5ARkP6kR5AWGzhH5MbpETU2PByqgKmVrNrbSq 9brlNmR4m7f9hExPdKp+p6TnpoiG+O60aCm0xK6aoD66vRwjnVaPpUTbZLwXXx/mTSR9+2d/ f0W3XCGpaXFCYWX8AgVe0Ew/yiTpsSq8pefSZS0mZT7I0Er7xIAahihZa07FdRwxwp5PY1B3 fMCLmE1fA6Cvvi/wbSYFeBRm88pdta+aevzulk4pd3YJdAPZMmaBonvu5pf1jp2gd1SF/HDY cZfcSBocBnLfxxIPBEQFY46m+CrwHL4dlW0qnrM/fZxvzeVkVM3ieezWDbWUoXiqcF9lUaCp 3na/m3/RBUbMtCexhKO8262h/+JliT+MG4XPO3mrKU22gTLroAVIAc2fgu7/tmmtmiVYPMGL XQUxQMoirdnoSRHSfG4BXVUukWsrhMaHtZdDeA+wAWM0bbPpRaUAHAeSTxMY8Bgs9U5LRQm3 0GEt8nkDjtutPuSU331y1uPhTa7OCxQIWpcYyYBFFIB+4O6/991iQ/TRNF+FqLzlsfyBTz73 zGNqm45mqkXiskIka68+Dgrng6Rm3QAdSZtji2/Y45vxloRiFKND2Bw1WXm0A==
  • Ironport-hdrordr: A9a23:H/7+Bat2XYqqiBYevubo4vhj7skCpIMji2hC6mlwRA09TyXGra 2TdaUgvyMc1gx7ZJhAo6HnBEDkex/hHPFOkO0s1NuZLWvbUQiTXeJfBOnZskTd8kTFn4Yzu8 ddmsBFeaXN5DNB/KHHCWeDYrMdKe28gduVbKrlvgRQZDAvT5slwxZyCw6dHEEzbA5aBaAhHJ 7ZwsZcvTKvdVkec8z+XxA+Lp3+juyOsKijTQ8NBhYh5gXLpTS06ITiGxzd+hsFSTtAzZor7G CAuQ3k4aeIte2913bnph3uxqUTvOGk5spIBcSKhMRQAjLwijywbIAkYLGGtCBdmpDQ1L5/+u Osnz4Qe+BIr1/BdGC8phXgnyP61iw11nPkwViExVP+vM3QXlsBeoB8rLMcViGcx1srvdl63q 4O9XmerYBrARTJmzm4z8TUVittilG/rRMZ4KUuZkRkIMYjgYJq3MUiFQJuYeE99RvBmfca+T xVfYnhDPU/SyLkU5mWhBgi/DWWZAVOIv63eDl+hiWr6UktoJlY9Tpo+CVNpAZxyHt6cegx29 j5
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZBcqVVYy6JUP3JkCD8gm8EMBh8K5aUVgA
  • Thread-topic: [PATCH] tools/oxenstored: Render backtraces more nicely in Syslog


> On 1 Dec 2022, at 21:19, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> wrote:
> 
> fallback_exception_handler feeds a string with embedded newlines directly into
> syslog().  While this is an improvement on getting nothing, syslogd escapes
> all control characters it gets, and emits one (long) line into the log.
> 
> Fix the problem generally in the syslog stub.  As we already have a local copy
> of the string, split it in place and emit one syslog() call per line.
> 
> Also tweak Logging.msg_of to avoid putting an extra newline on a string which
> already ends with one.
> 
> Fixes: ee7815f49faf ("tools/oxenstored: Set uncaught exception handler")
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Christian Lindig <christian.lindig@xxxxxxxxxx>
> CC: David Scott <dave@xxxxxxxxxx>
> CC: Edwin Torok <edvin.torok@xxxxxxxxxx>
> CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>

Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>

> ---
> tools/ocaml/xenstored/logging.ml     |  2 +-
> tools/ocaml/xenstored/syslog_stubs.c | 26 +++++++++++++++++++++++---
> 2 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/ocaml/xenstored/logging.ml 
> b/tools/ocaml/xenstored/logging.ml
> index 255051437d60..f233bc9a3956 100644
> --- a/tools/ocaml/xenstored/logging.ml
> +++ b/tools/ocaml/xenstored/logging.ml
> @@ -344,7 +344,7 @@ let watch_not_fired ~con perms path =
>       access_logging ~tid:0 ~con ~data Watch_not_fired ~level:Info
> 
> let msg_of exn bt =
> -     Printf.sprintf "Fatal exception: %s\n%s\n" (Printexc.to_string exn)
> +     Printf.sprintf "Fatal exception: %s\n%s" (Printexc.to_string exn)
>               (Printexc.raw_backtrace_to_string bt)
> 
> let fallback_exception_handler exn bt =
> diff --git a/tools/ocaml/xenstored/syslog_stubs.c 
> b/tools/ocaml/xenstored/syslog_stubs.c
> index e16c3a9491d0..760e78ff73dc 100644
> --- a/tools/ocaml/xenstored/syslog_stubs.c
> +++ b/tools/ocaml/xenstored/syslog_stubs.c
> @@ -37,14 +37,34 @@ value stub_syslog(value facility, value level, value msg)
> {
>       CAMLparam3(facility, level, msg);
>       char *c_msg = strdup(String_val(msg));

Is this working as expected? An OCaml string may contain embedded null bytes.

> +     char *s = c_msg, *ss;
>       int c_facility = __syslog_facility_table[Int_val(facility)]
>                      | __syslog_level_table[Int_val(level)];
> 
>       if ( !c_msg )
>               caml_raise_out_of_memory();
> -     caml_enter_blocking_section();
> -     syslog(c_facility, "%s", c_msg);
> -     caml_leave_blocking_section();
> +
> +     /*
> +      * syslog() doesn't like embedded newlines, and c_msg generally
> +      * contains them.
> +      *
> +      * Split the message in place by converting \n to \0, and issue one
> +      * syslog() call per line, skipping the final iteration if c_msg ends
> +      * with a newline anyway.
> +      */
> +     do {
> +             ss = strchr(s, '\n');
> +             if ( ss )
> +                     *ss = '\0';
> +             else if ( *s == '\0' )
> +                     break;
> +
> +             caml_enter_blocking_section();
> +             syslog(c_facility, "%s", s);
> +             caml_leave_blocking_section();
> +
> +             s = ss + 1;
> +     } while ( ss );
> 
>       free(c_msg);
>       CAMLreturn(Val_unit);
> -- 
> 2.11.0
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.