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

4.104.114.84.95
Last change on this file since e180a77e was e180a77e, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 18:28:24

2002-01-04 Ralf Corsepius <corsepiu@…>

  • src/clockgetres.c: Apply rtems_set_errno_and_return_minus_one.
  • src/clockgettime.c: Apply rtems_set_errno_and_return_minus_one.
  • src/clocksettime.c: Apply rtems_set_errno_and_return_minus_one.
  • src/killinfo.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueueclose.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuecreatesupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuegetattr.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuenotify.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueueopen.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuerecvsupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuesendsupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuesetattr.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueueunlink.c: Apply rtems_set_errno_and_return_minus_one.
  • src/nanosleep.c: Apply rtems_set_errno_and_return_minus_one.
  • src/pthreadkill.c: Apply rtems_set_errno_and_return_minus_one.
  • src/pthreadsigmask.c: Apply rtems_set_errno_and_return_minus_one.
  • src/ptimer1.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sched.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semaphorecreatesupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semaphorewaitsupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semclose.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semdestroy.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semgetvalue.c: Apply rtems_set_errno_and_return_minus_one.
  • src/seminit.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semopen.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sempost.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semunlink.c: Apply rtems_set_errno_and_return_minus_one.
  • src/setpgid.c: Apply rtems_set_errno_and_return_minus_one.
  • src/setsid.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigaction.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigaddset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigdelset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigemptyset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigfillset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigismember.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigpending.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigtimedwait.c: Apply rtems_set_errno_and_return_minus_one.
  • src/utsname.c: Apply rtems_set_errno_and_return_minus_one.
  • 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#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  Objects_Locations              location;
55 
56  _Thread_Disable_dispatch();
57
58  if ( oflag & O_CREAT ) {
59    va_start(arg, oflag);
60    mode = (mode_t) va_arg( arg, unsigned int );
61    attr = (struct mq_attr *) va_arg( arg, struct mq_attr * );
62    va_end(arg);
63  }
64 
65  status = _POSIX_Message_queue_Name_to_id( name, &the_mq_id );
66 
67  /*
68   *  If the name to id translation worked, then the message queue exists
69   *  and we can just return a pointer to the id.  Otherwise we may
70   *  need to check to see if this is a "message queue does not exist"
71   *  or some other miscellaneous error on the name.
72   */
73 
74  if ( status ) {
75 
76    /*
77     * Unless provided a valid name that did not already exist
78     * and we are willing to create then it is an error.
79     */
80
81    if ( !( status == ENOENT && (oflag & O_CREAT) ) ) {
82      _Thread_Enable_dispatch();
83      rtems_set_errno_and_return_minus_one_cast( status, mqd_t );
84    }
85
86  } else {                /* name -> ID translation succeeded */
87 
88    /*
89     * Check for existence with creation.
90     */
91
92    if ( (oflag & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL) ) {
93      _Thread_Enable_dispatch();
94      rtems_set_errno_and_return_minus_one_cast( EEXIST, mqd_t );
95    }
96
97    /*
98     * XXX In this case we need to do an ID->pointer conversion to
99     *     check the mode.   This is probably a good place for a subroutine.
100     */
101
102    the_mq = _POSIX_Message_queue_Get( the_mq_id, &location );
103    the_mq->open_count += 1;
104    _Thread_Enable_dispatch();
105    _Thread_Enable_dispatch();
106    return (mqd_t)the_mq->Object.id;
107 
108  }
109 
110  /*
111   *  At this point, the message queue does not exist and everything has been
112   *  checked. We should go ahead and create a message queue.
113   */
114 
115  status = _POSIX_Message_queue_Create_support(
116    name,
117    TRUE,         /* shared across processes */
118    oflag,
119    attr,
120    &the_mq
121  );
122 
123  /*
124   * errno was set by Create_support, so don't set it again.
125   */
126
127  _Thread_Enable_dispatch();
128
129  if ( status == -1 )
130    return (mqd_t) -1;
131 
132  return (mqd_t) the_mq->Object.id;
133}
134
135
136
137
138
Note: See TracBrowser for help on using the repository browser.