diff options
author | jilles <jilles@FreeBSD.org> | 2016-02-07 22:12:39 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2016-02-07 22:12:39 +0000 |
commit | b2791f185cba92ad0c81fd19ad5ab4d88fd2681c (patch) | |
tree | d1ff67b50654cbedfcbd100e9ccea7def00ef75f /tools/regression | |
parent | 6e7e5621d9b1fb2151c468d82074db9c0e91b6ee (diff) | |
download | FreeBSD-src-b2791f185cba92ad0c81fd19ad5ab4d88fd2681c.zip FreeBSD-src-b2791f185cba92ad0c81fd19ad5ab4d88fd2681c.tar.gz |
semget(): Check for [EEXIST] error first.
Although POSIX literally permits failing with [EINVAL] if IPC_CREAT and
IPC_EXCL were both passed, the semaphore set already exists and has fewer
semaphores than nsems, this does not allow an application to retry safely:
if the [EINVAL] is actually because of the semmsl limit, an infinite loop
would result.
PR: 206927
Diffstat (limited to 'tools/regression')
-rw-r--r-- | tools/regression/sysvsem/semtest.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/regression/sysvsem/semtest.c b/tools/regression/sysvsem/semtest.c index 8a997d0..39c4164 100644 --- a/tools/regression/sysvsem/semtest.c +++ b/tools/regression/sysvsem/semtest.c @@ -152,6 +152,15 @@ main(int argc, char *argv[]) print_semid_ds(&s_ds, 0600); + errno = 0; + if (semget(semkey, 1, IPC_CREAT | IPC_EXCL | 0600) != -1 || + errno != EEXIST) + err(1, "semget IPC_EXCL 1 did not fail with [EEXIST]"); + errno = 0; + if (semget(semkey, 2, IPC_CREAT | IPC_EXCL | 0600) != -1 || + errno != EEXIST) + err(1, "semget IPC_EXCL 2 did not fail with [EEXIST]"); + for (child_count = 0; child_count < 5; child_count++) { switch ((child_pid = fork())) { case -1: |