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 | |
---|
36 | int _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 | /* |
---|
51 | * There is no real basis for the default values. They will work |
---|
52 | * but were not compared against any existing implementation for |
---|
53 | * compatibility. See README.mqueue for an example program we |
---|
54 | * think will print out the defaults. Report anything you find with it. |
---|
55 | */ |
---|
56 | |
---|
57 | if ( attr_ptr == NULL ) { |
---|
58 | attr.mq_maxmsg = 10; |
---|
59 | attr.mq_msgsize = 16; |
---|
60 | } else { |
---|
61 | if ( attr_ptr->mq_maxmsg < 0 ){ |
---|
62 | _Thread_Enable_dispatch(); |
---|
63 | set_errno_and_return_minus_one( EINVAL ); |
---|
64 | } |
---|
65 | |
---|
66 | if ( attr_ptr->mq_msgsize < 0 ){ |
---|
67 | _Thread_Enable_dispatch(); |
---|
68 | set_errno_and_return_minus_one( EINVAL ); |
---|
69 | } |
---|
70 | |
---|
71 | attr = *attr_ptr; |
---|
72 | } |
---|
73 | |
---|
74 | #if defined(RTEMS_MULTIPROCESSING) |
---|
75 | if ( pshared == PTHREAD_PROCESS_SHARED && |
---|
76 | !( _Objects_MP_Allocate_and_open( &_POSIX_Message_queue_Information, 0, |
---|
77 | the_mq->Object.id, FALSE ) ) ) { |
---|
78 | _POSIX_Message_queue_Free( the_mq ); |
---|
79 | _Thread_Enable_dispatch(); |
---|
80 | set_errno_and_return_minus_one( ENFILE ); |
---|
81 | } |
---|
82 | #endif |
---|
83 | |
---|
84 | if ( name ) { |
---|
85 | |
---|
86 | if( strlen(name) > PATH_MAX ) { /* XXX - on non-null terminated name? */ |
---|
87 | _Thread_Enable_dispatch(); |
---|
88 | set_errno_and_return_minus_one( ENAMETOOLONG ); |
---|
89 | } |
---|
90 | |
---|
91 | /* |
---|
92 | * XXX Greater than NAME_MAX while POSIX_NO_TRUNC in effect. |
---|
93 | * XXX Error description in POSIX book different for mq_open and mq_unlink |
---|
94 | * Why??? |
---|
95 | */ |
---|
96 | } |
---|
97 | |
---|
98 | the_mq = _POSIX_Message_queue_Allocate(); |
---|
99 | if ( !the_mq ) { |
---|
100 | _Thread_Enable_dispatch(); |
---|
101 | set_errno_and_return_minus_one( ENFILE ); |
---|
102 | } |
---|
103 | |
---|
104 | the_mq->process_shared = pshared; |
---|
105 | the_mq->oflag = oflag; |
---|
106 | |
---|
107 | if ( name ) { |
---|
108 | the_mq->named = TRUE; |
---|
109 | the_mq->open_count = 1; |
---|
110 | the_mq->linked = TRUE; |
---|
111 | } |
---|
112 | else { |
---|
113 | the_mq->named = FALSE; |
---|
114 | |
---|
115 | } |
---|
116 | |
---|
117 | if ( oflag & O_NONBLOCK ) |
---|
118 | the_mq->blocking = FALSE; |
---|
119 | else |
---|
120 | the_mq->blocking = TRUE; |
---|
121 | |
---|
122 | /* XXX |
---|
123 | * |
---|
124 | * Note that this should be based on the current scheduling policy. |
---|
125 | */ |
---|
126 | |
---|
127 | /* XXX |
---|
128 | * |
---|
129 | * Message and waiting disciplines are not distinguished. |
---|
130 | */ |
---|
131 | /* |
---|
132 | the_mq_attr->message_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
133 | the_mq_attr->waiting_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
134 | */ |
---|
135 | |
---|
136 | |
---|
137 | the_mq->Message_queue.Attributes.discipline = |
---|
138 | CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
139 | the_mq_attr = &the_mq->Message_queue.Attributes; |
---|
140 | |
---|
141 | if ( ! _CORE_message_queue_Initialize( |
---|
142 | &the_mq->Message_queue, |
---|
143 | OBJECTS_POSIX_MESSAGE_QUEUES, |
---|
144 | the_mq_attr, |
---|
145 | attr.mq_maxmsg, |
---|
146 | attr.mq_msgsize, |
---|
147 | #if defined(RTEMS_MULTIPROCESSING) |
---|
148 | _POSIX_Message_queue_MP_Send_extract_proxy |
---|
149 | #else |
---|
150 | NULL |
---|
151 | #endif |
---|
152 | ) ) { |
---|
153 | |
---|
154 | #if defined(RTEMS_MULTIPROCESSING) |
---|
155 | if ( pshared == PTHREAD_PROCESS_SHARED ) |
---|
156 | _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id ); |
---|
157 | #endif |
---|
158 | |
---|
159 | _POSIX_Message_queue_Free( the_mq ); |
---|
160 | _Thread_Enable_dispatch(); |
---|
161 | set_errno_and_return_minus_one( ENOSPC ); |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | /* XXX - need Names to be a string!!! */ |
---|
166 | _Objects_Open( |
---|
167 | &_POSIX_Message_queue_Information, |
---|
168 | &the_mq->Object, |
---|
169 | (char *) name |
---|
170 | ); |
---|
171 | |
---|
172 | *message_queue = the_mq; |
---|
173 | |
---|
174 | #if defined(RTEMS_MULTIPROCESSING) |
---|
175 | if ( pshared == PTHREAD_PROCESS_SHARED ) |
---|
176 | _POSIX_Message_queue_MP_Send_process_packet( |
---|
177 | POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, |
---|
178 | the_mq->Object.id, |
---|
179 | (char *) name, |
---|
180 | 0 /* Not used */ |
---|
181 | ); |
---|
182 | #endif |
---|
183 | |
---|
184 | _Thread_Enable_dispatch(); |
---|
185 | return 0; |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|