From patchwork Thu Sep 22 08:46:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Wagner X-Patchwork-Id: 9344763 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 19365601C2 for ; Thu, 22 Sep 2016 08:47:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BA102A8D9 for ; Thu, 22 Sep 2016 08:47:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3DD62A8DC; Thu, 22 Sep 2016 08:47:35 +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=-6.9 required=2.0 tests=BAYES_00,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 1729E2A8D9 for ; Thu, 22 Sep 2016 08:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933488AbcIVIrS (ORCPT ); Thu, 22 Sep 2016 04:47:18 -0400 Received: from atlantic540.startdedicated.de ([188.138.9.77]:43340 "EHLO atlantic540.startdedicated.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933377AbcIVIqy (ORCPT ); Thu, 22 Sep 2016 04:46:54 -0400 Received: from atlantic540.startdedicated.de (localhost [127.0.0.1]) by filter.mynetwork.local (Postfix) with ESMTP id AAE98500138; Thu, 22 Sep 2016 10:46:51 +0200 (CEST) Received: from localhost (unknown [212.118.206.70]) by atlantic540.startdedicated.de (Postfix) with ESMTPSA id 56F325001E1; Thu, 22 Sep 2016 10:46:51 +0200 (CEST) From: Daniel Wagner To: Jeff Layton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Wagner Subject: [PATCH v0 3/3] posix03: Do not kill everything in the process group Date: Thu, 22 Sep 2016 10:46:07 +0200 Message-Id: <1474533967-4404-4-git-send-email-wagi@monom.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1474533967-4404-1-git-send-email-wagi@monom.org> References: <1474533967-4404-1-git-send-email-wagi@monom.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Daniel Wagner kill(0, SIGINT) sends to all in the process group the signal including the parent shell. Instead remember the PIDs of all children and just send the signal to these processes. Reported-by: Dave Chinner Signed-off-by: Daniel Wagner --- posix03.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/posix03.c b/posix03.c index a36caa5..4ee130b 100644 --- a/posix03.c +++ b/posix03.c @@ -71,13 +71,18 @@ static int fcntl_unlock(int fd, off_t off, off_t len) return fcntl(fd, F_SETLKW, &fl); } +/* The PIDs of all children */ +static pid_t *cpids; + static void kill_children() { siginfo_t infop; + int i; signal(SIGINT, SIG_IGN); - kill(0, SIGINT); + for (i = 0; cpids[i]; i++) + kill(cpids[i], SIGINT); while (waitid(P_ALL, 0, &infop, WEXITED) != -1); } @@ -161,14 +166,21 @@ int main(int argc, char *argv[]) signal(SIGINT, sighandler); + cpids = malloc((num + 1) * sizeof(pid_t)); + if (!cpids) + err(1, "malloc"); + cpids[num] = 0; + for (i = 0; i < num; i++) { - switch (fork()) { + pid_t pid = fork(); + switch (pid) { case 0: signal(SIGINT, SIG_DFL); return do_child(lockfd, i, to_lockers[0], from_lockers[1]); case -1: err(1, "fork failed"); } + cpids[i] = pid; } close(to_lockers[0]); @@ -208,5 +220,6 @@ int main(int argc, char *argv[]) printf("%ld.%09ld\n", total.tv_sec, total.tv_nsec); kill_children(); + free(cpids); return 0; }