diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 16:34:38 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2018-12-27 16:34:38 +0000 |
commit | 7576c27563a3e43c0a276bf222244bcaf220a6fa (patch) | |
tree | ad96fd1f1b9b57a50005db7803f6b79e748bb820 /sysvipc | |
parent | ab5f5211585bf0f33bbfa2d4aaf17e4f0d1fa564 (diff) | |
parent | 064374be911f72dfaec8a75f06da1f9fc1827712 (diff) |
Merge branch 't/hurdsig-global-dispositions' into refs/top-bases/t/hurdsig-SA_SIGINFO
Diffstat (limited to 'sysvipc')
-rw-r--r-- | sysvipc/Makefile | 8 | ||||
-rw-r--r-- | sysvipc/ftok.c | 2 | ||||
-rw-r--r-- | sysvipc/msgctl.c | 2 | ||||
-rw-r--r-- | sysvipc/msgget.c | 2 | ||||
-rw-r--r-- | sysvipc/msgrcv.c | 2 | ||||
-rw-r--r-- | sysvipc/msgsnd.c | 2 | ||||
-rw-r--r-- | sysvipc/semctl.c | 2 | ||||
-rw-r--r-- | sysvipc/semget.c | 2 | ||||
-rw-r--r-- | sysvipc/semop.c | 2 | ||||
-rw-r--r-- | sysvipc/semtimedop.c | 2 | ||||
-rw-r--r-- | sysvipc/shmat.c | 2 | ||||
-rw-r--r-- | sysvipc/shmctl.c | 2 | ||||
-rw-r--r-- | sysvipc/shmdt.c | 2 | ||||
-rw-r--r-- | sysvipc/shmget.c | 2 | ||||
-rw-r--r-- | sysvipc/sys/ipc.h | 6 | ||||
-rw-r--r-- | sysvipc/sys/msg.h | 5 | ||||
-rw-r--r-- | sysvipc/sys/sem.h | 5 | ||||
-rw-r--r-- | sysvipc/sys/shm.h | 5 | ||||
-rw-r--r-- | sysvipc/test-sysvmsg.c | 128 | ||||
-rw-r--r-- | sysvipc/test-sysvsem.c | 123 | ||||
-rw-r--r-- | sysvipc/test-sysvshm.c | 131 |
21 files changed, 407 insertions, 30 deletions
diff --git a/sysvipc/Makefile b/sysvipc/Makefile index 5f3479e4c4..d05bf3e3ec 100644 --- a/sysvipc/Makefile +++ b/sysvipc/Makefile @@ -1,4 +1,4 @@ -# Copyright (C) 1995-2016 Free Software Foundation, Inc. +# Copyright (C) 1995-2018 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or @@ -30,7 +30,9 @@ routines := ftok \ semop semget semctl semtimedop \ shmat shmdt shmget shmctl +tests := test-sysvmsg test-sysvsem test-sysvshm + include ../Rules -CFLAGS-msgrcv.c = -fexceptions -fasynchronous-unwind-tables -CFLAGS-msgsnd.c = -fexceptions -fasynchronous-unwind-tables +CFLAGS-msgrcv.c += -fexceptions -fasynchronous-unwind-tables +CFLAGS-msgsnd.c += -fexceptions -fasynchronous-unwind-tables diff --git a/sysvipc/ftok.c b/sysvipc/ftok.c index ee3880400b..364f510912 100644 --- a/sysvipc/ftok.c +++ b/sysvipc/ftok.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/msgctl.c b/sysvipc/msgctl.c index 99b0fcb4d9..29d112fb33 100644 --- a/sysvipc/msgctl.c +++ b/sysvipc/msgctl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/msgget.c b/sysvipc/msgget.c index 7772e4ab95..d193f433be 100644 --- a/sysvipc/msgget.c +++ b/sysvipc/msgget.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/msgrcv.c b/sysvipc/msgrcv.c index 2055e3ce10..f1ad93a39c 100644 --- a/sysvipc/msgrcv.c +++ b/sysvipc/msgrcv.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/msgsnd.c b/sysvipc/msgsnd.c index d52d3cbb04..7af777221a 100644 --- a/sysvipc/msgsnd.c +++ b/sysvipc/msgsnd.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995. diff --git a/sysvipc/semctl.c b/sysvipc/semctl.c index 60409f5891..90fb8bf0a2 100644 --- a/sysvipc/semctl.c +++ b/sysvipc/semctl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/semget.c b/sysvipc/semget.c index f7a6e09580..6b1c991e59 100644 --- a/sysvipc/semget.c +++ b/sysvipc/semget.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/semop.c b/sysvipc/semop.c index 923a44f085..3c6e23de61 100644 --- a/sysvipc/semop.c +++ b/sysvipc/semop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995. diff --git a/sysvipc/semtimedop.c b/sysvipc/semtimedop.c index 61e011223c..4163c78791 100644 --- a/sysvipc/semtimedop.c +++ b/sysvipc/semtimedop.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003-2016 Free Software Foundation, Inc. +/* Copyright (C) 2003-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2003. diff --git a/sysvipc/shmat.c b/sysvipc/shmat.c index d9fc4db566..c9d9ca784c 100644 --- a/sysvipc/shmat.c +++ b/sysvipc/shmat.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/shmctl.c b/sysvipc/shmctl.c index 79e9cbe828..55381b8405 100644 --- a/sysvipc/shmctl.c +++ b/sysvipc/shmctl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/shmdt.c b/sysvipc/shmdt.c index c407be5072..e95b2502bd 100644 --- a/sysvipc/shmdt.c +++ b/sysvipc/shmdt.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995. diff --git a/sysvipc/shmget.c b/sysvipc/shmget.c index 27cdd29d4f..f3e9d68ec1 100644 --- a/sysvipc/shmget.c +++ b/sysvipc/shmget.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, August 1995. diff --git a/sysvipc/sys/ipc.h b/sysvipc/sys/ipc.h index 70bd7a6968..b8c6836e37 100644 --- a/sysvipc/sys/ipc.h +++ b/sysvipc/sys/ipc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -20,10 +20,6 @@ #include <features.h> -#if !defined __USE_MISC && !defined __USE_XOPEN && __GNUC__ >= 2 -# warning "Files using this header must be compiled with _GNU_SOURCE or _XOPEN_SOURCE" -#endif - /* Get system dependent definition of `struct ipc_perm' and more. */ #include <bits/ipctypes.h> #include <bits/ipc.h> diff --git a/sysvipc/sys/msg.h b/sysvipc/sys/msg.h index 4dc559f49a..1635839617 100644 --- a/sysvipc/sys/msg.h +++ b/sysvipc/sys/msg.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -30,8 +30,7 @@ #include <bits/msq.h> /* Define types required by the standard. */ -#define __need_time_t -#include <time.h> +#include <bits/types/time_t.h> #ifndef __pid_t_defined typedef __pid_t pid_t; diff --git a/sysvipc/sys/sem.h b/sysvipc/sys/sem.h index 1b32092922..200765bcba 100644 --- a/sysvipc/sys/sem.h +++ b/sysvipc/sys/sem.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -30,8 +30,7 @@ #include <bits/sem.h> #ifdef __USE_GNU -# define __need_timespec -# include <time.h> +# include <bits/types/struct_timespec.h> #endif /* The following System V style IPC functions implement a semaphore diff --git a/sysvipc/sys/shm.h b/sysvipc/sys/shm.h index df263dcba6..8936af7594 100644 --- a/sysvipc/sys/shm.h +++ b/sysvipc/sys/shm.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1995-2016 Free Software Foundation, Inc. +/* Copyright (C) 1995-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -30,8 +30,7 @@ #include <bits/shm.h> /* Define types required by the standard. */ -#define __need_time_t -#include <time.h> +#include <bits/types/time_t.h> #ifdef __USE_XOPEN # ifndef __pid_t_defined diff --git a/sysvipc/test-sysvmsg.c b/sysvipc/test-sysvmsg.c new file mode 100644 index 0000000000..1e0471807c --- /dev/null +++ b/sysvipc/test-sysvmsg.c @@ -0,0 +1,128 @@ +/* Basic tests for SYSV message queue functions. + Copyright (C) 2016-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> + +#include <support/support.h> +#include <support/check.h> +#include <support/temp_file.h> + +#define TEXTSIZE 32 +struct msgbuf_t +{ +#ifdef _GNU_SOURCE + __syscall_slong_t type; +#else + long type; +#endif + char buf[TEXTSIZE]; +}; + +#define MSGTYPE 0x01020304 +#define MSGDATA "0123456789" + +/* These are for the temporary file we generate. */ +static char *name; +static int msqid; + +static void +remove_msq (void) +{ + /* Enforce message queue removal in case of early test failure. + Ignore error since the msgq may already have being removed. */ + msgctl (msqid, IPC_RMID, NULL); +} + +static void +do_prepare (int argc, char *argv[]) +{ + int fd = create_temp_file ("tst-sysvmsg.", &name); + if (fd == -1) + FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno); +} + +#define PREPARE do_prepare + +/* It is not an extensive test, but rather a functional one aimed to check + correct parameter passing on kernel. */ + +#define MSGQ_MODE 0644 + +static int +do_test (void) +{ + atexit (remove_msq); + + key_t key = ftok (name, 'G'); + if (key == -1) + FAIL_EXIT1 ("ftok failed"); + + msqid = msgget (key, MSGQ_MODE | IPC_CREAT); + if (msqid == -1) + { + if (errno == ENOSYS) + FAIL_UNSUPPORTED ("msgget not supported"); + FAIL_EXIT1 ("msgget failed (errno=%d)", errno); + } + + /* Get message queue kernel information and do some sanity checks. */ + struct msqid_ds msginfo; + if (msgctl (msqid, IPC_STAT, &msginfo) == -1) + FAIL_EXIT1 ("msgctl with IPC_STAT failed (errno=%d)", errno); + + if (msginfo.msg_perm.__key != key) + FAIL_EXIT1 ("msgid_ds::msg_perm::key (%d) != %d", + (int) msginfo.msg_perm.__key, (int) key); + if (msginfo.msg_perm.mode != MSGQ_MODE) + FAIL_EXIT1 ("msgid_ds::msg_perm::mode (%o) != %o", + msginfo.msg_perm.mode, MSGQ_MODE); + if (msginfo.msg_qnum != 0) + FAIL_EXIT1 ("msgid_ds::msg_qnum (%lu) != 0", + (long unsigned) msginfo.msg_qnum); + + /* Check if last argument (IPC_NOWAIT) is correctly handled. */ + struct msgbuf_t msg2rcv = { 0 }; + if (msgrcv (msqid, &msg2rcv, sizeof (msg2rcv.buf), MSGTYPE, + IPC_NOWAIT) == -1 + && errno != ENOMSG) + FAIL_EXIT1 ("msgrcv failed (errno=%d)", errno); + + struct msgbuf_t msg2snd = { MSGTYPE, MSGDATA }; + if (msgsnd (msqid, &msg2snd, sizeof (msg2snd.buf), 0) == -1) + FAIL_EXIT1 ("msgsnd failed (errno=%d)", errno); + + if (msgrcv (msqid, &msg2rcv, sizeof (msg2rcv.buf), MSGTYPE, 0) == -1) + FAIL_EXIT1 ("msgrcv failed (errno=%d)", errno); + + int ret = 0; + if (strncmp (msg2snd.buf, msg2rcv.buf, TEXTSIZE) != 0) + ret = 1; + + if (msgctl (msqid, IPC_RMID, NULL) == -1) + FAIL_EXIT1 ("msgctl failed"); + + return ret; +} + +#include <support/test-driver.c> diff --git a/sysvipc/test-sysvsem.c b/sysvipc/test-sysvsem.c new file mode 100644 index 0000000000..a8e9bff000 --- /dev/null +++ b/sysvipc/test-sysvsem.c @@ -0,0 +1,123 @@ +/* Basic tests for SYSV semaphore functions. + Copyright (C) 2016-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/sem.h> + +#include <support/support.h> +#include <support/check.h> +#include <support/temp_file.h> + +/* These are for the temporary file we generate. */ +static char *name; +static int semid; + +static void +remove_sem (void) +{ + /* Enforce message queue removal in case of early test failure. + Ignore error since the sem may already have being removed. */ + semctl (semid, 0, IPC_RMID, 0); +} + +static void +do_prepare (int argc, char *argv[]) +{ + int fd = create_temp_file ("tst-sysvsem.", &name); + if (fd == -1) + FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno); +} + +#define PREPARE do_prepare + +/* It is not an extensive test, but rather a functional one aimed to check + correct parameter passing on kernel. */ + +#define SEM_MODE 0644 + +union semun +{ + int val; + struct semid_ds *buf; + unsigned short *array; +}; + +static int +do_test (void) +{ + atexit (remove_sem); + + key_t key = ftok (name, 'G'); + if (key == -1) + FAIL_EXIT1 ("ftok failed"); + + semid = semget(key, 1, IPC_CREAT | IPC_EXCL | SEM_MODE); + if (semid == -1) + { + if (errno == ENOSYS) + FAIL_UNSUPPORTED ("msgget not supported"); + FAIL_EXIT1 ("semget failed (errno=%d)", errno); + } + + /* Get semaphore kernel information and do some sanity checks. */ + struct semid_ds seminfo; + if (semctl (semid, 0, IPC_STAT, (union semun) { .buf = &seminfo }) == -1) + FAIL_EXIT1 ("semctl with IPC_STAT failed (errno=%d)", errno); + + if (seminfo.sem_perm.__key != key) + FAIL_EXIT1 ("semid_ds::sem_perm::key (%d) != %d", + (int) seminfo.sem_perm.__key, (int) key); + if (seminfo.sem_perm.mode != SEM_MODE) + FAIL_EXIT1 ("semid_ds::sem_perm::mode (%o) != %o", + seminfo.sem_perm.mode, SEM_MODE); + if (seminfo.sem_nsems != 1) + FAIL_EXIT1 ("semid_ds::sem_nsems (%lu) != 1", + (long unsigned) seminfo.sem_nsems); + + /* Some lock/unlock basic tests. */ + struct sembuf sb1 = { 0, 1, 0 }; + if (semop (semid, &sb1, 1) == -1) + FAIL_EXIT1 ("semop failed (errno=%i)", errno); + + struct sembuf sb2 = { 0, -1, 0 }; + if (semop (semid, &sb2, 1) == -1) + FAIL_EXIT1 ("semop failed (errno=%i)", errno); + +#ifdef _GNU_SOURCE + /* Set a time for half a second. The semaphore operation should timeout + with EAGAIN. */ + struct timespec ts = { 0 /* sec */, 500000000 /* nsec */ }; + if (semtimedop (semid, &sb2, 1, &ts) != -1 + || (errno != EAGAIN && errno != ENOSYS)) + FAIL_EXIT1 ("semtimedop succeed or returned errno != {EAGAIN,ENOSYS} " + "(errno=%i)", errno); +#endif + + /* Finally free up the semnaphore resource. */ + if (semctl (semid, 0, IPC_RMID, 0) == -1) + FAIL_EXIT1 ("semctl failed (errno=%d)", errno); + + return 0; +} + +#include <support/test-driver.c> diff --git a/sysvipc/test-sysvshm.c b/sysvipc/test-sysvshm.c new file mode 100644 index 0000000000..a7c2e0bd40 --- /dev/null +++ b/sysvipc/test-sysvshm.c @@ -0,0 +1,131 @@ +/* Basic tests for SYSV shared memory functions. + Copyright (C) 2016-2018 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> + +#include <support/support.h> +#include <support/check.h> +#include <support/temp_file.h> + +/* These are for the temporary file we generate. */ +static char *name; +static int shmid; + +static void +remove_shm (void) +{ + /* Enforce message queue removal in case of early test failure. + Ignore error since the shm may already have being removed. */ + shmctl (shmid, IPC_RMID, 0); +} + +static void +do_prepare (int argc, char *argv[]) +{ + int fd = create_temp_file ("tst-sysvshm.", &name); + if (fd == -1) + FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno); +} + +#define PREPARE do_prepare + +/* It is not an extensive test, but rather a functional one aimed to check + correct parameter passing on kernel. */ + +#define CHECK_EQ(v, k) \ + if ((v) != (k)) \ + FAIL_EXIT1("%d != %d", v, k) + +#define SHM_MODE 0666 + +static int +do_test (void) +{ + atexit (remove_shm); + + key_t key = ftok (name, 'G'); + if (key == -1) + FAIL_EXIT1 ("ftok failed"); + + long int pgsz = sysconf (_SC_PAGESIZE); + if (pgsz == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE) failed (errno = %d)", errno); + + shmid = shmget(key, pgsz, IPC_CREAT | IPC_EXCL | SHM_MODE); + if (shmid == -1) + { + if (errno == ENOSYS) + FAIL_UNSUPPORTED ("shmget not supported"); + FAIL_EXIT1 ("shmget failed (errno=%d)", errno); + } + + /* Get shared memory kernel information and do some sanity checks. */ + struct shmid_ds shminfo; + if (shmctl (shmid, IPC_STAT, &shminfo) == -1) + FAIL_EXIT1 ("shmctl with IPC_STAT failed (errno=%d)", errno); + + if (shminfo.shm_perm.__key != key) + FAIL_EXIT1 ("shmid_ds::shm_perm::key (%d) != %d", + (int) shminfo.shm_perm.__key, (int) key); + if (shminfo.shm_perm.mode != SHM_MODE) + FAIL_EXIT1 ("shmid_ds::shm_perm::mode (%o) != %o", + shminfo.shm_perm.mode, SHM_MODE); + if (shminfo.shm_segsz != pgsz) + FAIL_EXIT1 ("shmid_ds::shm_segsz (%lu) != %lu", + (long unsigned) shminfo.shm_segsz, pgsz); + + /* Attach on shared memory and realize some operations. */ + int *shmem = shmat (shmid, NULL, 0); + if (shmem == (void*) -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + shmem[0] = 0x55555555; + shmem[32] = 0x44444444; + shmem[64] = 0x33333333; + shmem[128] = 0x22222222; + + if (shmdt (shmem) == -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + shmem = shmat (shmid, NULL, SHM_RDONLY); + if (shmem == (void*) -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + CHECK_EQ (shmem[0], 0x55555555); + CHECK_EQ (shmem[32], 0x44444444); + CHECK_EQ (shmem[64], 0x33333333); + CHECK_EQ (shmem[128], 0x22222222); + + if (shmdt (shmem) == -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + /* Finally free up the semnaphore resource. */ + if (shmctl (shmid, IPC_RMID, 0) == -1) + FAIL_EXIT1 ("semctl failed (errno=%d)", errno); + + return 0; +} + +#include <support/test-driver.c> |