Update.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / msgctl.c
blob684365a92275faecb3c1532267d0fd8144f68f38
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.
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.
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.
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. */
20 #include <errno.h>
21 #include <sys/msg.h>
22 #include <ipc_priv.h>
24 #include <sysdep.h>
25 #include <string.h>
26 #include <sys/syscall.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 *__msg_first; /* pointer to first message on queue */
35 struct msg *__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 *__wwait; /* ??? */
40 struct wait_queue *__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 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
67 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, buf);
69 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
70 #endif
72 int
73 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
75 #if __ASSUME_32BITUIDS > 0
76 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
77 #else
78 switch (cmd) {
79 case MSG_STAT:
80 case IPC_STAT:
81 case IPC_SET:
82 break;
83 default:
84 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, buf);
88 int result;
89 struct __old_msqid_ds old;
91 #ifdef __NR_getuid32
92 if (__libc_missing_32bit_uids <= 0)
94 if (__libc_missing_32bit_uids < 0)
96 int save_errno = errno;
98 /* Test presence of new IPC by testing for getuid32 syscall. */
99 result = INLINE_SYSCALL (getuid32, 0);
100 if (result == -1 && errno == ENOSYS)
101 __libc_missing_32bit_uids = 1;
102 else
103 __libc_missing_32bit_uids = 0;
104 __set_errno(save_errno);
106 if (__libc_missing_32bit_uids <= 0)
108 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
109 return result;
112 #endif
113 if (cmd == IPC_SET)
115 old.msg_perm.uid = buf->msg_perm.uid;
116 old.msg_perm.gid = buf->msg_perm.gid;
117 old.msg_perm.mode = buf->msg_perm.mode;
118 old.msg_qbytes = buf->msg_qbytes;
119 if (old.msg_perm.uid != buf->msg_perm.uid ||
120 old.msg_perm.gid != buf->msg_perm.gid ||
121 old.msg_qbytes != buf->msg_qbytes)
123 __set_errno (EINVAL);
124 return -1;
127 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, &old);
128 if (result != -1 && cmd != IPC_SET)
130 memset(buf, 0, sizeof(*buf));
131 buf->msg_perm.__key = old.msg_perm.__key;
132 buf->msg_perm.uid = old.msg_perm.uid;
133 buf->msg_perm.gid = old.msg_perm.gid;
134 buf->msg_perm.cuid = old.msg_perm.cuid;
135 buf->msg_perm.cgid = old.msg_perm.cgid;
136 buf->msg_perm.mode = old.msg_perm.mode;
137 buf->msg_perm.__seq = old.msg_perm.__seq;
138 buf->msg_stime = old.msg_stime;
139 buf->msg_rtime = old.msg_rtime;
140 buf->msg_ctime = old.msg_ctime;
141 buf->__msg_cbytes = old.__msg_cbytes;
142 buf->msg_qnum = old.msg_qnum;
143 buf->msg_qbytes = old.msg_qbytes;
144 buf->msg_lspid = old.msg_lspid;
145 buf->msg_lrpid = old.msg_lrpid;
147 return result;
149 #endif
152 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);