1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 */ 8 9 /* 10 mq_close test plan: 11 1. Create a new message queue 12 2. Close the message queue, verify success 13 3. Attempt to close the same descriptor again, and verify that mq_close 14 returns EBADF 15 */ 16 17 #include <stdio.h> 18 #include <mqueue.h> 19 #include <sys/types.h> 20 #include <unistd.h> 21 #include <fcntl.h> 22 #include <sys/stat.h> 23 #include <errno.h> 24 #include "posixtest.h" 25 26 #define TEST "3-1" 27 #define FUNCTION "mq_close" 28 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 29 30 int main(void) 31 { 32 char qname[50]; 33 mqd_t queue; 34 35 sprintf(qname, "/" FUNCTION "_" TEST "_%d", getpid()); 36 37 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 38 if (queue == (mqd_t) - 1) { 39 perror(ERROR_PREFIX "mq_open"); 40 return PTS_UNRESOLVED; 41 } 42 43 if (mq_close(queue) == -1) { 44 perror(ERROR_PREFIX "mq_close"); 45 mq_unlink(qname); 46 return PTS_UNRESOLVED; 47 } 48 49 if (mq_unlink(qname) != 0) { 50 perror("mq_unlink() did not return success"); 51 return PTS_UNRESOLVED; 52 } 53 54 if (mq_close(queue) != -1) { 55 printf("mq_close() did not return failure\n"); 56 printf("Test FAILED\n"); 57 return PTS_FAIL; 58 } 59 if (errno != EBADF) { 60 printf("errno != EBADF\n"); 61 return PTS_FAIL; 62 } 63 64 printf("Test PASSED\n"); 65 return PTS_PASS; 66 } 67