From owner-svn-src-all@FreeBSD.ORG Sat Jun 6 19:07:15 2009 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E921A106566C; Sat, 6 Jun 2009 19:07:15 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BCBFC8FC12; Sat, 6 Jun 2009 19:07:15 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n56J7Fqf069362; Sat, 6 Jun 2009 19:07:15 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n56J7FI6069361; Sat, 6 Jun 2009 19:07:15 GMT (envelope-from des@svn.freebsd.org) Message-Id: <200906061907.n56J7FI6069361@svn.freebsd.org> From: Dag-Erling Smorgrav Date: Sat, 6 Jun 2009 19:07:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r193592 - head/tools/regression/lib/libutil X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 06 Jun 2009 19:07:16 -0000 Author: des Date: Sat Jun 6 19:07:15 2009 New Revision: 193592 URL: http://svn.freebsd.org/changeset/base/193592 Log: Check that flopen() can lock against self and that children inherit the lock. Modified: head/tools/regression/lib/libutil/test-flopen.c Modified: head/tools/regression/lib/libutil/test-flopen.c ============================================================================== --- head/tools/regression/lib/libutil/test-flopen.c Sat Jun 6 18:47:03 2009 (r193591) +++ head/tools/regression/lib/libutil/test-flopen.c Sat Jun 6 19:07:15 2009 (r193592) @@ -30,6 +30,7 @@ #include __FBSDID("$FreeBSD$"); +#include #include #include @@ -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