Home | History | Annotate | Download | only in lib
      1 /*
      2  * Copyright (c) 2017 Xiao yang <yangx.jy (at) 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 #define TST_NO_DEFAULT_MAIN
     22 #include "tst_test.h"
     23 #include "tst_safe_sysv_ipc.h"
     24 
     25 int safe_msgget(const char *file, const int lineno, key_t key, int msgflg)
     26 {
     27 	int rval;
     28 
     29 	rval = msgget(key, msgflg);
     30 	if (rval == -1) {
     31 		tst_brk(TBROK | TERRNO, "%s:%d: msgget(%i, %x) failed",
     32 			file, lineno, (int)key, msgflg);
     33 	}
     34 
     35 	return rval;
     36 }
     37 
     38 int safe_msgsnd(const char *file, const int lineno, int msqid, const void *msgp,
     39 		size_t msgsz, int msgflg)
     40 {
     41 	int rval;
     42 
     43 	rval = msgsnd(msqid, msgp, msgsz, msgflg);
     44 	if (rval == -1) {
     45 		tst_brk(TBROK | TERRNO,
     46 			"%s:%d: msgsnd(%i, %p, %zu, %x) failed",
     47 			file, lineno, msqid, msgp, msgsz, msgflg);
     48 	}
     49 
     50 	return rval;
     51 }
     52 
     53 ssize_t safe_msgrcv(const char *file, const int lineno, int msqid, void *msgp,
     54 		size_t msgsz, long msgtyp, int msgflg)
     55 {
     56 	ssize_t rval;
     57 
     58 	rval = msgrcv(msqid, msgp, msgsz, msgtyp, msgflg);
     59 	if (rval == -1) {
     60 		tst_brk(TBROK | TERRNO,
     61 			"%s:%d: msgrcv(%i, %p, %zu, %li, %x) failed",
     62 			file, lineno, msqid, msgp, msgsz, msgtyp, msgflg);
     63 	}
     64 
     65 	return rval;
     66 }
     67 
     68 int safe_msgctl(const char *file, const int lineno, int msqid, int cmd,
     69 		struct msqid_ds *buf)
     70 {
     71 	int  rval;
     72 
     73 	rval = msgctl(msqid, cmd, buf);
     74 	if (rval == -1) {
     75 		tst_brk(TBROK | TERRNO, "%s:%d: msgctl(%i, %i, %p) failed",
     76 			file, lineno, msqid, cmd, buf);
     77 	}
     78 
     79 	return rval;
     80 }
     81