]> granicus.if.org Git - strace/blob - mq.c
mq.c: introduce do_mq_timedsend and do_mq_timedreceive
[strace] / mq.c
1 /*
2  * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
3  * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
4  * Copyright (c) 2015-2018 The strace developers.
5  * All rights reserved.
6  *
7  * SPDX-License-Identifier: LGPL-2.1-or-later
8  */
9
10 #include "defs.h"
11 #include <fcntl.h>
12
13 SYS_FUNC(mq_open)
14 {
15         printpath(tcp, tcp->u_arg[0]);
16         tprints(", ");
17         /* flags */
18         tprint_open_modes(tcp->u_arg[1]);
19         if (tcp->u_arg[1] & O_CREAT) {
20                 /* mode */
21                 tprints(", ");
22                 print_numeric_umode_t(tcp->u_arg[2]);
23                 tprints(", ");
24                 printmqattr(tcp, tcp->u_arg[3], false);
25         }
26         return RVAL_DECODED | RVAL_FD;
27 }
28
29 static int
30 do_mq_timedsend(struct tcb *const tcp, const print_obj_by_addr_fn print_ts)
31 {
32         printfd(tcp, tcp->u_arg[0]);
33         tprints(", ");
34         printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
35         tprintf(", %" PRI_klu ", %u, ", tcp->u_arg[2],
36                 (unsigned int) tcp->u_arg[3]);
37         print_ts(tcp, tcp->u_arg[4]);
38         return RVAL_DECODED;
39 }
40
41 SYS_FUNC(mq_timedsend)
42 {
43         return do_mq_timedsend(tcp, print_timespec);
44 }
45
46 static int
47 do_mq_timedreceive(struct tcb *const tcp, const print_obj_by_addr_fn print_ts)
48 {
49         if (entering(tcp)) {
50                 printfd(tcp, tcp->u_arg[0]);
51                 tprints(", ");
52         } else {
53                 if (syserror(tcp))
54                         printaddr(tcp->u_arg[1]);
55                 else
56                         printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
57                 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
58                 printnum_int(tcp, tcp->u_arg[3], "%u");
59                 tprints(", ");
60                 /*
61                  * Since the timeout parameter is read by the kernel
62                  * on entering syscall, it has to be decoded the same way
63                  * whether the syscall has failed or not.
64                  */
65                 temporarily_clear_syserror(tcp);
66                 print_ts(tcp, tcp->u_arg[4]);
67                 restore_cleared_syserror(tcp);
68         }
69         return 0;
70 }
71
72 SYS_FUNC(mq_timedreceive)
73 {
74         return do_mq_timedreceive(tcp, print_timespec);
75 }
76
77 SYS_FUNC(mq_notify)
78 {
79         printfd(tcp, tcp->u_arg[0]);
80         tprints(", ");
81         print_sigevent(tcp, tcp->u_arg[1]);
82         return RVAL_DECODED;
83 }
84
85 SYS_FUNC(mq_getsetattr)
86 {
87         if (entering(tcp)) {
88                 printfd(tcp, tcp->u_arg[0]);
89                 tprints(", ");
90                 printmqattr(tcp, tcp->u_arg[1], true);
91                 tprints(", ");
92         } else {
93                 printmqattr(tcp, tcp->u_arg[2], true);
94         }
95         return 0;
96 }