]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/i386/msgctl.c
Update.
[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 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.
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 Library General Public License for more details.
14
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. */
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
28 #include "kernel-features.h"
29
30 struct __old_msqid_ds
31 {
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() */
45 };
46
47 /* Allows to control internal state and destruction of message queue
48 objects. */
49 int __old_msgctl (int, int, struct __old_msqid_ds *);
50 int __new_msgctl (int, int, struct msqid_ds *);
51
52 #ifdef __NR_getuid32
53 # if __ASSUME_32BITUIDS == 0
54 /* This variable is shared with all files that need to check for 32bit
55 uids. */
56 extern int __libc_missing_32bit_uids;
57 # endif
58 #endif
59
60 int
61 __old_msgctl (int msqid, int cmd, struct __old_msqid_ds *buf)
62 {
63 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, buf);
64 }
65
66 int
67 __new_msgctl (int msqid, int cmd, struct msqid_ds *buf)
68 {
69 #if __ASSUME_32BITUIDS > 0
70 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
71 #else
72 switch (cmd) {
73 case MSG_STAT:
74 case IPC_STAT:
75 case IPC_SET:
76 break;
77 default:
78 return INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, buf);
79 }
80
81 {
82 int result;
83 struct __old_msqid_ds old;
84
85 #ifdef __NR_getuid32
86 if (__libc_missing_32bit_uids <= 0)
87 {
88 if (__libc_missing_32bit_uids < 0)
89 {
90 int save_errno = errno;
91
92 /* Test presence of new IPC by testing for getuid32 syscall. */
93 result = INLINE_SYSCALL (getuid32, 0);
94 if (result == -1 && errno == ENOSYS)
95 __libc_missing_32bit_uids = 1;
96 else
97 __libc_missing_32bit_uids = 0;
98 __set_errno(save_errno);
99 }
100 if (__libc_missing_32bit_uids <= 0)
101 {
102 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd | __IPC_64, 0, buf);
103 return result;
104 }
105 }
106 #endif
107 if (cmd == IPC_SET)
108 {
109 old.msg_perm.uid = buf->msg_perm.uid;
110 old.msg_perm.gid = buf->msg_perm.gid;
111 old.msg_perm.mode = buf->msg_perm.mode;
112 old.msg_qbytes = buf->msg_qbytes;
113 if (old.msg_perm.uid != buf->msg_perm.uid ||
114 old.msg_perm.gid != buf->msg_perm.gid ||
115 old.msg_qbytes != buf->msg_qbytes)
116 {
117 __set_errno (EINVAL);
118 return -1;
119 }
120 }
121 result = INLINE_SYSCALL (ipc, 5, IPCOP_msgctl, msqid, cmd, 0, &old);
122 if (result != -1 && cmd != IPC_SET)
123 {
124 memset(buf, 0, sizeof(*buf));
125 buf->msg_perm.__key = old.msg_perm.__key;
126 buf->msg_perm.uid = old.msg_perm.uid;
127 buf->msg_perm.gid = old.msg_perm.gid;
128 buf->msg_perm.cuid = old.msg_perm.cuid;
129 buf->msg_perm.cgid = old.msg_perm.cgid;
130 buf->msg_perm.mode = old.msg_perm.mode;
131 buf->msg_perm.__seq = old.msg_perm.__seq;
132 buf->msg_stime = old.msg_stime;
133 buf->msg_rtime = old.msg_rtime;
134 buf->msg_ctime = old.msg_ctime;
135 buf->__msg_cbytes = old.__msg_cbytes;
136 buf->msg_qnum = old.msg_qnum;
137 buf->msg_qbytes = old.msg_qbytes;
138 buf->msg_lspid = old.msg_lspid;
139 buf->msg_lrpid = old.msg_lrpid;
140 }
141 return result;
142 }
143 #endif
144 }
145
146 #if defined PIC && DO_VERSIONING
147 default_symbol_version (__new_msgctl, msgctl, GLIBC_2.2);
148 symbol_version (__old_msgctl, msgctl, GLIBC_2.0);
149 #else
150 weak_alias (__new_msgctl, msgctl);
151 #endif