<div dir="ltr"><div class="gmail_default" style="color:#000000">Hi Dmitry,</div><div class="gmail_default" style="color:#000000"><br></div><div class="gmail_default" style="color:#000000">Thanks for the comments! I've attached a v2 patch. <br></div><div class="gmail_default" style="color:#000000"><br></div><div class="gmail_default" style="color:#000000">Regards,</div><div class="gmail_default" style="color:#000000">Shankara<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 8, 2019 at 5:29 PM Dmitry V. Levin <<a href="mailto:ldv@altlinux.org">ldv@altlinux.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On Fri, Jan 11, 2019 at 07:12:11PM -0800, shankarapailoor wrote:<br>
> Hi,<br>
> <br>
> strace doesn't honor xlat_styles when printing rlimit fields. Attached<br>
> is a patch which corrects this.<br>
> <br>
> Regards,<br>
> Shankara Pailoor<br>
<br>
> From 89ef3e2a7634c16d78ca539cda8242e9f72f01c4 Mon Sep 17 00:00:00 2001<br>
> From: Shankara Pailoor <<a href="mailto:shankarapailoor@gmail.com" target="_blank">shankarapailoor@gmail.com</a>><br>
> Date: Fri, 11 Jan 2019 19:07:33 -0800<br>
> Subject: [PATCH v1] handle xlat_styles when printing rlim_cur, rlim_max<br>
> <br>
> * resource.c (sprint_rlimit{32, 64}, print_rlimfield{32,64},<br>
> print_rlimit{32, 64}): handle xlat styles.<br>
> * tests/setrlimit.c: Add XLAT_{ABBREV, RAW, VERBOSE} macros.<br>
> * tests/xgetrlimit.c (sprint_rlim): Likewise.<br>
> * tests/setrlimit-Xabbrev.c: Add new test for rlimit xlat_style.<br>
> * tests/setrlimit-Xraw.c: Likewise.<br>
> * tests/setrlimit-Xverbose.c: Likewise.<br>
> * tests/pure_executables.list: Add setrlimit-X{abbrev, raw,<br>
> verbose} tests.<br>
> * tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a>: Likewise.<br>
> ---<br>
> resource.c | 49 ++++++++++++++++++++++++++++++++-----<br>
> tests/.gitignore | 3 +++<br>
> tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a> | 3 +++<br>
> tests/pure_executables.list | 3 +++<br>
> tests/setrlimit.c | 22 +++++++++++++++++<br>
> tests/xgetrlimit.c | 39 +++++++++++++++++++++++++----<br>
> 6 files changed, 108 insertions(+), 11 deletions(-)<br>
> <br>
> diff --git a/resource.c b/resource.c<br>
> index 724223ef..3572555b 100644<br>
> --- a/resource.c<br>
> +++ b/resource.c<br>
> @@ -20,17 +20,31 @@ static const char *<br>
> sprint_rlim64(uint64_t lim)<br>
> {<br>
> static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];<br>
> + if ((lim != UINT64_MAX && lim % 1024 > 0) || (lim <= 1024))<br>
> + return NULL;<br>
<br>
Instead of replicating the check, ...<br>
> <br>
> if (lim == UINT64_MAX)<br>
> return "RLIM64_INFINITY";<br>
> <br>
> if (lim > 1024 && lim % 1024 == 0)<br>
> xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);<br>
> - else<br>
> - xsprintf(buf, "%" PRIu64, lim);<br>
<br>
... you could just return NULL here.<br>
<br>
Alternatively, you could inverse the check, e.g.<br>
<br>
if (lim <= 1024 || lim % 1024)<br>
return NULL;<br>
xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);<br>
<br>
> return buf;<br>
> }<br>
> <br>
> +static void<br>
> +print_rlimfield64(uint64_t rlim_field) {<br>
> + const char *str = sprint_rlim64(rlim_field);<br>
> +<br>
> + if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV) <br>
> + tprintf("%" PRIu64, rlim_field);<br>
> +<br>
> + if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)<br>
> + return;<br>
> +<br>
> + (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE<br>
> + ? tprints_comment : tprints)(str);<br>
> +}<br>
> +<br>
> static void<br>
> print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)<br>
> {<br>
> @@ -40,8 +54,11 @@ print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)<br>
> } rlim;<br>
> <br>
> if (!umove_or_printaddr(tcp, addr, &rlim)) {<br>
> - tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));<br>
> - tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));<br>
> + tprints("{rlim_cur=");<br>
> + print_rlimfield64(rlim.rlim_cur);<br>
> + tprints(", rlim_max=");<br>
> + print_rlimfield64(rlim.rlim_max);<br>
> + tprints("}");<br>
> }<br>
> }<br>
> <br>
> @@ -52,6 +69,9 @@ sprint_rlim32(uint32_t lim)<br>
> {<br>
> static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];<br>
> <br>
> + if ((lim != UINT32_MAX && lim % 1024 > 0) || (lim <= 1024))<br>
> + return NULL;<br>
<br>
Likewise, there is no need to replicate the check.<br>
<br>
> if (lim == UINT32_MAX)<br>
> return "RLIM_INFINITY";<br>
> <br>
> @@ -62,6 +82,20 @@ sprint_rlim32(uint32_t lim)<br>
> return buf;<br>
> }<br>
> <br>
> +static void<br>
> +print_rlimfield32(uint32_t rlim_field) {<br>
> + const char *str = sprint_rlim32(rlim_field);<br>
> +<br>
> + if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV) <br>
> + tprintf("%" PRIu32, rlim_field);<br>
> +<br>
> + if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)<br>
> + return;<br>
> +<br>
> + (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE<br>
> + ? tprints_comment : tprints)(str);<br>
> +}<br>
> +<br>
> static void<br>
> print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)<br>
> {<br>
> @@ -71,8 +105,11 @@ print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)<br>
> } rlim;<br>
> <br>
> if (!umove_or_printaddr(tcp, addr, &rlim)) {<br>
> - tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));<br>
> - tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));<br>
> + tprints("{rlim_cur=");<br>
> + print_rlimfield32(rlim.rlim_cur);<br>
> + tprints(", rlim_max=");<br>
> + print_rlimfield32(rlim.rlim_max);<br>
> + tprints("}");<br>
> }<br>
> }<br>
> <br>
> diff --git a/tests/.gitignore b/tests/.gitignore<br>
> index 24b17017..327a75cf 100644<br>
> --- a/tests/.gitignore<br>
> +++ b/tests/.gitignore<br>
> @@ -501,6 +501,9 @@ setresuid32<br>
> setreuid<br>
> setreuid32<br>
> setrlimit<br>
> +setrlimit-Xabbrev<br>
> +setrlimit-Xraw<br>
> +setrlimit-Xverbose<br>
> setuid<br>
> setuid32<br>
> shmxt<br>
> diff --git a/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a> b/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a><br>
> index e2e70a12..1c11d2da 100644<br>
> --- a/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a><br>
> +++ b/tests/<a href="http://gen_tests.in" rel="noreferrer" target="_blank">gen_tests.in</a><br>
> @@ -414,6 +414,9 @@ setresuid32 -a21<br>
> setreuid -a15<br>
> setreuid32 -a17<br>
> setrlimit -a27<br>
> +setrlimit-Xabbrev -a1 -e trace=setrlimit -Xabbrev<br>
> +setrlimit-Xraw -a1 -e trace=setrlimit -Xraw<br>
> +setrlimit-Xverbose -a1 -e trace=setrlimit -Xverbose<br>
> setuid -a10<br>
> setuid32 -a12<br>
> shmxt -a11 -e trace='/(osf_)?shmat,shmdt'<br>
> diff --git a/tests/pure_executables.list b/tests/pure_executables.list<br>
> index 23aabb9e..616ee9ed 100755<br>
> --- a/tests/pure_executables.list<br>
> +++ b/tests/pure_executables.list<br>
> @@ -420,6 +420,9 @@ setresuid32<br>
> setreuid<br>
> setreuid32<br>
> setrlimit<br>
> +setrlimit-Xabbrev<br>
> +setrlimit-Xraw<br>
> +setrlimit-Xverbose<br>
> setuid<br>
> setuid32<br>
> shmxt<br>
> diff --git a/tests/setrlimit.c b/tests/setrlimit.c<br>
> index f199abe1..084e7beb 100644<br>
> --- a/tests/setrlimit.c<br>
> +++ b/tests/setrlimit.c<br>
> @@ -23,7 +23,14 @@ main(void)<br>
> for (xlat = resources; xlat->str; ++xlat) {<br>
> unsigned long res = 0xfacefeed00000000ULL | xlat->val;<br>
> long rc = syscall(__NR_setrlimit, res, 0);<br>
> +#if XLAT_RAW<br>
> + printf("setrlimit(%#lx, NULL) = %s\n", xlat->val, sprintrc(rc));<br>
> +#elif XLAT_VERBOSE<br>
> + printf("setrlimit(%#lx /* %s */, NULL) = %s\n", xlat->val,<br>
> + xlat->str, sprintrc(rc));<br>
> +#else<br>
> printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));<br>
> +#endif<br>
> <br>
> struct rlimit libc_rlim = {};<br>
> if (getrlimit((int) res, &libc_rlim))<br>
> @@ -33,10 +40,25 @@ main(void)<br>
> <br>
> rc = syscall(__NR_setrlimit, res, rlimit);<br>
> const char *errstr = sprintrc(rc);<br>
> +#if XLAT_RAW<br>
> + printf("setrlimit(%#lx, {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> + xlat->val,<br>
> + sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> + errstr);<br>
> +#elif XLAT_VERBOSE<br>
> + printf("setrlimit(%#lx /* %s */,"<br>
> + " {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> + xlat->val,<br>
> + xlat->str,<br>
> + sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> + errstr);<br>
> +#else<br>
> printf("setrlimit(%s, {rlim_cur=%s, rlim_max=%s}) = %s\n",<br>
> xlat->str,<br>
> sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),<br>
> errstr);<br>
> +#endif<br>
> +<br>
> }<br>
> <br>
> puts("+++ exited with 0 +++");<br>
> diff --git a/tests/xgetrlimit.c b/tests/xgetrlimit.c<br>
> index b807f290..3efd4baf 100644<br>
> --- a/tests/xgetrlimit.c<br>
> +++ b/tests/xgetrlimit.c<br>
> @@ -18,24 +18,53 @@<br>
> <br>
> const char *<br>
> sprint_rlim(kernel_ulong_t lim)<br>
> -{<br>
> +{ <br>
> + static char buf[2][1024+sizeof(lim)*3 + sizeof("*1024")];<br>
<br>
Why 1024?<br>
<br>
<br>
-- <br>
ldv<br>
-- <br>
Strace-devel mailing list<br>
<a href="mailto:Strace-devel@lists.strace.io" target="_blank">Strace-devel@lists.strace.io</a><br>
<a href="https://lists.strace.io/mailman/listinfo/strace-devel" rel="noreferrer" target="_blank">https://lists.strace.io/mailman/listinfo/strace-devel</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">Regards,<div>Shankara Pailoor</div></div>