| File: | /home/joel/rtems-4.11-work/build/rtems/c/src/../../cpukit/posix/src/mqueueopen.c |
| Location: | line 66, column 5 |
| Description: | Value stored to 'mode' is never read |
| 1 | /* |
| 2 | * NOTE: The structure of the routines is identical to that of POSIX |
| 3 | * Message_queues to leave the option of having unnamed message |
| 4 | * queues at a future date. They are currently not part of the |
| 5 | * POSIX standard but unnamed message_queues are. This is also |
| 6 | * the reason for the apparently unnecessary tracking of |
| 7 | * the process_shared attribute. [In addition to the fact that |
| 8 | * it would be trivial to add pshared to the mq_attr structure |
| 9 | * and have process private message queues.] |
| 10 | * |
| 11 | * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open |
| 12 | * time. |
| 13 | * |
| 14 | * COPYRIGHT (c) 1989-2009. |
| 15 | * On-Line Applications Research Corporation (OAR). |
| 16 | * |
| 17 | * The license and distribution terms for this file may be |
| 18 | * found in the file LICENSE in this distribution or at |
| 19 | * http://www.rtems.com/license/LICENSE. |
| 20 | * |
| 21 | * $Id: mqueueopen.c,v 1.16 2009/08/06 19:26:56 joel Exp $ |
| 22 | */ |
| 23 | |
| 24 | #if HAVE_CONFIG_H1 |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
| 28 | #include <stdarg.h> |
| 29 | |
| 30 | #include <pthread.h> |
| 31 | #include <limits.h> |
| 32 | #include <errno(*__errno_location ()).h> |
| 33 | #include <fcntl.h> |
| 34 | #include <mqueue.h> |
| 35 | |
| 36 | #include <rtems/system.h> |
| 37 | #include <rtems/score/watchdog.h> |
| 38 | #include <rtems/seterr.h> |
| 39 | #include <rtems/posix/mqueue.h> |
| 40 | #include <rtems/posix/time.h> |
| 41 | |
| 42 | /* |
| 43 | * 15.2.2 Open a Message Queue, P1003.1b-1993, p. 272 |
| 44 | */ |
| 45 | mqd_t mq_open( |
| 46 | const char *name, |
| 47 | int oflag, |
| 48 | ... |
| 49 | /* mode_t mode, */ |
| 50 | /* struct mq_attr attr */ |
| 51 | ) |
| 52 | { |
| 53 | va_list arg; |
| 54 | mode_t mode; |
| 55 | struct mq_attr *attr = NULL((void *)0); |
| 56 | int status; |
| 57 | Objects_Id the_mq_id; |
| 58 | POSIX_Message_queue_Control *the_mq; |
| 59 | POSIX_Message_queue_Control_fd *the_mq_fd; |
| 60 | Objects_Locations location; |
| 61 | |
| 62 | _Thread_Disable_dispatch(); |
| 63 | |
| 64 | if ( oflag & O_CREAT0100 ) { |
| 65 | va_start(arg, oflag)__builtin_va_start(arg, oflag); |
| 66 | mode = (mode_t) va_arg( arg, unsigned int )__builtin_va_arg(arg, unsigned int); |
Value stored to 'mode' is never read | |
| 67 | attr = (struct mq_attr *) va_arg( arg, struct mq_attr * )__builtin_va_arg(arg, struct mq_attr *); |
| 68 | va_end(arg)__builtin_va_end(arg); |
| 69 | } |
| 70 | |
| 71 | the_mq_fd = _POSIX_Message_queue_Allocate_fd(); |
| 72 | if ( !the_mq_fd ) { |
| 73 | _Thread_Enable_dispatch(); |
| 74 | rtems_set_errno_and_return_minus_one( ENFILE )do { (*__errno_location ()) = (23); return -1; } while(0); |
| 75 | } |
| 76 | the_mq_fd->oflag = oflag; |
| 77 | |
| 78 | status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id ); |
| 79 | |
| 80 | /* |
| 81 | * If the name to id translation worked, then the message queue exists |
| 82 | * and we can just return a pointer to the id. Otherwise we may |
| 83 | * need to check to see if this is a "message queue does not exist" |
| 84 | * or some other miscellaneous error on the name. |
| 85 | */ |
| 86 | if ( status ) { |
| 87 | /* |
| 88 | * Unless provided a valid name that did not already exist |
| 89 | * and we are willing to create then it is an error. |
| 90 | */ |
| 91 | if ( !( status == ENOENT2 && (oflag & O_CREAT0100) ) ) { |
| 92 | _POSIX_Message_queue_Free_fd( the_mq_fd ); |
| 93 | _Thread_Enable_dispatch(); |
| 94 | rtems_set_errno_and_return_minus_one_cast( status, mqd_t )do { (*__errno_location ()) = (status); return (mqd_t) -1; } while (0); |
| 95 | } |
| 96 | |
| 97 | } else { /* name -> ID translation succeeded */ |
| 98 | /* |
| 99 | * Check for existence with creation. |
| 100 | */ |
| 101 | if ( (oflag & (O_CREAT0100 | O_EXCL0200)) == (O_CREAT0100 | O_EXCL0200) ) { |
| 102 | _POSIX_Message_queue_Free_fd( the_mq_fd ); |
| 103 | _Thread_Enable_dispatch(); |
| 104 | rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t )do { (*__errno_location ()) = (17); return (mqd_t) -1; } while (0); |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * In this case we need to do an ID->pointer conversion to |
| 109 | * check the mode. |
| 110 | */ |
| 111 | the_mq = _POSIX_Message_queue_Get( the_mq_id, &location ); |
| 112 | the_mq->open_count += 1; |
| 113 | the_mq_fd->Queue = the_mq; |
| 114 | _Objects_Open_string( |
| 115 | &_POSIX_Message_queue_Information_fds, |
| 116 | &the_mq_fd->Object, |
| 117 | NULL((void *)0) |
| 118 | ); |
| 119 | _Thread_Enable_dispatch(); |
| 120 | _Thread_Enable_dispatch(); |
| 121 | return (mqd_t)the_mq_fd->Object.id; |
| 122 | |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * At this point, the message queue does not exist and everything has been |
| 127 | * checked. We should go ahead and create a message queue. |
| 128 | */ |
| 129 | status = _POSIX_Message_queue_Create_support( |
| 130 | name, |
| 131 | true1, /* shared across processes */ |
| 132 | attr, |
| 133 | &the_mq |
| 134 | ); |
| 135 | |
| 136 | /* |
| 137 | * errno was set by Create_support, so don't set it again. |
| 138 | */ |
| 139 | if ( status == -1 ) { |
| 140 | _POSIX_Message_queue_Free_fd( the_mq_fd ); |
| 141 | _Thread_Enable_dispatch(); |
| 142 | return (mqd_t) -1; |
| 143 | } |
| 144 | |
| 145 | the_mq_fd->Queue = the_mq; |
| 146 | _Objects_Open_string( |
| 147 | &_POSIX_Message_queue_Information_fds, |
| 148 | &the_mq_fd->Object, |
| 149 | NULL((void *)0) |
| 150 | ); |
| 151 | |
| 152 | _Thread_Enable_dispatch(); |
| 153 | |
| 154 | return (mqd_t) the_mq_fd->Object.id; |
| 155 | } |