]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/unix/sysv/linux/semctl.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / semctl.c
1 /* Copyright (C) 1995-2016 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 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.
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 Lesser General Public License for more details.
14
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/>. */
18
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <sys/sem.h>
22 #include <ipc_priv.h>
23
24 #include <sysdep.h>
25 #include <string.h>
26 #include <sys/syscall.h>
27 #include <shlib-compat.h>
28
29 #include <kernel-features.h>
30
31 struct __old_semid_ds
32 {
33 struct __old_ipc_perm sem_perm; /* operation permission struct */
34 __time_t sem_otime; /* last semop() time */
35 __time_t sem_ctime; /* last time changed by semctl() */
36 struct sem *__sembase; /* ptr to first semaphore in array */
37 struct sem_queue *__sem_pending; /* pending operations */
38 struct sem_queue *__sem_pending_last; /* last pending operation */
39 struct sem_undo *__undo; /* ondo requests on this array */
40 unsigned short int sem_nsems; /* number of semaphores in set */
41 };
42
43 /* Define a `union semun' suitable for Linux here. */
44 union semun
45 {
46 int val; /* value for SETVAL */
47 struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
48 unsigned short int *array; /* array for GETALL & SETALL */
49 struct seminfo *__buf; /* buffer for IPC_INFO */
50 struct __old_semid_ds *__old_buf;
51 };
52
53 /* Return identifier for array of NSEMS semaphores associated with
54 KEY. */
55 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
56 int __old_semctl (int semid, int semnum, int cmd, ...);
57 #endif
58 int __new_semctl (int semid, int semnum, int cmd, ...);
59
60 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2)
61 int
62 attribute_compat_text_section
63 __old_semctl (int semid, int semnum, int cmd, ...)
64 {
65 union semun arg;
66 va_list ap;
67
68 /* Get the argument only if required. */
69 arg.buf = NULL;
70 switch (cmd)
71 {
72 case SETVAL: /* arg.val */
73 case GETALL: /* arg.array */
74 case SETALL:
75 case IPC_STAT: /* arg.buf */
76 case IPC_SET:
77 case SEM_STAT:
78 case IPC_INFO: /* arg.__buf */
79 case SEM_INFO:
80 va_start (ap, cmd);
81 arg = va_arg (ap, union semun);
82 va_end (ap);
83 break;
84 }
85
86 return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd,
87 &arg);
88 }
89 compat_symbol (libc, __old_semctl, semctl, GLIBC_2_0);
90 #endif
91
92 int
93 __new_semctl (int semid, int semnum, int cmd, ...)
94 {
95 union semun arg;
96 va_list ap;
97
98 /* Get the argument only if required. */
99 arg.buf = NULL;
100 switch (cmd)
101 {
102 case SETVAL: /* arg.val */
103 case GETALL: /* arg.array */
104 case SETALL:
105 case IPC_STAT: /* arg.buf */
106 case IPC_SET:
107 case SEM_STAT:
108 case IPC_INFO: /* arg.__buf */
109 case SEM_INFO:
110 va_start (ap, cmd);
111 arg = va_arg (ap, union semun);
112 va_end (ap);
113 break;
114 }
115
116 return INLINE_SYSCALL (ipc, 5, IPCOP_semctl, semid, semnum, cmd | __IPC_64,
117 &arg);
118 }
119
120 versioned_symbol (libc, __new_semctl, semctl, GLIBC_2_2);