From: Jan Stancek <jstancek@redhat.com>
To: ltp-list@lists.sourceforge.net
Subject: [LTP] [PATCH] kill05: fix race condition in do_master_child
Date: Wed, 27 Apr 2011 08:31:48 +0200 [thread overview]
Message-ID: <4DB7B854.8010304@redhat.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 333 bytes --]
There is a race condition when starting child. Master child can go
forward before child changes its reuid.
Fix this by waiting until child is ready.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
testcases/kernel/syscalls/kill/kill05.c | 25 +++++++++++++++++--------
1 files changed, 17 insertions(+), 8 deletions(-)
[-- Attachment #2: 0001-kill05-fix-race-condition-in-do_master_child.patch --]
[-- Type: text/x-patch, Size: 1146 bytes --]
diff --git a/testcases/kernel/syscalls/kill/kill05.c b/testcases/kernel/syscalls/kill/kill05.c
index e44b690..fe34788 100644
--- a/testcases/kernel/syscalls/kill/kill05.c
+++ b/testcases/kernel/syscalls/kill/kill05.c
@@ -130,6 +130,16 @@ int main(int ac, char **av)
tst_exit();
}
+void wait_for_flag(int value)
+{
+ while (1) {
+ if (*flag == value)
+ break;
+ else
+ sleep(1);
+ }
+}
+
/*
* do_master_child()
*/
@@ -160,6 +170,7 @@ void do_master_child(char **av)
perror("setreuid failed (in child)");
exit(1);
}
+ *flag = 1;
#ifdef UCLINUX
if (self_exec(av[0], "") < 0) {
perror("self_exec failed");
@@ -175,10 +186,13 @@ void do_master_child(char **av)
exit(1);
}
+ /* wait until child sets its euid */
+ wait_for_flag(1);
+
TEST(kill(pid1, TEST_SIG));
/* signal the child that we're done */
- *flag = 1;
+ *flag = 2;
if (waitpid(pid1, &status, 0) == -1) {
perror("waitpid failed");
@@ -204,13 +218,8 @@ void do_master_child(char **av)
void do_child()
{
-
- while (1) {
- if (*flag == 1)
- exit(0);
- else
- sleep(1);
- }
+ wait_for_flag(2);
+ exit(0);
}
void setup(void)
[-- Attachment #3: Type: text/plain, Size: 355 bytes --]
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
[-- Attachment #4: Type: text/plain, Size: 155 bytes --]
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
next reply other threads:[~2011-04-27 6:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-27 6:31 Jan Stancek [this message]
2011-05-04 16:58 ` [LTP] [PATCH] kill05: fix race condition in do_master_child Garrett Cooper
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=4DB7B854.8010304@redhat.com \
--to=jstancek@redhat.com \
--cc=ltp-list@lists.sourceforge.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.