]> granicus.if.org Git - strace/commitdiff
Honor xlat styles when decoding resource limits
authorShankara Pailoor <shankarapailoor@gmail.com>
Sat, 12 Jan 2019 03:07:33 +0000 (19:07 -0800)
committerDmitry V. Levin <ldv@altlinux.org>
Sun, 17 Feb 2019 22:28:31 +0000 (22:28 +0000)
* resource.c (sprint_rlim64, sprint_rlim32): Remove.
(print_rlim64_t, print_rlim32_t): New functions.
(print_rlimit64, print_rlimit32): Use them.
* tests/setrlimit-Xabbrev.c: New file.
* tests/setrlimit-Xraw.c: Likewise.
* tests/setrlimit-Xverbose.c: Likewise.
* tests/setrlimit.c (main): Handle XLAT_ABBREV, XLAT_RAW,
and XLAT_VERBOSE macros.
* tests/xgetrlimit.c (sprint_rlim): Likewise.
* tests/gen_tests.in (setrlimit-Xabbrev, setrlimit-Xraw,
setrlimit-Xverbose): New tests.
* tests/pure_executables.list: Add setrlimit-Xabbrev, setrlimit-Xraw,
and setrlimit-Xverbose.
* tests/.gitignore: Likewise.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
resource.c
tests/.gitignore
tests/gen_tests.in
tests/pure_executables.list
tests/setrlimit-Xabbrev.c [new file with mode: 0644]
tests/setrlimit-Xraw.c [new file with mode: 0644]
tests/setrlimit-Xverbose.c [new file with mode: 0644]
tests/setrlimit.c
tests/xgetrlimit.c

index 724223ef03f51c6a7bb102be48a73fcd4cac58ad..259840a6c9cde086fbd65fb885707d6edf1c541e 100644 (file)
 
 #include "xlat/resources.h"
 
-static const char *
-sprint_rlim64(uint64_t lim)
-{
-       static char buf[sizeof(uint64_t)*3 + sizeof("*1024")];
+static void
+print_rlim64_t(uint64_t lim) {
+       const char *str = NULL;
 
        if (lim == UINT64_MAX)
-               return "RLIM64_INFINITY";
+               str = "RLIM64_INFINITY";
+       else if (lim > 1024 && lim % 1024 == 0) {
+               static char buf[sizeof(lim) * 3 + sizeof("*1024")];
 
-       if (lim > 1024 && lim % 1024 == 0)
                xsprintf(buf, "%" PRIu64 "*1024", lim / 1024);
-       else
-               xsprintf(buf, "%" PRIu64, lim);
-       return buf;
+               str = buf;
+       }
+
+       if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+               tprintf("%" PRIu64, lim);
+
+       if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+               return;
+
+       (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
+                ? tprints_comment : tprints)(str);
 }
 
 static void
@@ -40,26 +48,37 @@ print_rlimit64(struct tcb *const tcp, const kernel_ulong_t addr)
        } rlim;
 
        if (!umove_or_printaddr(tcp, addr, &rlim)) {
-               tprintf("{rlim_cur=%s,", sprint_rlim64(rlim.rlim_cur));
-               tprintf(" rlim_max=%s}", sprint_rlim64(rlim.rlim_max));
+               tprints("{rlim_cur=");
+               print_rlim64_t(rlim.rlim_cur);
+               tprints(", rlim_max=");
+               print_rlim64_t(rlim.rlim_max);
+               tprints("}");
        }
 }
 
 #if !defined(current_wordsize) || current_wordsize == 4
 
-static const char *
-sprint_rlim32(uint32_t lim)
-{
-       static char buf[sizeof(uint32_t)*3 + sizeof("*1024")];
+static void
+print_rlim32_t(uint32_t lim) {
+       const char *str = NULL;
 
        if (lim == UINT32_MAX)
-               return "RLIM_INFINITY";
+               str = "RLIM_INFINITY";
+       else if (lim > 1024 && lim % 1024 == 0) {
+               static char buf[sizeof(lim) * 3 + sizeof("*1024")];
 
-       if (lim > 1024 && lim % 1024 == 0)
                xsprintf(buf, "%" PRIu32 "*1024", lim / 1024);
-       else
-               xsprintf(buf, "%" PRIu32, lim);
-       return buf;
+               str = buf;
+       }
+
+       if (!str || xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+               tprintf("%" PRIu32, lim);
+
+       if (!str || xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+               return;
+
+       (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
+                ? tprints_comment : tprints)(str);
 }
 
 static void
@@ -71,8 +90,11 @@ print_rlimit32(struct tcb *const tcp, const kernel_ulong_t addr)
        } rlim;
 
        if (!umove_or_printaddr(tcp, addr, &rlim)) {
-               tprintf("{rlim_cur=%s,", sprint_rlim32(rlim.rlim_cur));
-               tprintf(" rlim_max=%s}", sprint_rlim32(rlim.rlim_max));
+               tprints("{rlim_cur=");
+               print_rlim32_t(rlim.rlim_cur);
+               tprints(", rlim_max=");
+               print_rlim32_t(rlim.rlim_max);
+               tprints("}");
        }
 }
 
index eb08d8f98d968d25f97f10e4aafc7012ee985bbf..5fd5c0a9c62afe2fd3c13b10acb977783baa664b 100644 (file)
@@ -502,6 +502,9 @@ setresuid32
 setreuid
 setreuid32
 setrlimit
+setrlimit-Xabbrev
+setrlimit-Xraw
+setrlimit-Xverbose
 setuid
 setuid32
 shmxt
index 9cb21491adbd72ef7e1cabd7ec9ab254269aa02e..b988656581df7a88bf01fefcbc53e487ee5528dd 100644 (file)
@@ -414,6 +414,9 @@ setresuid32 -a21
 setreuid       -a15
 setreuid32     -a17
 setrlimit      -a27
+setrlimit-Xabbrev      -a27 -e trace=setrlimit -Xabbrev
+setrlimit-Xraw -a19 -e trace=setrlimit -Xraw
+setrlimit-Xverbose     -a36 -e trace=setrlimit -Xverbose
 setuid -a10
 setuid32       -a12
 shmxt  -a11 -e trace='/(osf_)?shmat,shmdt'
index 23aabb9edbba7bc565c86ca19075c5d3bbd43d12..616ee9ed095d7033f7dc3b7d1100eeac3d71c1bd 100755 (executable)
@@ -420,6 +420,9 @@ setresuid32
 setreuid
 setreuid32
 setrlimit
+setrlimit-Xabbrev
+setrlimit-Xraw
+setrlimit-Xverbose
 setuid
 setuid32
 shmxt
diff --git a/tests/setrlimit-Xabbrev.c b/tests/setrlimit-Xabbrev.c
new file mode 100644 (file)
index 0000000..d5cf2ad
--- /dev/null
@@ -0,0 +1 @@
+#include "setrlimit.c"
diff --git a/tests/setrlimit-Xraw.c b/tests/setrlimit-Xraw.c
new file mode 100644 (file)
index 0000000..1a5ead0
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW 1
+#include "setrlimit.c"
diff --git a/tests/setrlimit-Xverbose.c b/tests/setrlimit-Xverbose.c
new file mode 100644 (file)
index 0000000..20cd135
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "setrlimit.c"
index f199abe1c4666e0b2b678f29bc778cef2ebe0e61..a128d5a84118a106e751cfb3027faae3f6fdf2a8 100644 (file)
@@ -23,7 +23,16 @@ main(void)
        for (xlat = resources; xlat->str; ++xlat) {
                unsigned long res = 0xfacefeed00000000ULL | xlat->val;
                long rc = syscall(__NR_setrlimit, res, 0);
+# if XLAT_RAW
+               printf("setrlimit(%#x, NULL) = %s\n",
+                      (unsigned int) xlat->val, sprintrc(rc));
+# elif XLAT_VERBOSE
+               printf("setrlimit(%#x /* %s */, NULL) = %s\n",
+                      (unsigned int) xlat->val,
+                      xlat->str, sprintrc(rc));
+# else
                printf("setrlimit(%s, NULL) = %s\n", xlat->str, sprintrc(rc));
+# endif
 
                struct rlimit libc_rlim = {};
                if (getrlimit((int) res, &libc_rlim))
@@ -33,10 +42,23 @@ main(void)
 
                rc = syscall(__NR_setrlimit, res, rlimit);
                const char *errstr = sprintrc(rc);
+# if XLAT_RAW
+               printf("setrlimit(%#x, {rlim_cur=%s, rlim_max=%s}) = %s\n",
+                      (unsigned int) xlat->val,
+                      sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
+                      errstr);
+# elif XLAT_VERBOSE
+               printf("setrlimit(%#x /* %s */,"
+                      " {rlim_cur=%s, rlim_max=%s}) = %s\n",
+                      (unsigned int) xlat->val, xlat->str,
+                      sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
+                      errstr);
+# else
                printf("setrlimit(%s, {rlim_cur=%s, rlim_max=%s}) = %s\n",
                       xlat->str,
                       sprint_rlim(rlimit[0]), sprint_rlim(rlimit[1]),
                       errstr);
+# endif
        }
 
        puts("+++ exited with 0 +++");
index b807f2903ce7c6b5e0a89a485bf9caa0832cb109..deaad254368aab66c55452faea914441ed8262e2 100644 (file)
 const char *
 sprint_rlim(kernel_ulong_t lim)
 {
+       static char buf[2][ /* space for 2 llu strings */
+                               2*sizeof(lim)*3 +
+                           /* space for XLAT_STYLE_ABBREV decoding */
+                               sizeof("*1024") + sizeof("RLIM64_INFINITY") +
+                           /* space for C style comments */
+                               6];
+       static unsigned int i;
+
+       i &= 1;
+
+#if XLAT_RAW
+       sprintf(buf[i], "%llu", (unsigned long long) lim);
+       return buf[i++];
+#else
        if (sizeof(lim) == sizeof(uint64_t)) {
-               if (lim == (kernel_ulong_t) -1ULL)
+               if (lim == (kernel_ulong_t) -1ULL) {
+# if XLAT_VERBOSE
+                       sprintf(buf[i], "%llu /* RLIM64_INFINITY */",
+                               (unsigned long long) lim);
+                       return buf[i++];
+# else /* XLAT_ABBREV */
                        return "RLIM64_INFINITY";
+# endif
+               }
        } else {
-               if (lim == (kernel_ulong_t) -1U)
+               if (lim == (kernel_ulong_t) -1U) {
+# if XLAT_VERBOSE
+                       sprintf(buf[i], "%llu /* RLIM_INFINITY */",
+                               (unsigned long long) lim);
+                       return buf[i++];
+# else /* XLAT_ABBREV */
                        return "RLIM_INFINITY";
+# endif
+               }
        }
 
-       static char buf[2][sizeof(lim)*3 + sizeof("*1024")];
-       static int i;
-       i &= 1;
        if (lim > 1024 && lim % 1024 == 0)
+# if XLAT_VERBOSE
+               sprintf(buf[i], "%llu /* %llu*1024 */",
+                       (unsigned long long) lim,
+                       (unsigned long long) lim / 1024);
+# else /* XLAT_ABBREV */
                sprintf(buf[i], "%llu*1024", (unsigned long long) lim / 1024);
+# endif
        else
                sprintf(buf[i], "%llu", (unsigned long long) lim);
 
        return buf[i++];
+#endif /* !XLAT_RAW */
 }
 
 #ifdef NR_GETRLIMIT