]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/msgctl.c
* sysdeps/gnu/bits/msq.h: Qualify kernel's
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / msgctl.c
1 /* Copyright (C) 1995, 1997, 1998, 2000 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.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
9
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 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
19
20 #include <errno.h>
21 #include <sys/msg.h>
22 #include <ipc_priv.h>
23
24 #include <sysdep.h>
25 #include <string.h>
26 #include <sys/syscall.h>
27 #include <shlib-compat.h>
28 #include <bp-checks.h>
29
30 #include "kernel-features.h"
31
32 struct __old_msqid_ds
33 {
34 struct __old_ipc_perm msg_perm; /* structure describing operation permission */
35 struct msg *__unbounded __msg_first; /* pointer to first message on queue */
36 struct msg *__unbounded __msg_last; /* pointer to last message on queue */
37 __time_t msg_stime; /* time of last msgsnd command */
38 __time_t msg_rtime; /* time of last msgrcv command */
39 __time_t msg_ctime; /* time of last change */
40 struct wait_queue *__unbounded __wwait; /* ??? */
41 struct wait_queue *__unbounded __rwait; /* ??? */
42 unsigned short int __msg_cbytes; /* current number of bytes on queue */
43 unsigned short int msg_qnum; /* number of messages currently on queue */
44 unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
45 __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
46 __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
47 };
48
49 /* Allows to control internal state and destruction of message queue
50 objects. */
51 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
52 int __old_msgctl (int, int, struct __old_msqid_ds *);
53 #endif
54 int __new_msgctl (int, int, struct msqid_ds *);
55
56 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
57 int
58 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
59 {
60 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, CHECK_1 (buf));
61 }
62 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
63 #endif
64
65 int
66 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
67 {
68 #if __ASSUME_32BITUIDS > 0
69 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
70 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
71 #else
72 switch (cmd) {
73 case MSG_STAT:
74 case IPC_STAT:
75 case IPC_SET:
76 break;
77 default:
78 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
79 msqid, cmd, 0, CHECK_1 (buf));
80 }
81
82 {
83 int save_errno = errno, result;
84 struct __old_msqid_ds old;
85
86 /* Unfortunately there is no way how to find out for sure whether
87 we should use old or new msgctl. */
88 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
89 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
90 if (result != -1 || errno != EINVAL)
91 return result;
92
93 __set_errno(save_errno);
94 if (cmd == IPC_SET)
95 {
96 old.msg_perm.uid = buf->msg_perm.uid;
97 old.msg_perm.gid = buf->msg_perm.gid;
98 old.msg_perm.mode = buf->msg_perm.mode;
99 old.msg_qbytes = buf->msg_qbytes;
100 if (old.msg_perm.uid != buf->msg_perm.uid ||
101 old.msg_perm.gid != buf->msg_perm.gid ||
102 old.msg_qbytes != buf->msg_qbytes)
103 {
104 __set_errno (EINVAL);
105 return -1;
106 }
107 }
108 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
109 msqid, cmd, 0, __ptrvalue (&old));
110 if (result != -1 && cmd != IPC_SET)
111 {
112 memset(buf, 0, sizeof(*buf));
113 buf->msg_perm.__key = old.msg_perm.__key;
114 buf->msg_perm.uid = old.msg_perm.uid;
115 buf->msg_perm.gid = old.msg_perm.gid;
116 buf->msg_perm.cuid = old.msg_perm.cuid;
117 buf->msg_perm.cgid = old.msg_perm.cgid;
118 buf->msg_perm.mode = old.msg_perm.mode;
119 buf->msg_perm.__seq = old.msg_perm.__seq;
120 buf->msg_stime = old.msg_stime;
121 buf->msg_rtime = old.msg_rtime;
122 buf->msg_ctime = old.msg_ctime;
123 buf->__msg_cbytes = old.__msg_cbytes;
124 buf->msg_qnum = old.msg_qnum;
125 buf->msg_qbytes = old.msg_qbytes;
126 buf->msg_lspid = old.msg_lspid;
127 buf->msg_lrpid = old.msg_lrpid;
128 }
129 return result;
130 }
131 #endif
132 }
133
134 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);