• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
40 	if (rval == -1) {
41 		tst_brk_(file, lineno, TBROK | TERRNO,
42 			"mq_open(%s,%d,%04o,%p) failed", pathname, oflags,
43 			mode, attr);
44 	}
45 
46 	return rval;
47 }
48 
49 #endif /* TST_SAFE_POSIX_IPC_H__ */
50