From patchwork Wed Apr 11 06:44:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 10334887 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 29CEF60134 for ; Wed, 11 Apr 2018 06:44:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A02E1FF62 for ; Wed, 11 Apr 2018 06:44:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0FD0237F1; Wed, 11 Apr 2018 06:44:34 +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 6E2DC1FF62 for ; Wed, 11 Apr 2018 06:44:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752068AbeDKGoW (ORCPT ); Wed, 11 Apr 2018 02:44:22 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:39775 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751872AbeDKGoW (ORCPT ); Wed, 11 Apr 2018 02:44:22 -0400 X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38770998" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 Apr 2018 14:44:20 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 033EB4D0EFC7 for ; Wed, 11 Apr 2018 14:44:16 +0800 (CST) Received: from localhost.localdomain (10.167.226.132) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Wed, 11 Apr 2018 14:44:14 +0800 From: Gu Jinxiang To: Subject: [PATCH v2] btrfs-progs: remove meaningless process Date: Wed, 11 Apr 2018 14:44:13 +0800 Message-ID: <1523429053-6834-1-git-send-email-gujx@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.132] X-yoursite-MailScanner-ID: 033EB4D0EFC7.A9C99 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Variable do_wait is synchronized with the variable do_background, when if(do_background) is true, if(!do_wait) is also true, so parent process will goto out immediately. The following wait never be run. And if option -B is chosen, when do_background is 0 and do_wait is 1, there is no need to fork a child process to wait for scrub over. So remove unnecessary process. Since parent process go out immediately, so remove SIGINT process of parent process too. Changelog: v2: remove the SIGINT process of parent process. v1: remove do_wait variable and wait process Signed-off-by: Gu Jinxiang --- cmds-scrub.c | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/cmds-scrub.c b/cmds-scrub.c index efd7db94..c5f908f4 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -312,16 +312,6 @@ static void scrub_sigint_record_progress(int signal) perror("Scrub cancel failed"); } -static int scrub_handle_sigint_parent(void) -{ - struct sigaction sa = { - .sa_handler = SIG_IGN, - .sa_flags = SA_RESTART, - }; - - return sigaction(SIGINT, &sa, NULL); -} - static int scrub_handle_sigint_child(int fd) { struct sigaction sa = { @@ -1109,7 +1099,6 @@ static int scrub_start(int argc, char **argv, int resume) int print_raw = 0; char *path; int do_background = 1; - int do_wait = 0; int do_print = 0; int do_quiet = 0; int do_record = 1; @@ -1147,7 +1136,6 @@ static int scrub_start(int argc, char **argv, int resume) switch (c) { case 'B': do_background = 0; - do_wait = 1; do_print = 1; break; case 'd': @@ -1374,28 +1362,10 @@ static int scrub_start(int argc, char **argv, int resume) } if (pid) { - int stat; - scrub_handle_sigint_parent(); if (!do_quiet) printf("scrub %s on %s, fsid %s (pid=%d)\n", n_start ? "started" : "resumed", path, fsid, pid); - if (!do_wait) { - err = 0; - goto out; - } - ret = wait(&stat); - if (ret != pid) { - error_on(!do_quiet, "wait failed (ret=%d): %m", - ret); - err = 1; - goto out; - } - if (!WIFEXITED(stat) || WEXITSTATUS(stat)) { - error_on(!do_quiet, "scrub process failed"); - err = WIFEXITED(stat) ? WEXITSTATUS(stat) : -1; - goto out; - } err = 0; goto out; }