1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2017-2019 Petr Vorel pvorel@suse.cz
4 */
5
6 #ifndef TST_SAFE_POSIX_IPC_H__
7 #define TST_SAFE_POSIX_IPC_H__
8
9 #include <mqueue.h>
10 #include <stdarg.h>
11
12 #define SAFE_MQ_OPEN(pathname, oflags, ...) \
13 safe_mq_open(__FILE__, __LINE__, (pathname), (oflags), ##__VA_ARGS__)
14
safe_mq_open(const char * file,const int lineno,const char * pathname,int oflags,...)15 static inline int safe_mq_open(const char *file, const int lineno,
16 const char *pathname, int oflags, ...)
17 {
18 va_list ap;
19 int rval;
20 mode_t mode;
21 struct mq_attr *attr;
22
23 va_start(ap, oflags);
24
25 /* Android's NDK's mode_t is smaller than an int, which results in
26 * SIGILL here when passing the mode_t type.
27 */
28 #ifndef __ANDROID__
29 mode = va_arg(ap, mode_t);
30 #else
31 mode = va_arg(ap, int);
32 #endif
33
34 attr = va_arg(ap, struct mq_attr *);
35
36 va_end(ap);
37
38 rval = mq_open(pathname, oflags, mode, attr);
39 if (rval == -1) {
40 tst_brk(TBROK | TERRNO, "%s:%d: mq_open(%s,%d,0%o,%p) failed",
41 file, lineno, pathname, oflags, mode, attr);
42 }
43
44 return rval;
45 }
46
47 #endif /* TST_SAFE_POSIX_IPC_H__ */
48