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. */
26 #include <sys/syscall.h>
28 #include "kernel-features.h"
32 struct __old_ipc_perm msg_perm; /* structure describing operation permission */
33 struct msg *__msg_first; /* pointer to first message on queue */
34 struct msg *__msg_last; /* pointer to last message on queue */
35 __time_t msg_stime; /* time of last msgsnd command */
36 __time_t msg_rtime; /* time of last msgrcv command */
37 __time_t msg_ctime; /* time of last change */
38 struct wait_queue *__wwait; /* ??? */
39 struct wait_queue *__rwait; /* ??? */
40 unsigned short int __msg_cbytes; /* current number of bytes on queue */
41 unsigned short int msg_qnum; /* number of messages currently on queue */
42 unsigned short int msg_qbytes; /* max number of bytes allowed on queue */
43 __ipc_pid_t msg_lspid; /* pid of last msgsnd() */
44 __ipc_pid_t msg_lrpid; /* pid of last msgrcv() */
47 /* Allows to control internal state and destruction of message queue
49 int __new_msgctl (int, int, struct msqid_ds *);
52 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
54 /* This is a misnomer -- Alpha had 32-bit uids at the beginning
55 of time. However, msg_qnum and msg_qbytes changed size at
56 the same time the size of uid changed elsewhere. */
57 #if __ASSUME_32BITUIDS > 0
58 return INLINE_SYSCALL (msgctl, 3, msqid, cmd | __IPC_64, buf);
66 return INLINE_SYSCALL (msgctl, 3, msqid, cmd, buf);
70 int save_errno = errno, result;
71 struct __old_msqid_ds old;
73 /* Unfortunately there is no way how to find out for sure whether
74 we should use old or new msgctl. */
75 result = INLINE_SYSCALL (msgctl, 3, msqid, cmd | __IPC_64, buf);
76 if (result != -1 || errno != EINVAL)
79 __set_errno(save_errno);
82 old.msg_perm.uid = buf->msg_perm.uid;
83 old.msg_perm.gid = buf->msg_perm.gid;
84 old.msg_perm.mode = buf->msg_perm.mode;
85 old.msg_qbytes = buf->msg_qbytes;
86 if (old.msg_perm.uid != buf->msg_perm.uid ||
87 old.msg_perm.gid != buf->msg_perm.gid ||
88 old.msg_qbytes != buf->msg_qbytes)
94 result = INLINE_SYSCALL (msgctl, 3, msqid, cmd, &old);
95 if (result != -1 && cmd != IPC_SET)
97 memset(buf, 0, sizeof(*buf));
98 buf->msg_perm.__key = old.msg_perm.__key;
99 buf->msg_perm.uid = old.msg_perm.uid;
100 buf->msg_perm.gid = old.msg_perm.gid;
101 buf->msg_perm.cuid = old.msg_perm.cuid;
102 buf->msg_perm.cgid = old.msg_perm.cgid;
103 buf->msg_perm.mode = old.msg_perm.mode;
104 buf->msg_perm.__seq = old.msg_perm.__seq;
105 buf->msg_stime = old.msg_stime;
106 buf->msg_rtime = old.msg_rtime;
107 buf->msg_ctime = old.msg_ctime;
108 buf->__msg_cbytes = old.__msg_cbytes;
109 buf->msg_qnum = old.msg_qnum;
110 buf->msg_qbytes = old.msg_qbytes;
111 buf->msg_lspid = old.msg_lspid;
112 buf->msg_lrpid = old.msg_lrpid;
119 #include <shlib-compat.h>
120 versioned_symbol (libc, __new_msgctl, msgctl, GLIBC_2_2);