From patchwork Fri Jul 1 14:55:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 71312 Delivered-To: patches@linaro.org Received: by 10.140.28.4 with SMTP id 4csp344550qgy; Fri, 1 Jul 2016 07:55:27 -0700 (PDT) X-Received: by 10.194.78.147 with SMTP id b19mr4080519wjx.31.1467384927013; Fri, 01 Jul 2016 07:55:27 -0700 (PDT) Return-Path: Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by mx.google.com with ESMTPS id uk8si3929052wjb.66.2016.07.01.07.55.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Jul 2016 07:55:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) client-ip=2001:8b0:1d0::2; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::2 as permitted sender) smtp.mailfrom=pm215@archaic.org.uk; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from pm215 by orth.archaic.org.uk with local (Exim 4.84_2) (envelope-from ) id 1bIzqo-0007lR-9l; Fri, 01 Jul 2016 15:55:26 +0100 From: Peter Maydell To: ltp@lists.linux.it Cc: patches@linaro.org Subject: [PATCH] syscalls/mmap16: close open files in cleanup path Date: Fri, 1 Jul 2016 15:55:25 +0100 Message-Id: <1467384925-24792-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.9.1 If the mmap16 test fails while the do_test() function still has its filedescriptor open, the cleanup function's attempt to unmount will fail with EBUSY, resulting in a lot of noise in the test log, a leaked mounted filesystem and unnecessary test failures later in the run. Make the do_test() file descriptor global so we can close it in the cleanup function if necessary. Signed-off-by: Peter Maydell --- I noticed this because QEMU linux-user mode happens to fail this test at the moment, so it exercises the broken failure path. testcases/kernel/syscalls/mmap/mmap16.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) -- 1.9.1 diff --git a/testcases/kernel/syscalls/mmap/mmap16.c b/testcases/kernel/syscalls/mmap/mmap16.c index ca1f47d..5d943a0 100644 --- a/testcases/kernel/syscalls/mmap/mmap16.c +++ b/testcases/kernel/syscalls/mmap/mmap16.c @@ -48,6 +48,7 @@ static const char *device; static const char *fs_type = "ext4"; static int mount_flag; static int chdir_flag; +static int parentfd; static int page_size; static int bug_reproduced; @@ -91,7 +92,7 @@ int main(int ac, char **av) static void do_test(void) { - int fd, ret, status; + int ret, status; pid_t child; char buf[FS_BLOCKSIZE]; @@ -105,12 +106,12 @@ static void do_test(void) case 0: do_child(); default: - fd = SAFE_OPEN(cleanup, "testfilep", O_RDWR); + parentfd = SAFE_OPEN(cleanup, "testfilep", O_RDWR); memset(buf, 'a', FS_BLOCKSIZE); TST_SAFE_CHECKPOINT_WAIT(cleanup, 0); while (1) { - ret = write(fd, buf, FS_BLOCKSIZE); + ret = write(parentfd, buf, FS_BLOCKSIZE); if (ret < 0) { if (errno == ENOSPC) { break; @@ -120,7 +121,7 @@ static void do_test(void) } } } - SAFE_CLOSE(cleanup, fd); + SAFE_CLOSE(cleanup, parentfd); TST_SAFE_CHECKPOINT_WAKE(cleanup, 0); } @@ -231,6 +232,8 @@ static void do_child(void) static void cleanup(void) { + if (parentfd > 0) + close(parentfd); if (chdir_flag && chdir("..")) tst_resm(TWARN | TERRNO, "chdir('..') failed"); if (mount_flag && tst_umount(MNTPOINT) < 0)