source: rtems/c/src/exec/posix/src/mqueueopen.c @ 7fbef786

4.104.114.84.95
Last change on this file since 7fbef786 was 7fbef786, checked in by Jennifer Averett <Jennifer.Averett@…>, on 12/23/99 at 22:09:36

+ Debugged.

  • Property mode set to 100644
File size: 3.4 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 *  15.2.2 Open a Message Queue, P1003.1b-1993, p. 272
34 */
35
36mqd_t mq_open(
37  const char *name,
38  int         oflag,
39  ...
40  /* mode_t mode, */
41  /* struct mq_attr  attr */
42)
43{
44  va_list                        arg;
45  mode_t                         mode;
46  struct mq_attr                *attr;
47  int                            status;
48  Objects_Id                     the_mq_id;
49  POSIX_Message_queue_Control   *the_mq;
50  Objects_Locations              location;
51 
52  _Thread_Disable_dispatch();
53
54  if ( oflag & O_CREAT ) {
55    va_start(arg, oflag);
56    mode = (mode_t) va_arg( arg, mode_t );
57    attr = (struct mq_attr *) va_arg( arg, struct mq_attr * );
58    va_end(arg);
59  }
60 
61  status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id );
62 
63  /*
64   *  If the name to id translation worked, then the message queue exists
65   *  and we can just return a pointer to the id.  Otherwise we may
66   *  need to check to see if this is a "message queue does not exist"
67   *  or some other miscellaneous error on the name.
68   */
69 
70  if ( status ) {
71 
72    /*
73     * Unless provided a valid name that did not already exist
74     * and we are willing to create then it is an error.
75     */
76
77    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
78      _Thread_Enable_dispatch();
79      set_errno_and_return_minus_one_cast( status, mqd_t );
80    }
81
82  } else {                /* name -> ID translation succeeded */
83 
84    /*
85     * Check for existence with creation.
86     */
87
88    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
89      _Thread_Enable_dispatch();
90      set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
91    }
92
93    /*
94     * XXX In this case we need to do an ID->pointer conversion to
95     *     check the mode.   This is probably a good place for a subroutine.
96     */
97
98    the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
99    the_mq->open_count += 1;
100    _Thread_Enable_dispatch();
101    _Thread_Enable_dispatch();
102    return (mqd_t)the_mq->Object.id;
103 
104  }
105 
106  /* XXX verify this comment...
107   *
108   *  At this point, the message queue does not exist and everything has been
109   *  checked. We should go ahead and create a message queue.
110   */
111 
112  status = _POSIX_Message_queue_Create_support(
113    name,
114    TRUE,         /* shared across processes */
115    oflag,
116    attr,
117    &the_mq
118  );
119 
120  /*
121   * errno was set by Create_support, so don't set it again.
122   */
123
124  _Thread_Enable_dispatch();
125
126  if ( status == -1 )
127    return (mqd_t) -1;
128 
129  return (mqd_t) the_mq->Object.id;
130}
131
Note: See TracBrowser for help on using the repository browser.