1 /* Copyright (C) 1995-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
25 #include <sys/syscall.h>
26 #include <shlib-compat.h>
28 #include <kernel-features.h>
32 struct __old_ipc_perm msg_perm
; /* structure describing operation permission */
33 struct msg
*__msg_first
; /* pointer to first message on queue */
34 struct msg
*__msg_last
; /* pointer to last message on queue */
35 __time_t msg_stime
; /* time of last msgsnd command */
36 __time_t msg_rtime
; /* time of last msgrcv command */
37 __time_t msg_ctime
; /* time of last change */
38 struct wait_queue
*__wwait
; /* ??? */
39 struct wait_queue
*__rwait
; /* ??? */
40 unsigned short int __msg_cbytes
; /* current number of bytes on queue */
41 unsigned short int msg_qnum
; /* number of messages currently on queue */
42 unsigned short int msg_qbytes
; /* max number of bytes allowed on queue */
43 __ipc_pid_t msg_lspid
; /* pid of last msgsnd() */
44 __ipc_pid_t msg_lrpid
; /* pid of last msgrcv() */
47 /* Allows to control internal state and destruction of message queue
49 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
50 int __old_msgctl (int, int, struct __old_msqid_ds
*);
52 int __new_msgctl (int, int, struct msqid_ds
*);
54 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
56 attribute_compat_text_section
57 __old_msgctl (int msqid
, int cmd
, struct __old_msqid_ds
*buf
)
59 return INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
, msqid
, cmd
, 0, buf
);
61 compat_symbol (libc
, __old_msgctl
, msgctl
, GLIBC_2_0
);
65 __new_msgctl (int msqid
, int cmd
, struct msqid_ds
*buf
)
67 #if __ASSUME_IPC64 > 0
68 return INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
69 msqid
, cmd
| __IPC_64
, 0, buf
);
77 return INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
83 struct __old_msqid_ds old
;
85 /* Unfortunately there is no way how to find out for sure whether
86 we should use old or new msgctl. */
87 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
,
88 msqid
, cmd
| __IPC_64
, 0, buf
);
89 if (result
!= -1 || errno
!= EINVAL
)
94 old
.msg_perm
.uid
= buf
->msg_perm
.uid
;
95 old
.msg_perm
.gid
= buf
->msg_perm
.gid
;
96 old
.msg_perm
.mode
= buf
->msg_perm
.mode
;
97 old
.msg_qbytes
= buf
->msg_qbytes
;
98 if (old
.msg_perm
.uid
!= buf
->msg_perm
.uid
||
99 old
.msg_perm
.gid
!= buf
->msg_perm
.gid
||
100 old
.msg_qbytes
!= buf
->msg_qbytes
)
102 __set_errno (EINVAL
);
106 result
= INLINE_SYSCALL (ipc
, 5, IPCOP_msgctl
, msqid
, cmd
, 0, &old
);
107 if (result
!= -1 && cmd
!= IPC_SET
)
109 memset(buf
, 0, sizeof(*buf
));
110 buf
->msg_perm
.__key
= old
.msg_perm
.__key
;
111 buf
->msg_perm
.uid
= old
.msg_perm
.uid
;
112 buf
->msg_perm
.gid
= old
.msg_perm
.gid
;
113 buf
->msg_perm
.cuid
= old
.msg_perm
.cuid
;
114 buf
->msg_perm
.cgid
= old
.msg_perm
.cgid
;
115 buf
->msg_perm
.mode
= old
.msg_perm
.mode
;
116 buf
->msg_perm
.__seq
= old
.msg_perm
.__seq
;
117 buf
->msg_stime
= old
.msg_stime
;
118 buf
->msg_rtime
= old
.msg_rtime
;
119 buf
->msg_ctime
= old
.msg_ctime
;
120 buf
->__msg_cbytes
= old
.__msg_cbytes
;
121 buf
->msg_qnum
= old
.msg_qnum
;
122 buf
->msg_qbytes
= old
.msg_qbytes
;
123 buf
->msg_lspid
= old
.msg_lspid
;
124 buf
->msg_lrpid
= old
.msg_lrpid
;
131 versioned_symbol (libc
, __new_msgctl
, msgctl
, GLIBC_2_2
);