Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / msgctl.c
blobfa5a82fa383cb55060bd4ad59de93a9e6c70a4db
1 /* Copyright (C) 1995,1997,1998,2000,2004,2006 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/>. */
19 #include <errno.h>
20 #include <sys/msg.h>
21 #include <ipc_priv.h>
23 #include <sysdep.h>
24 #include <string.h>
25 #include <sys/syscall.h>
26 #include <bp-checks.h>
28 #include <kernel-features.h>
29 #include <shlib-compat.h>
31 struct __old_msqid_ds
33 struct __old_ipc_perm msg_perm; /* structure describing operation permission */
34 struct msg *__unbounded __msg_first; /* pointer to first message on queue */
35 struct msg *__unbounded __msg_last; /* pointer to last message on queue */
36 __time_t msg_stime; /* time of last msgsnd command */
37 __time_t msg_rtime; /* time of last msgrcv command */
38 __time_t msg_ctime; /* time of last change */
39 struct wait_queue *__unbounded __wwait; /* ??? */
40 struct wait_queue *__unbounded __rwait; /* ??? */
41 unsigned short int __msg_cbytes; /* current number of bytes on queue */
42 unsigned short int msg_qnum; /* number of messages currently on queue */
43 unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
44 __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
45 __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
48 /* Allows to control internal state and destruction of message queue
49 objects. */
50 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
51 int __old_msgctl (int, int, struct __old_msqid_ds *);
52 #endif
53 int __new_msgctl (int, int, struct msqid_ds *);
55 #ifdef __NR_getuid32
56 # if __ASSUME_32BITUIDS == 0
57 /* This variable is shared with all files that need to check for 32bit
58 uids. */
59 extern int __libc_missing_32bit_uids;
60 # endif
61 #endif
63 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
64 int
65 attribute_compat_text_section
66 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
68 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
69 msqid, cmd, 0, CHECK_1 (buf));
71 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
72 #endif
74 int
75 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
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));
92 int result;
93 struct __old_msqid_ds old;
95 #ifdef __NR_getuid32
96 if (__libc_missing_32bit_uids <= 0)
98 if (__libc_missing_32bit_uids < 0)
100 int save_errno = errno;
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);
110 if (__libc_missing_32bit_uids <= 0)
112 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
113 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
114 return result;
117 #endif
118 if (cmd == IPC_SET)
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)
128 __set_errno (EINVAL);
129 return -1;
132 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
133 msqid, cmd, 0, __ptrvalue (&old));
134 if (result != -1 && cmd != IPC_SET)
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;
153 return result;
155 #endif
158 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);