summaryrefslogtreecommitdiffstats
path: root/tools/regression
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2009-06-06 19:07:15 +0000
committerdes <des@FreeBSD.org>2009-06-06 19:07:15 +0000
commit7758932884199b8e72ce2ee07f29a0a6614451ce (patch)
treee81838ea7ec1b60f0daa6ad9ec944e0b5fda485a /tools/regression
parent94e760567d654ada216cd794352e9deca31dff08 (diff)
downloadFreeBSD-src-7758932884199b8e72ce2ee07f29a0a6614451ce.zip
FreeBSD-src-7758932884199b8e72ce2ee07f29a0a6614451ce.tar.gz
Check that flopen() can lock against self and that children inherit the lock.
Diffstat (limited to 'tools/regression')
-rw-r--r--tools/regression/lib/libutil/test-flopen.c47
1 files changed, 41 insertions, 6 deletions
diff --git a/tools/regression/lib/libutil/test-flopen.c b/tools/regression/lib/libutil/test-flopen.c
index c8191d0..30b1b89 100644
--- a/tools/regression/lib/libutil/test-flopen.c
+++ b/tools/regression/lib/libutil/test-flopen.c
@@ -30,6 +30,7 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/signal.h>
#include <sys/types.h>
#include <sys/fcntl.h>
@@ -89,14 +90,13 @@ test_flopen_open(void)
return (result);
}
-#if FLOPEN_CAN_LOCK_AGAINST_SELF
/*
* Test that flopen() can lock against itself
*/
const char *
test_flopen_lock_self(void)
{
- const char *fn = "test_flopen_lock";
+ const char *fn = "test_flopen_lock_self";
const char *result = NULL;
int fd1, fd2;
@@ -115,7 +115,6 @@ test_flopen_lock_self(void)
unlink(fn);
return (result);
}
-#endif
/*
* Test that flopen() can lock against other processes
@@ -123,7 +122,7 @@ test_flopen_lock_self(void)
const char *
test_flopen_lock_other(void)
{
- const char *fn = "test_flopen_lock";
+ const char *fn = "test_flopen_lock_other";
const char *result = NULL;
volatile int fd1, fd2;
@@ -148,16 +147,52 @@ test_flopen_lock_other(void)
return (result);
}
+/*
+ * Test that child processes inherit the lock
+ */
+const char *
+test_flopen_lock_child(void)
+{
+ const char *fn = "test_flopen_lock_child";
+ const char *result = NULL;
+ pid_t pid;
+ volatile int fd1, fd2;
+
+ unlink(fn);
+ fd1 = flopen(fn, O_RDWR|O_CREAT, 0640);
+ if (fd1 < 0) {
+ result = strerror(errno);
+ } else {
+ if ((pid = fork()) == 0) {
+ select(0, 0, 0, 0, 0);
+ _exit(0);
+ }
+ close(fd1);
+ fd2 = -42;
+ if (vfork() == 0) {
+ fd2 = flopen(fn, O_RDWR|O_NONBLOCK);
+ close(fd2);
+ _exit(0);
+ }
+ if (fd2 == -42)
+ result = "vfork() doesn't work as expected";
+ if (fd2 >= 0)
+ result = "second open succeeded";
+ kill(pid, SIGINT);
+ }
+ unlink(fn);
+ return (result);
+}
+
static struct test {
const char *name;
const char *(*func)(void);
} t[] = {
{ "flopen_create", test_flopen_create },
{ "flopen_open", test_flopen_open },
-#if FLOPEN_CAN_LOCK_AGAINST_SELF
{ "flopen_lock_self", test_flopen_lock_self },
-#endif
{ "flopen_lock_other", test_flopen_lock_other },
+ { "flopen_lock_child", test_flopen_lock_child },
};
int
OpenPOWER on IntegriCloud