source: rtems/c/src/exec/posix/src/mqueueopen.c @ a148f56

4.104.114.84.95
Last change on this file since a148f56 was a148f56, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/00 at 14:00:38

Removed warnings.

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