1 /*
2 * Copyright (c) 2017 Xiao yang <yangx.jy@cn.fujitsu.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <sys/types.h>
19 #include <sys/ipc.h>
20 #include <sys/msg.h>
21 #include <sys/shm.h>
22 #define TST_NO_DEFAULT_MAIN
23 #include "tst_test.h"
24 #include "tst_safe_sysv_ipc.h"
25
safe_msgget(const char * file,const int lineno,key_t key,int msgflg)26 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg)
27 {
28 int rval;
29
30 rval = msgget(key, msgflg);
31 if (rval == -1) {
32 tst_brk(TBROK | TERRNO, "%s:%d: msgget(%i, %x) failed",
33 file, lineno, (int)key, msgflg);
34 }
35
36 return rval;
37 }
38
safe_msgsnd(const char * file,const int lineno,int msqid,const void * msgp,size_t msgsz,int msgflg)39 int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
40 size_t msgsz, int msgflg)
41 {
42 int rval;
43
44 rval = msgsnd(msqid, msgp, msgsz, msgflg);
45 if (rval == -1) {
46 tst_brk(TBROK | TERRNO,
47 "%s:%d: msgsnd(%i, %p, %zu, %x) failed",
48 file, lineno, msqid, msgp, msgsz, msgflg);
49 }
50
51 return rval;
52 }
53
safe_msgrcv(const char * file,const int lineno,int msqid,void * msgp,size_t msgsz,long msgtyp,int msgflg)54 ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
55 size_t msgsz, long msgtyp, int msgflg)
56 {
57 ssize_t rval;
58
59 rval = msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
60 if (rval == -1) {
61 tst_brk(TBROK | TERRNO,
62 "%s:%d: msgrcv(%i, %p, %zu, %li, %x) failed",
63 file, lineno, msqid, msgp, msgsz, msgtyp, msgflg);
64 }
65
66 return rval;
67 }
68
safe_msgctl(const char * file,const int lineno,int msqid,int cmd,struct msqid_ds * buf)69 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
70 struct msqid_ds *buf)
71 {
72 int rval;
73
74 rval = msgctl(msqid, cmd, buf);
75 if (rval == -1) {
76 tst_brk(TBROK | TERRNO, "%s:%d: msgctl(%i, %i, %p) failed",
77 file, lineno, msqid, cmd, buf);
78 }
79
80 return rval;
81 }
82
safe_shmget(const char * file,const int lineno,key_t key,size_t size,int shmflg)83 int safe_shmget(const char *file, const int lineno, key_t key, size_t size,
84 int shmflg)
85 {
86 int rval;
87
88 rval = shmget(key, size, shmflg);
89 if (rval == -1) {
90 tst_brk(TBROK | TERRNO, "%s:%d: shmget(%i, %zu, %x) failed",
91 file, lineno, (int)key, size, shmflg);
92 }
93
94 return rval;
95 }
96
safe_shmat(const char * file,const int lineno,int shmid,const void * shmaddr,int shmflg)97 void *safe_shmat(const char *file, const int lineno, int shmid,
98 const void *shmaddr, int shmflg)
99 {
100 void *rval;
101
102 rval = shmat(shmid, shmaddr, shmflg);
103 if (rval == (void *)-1) {
104 tst_brk(TBROK | TERRNO, "%s:%d: shmat(%i, %p, %x) failed",
105 file, lineno, shmid, shmaddr, shmflg);
106 }
107
108 return rval;
109 }
110
safe_shmdt(const char * file,const int lineno,const void * shmaddr)111 int safe_shmdt(const char *file, const int lineno, const void *shmaddr)
112 {
113 int rval;
114
115 rval = shmdt(shmaddr);
116 if (rval == -1) {
117 tst_brk(TBROK | TERRNO, "%s:%d: shmdt(%p) failed",
118 file, lineno, shmaddr);
119 }
120
121 return rval;
122 }
123
safe_shmctl(const char * file,const int lineno,int shmid,int cmd,struct shmid_ds * buf)124 int safe_shmctl(const char *file, const int lineno, int shmid, int cmd,
125 struct shmid_ds *buf)
126 {
127 int rval;
128
129 rval = shmctl(shmid, cmd, buf);
130 if (rval == -1) {
131 tst_brk(TBROK | TERRNO, "%s:%d: shmctl(%i, %i, %p) failed",
132 file, lineno, shmid, cmd, buf);
133 }
134
135 return rval;
136 }
137