From patchwork Mon May 21 05:42:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 10413987 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BEE106032B for ; Mon, 21 May 2018 05:53:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AAC2C20163 for ; Mon, 21 May 2018 05:53:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F2A72876C; Mon, 21 May 2018 05:53:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376FA20163 for ; Mon, 21 May 2018 05:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751065AbeEUFxf (ORCPT ); Mon, 21 May 2018 01:53:35 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:48663 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750962AbeEUFxf (ORCPT ); Mon, 21 May 2018 01:53:35 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="40150619" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 May 2018 13:53:33 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 4D4304D0EFE1; Mon, 21 May 2018 13:53:33 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.185) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Mon, 21 May 2018 13:53:34 +0800 From: Xiao Yang To: CC: , , , Xiao Yang Subject: [PATCH] generic/484: Need another process to check record locks Date: Mon, 21 May 2018 13:42:00 +0800 Message-ID: <1526881320-10983-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.185] X-yoursite-MailScanner-ID: 4D4304D0EFE1.A918C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 1) According to fcntl(2) manpage, A single process always gets F_UNLCK in the l_type field when using fcntl(F_GETLK) to acquire the existing lock set by itself because it could convert the existing lock to a new lock unconditionally. So we need another process to check if the lock exists. 2) Remove redundant exit(0). Signed-off-by: Xiao Yang --- src/t_locks_execve.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/t_locks_execve.c b/src/t_locks_execve.c index 9ad2dc3..d99d7de 100644 --- a/src/t_locks_execve.c +++ b/src/t_locks_execve.c @@ -8,6 +8,7 @@ #include #include #include +#include #include static void err_exit(char *op, int errn) @@ -32,12 +33,24 @@ struct flock fl = { static void checklock(int fd) { - if (fcntl(fd, F_GETLK, &fl) < 0) - err_exit("getlk", errno); - if (fl.l_type == F_UNLCK) { - printf("record lock is not preserved across execve(2)\n"); - exit(1); + pid_t pid; + + pid = fork(); + if (pid < 0) + err_exit("fork", errno); + + if (!pid) { + if (fcntl(fd, F_GETLK, &fl) < 0) + err_exit("getlk", errno); + if (fl.l_type == F_UNLCK) { + printf("record lock is not preserved across execve(2)\n"); + exit(1); + } + exit(0); } + + waitpid(pid, NULL, 0); + exit(0); } @@ -52,7 +65,6 @@ int main(int argc, char **argv) if (argc == 3) { fd = atoi(argv[2]); checklock(fd); - exit(0); } fd = open(argv[1], O_WRONLY|O_CREAT, 0755);