source: rtems/cpukit/posix/src/mqueuecreatesupp.c @ d4548d1

4.104.114.84.95
Last change on this file since d4548d1 was d4548d1, checked in by Jennifer Averett <Jennifer.Averett@…>, on Dec 23, 1999 at 10:07:11 PM

+ Made work
+ Added checks for valid attribute maxmsg and msgsize
+ Added check for ENAMETOOLONG

  • Property mode set to 100644
File size: 4.5 KB
Line 
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 *  $Id$
15 */
16
17#include <stdarg.h>
18
19#include <pthread.h>
20#include <limits.h>
21#include <errno.h>
22#include <fcntl.h>
23#include <mqueue.h>
24
25#include <rtems/system.h>
26#include <rtems/score/watchdog.h>
27#include <rtems/posix/seterr.h>
28#include <rtems/posix/mqueue.h>
29#include <rtems/posix/time.h>
30
31/*PAGE
32 *
33 *  _POSIX_Message_queue_Create_support
34 */
35 
36int _POSIX_Message_queue_Create_support(
37  const char                    *name,
38  int                            pshared,
39  unsigned int                   oflag,
40  struct mq_attr                *attr_ptr,
41  POSIX_Message_queue_Control  **message_queue
42)
43{
44  POSIX_Message_queue_Control   *the_mq;
45  CORE_message_queue_Attributes *the_mq_attr;
46  struct mq_attr                 attr;
47
48  _Thread_Disable_dispatch();
49 
50  if ( attr_ptr == NULL ) {
51    attr.mq_maxmsg  = 0;  /* XXX */
52    attr.mq_msgsize = 0;  /* XXX */
53  } else {
54    if ( attr_ptr->mq_maxmsg < 0 ){
55      _Thread_Enable_dispatch();
56      set_errno_and_return_minus_one( EINVAL );
57    }
58
59    if ( attr_ptr->mq_msgsize < 0 ){
60      _Thread_Enable_dispatch();
61      set_errno_and_return_minus_one( EINVAL );
62    }
63
64    attr = *attr_ptr;
65  }
66
67#if defined(RTEMS_MULTIPROCESSING)
68  if ( pshared == PTHREAD_PROCESS_SHARED &&
69       !( _Objects_MP_Allocate_and_open( &_POSIX_Message_queue_Information, 0,
70                            the_mq->Object.id, FALSE ) ) ) {
71    _POSIX_Message_queue_Free( the_mq );
72    _Thread_Enable_dispatch();
73    set_errno_and_return_minus_one( ENFILE );
74  }
75#endif
76 
77  if ( name ) {
78
79    if( strlen(name) > PATH_MAX ) {  /* XXX - Is strlen ok to use here ? */
80      _Thread_Enable_dispatch();
81      set_errno_and_return_minus_one( ENAMETOOLONG );
82    }
83
84    /*
85     * XXX Greater than NAME_MAX while POSIX_NO_TRUNC in effect.
86     * XXX Error description in POSIX book different for mq_open and mq_unlink
87     *     Why???
88     */
89  }
90
91  the_mq = _POSIX_Message_queue_Allocate();
92  if ( !the_mq ) {
93    _Thread_Enable_dispatch();
94    set_errno_and_return_minus_one( ENFILE );
95  }
96 
97  the_mq->process_shared  = pshared;
98 
99  if ( name ) {
100    the_mq->named = TRUE;
101    the_mq->open_count = 1;
102    the_mq->linked = TRUE;
103 }
104  else {
105    the_mq->named = FALSE;
106
107  }
108
109  if ( oflag & O_NONBLOCK ) 
110    the_mq->blocking = FALSE;
111  else
112    the_mq->blocking = TRUE;
113 
114  /* XXX
115   *
116   *  Note that this should be based on the current scheduling policy.
117   */
118
119  /* XXX
120   *
121   *  Message and waiting disciplines are not distinguished.
122   */
123/*
124  the_mq_attr->message_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
125  the_mq_attr->waiting_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
126 */
127   
128
129  the_mq->Message_queue.Attributes.discipline =
130                                         CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
131  the_mq_attr = &the_mq->Message_queue.Attributes;
132
133  if ( ! _CORE_message_queue_Initialize(
134           &the_mq->Message_queue,
135           OBJECTS_POSIX_MESSAGE_QUEUES,
136           the_mq_attr,
137           attr.mq_maxmsg,
138           attr.mq_msgsize,
139#if defined(RTEMS_MULTIPROCESSING)
140           _POSIX_Message_queue_MP_Send_extract_proxy
141#else
142           NULL
143#endif
144      ) ) {
145
146#if defined(RTEMS_MULTIPROCESSING)
147    if ( pshared == PTHREAD_PROCESS_SHARED )
148      _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id );
149#endif
150 
151    _POSIX_Message_queue_Free( the_mq );
152    _Thread_Enable_dispatch();
153    set_errno_and_return_minus_one( ENOSPC );
154  }
155
156 
157  /* XXX - need Names to be a string!!! */
158  _Objects_Open(
159    &_POSIX_Message_queue_Information,
160    &the_mq->Object,
161    (char *) name
162  );
163 
164  *message_queue = the_mq;
165 
166#if defined(RTEMS_MULTIPROCESSING)
167  if ( pshared == PTHREAD_PROCESS_SHARED )
168    _POSIX_Message_queue_MP_Send_process_packet(
169      POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
170      the_mq->Object.id,
171      (char *) name,
172      0                          /* Not used */
173    );
174#endif
175 
176  _Thread_Enable_dispatch();
177  return 0;
178}
179
180
181
182
183
Note: See TracBrowser for help on using the repository browser.