1 /*
2 * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
3 *
4 * Licensed under the GNU GPLv2 or later.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program 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
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 /*
21 * Setups futex in shared memory needed for synchronization between multiple
22 * processes.
23 */
24
25 static futex_t *futex;
26
setup(void)27 static void setup(void)
28 {
29 int fd;
30
31 fd = shm_open("/LTP_futex_wait", O_RDWR | O_CREAT | O_EXCL, 0);
32
33 if (fd < 0) {
34 tst_brkm(TBROK | TERRNO, NULL,
35 "shm_open(/LTP_futex_wait,O_RDWR|O_CREAT|O_EXCL,775)");
36 }
37 if (shm_unlink("/LTP_futex_wait"))
38 tst_brkm(TBROK | TERRNO, NULL, "shm_unlink(/LTP_futex_wait)");
39
40 futex = SAFE_MMAP(NULL, NULL, sizeof(*futex), PROT_READ | PROT_WRITE,
41 MAP_ANONYMOUS | MAP_SHARED, fd, 0);
42
43 SAFE_CLOSE(NULL, fd);
44
45 *futex = FUTEX_INITIALIZER;
46 }
47