diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-29 21:55:01 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2002-12-29 21:55:01 +0000 |
commit | d3267a351c3cd5bff4929d562d14419d1bf94fad (patch) | |
tree | d983461fc5a00db6eeee4d146b276005ab9d91b1 | |
parent | b57ae452b4f7a90dee3b5e0e2fe313ad76a0b91f (diff) |
o pass a random value as the second arg to ftok()
o call semget() with IPC_EXCL
This fixes a problem whereby multiple concurrent copies of the
regress test could use the same key and stomp over themselves,
leading one to falsely believe there is a kernel bug.
-rw-r--r-- | regress/sys/kern/sysvsem/semtest.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/regress/sys/kern/sysvsem/semtest.c b/regress/sys/kern/sysvsem/semtest.c index f65a593a84d..fddb0099e5a 100644 --- a/regress/sys/kern/sysvsem/semtest.c +++ b/regress/sys/kern/sysvsem/semtest.c @@ -48,6 +48,7 @@ #include <err.h> #include <errno.h> +#include <limits.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -128,7 +129,7 @@ main(argc, argv) if (sigaction(SIGCHLD, &sa, NULL) == -1) err(1, "sigaction SIGCHLD"); - semkey = ftok(keyname, 4160); + semkey = ftok(keyname, arc4random() & INT_MAX); /* * Initialize child_pid to ourselves to that the cleanup function @@ -143,7 +144,8 @@ main(argc, argv) if (atexit(cleanup) == -1) err(1, "atexit"); - if ((sender_semid = semget(semkey, 1, IPC_CREAT | 0640)) == -1) + sender_semid = semget(semkey, 1, IPC_CREAT | IPC_EXCL | 0640); + if (sender_semid == -1) err(1, "semget"); |