]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/msgctl.c
Update to LGPL v2.1.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / 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 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.
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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 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 <bp-checks.h>
28
29 #include "kernel-features.h"
30 #include <shlib-compat.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 #ifdef __NR_getuid32
57 # if __ASSUME_32BITUIDS == 0
58 /* This variable is shared with all files that need to check for 32bit
59 uids. */
60 extern int __libc_missing_32bit_uids;
61 # endif
62 #endif
63
64 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
65 int
66 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
67 {
68 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
69 msqid, cmd, 0, CHECK_1 (buf));
70 }
71 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
72 #endif
73
74 int
75 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
76 {
77 #if __ASSUME_32BITUIDS > 0
78 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
79 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
80 #else
81 switch (cmd) {
82 case MSG_STAT:
83 case IPC_STAT:
84 case IPC_SET:
85 break;
86 default:
87 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
88 msqid, cmd, 0, CHECK_1 (buf));
89 }
90
91 {
92 int result;
93 struct __old_msqid_ds old;
94
95 #ifdef __NR_getuid32
96 if (__libc_missing_32bit_uids <= 0)
97 {
98 if (__libc_missing_32bit_uids < 0)
99 {
100 int save_errno = errno;
101
102 /* Test presence of new IPC by testing for getuid32 syscall. */
103 result = INLINE_SYSCALL (getuid32, 0);
104 if (result == -1 && errno == ENOSYS)
105 __libc_missing_32bit_uids = 1;
106 else
107 __libc_missing_32bit_uids = 0;
108 __set_errno(save_errno);
109 }
110 if (__libc_missing_32bit_uids <= 0)
111 {
112 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
113 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
114 return result;
115 }
116 }
117 #endif
118 if (cmd == IPC_SET)
119 {
120 old.msg_perm.uid = buf->msg_perm.uid;
121 old.msg_perm.gid = buf->msg_perm.gid;
122 old.msg_perm.mode = buf->msg_perm.mode;
123 old.msg_qbytes = buf->msg_qbytes;
124 if (old.msg_perm.uid != buf->msg_perm.uid ||
125 old.msg_perm.gid != buf->msg_perm.gid ||
126 old.msg_qbytes != buf->msg_qbytes)
127 {
128 __set_errno (EINVAL);
129 return -1;
130 }
131 }
132 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
133 msqid, cmd, 0, __ptrvalue (&old));
134 if (result != -1 && cmd != IPC_SET)
135 {
136 memset(buf, 0, sizeof(*buf));
137 buf->msg_perm.__key = old.msg_perm.__key;
138 buf->msg_perm.uid = old.msg_perm.uid;
139 buf->msg_perm.gid = old.msg_perm.gid;
140 buf->msg_perm.cuid = old.msg_perm.cuid;
141 buf->msg_perm.cgid = old.msg_perm.cgid;
142 buf->msg_perm.mode = old.msg_perm.mode;
143 buf->msg_perm.__seq = old.msg_perm.__seq;
144 buf->msg_stime = old.msg_stime;
145 buf->msg_rtime = old.msg_rtime;
146 buf->msg_ctime = old.msg_ctime;
147 buf->__msg_cbytes = old.__msg_cbytes;
148 buf->msg_qnum = old.msg_qnum;
149 buf->msg_qbytes = old.msg_qbytes;
150 buf->msg_lspid = old.msg_lspid;
151 buf->msg_lrpid = old.msg_lrpid;
152 }
153 return result;
154 }
155 #endif
156 }
157
158 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);