2015-12-17 17:56:48 +00:00
/*
* Copyright ( c ) 2015 Elvira Khabirova < lineprinter0 @ gmail . com >
2016-01-06 11:52:43 +00:00
* Copyright ( c ) 2016 Dmitry V . Levin < ldv @ altlinux . org >
2018-12-24 23:46:43 +00:00
* Copyright ( c ) 2015 - 2018 The strace developers .
2015-12-17 17:56:48 +00:00
* All rights reserved .
*
2018-12-10 00:00:00 +00:00
* SPDX - License - Identifier : GPL - 2.0 - or - later
2015-12-17 17:56:48 +00:00
*/
2016-01-02 13:28:43 +00:00
# include "tests.h"
2016-01-06 11:52:43 +00:00
2015-08-19 05:28:48 +03:00
# ifdef HAVE_MQUEUE_H
2016-01-06 11:52:43 +00:00
# include <fcntl.h>
# include <mqueue.h>
2017-02-10 00:14:45 +00:00
# include <stdio.h>
2016-01-06 11:52:43 +00:00
# include <stdlib.h>
# include <unistd.h>
# include <sys / stat.h>
2015-08-19 05:28:48 +03:00
int
2017-06-17 22:23:09 +00:00
main ( void )
2015-08-19 05:28:48 +03:00
{
struct mq_attr attr ;
( void ) close ( 0 ) ;
2017-02-10 00:14:45 +00:00
2017-04-14 16:25:05 +00:00
char * name ;
if ( asprintf ( & name , " /strace-mq-%u.sample " , getpid ( ) ) < 0 )
perror_msg_and_fail ( " asprintf " ) ;
if ( mq_open ( name , O_CREAT , 0700 , NULL ) )
2016-01-06 11:52:43 +00:00
perror_msg_and_skip ( " mq_open " ) ;
2017-04-14 16:25:05 +00:00
printf ( " mq_open( \" %s \" , O_RDONLY|O_CREAT, 0700, NULL) = 0 \n " , name + 1 ) ;
2017-02-10 00:14:45 +00:00
2016-01-06 11:52:43 +00:00
if ( mq_getattr ( 0 , & attr ) )
perror_msg_and_skip ( " mq_getattr " ) ;
2017-02-10 00:14:45 +00:00
printf ( " mq_getsetattr(0, NULL, {mq_flags=0, mq_maxmsg=%lld "
" , mq_msgsize=%lld, mq_curmsgs=0}) = 0 \n " ,
( long long ) attr . mq_maxmsg ,
( long long ) attr . mq_msgsize ) ;
if ( mq_setattr ( 0 , & attr , NULL ) )
2016-01-06 11:52:43 +00:00
perror_msg_and_skip ( " mq_setattr " ) ;
2017-02-10 00:14:45 +00:00
printf ( " mq_getsetattr(0, {mq_flags=0, mq_maxmsg=%lld "
" , mq_msgsize=%lld, mq_curmsgs=0}, NULL) = 0 \n " ,
( long long ) attr . mq_maxmsg ,
( long long ) attr . mq_msgsize ) ;
2017-04-14 16:25:05 +00:00
if ( mq_unlink ( name ) )
2016-01-06 11:52:43 +00:00
perror_msg_and_skip ( " mq_unlink " ) ;
2017-04-14 16:25:05 +00:00
printf ( " mq_unlink( \" %s \" ) = 0 \n " , name + 1 ) ;
2017-02-10 00:14:45 +00:00
puts ( " +++ exited with 0 +++ " ) ;
2015-08-19 05:28:48 +03:00
return 0 ;
}
# else
2016-01-06 11:52:43 +00:00
SKIP_MAIN_UNDEFINED ( " HAVE_MQUEUE_H " )
2015-08-19 05:28:48 +03:00
# endif