Browse Source

Honor xlat styles when decoding ioprio_get and ioprio_set

* 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>
Shankara Pailoor 11 months ago
parent
commit
98b7f71721
8 changed files with 82 additions and 21 deletions
  1. 12
    3
      ioprio.c
  2. 3
    0
      tests/.gitignore
  3. 3
    0
      tests/gen_tests.in
  4. 1
    0
      tests/ioprio-Xabbrev.c
  5. 2
    0
      tests/ioprio-Xraw.c
  6. 2
    0
      tests/ioprio-Xverbose.c
  7. 56
    18
      tests/ioprio.c
  8. 3
    0
      tests/pure_executables.list

+ 12
- 3
ioprio.c View File

@@ -45,8 +45,10 @@ SYS_FUNC(ioprio_get)
45 45
 	} else {
46 46
 		if (syserror(tcp))
47 47
 			return 0;
48
-
49
-		tcp->auxstr = sprint_ioprio(tcp->u_rval);
48
+		if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
49
+			tcp->auxstr = NULL;
50
+		else
51
+			tcp->auxstr = sprint_ioprio(tcp->u_rval);
50 52
 		return RVAL_STR;
51 53
 	}
52 54
 }
@@ -58,7 +60,14 @@ SYS_FUNC(ioprio_set)
58 60
 	/* int who */
59 61
 	tprintf(", %d, ", (int) tcp->u_arg[1]);
60 62
 	/* int ioprio */
61
-	tprints(sprint_ioprio(tcp->u_arg[2]));
63
+	if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
64
+		tprintf("%d", (int) tcp->u_arg[2]);
65
+
66
+	if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
67
+		return RVAL_DECODED;
68
+
69
+	(xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
70
+		? tprints_comment : tprints)(sprint_ioprio(tcp->u_arg[2]));
62 71
 
63 72
 	return RVAL_DECODED;
64 73
 }

+ 3
- 0
tests/.gitignore View File

@@ -176,6 +176,9 @@ ioctl_v4l2
176 176
 ioperm
177 177
 iopl
178 178
 ioprio
179
+ioprio-Xabbrev
180
+ioprio-Xraw
181
+ioprio-Xverbose
179 182
 ip_mreq
180 183
 ipc
181 184
 ipc_msg

+ 3
- 0
tests/gen_tests.in View File

@@ -147,6 +147,9 @@ ioctl_v4l2	+ioctl.test
147 147
 ioperm	-a27
148 148
 iopl	-a8
149 149
 ioprio	-a18 -e trace=ioprio_get,ioprio_set
150
+ioprio-Xabbrev	-a18 -e trace=ioprio_get,ioprio_set -Xabbrev
151
+ioprio-Xraw	-a18 -e trace=ioprio_get,ioprio_set -Xraw
152
+ioprio-Xverbose	-a18 -e trace=ioprio_get,ioprio_set -Xverbose
150 153
 ip_mreq	-e trace=setsockopt
151 154
 ipc	-a19
152 155
 ipc_msg	+ipc.sh -a26

+ 1
- 0
tests/ioprio-Xabbrev.c View File

@@ -0,0 +1 @@
1
+#include "ioprio.c"

+ 2
- 0
tests/ioprio-Xraw.c View File

@@ -0,0 +1,2 @@
1
+#define XLAT_RAW 1
2
+#include "ioprio.c"

+ 2
- 0
tests/ioprio-Xverbose.c View File

@@ -0,0 +1,2 @@
1
+#define XLAT_VERBOSE 1
2
+#include "ioprio.c"

+ 56
- 18
tests/ioprio.c View File

@@ -27,14 +27,6 @@ enum {
27 27
 # include "xlat.h"
28 28
 # include "xlat/ioprio_class.h"
29 29
 
30
-void
31
-print_ioprio(unsigned long val)
32
-{
33
-	printf(" (IOPRIO_PRIO_VALUE(");
34
-	printxval(ioprio_class, val >> 13, "IOPRIO_CLASS_???");
35
-	printf(", %d))", (int) (val & 0x1fff));
36
-}
37
-
38 30
 int
39 31
 main(void)
40 32
 {
@@ -44,32 +36,78 @@ main(void)
44 36
 		(kernel_ulong_t) 0xbadc0dedda7a1057ULL;
45 37
 	static const kernel_ulong_t bogus_ioprio =
46 38
 		(kernel_ulong_t) 0xdec0ded1facefeedULL;
39
+# if !XLAT_RAW
47 40
 	static const char * const bogus_ioprio_str =
48 41
 		"IOPRIO_PRIO_VALUE(0x7d677 /* IOPRIO_CLASS_??? */, 7917)";
42
+# endif
49 43
 
50 44
 	long rc;
45
+	const char *errstr;
51 46
 
52 47
 	rc = syscall(__NR_ioprio_get, bogus_which, bogus_who);
48
+	errstr = sprintrc(rc);
49
+# if XLAT_RAW
50
+	printf("ioprio_get(%#x, %d) = %s\n",
51
+	       (int) bogus_which, (int) bogus_who, errstr);
52
+# else /* XLAT_ABBREV || XLAT_VERBOSE */
53 53
 	printf("ioprio_get(%#x /* IOPRIO_WHO_??? */, %d) = %s\n",
54
-	       (int) bogus_which, (int) bogus_who, sprintrc(rc));
54
+	       (int) bogus_which, (int) bogus_who, errstr);
55
+# endif
55 56
 
56 57
 	rc = syscall(__NR_ioprio_get, 1, 0);
57
-	printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", sprintrc(rc));
58
-
59
-	if (rc >= -1)
60
-		print_ioprio(rc);
61
-
58
+	errstr = sprintrc(rc);
59
+# if XLAT_RAW
60
+	printf("ioprio_get(0x1, 0) = %s\n", errstr);
61
+# elif XLAT_VERBOSE
62
+	printf("ioprio_get(0x1 /* IOPRIO_WHO_PROCESS */, 0) = %s", errstr);
63
+	if (rc >= 0) {
64
+		printf(" (IOPRIO_PRIO_VALUE(%u /* ", (unsigned int) rc >> 13);
65
+		printxval(ioprio_class, (unsigned int) rc >> 13,
66
+			  "IOPRIO_CLASS_???");
67
+		printf(" */, %u))", (unsigned int) rc & 0x1fff);
68
+	}
69
+	puts("");
70
+# else /* XLAT_ABBREV */
71
+	printf("ioprio_get(IOPRIO_WHO_PROCESS, 0) = %s", errstr);
72
+	if (rc >= 0) {
73
+		printf(" (IOPRIO_PRIO_VALUE(");
74
+		printxval(ioprio_class, (unsigned int) rc >> 13,
75
+			  "IOPRIO_CLASS_???");
76
+		printf(", %u))", (unsigned int) rc & 0x1fff);
77
+	}
62 78
 	puts("");
79
+# endif
63 80
 
64 81
 	rc = syscall(__NR_ioprio_set, 2, 0, 8191);
65
-	printf("ioprio_set(IOPRIO_WHO_PGRP, 0, "
66
-	       "IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n",
67
-	       sprintrc(rc));
82
+	errstr = sprintrc(rc);
83
+# if XLAT_RAW
84
+	printf("ioprio_set(%#x, 0, 8191) = %s\n", 2, errstr);
85
+# elif XLAT_VERBOSE
86
+	printf("ioprio_set(%#x /* IOPRIO_WHO_PGRP */, 0, 8191"
87
+	       " /* IOPRIO_PRIO_VALUE(0 /* IOPRIO_CLASS_NONE */, 8191) */)"
88
+	       " = %s\n",
89
+	       2, errstr);
90
+# else /* XLAT_ABBREV */
91
+	printf("ioprio_set(IOPRIO_WHO_PGRP, 0"
92
+	       ", IOPRIO_PRIO_VALUE(IOPRIO_CLASS_NONE, 8191)) = %s\n",
93
+	       errstr);
94
+# endif
68 95
 
69 96
 	rc = syscall(__NR_ioprio_set, bogus_which, bogus_who, bogus_ioprio);
97
+	errstr = sprintrc(rc);
98
+# if XLAT_RAW
99
+	printf("ioprio_set(%#x, %d, %d) = %s\n",
100
+	       (int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
101
+	       errstr);
102
+# elif XLAT_VERBOSE
103
+	printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %d /* %s */) = %s\n",
104
+	       (int) bogus_which, (int) bogus_who, (int) bogus_ioprio,
105
+	       bogus_ioprio_str, errstr);
106
+# else /* XLAT_ABBREV */
70 107
 	printf("ioprio_set(%#x /* IOPRIO_WHO_??? */, %d, %s) = %s\n",
71 108
 	       (int) bogus_which, (int) bogus_who, bogus_ioprio_str,
72
-	       sprintrc(rc));
109
+	       errstr);
110
+# endif
73 111
 
74 112
 	puts("+++ exited with 0 +++");
75 113
 

+ 3
- 0
tests/pure_executables.list View File

@@ -144,6 +144,9 @@ ioctl_v4l2
144 144
 ioperm
145 145
 iopl
146 146
 ioprio
147
+ioprio-Xabbrev
148
+ioprio-Xraw
149
+ioprio-Xverbose
147 150
 ip_mreq
148 151
 ipc
149 152
 ipc_msg

Loading…
Cancel
Save