summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/msgctl.c
blob: f785804cbe0091f7e6bea1402cf73d18fec235cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* Copyright (C) 1995-2018 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

#include <sys/msg.h>
#include <ipc_priv.h>
#include <sysdep.h>
#include <shlib-compat.h>
#include <errno.h>

#ifndef DEFAULT_VERSION
# define DEFAULT_VERSION GLIBC_2_2
#endif

int
__new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
{
#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
  return INLINE_SYSCALL_CALL (msgctl, msqid, cmd | __IPC_64, buf);
#else
  return INLINE_SYSCALL_CALL (ipc, IPCOP_msgctl, msqid, cmd | __IPC_64, 0,
			      buf);
#endif
}
versioned_symbol (libc, __new_msgctl, msgctl, DEFAULT_VERSION);


#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
struct __old_msqid_ds
{
  struct __old_ipc_perm msg_perm;	/* structure describing operation permission */
  struct msg *__msg_first;		/* pointer to first message on queue */
  struct msg *__msg_last;		/* pointer to last message on queue */
  __time_t msg_stime;			/* time of last msgsnd command */
  __time_t msg_rtime;			/* time of last msgrcv command */
  __time_t msg_ctime;			/* time of last change */
  struct wait_queue *__wwait;		/* ??? */
  struct wait_queue *__rwait;		/* ??? */
  unsigned short int __msg_cbytes;	/* current number of bytes on queue */
  unsigned short int msg_qnum;		/* number of messages currently on queue */
  unsigned short int msg_qbytes;	/* max number of bytes allowed on queue */
  __ipc_pid_t msg_lspid;		/* pid of last msgsnd() */
  __ipc_pid_t msg_lrpid;		/* pid of last msgrcv() */
};

int
attribute_compat_text_section
__old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
{
#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
  return INLINE_SYSCALL_CALL (msgctl, msqid, cmd | __IPC_64, buf);
#else
  return INLINE_SYSCALL_CALL (ipc, IPCOP_msgctl, msqid, cmd, 0, buf);
#endif
}
compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
#endif

/* 64-bit time version */

struct __msqid_ds64
{
  struct ipc_perm msg_perm;	/* structure describing operation permission */
  __time64_t msg_stime;		/* time of last msgsnd command */
  __time64_t msg_rtime;		/* time of last msgrcv command */
  __time64_t msg_ctime;		/* time of last change */
  unsigned long int __msg_cbytes; /* current number of bytes on queue */
  msgqnum_t msg_qnum;		/* number of messages currently on queue */
  msglen_t msg_qbytes;		/* max number of bytes allowed on queue */
  __pid_t msg_lspid;		/* pid of last msgsnd() */
  __pid_t msg_lrpid;		/* pid of last msgrcv() */
  unsigned long int __glibc_reserved4;
  unsigned long int __glibc_reserved5;
};

int
__msgctl64 (int msqid, int cmd, struct __msqid_ds64 *buf)
{
  int result;
  struct msqid_ds buf32, *pbuf32 = NULL;

  if (cmd == IPC_SET && buf != NULL)
    {
      buf32.msg_qbytes = buf->msg_qbytes;
      buf32.msg_perm.uid = buf->msg_perm.uid;
      buf32.msg_perm.gid = buf->msg_perm.gid;
      buf32.msg_perm.mode = buf->msg_perm.mode;
    }

  if (cmd == IPC_SET || cmd == IPC_STAT)
    pbuf32 = &buf32;

#ifdef __ASSUME_DIRECT_SYSVIPC_SYSCALLS
  result = INLINE_SYSCALL_CALL (msgctl, msqid, cmd | __IPC_64, pbuf32);
#else
  result = INLINE_SYSCALL_CALL (ipc, IPCOP_msgctl, msqid, cmd | __IPC_64,
                                0, pbuf32);
#endif

  if (cmd == IPC_STAT && result == 0 && buf != NULL)
    {
      buf->msg_perm = buf32.msg_perm;
      buf->msg_stime = buf32.msg_stime;
      buf->msg_rtime = buf32.msg_rtime;
      buf->msg_ctime = buf32.msg_ctime;
      buf->__msg_cbytes = buf32.__msg_cbytes;
      buf->msg_qnum = buf32.msg_qnum;
      buf->msg_qbytes = buf32.msg_qbytes;
      buf->msg_lspid = buf32.msg_lspid;
      buf->msg_lrpid = buf32.msg_lrpid;
    }

  return result;
}