]> granicus.if.org Git - strace/blob - ioprio.c
tests: workaround systemd-nspawn habit of disabling unimplemented syscalls
[strace] / ioprio.c
1 /*
2  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2014-2019 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8
9 #include "defs.h"
10 #include "xstring.h"
11
12 #include "xlat/ioprio_who.h"
13 #include "xlat/ioprio_class.h"
14
15 #define IOPRIO_CLASS_SHIFT      (13)
16 #define IOPRIO_PRIO_MASK        ((1ul << IOPRIO_CLASS_SHIFT) - 1)
17
18 #define IOPRIO_PRIO_CLASS(mask) ((mask) >> IOPRIO_CLASS_SHIFT)
19 #define IOPRIO_PRIO_DATA(mask)  ((mask) & IOPRIO_PRIO_MASK)
20
21 static const char *
22 sprint_ioprio(unsigned int ioprio)
23 {
24         static char outstr[256];
25         char class_buf[64];
26         unsigned int class, data;
27
28         class = IOPRIO_PRIO_CLASS(ioprio);
29         data = IOPRIO_PRIO_DATA(ioprio);
30         sprintxval(class_buf, sizeof(class_buf), ioprio_class, class,
31                    "IOPRIO_CLASS_???");
32         xsprintf(outstr, "IOPRIO_PRIO_VALUE(%s, %d)", class_buf, data);
33
34         return outstr;
35 }
36
37 void
38 print_ioprio(unsigned int ioprio)
39 {
40         if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
41                 tprintf("%#x", ioprio);
42
43         if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
44                 return;
45
46         const char *str = sprint_ioprio(ioprio);
47
48         (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
49                 ? tprints_comment : tprints)(str);
50 }
51
52 SYS_FUNC(ioprio_get)
53 {
54         if (entering(tcp)) {
55                 /* int which */
56                 printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
57                 /* int who */
58                 tprintf(", %d", (int) tcp->u_arg[1]);
59                 return 0;
60         } else {
61                 if (syserror(tcp))
62                         return 0;
63                 if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
64                         tcp->auxstr = NULL;
65                 else
66                         tcp->auxstr = sprint_ioprio(tcp->u_rval);
67                 return RVAL_STR;
68         }
69 }
70
71 SYS_FUNC(ioprio_set)
72 {
73         /* int which */
74         printxval(ioprio_who, tcp->u_arg[0], "IOPRIO_WHO_???");
75         /* int who */
76         tprintf(", %d, ", (int) tcp->u_arg[1]);
77         /* int ioprio */
78         if (xlat_verbose(xlat_verbosity) != XLAT_STYLE_ABBREV)
79                 tprintf("%d", (int) tcp->u_arg[2]);
80
81         if (xlat_verbose(xlat_verbosity) == XLAT_STYLE_RAW)
82                 return RVAL_DECODED;
83
84         (xlat_verbose(xlat_verbosity) == XLAT_STYLE_VERBOSE
85                 ? tprints_comment : tprints)(sprint_ioprio(tcp->u_arg[2]));
86
87         return RVAL_DECODED;
88 }