]> granicus.if.org Git - strace/commitdiff
Honor xlat styles when decoding ioprio_get and ioprio_set
authorShankara Pailoor <shankarapailoor@gmail.com>
Sat, 12 Jan 2019 04:59:00 +0000 (20:59 -0800)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 18 Feb 2019 20:30:20 +0000 (20:30 +0000)
* ioprio.c (SYS_FUNC(ioprio_get), SYS_FUNC(ioprio_set)): Add xlat_style
support.
* tests/ioprio-Xabbrev.c: New file.
* tests/ioprio-Xraw.c: Likewise.
* tests/ioprio-Xverbose.c: Likewise.
* tests/ioprio.c: Handle XLAT_RAW, XLAT_ABBREV, and XLAT_VERBOSE macros.
* tests/gen_tests.in (ioprio-Xabbrev, ioprio-Xraw, ioprio-Xverbose): New
tests.
* tests/pure_executables.list: Add ioprio-Xabbrev, ioprio-Xraw, and
ioprio-Xverbose.
* tests/.gitignore: Likewise.

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

index 2d7c4f6a758ea3515e9d0c44ad4ef28280e83116..5a5c469ab022f0c93f68cb643488c618c0b3afa6 100644 (file)
--- a/ioprio.c
+++ b/ioprio.c
@@ -45,8 +45,10 @@ SYS_FUNC(ioprio_get)
        } else {
                if (syserror(tcp))
                        return 0;
-
-               tcp->auxstr = sprint_ioprio(tcp->u_rval);
+               if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+                       tcp->auxstr = NULL;
+               else
+                       tcp->auxstr = sprint_ioprio(tcp->u_rval);
                return RVAL_STR;
        }
 }
@@ -58,7 +60,14 @@ SYS_FUNC(ioprio_set)
        /* int who */
        tprintf(", %d, ", (int) tcp->u_arg[1]);
        /* int ioprio */
-       tprints(sprint_ioprio(tcp->u_arg[2]));
+       if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
+               tprintf("%d", (int) tcp->u_arg[2]);
+
+       if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
+               return RVAL_DECODED;
+
+       (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
+               ? tprints_comment : tprints)(sprint_ioprio(tcp->u_arg[2]));
 
        return RVAL_DECODED;
 }
index aecdf4324e659b6514e2f57d48d8e15483a80f6d..781e50a2d2e37708540a453b53045cabb398eb86 100644 (file)
@@ -176,6 +176,9 @@ ioctl_v4l2
 ioperm
 iopl
 ioprio
+ioprio-Xabbrev
+ioprio-Xraw
+ioprio-Xverbose
 ip_mreq
 ipc
 ipc_msg
index 3b35a67bdf8ecf1fce1e9900815431060246a88d..128f4ca8dba5256d79125ad5bac964322ecbac97 100644 (file)
@@ -147,6 +147,9 @@ ioctl_v4l2  +ioctl.test
 ioperm -a27
 iopl   -a8
 ioprio -a18 -e trace=ioprio_get,ioprio_set
+ioprio-Xabbrev -a18 -e trace=ioprio_get,ioprio_set -Xabbrev
+ioprio-Xraw    -a18 -e trace=ioprio_get,ioprio_set -Xraw
+ioprio-Xverbose        -a18 -e trace=ioprio_get,ioprio_set -Xverbose
 ip_mreq        -e trace=setsockopt
 ipc    -a19
 ipc_msg        +ipc.sh -a26
diff --git a/tests/ioprio-Xabbrev.c b/tests/ioprio-Xabbrev.c
new file mode 100644 (file)
index 0000000..01a07f4
--- /dev/null
@@ -0,0 +1 @@
+#include "ioprio.c"
diff --git a/tests/ioprio-Xraw.c b/tests/ioprio-Xraw.c
new file mode 100644 (file)
index 0000000..6a81506
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_RAW 1
+#include "ioprio.c"
diff --git a/tests/ioprio-Xverbose.c b/tests/ioprio-Xverbose.c
new file mode 100644 (file)
index 0000000..3c12bb6
--- /dev/null
@@ -0,0 +1,2 @@
+#define XLAT_VERBOSE 1
+#include "ioprio.c"
index 5c52b3dbc26e8f1983e716a0746e96e1a8acf55e..6c54ad65a099dd0b1c5a947dbe5ccd5dc39864f3 100644 (file)
@@ -27,14 +27,6 @@ enum {
 # include "xlat.h"
 # include "xlat/ioprio_class.h"
 
-void
-print_ioprio(unsigned long val)
-{
-       printf(" (IOPRIO_PRIO_VALUE(");
-       printxval(ioprio_class, val >> 13, "IOPRIO_CLASS_???");
-       printf(", %d))", (int) (val & 0x1fff));
-}
-
 int
 main(void)
 {
@@ -44,32 +36,78 @@ main(void)
                (kernel_ulong_t) 0xbadc0dedda7a1057ULL;
        static const kernel_ulong_t bogus_ioprio =
                (kernel_ulong_t) 0xdec0ded1facefeedULL;
+# if !XLAT_RAW
        static const char * const bogus_ioprio_str =
                "IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)";
+# endif
 
        long rc;
+       const char *errstr;
 
        rc = syscall(__NR_ioprio_get, bogus_which, bogus_who);
+       errstr = sprintrc(rc);
+# if XLAT_RAW
+       printf("ioprio_get(%#x, %d) = %s\n",
+              (int) bogus_which, (int) bogus_who, errstr);
+# else /* XLAT_ABBREV || XLAT_VERBOSE */
        printf("ioprio_get(%#x /* IOPRIO_WHO_??? */, %d) = %s\n",
-              (int) bogus_which, (int) bogus_who, sprintrc(rc));
+              (int) bogus_which, (int) bogus_who, errstr);
+# endif
 
        rc = syscall(__NR_ioprio_get, 1, 0);
-       printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", sprintrc(rc));
-
-       if (rc >= -1)
-               print_ioprio(rc);
-
+       errstr = sprintrc(rc);
+# if XLAT_RAW
+       printf("ioprio_get(0x1, 0) = %s\n", errstr);
+# elif XLAT_VERBOSE
+       printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s", errstr);
+       if (rc >= 0) {
+               printf(" (IOPRIO_PRIO_VALUE(%u /* ", (unsigned int) rc >> 13);
+               printxval(ioprio_class, (unsigned int) rc >> 13,
+                         "IOPRIO_CLASS_???");
+               printf(" */, %u))", (unsigned int) rc & 0x1fff);
+       }
+       puts("");
+# else /* XLAT_ABBREV */
+       printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", errstr);
+       if (rc >= 0) {
+               printf(" (IOPRIO_PRIO_VALUE(");
+               printxval(ioprio_class, (unsigned int) rc >> 13,
+                         "IOPRIO_CLASS_???");
+               printf(", %u))", (unsigned int) rc & 0x1fff);
+       }
        puts("");
+# endif
 
        rc = syscall(__NR_ioprio_set, 2, 0, 8191);
-       printf("ioprio_set(IOPRIO_WHO_PGRP, 0, "
-              "IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n",
-              sprintrc(rc));
+       errstr = sprintrc(rc);
+# if XLAT_RAW
+       printf("ioprio_set(%#x, 0, 8191) = %s\n", 2, errstr);
+# elif XLAT_VERBOSE
+       printf("ioprio_set(%#x /* IOPRIO_WHO_PGRP */, 0, 8191"
+              " /* IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 8191) */)"
+              " = %s\n",
+              2, errstr);
+# else /* XLAT_ABBREV */
+       printf("ioprio_set(IOPRIO_WHO_PGRP, 0"
+              ", IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n",
+              errstr);
+# endif
 
        rc = syscall(__NR_ioprio_set, bogus_which, bogus_who, bogus_ioprio);
+       errstr = sprintrc(rc);
+# if XLAT_RAW
+       printf("ioprio_set(%#x, %d, %d) = %s\n",
+              (int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
+              errstr);
+# elif XLAT_VERBOSE
+       printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %d /* %s */) = %s\n",
+              (int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
+              bogus_ioprio_str, errstr);
+# else /* XLAT_ABBREV */
        printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %s) = %s\n",
               (int) bogus_which, (int) bogus_who, bogus_ioprio_str,
-              sprintrc(rc));
+              errstr);
+# endif
 
        puts("+++ exited with 0 +++");
 
index af99bda628da2338f6df96b7092673198508450f..edb0be938fd00f46196a9aeaf9cda64e61ba6dfe 100755 (executable)
@@ -144,6 +144,9 @@ ioctl_v4l2
 ioperm
 iopl
 ioprio
+ioprio-Xabbrev
+ioprio-Xraw
+ioprio-Xverbose
 ip_mreq
 ipc
 ipc_msg