source: rtems/cpukit/posix/src/mqueueopen.c @ 1b074a1

4.104.114.84.95
Last change on this file since 1b074a1 was 53092d1, checked in by Joel Sherrill <joel.sherrill@…>, on 04/26/02 at 23:39:01

2001-04-26 Joel Sherrill <joel@…>

  • include/rtems/posix/mqueue.h, inline/rtems/posix/mqueue.inl, src/mqueue.c, src/mqueueclose.c, src/mqueuecreatesupp.c, src/mqueuegetattr.c, src/mqueuenotify.c, src/mqueueopen.c, src/mqueuerecvsupp.c, src/mqueuesendsupp.c, src/mqueuesetattr.c: Per PR81 reworked to add a message queue descriptor separate from the underlying message queue. This allows non-blocking to follow the "open" not the underlying queue.
  • Property mode set to 100644
File size: 3.9 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#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <stdarg.h>
22
23#include <pthread.h>
24#include <limits.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <mqueue.h>
28
29#include <rtems/system.h>
30#include <rtems/score/watchdog.h>
31#include <rtems/seterr.h>
32#include <rtems/posix/mqueue.h>
33#include <rtems/posix/time.h>
34
35/*PAGE
36 *
37 *  15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
38 */
39
40mqd_t mq_open(
41  const char *name,
42  int         oflag,
43  ...
44  /* mode_t mode, */
45  /* struct mq_attr  attr */
46)
47{
48  va_list                         arg;
49  mode_t                          mode;
50  struct mq_attr                 *attr = NULL;
51  int                             status;
52  Objects_Id                      the_mq_id;
53  POSIX_Message_queue_Control    *the_mq;
54  POSIX_Message_queue_Control_fd *the_mq_fd;
55  Objects_Locations               location;
56 
57  _Thread_Disable_dispatch();
58
59  if ( oflag & O_CREAT ) {
60    va_start(arg, oflag);
61    mode = (mode_t) va_arg( arg, unsigned int );
62    attr = (struct mq_attr *) va_arg( arg, struct mq_attr * );
63    va_end(arg);
64  }
65 
66  the_mq_fd = _POSIX_Message_queue_Allocate_fd();
67  if ( !the_mq_fd ) {
68    _Thread_Enable_dispatch();
69    rtems_set_errno_and_return_minus_one( ENFILE );
70  }
71  the_mq_fd->oflag = oflag;
72
73  status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id );
74
75  /*
76   *  If the name to id translation worked, then the message queue exists
77   *  and we can just return a pointer to the id.  Otherwise we may
78   *  need to check to see if this is a "message queue does not exist"
79   *  or some other miscellaneous error on the name.
80   */
81 
82  if ( status ) {
83 
84    /*
85     * Unless provided a valid name that did not already exist
86     * and we are willing to create then it is an error.
87     */
88
89    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
90      _POSIX_Message_queue_Free_fd( the_mq_fd );
91      _Thread_Enable_dispatch();
92      rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
93    }
94
95  } else {                /* name -> ID translation succeeded */
96 
97    /*
98     * Check for existence with creation.
99     */
100
101    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
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 );
105    }
106
107    /*
108     * In this case we need to do an ID->pointer conversion to
109     * check the mode.
110     */
111
112    the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
113    the_mq->open_count += 1;
114    the_mq_fd->Queue = the_mq;
115    _Thread_Enable_dispatch();
116    _Thread_Enable_dispatch();
117    return (mqd_t)the_mq_fd->Object.id;
118 
119  }
120 
121  /*
122   *  At this point, the message queue does not exist and everything has been
123   *  checked. We should go ahead and create a message queue.
124   */
125 
126  status = _POSIX_Message_queue_Create_support(
127    name,
128    TRUE,         /* shared across processes */
129    attr,
130    &the_mq
131  );
132 
133  /*
134   * errno was set by Create_support, so don't set it again.
135   */
136
137  if ( status == -1 ) {
138    _Thread_Enable_dispatch();
139    _POSIX_Message_queue_Free_fd( the_mq_fd );
140    return (mqd_t) -1;
141  }
142 
143  the_mq_fd->Queue = the_mq;
144  _Objects_Open(
145    &_POSIX_Message_queue_Information_fds,
146    &the_mq_fd->Object,
147    NULL
148  );
149 
150  _Thread_Enable_dispatch();
151
152  return (mqd_t) the_mq_fd->Object.id;
153}
154
155
156
157
158
Note: See TracBrowser for help on using the repository browser.