Updated to fedora-glibc-20060109T2152
[glibc/history.git] / sysdeps / unix / sysv / linux / msgctl.c
blob86fd34cf8cf15e74395da334df607371d860ce38
1 /* Copyright (C) 1995,1997,1998,2000,2002,2004,2006
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <errno.h>
22 #include <sys/msg.h>
23 #include <ipc_priv.h>
25 #include <sysdep.h>
26 #include <string.h>
27 #include <sys/syscall.h>
28 #include <shlib-compat.h>
29 #include <bp-checks.h>
31 #include <kernel-features.h>
33 struct __old_msqid_ds
35 struct __old_ipc_perm msg_perm; /* structure describing operation permission */
36 struct msg *__unbounded __msg_first; /* pointer to first message on queue */
37 struct msg *__unbounded __msg_last; /* pointer to last message on queue */
38 __time_t msg_stime; /* time of last msgsnd command */
39 __time_t msg_rtime; /* time of last msgrcv command */
40 __time_t msg_ctime; /* time of last change */
41 struct wait_queue *__unbounded __wwait; /* ??? */
42 struct wait_queue *__unbounded __rwait; /* ??? */
43 unsigned short int __msg_cbytes; /* current number of bytes on queue */
44 unsigned short int msg_qnum; /* number of messages currently on queue */
45 unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
46 __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
47 __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
50 /* Allows to control internal state and destruction of message queue
51 objects. */
52 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
53 int __old_msgctl (int, int, struct __old_msqid_ds *);
54 #endif
55 int __new_msgctl (int, int, struct msqid_ds *);
57 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
58 int
59 attribute_compat_text_section
60 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
62 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, CHECK_1 (buf));
64 compat_symbol (libc, __old_msgctl, msgctl, GLIBC_2_0);
65 #endif
67 int
68 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
70 #if __ASSUME_IPC64 > 0
71 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
72 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
73 #else
74 switch (cmd) {
75 case MSG_STAT:
76 case IPC_STAT:
77 case IPC_SET:
78 break;
79 default:
80 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
81 msqid, cmd, 0, CHECK_1 (buf));
85 int result;
86 struct __old_msqid_ds old;
88 /* Unfortunately there is no way how to find out for sure whether
89 we should use old or new msgctl. */
90 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
91 msqid, cmd | __IPC_64, 0, CHECK_1 (buf));
92 if (result != -1 || errno != EINVAL)
93 return result;
95 if (cmd == IPC_SET)
97 old.msg_perm.uid = buf->msg_perm.uid;
98 old.msg_perm.gid = buf->msg_perm.gid;
99 old.msg_perm.mode = buf->msg_perm.mode;
100 old.msg_qbytes = buf->msg_qbytes;
101 if (old.msg_perm.uid != buf->msg_perm.uid ||
102 old.msg_perm.gid != buf->msg_perm.gid ||
103 old.msg_qbytes != buf->msg_qbytes)
105 __set_errno (EINVAL);
106 return -1;
109 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl,
110 msqid, cmd, 0, __ptrvalue (&old));
111 if (result != -1 && cmd != IPC_SET)
113 memset(buf, 0, sizeof(*buf));
114 buf->msg_perm.__key = old.msg_perm.__key;
115 buf->msg_perm.uid = old.msg_perm.uid;
116 buf->msg_perm.gid = old.msg_perm.gid;
117 buf->msg_perm.cuid = old.msg_perm.cuid;
118 buf->msg_perm.cgid = old.msg_perm.cgid;
119 buf->msg_perm.mode = old.msg_perm.mode;
120 buf->msg_perm.__seq = old.msg_perm.__seq;
121 buf->msg_stime = old.msg_stime;
122 buf->msg_rtime = old.msg_rtime;
123 buf->msg_ctime = old.msg_ctime;
124 buf->__msg_cbytes = old.__msg_cbytes;
125 buf->msg_qnum = old.msg_qnum;
126 buf->msg_qbytes = old.msg_qbytes;
127 buf->msg_lspid = old.msg_lspid;
128 buf->msg_lrpid = old.msg_lrpid;
130 return result;
132 #endif
135 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);