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 Test that a closed message queue descriptor has been disassociated from 11 its message queue by attempting to set a notification on the descriptor 12 and verifying that mq_notify returns -1 and sets errno to EBADF 13 */ 14#include <stdio.h> 15#include <mqueue.h> 16#include <sys/types.h> 17#include <unistd.h> 18#include <fcntl.h> 19#include <sys/stat.h> 20#include <errno.h> 21#include <signal.h> 22#include "posixtest.h" 23 24#define TEST "4-1" 25#define FUNCTION "mq_close" 26#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " 27 28int main(void) 29{ 30 char qname[50]; 31 mqd_t queue; 32 struct sigevent se; 33 34 sprintf(qname, "/" FUNCTION "_" TEST "_%d", getpid()); 35 36 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 37 if (queue == (mqd_t) - 1) { 38 perror(ERROR_PREFIX "mq_open"); 39 return PTS_UNRESOLVED; 40 } 41 42 if (mq_close(queue) == -1) { 43 perror(ERROR_PREFIX "mq_close"); 44 return PTS_UNRESOLVED; 45 } 46 47 se.sigev_notify = SIGEV_SIGNAL; 48 se.sigev_signo = SIGUSR1; 49 50 if (mq_notify(queue, &se) != -1) { 51 printf("mq_notify() did not fail as expected\n"); 52 printf("Test FAILED\n"); 53 return PTS_FAIL; 54 } 55 56 if (errno != EBADF) { 57 printf("errno != EBADF\n"); 58 printf("Test FAILED\n"); 59 return PTS_FAIL; 60 } 61 62 if (mq_unlink(qname) != 0) { 63 perror("mq_unlink() did not return success"); 64 return PTS_UNRESOLVED; 65 } 66 67 printf("Test PASSED\n"); 68 return PTS_PASS; 69} 70