1 /* 2 * Copyright (c) 2003, Intel Corporation. All rights reserved. 3 * Created by: julie.n.fleischer 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 mq_timedsend() returns errno == EBADF if mqdes is not a valid 11 * message queue descriptor. 12 */ 13 14 #include <stdio.h> 15 #include <mqueue.h> 16 #include <fcntl.h> 17 #include <sys/stat.h> 18 #include <sys/types.h> 19 #include <unistd.h> 20 #include <string.h> 21 #include <errno.h> 22 #include <time.h> 23 #include "posixtest.h" 24 25 #define NAMESIZE 50 26 #define MSGSTR "0123456789" 27 28 int main(void) 29 { 30 char qname[NAMESIZE]; 31 const char *msgptr = MSGSTR; 32 struct timespec ts; 33 mqd_t queue; 34 int unresolved = 0, failure = 0; 35 36 sprintf(qname, "/mq_timedsend_11-1_%d", getpid()); 37 38 queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); 39 if (queue == (mqd_t) - 1) { 40 perror("mq_open() did not return success"); 41 return PTS_UNRESOLVED; 42 } 43 44 ts.tv_sec = time(NULL) + 1; 45 ts.tv_nsec = 0; 46 if (mq_timedsend(queue + 1, msgptr, strlen(msgptr), 1, &ts) != -1) { 47 printf("mq_timedsend() did not return -1 on invalid queue\n"); 48 failure = 1; 49 } 50 51 if (errno != EBADF) { 52 printf("errno != EBADF\n"); 53 failure = 1; 54 } 55 56 if (mq_close(queue) != 0) { 57 perror("mq_close() did not return success"); 58 unresolved = 1; 59 } 60 61 if (mq_unlink(qname) != 0) { 62 perror("mq_unlink() did not return success"); 63 unresolved = 1; 64 } 65 66 if (failure == 1) { 67 printf("Test FAILED\n"); 68 return PTS_FAIL; 69 } 70 71 if (unresolved == 1) { 72 printf("Test UNRESOLVED\n"); 73 return PTS_UNRESOLVED; 74 } 75 76 printf("Test PASSED\n"); 77 return PTS_PASS; 78 } 79