mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@monom.org>
To: Jeff Layton <jlayton@redhat.com>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	Daniel Wagner <daniel.wagner@bmw-carit.de>
Subject: [PATCH v0 3/3] posix03: Do not kill everything in the process group
Date: Thu, 22 Sep 2016 10:46:07 +0200	[thread overview]
Message-ID: <1474533967-4404-4-git-send-email-wagi@monom.org> (raw)
In-Reply-To: <1474533967-4404-1-git-send-email-wagi@monom.org>

From: Daniel Wagner <daniel.wagner@bmw-carit.de>

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 <david@fromorbit.com>
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
---
 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;
 }
-- 
2.5.5

      parent reply	other threads:[~2016-09-22  8:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-22  8:46 [PATCH v0 0/3] [RESEND] lockperf: a few small improvments Daniel Wagner
2016-09-22  8:46 ` [PATCH v0 1/3] Synchronize all clients on start up Daniel Wagner
2016-09-22  8:46 ` [PATCH v0 2/3] posix03, posix04: Use '-l' instead of '-i' as option argument name Daniel Wagner
2016-09-22  8:46 ` Daniel Wagner [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474533967-4404-4-git-send-email-wagi@monom.org \
    --to=wagi@monom.org \
    --cc=daniel.wagner@bmw-carit.de \
    --cc=jlayton@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®